-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,525 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <cstdlib> | ||
#include <cstring> | ||
#include <deque> | ||
|
||
#include "../consumerstatetable.h" | ||
#include "../dbconnector.h" | ||
#include "../table.h" | ||
#include "consumerstatetable.h" | ||
#include "util.h" | ||
|
||
using namespace swss; | ||
using namespace std; | ||
|
||
SWSSConsumerStateTable SWSSConsumerStateTable_new(SWSSDBConnector db, const char *tableName, | ||
const int32_t *p_popBatchSize, | ||
const int32_t *p_pri) { | ||
int popBatchSize = p_popBatchSize ? numeric_cast<int>(*p_popBatchSize) | ||
: TableConsumable::DEFAULT_POP_BATCH_SIZE; | ||
int pri = p_pri ? numeric_cast<int>(*p_pri) : 0; | ||
SWSSTry(return (SWSSConsumerStateTable) new ConsumerStateTable( | ||
(DBConnector *)db, string(tableName), popBatchSize, pri)); | ||
} | ||
|
||
void SWSSConsumerStateTable_free(SWSSConsumerStateTable tbl) { | ||
SWSSTry(delete (ConsumerStateTable *)tbl); | ||
} | ||
|
||
SWSSKeyOpFieldValuesArray SWSSConsumerStateTable_pops(SWSSConsumerStateTable tbl) { | ||
SWSSTry({ | ||
deque<KeyOpFieldsValuesTuple> vkco; | ||
((ConsumerStateTable *)tbl)->pops(vkco); | ||
return makeKeyOpFieldValuesArray(vkco); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef SWSS_COMMON_C_API_CONSUMERSTATETABLE_H | ||
#define SWSS_COMMON_C_API_CONSUMERSTATETABLE_H | ||
|
||
#include "dbconnector.h" | ||
#include "util.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
typedef struct SWSSConsumerStateTableOpaque *SWSSConsumerStateTable; | ||
|
||
// Pass NULL for popBatchSize and/or pri to use the default values | ||
SWSSConsumerStateTable SWSSConsumerStateTable_new(SWSSDBConnector db, const char *tableName, | ||
const int32_t *popBatchSize, const int32_t *pri); | ||
|
||
void SWSSConsumerStateTable_free(SWSSConsumerStateTable tbl); | ||
|
||
// Result array and all of its members must be freed using free() | ||
SWSSKeyOpFieldValuesArray SWSSConsumerStateTable_pops(SWSSConsumerStateTable tbl); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <cstring> | ||
#include <string> | ||
|
||
#include "../dbconnector.h" | ||
#include "dbconnector.h" | ||
#include "util.h" | ||
|
||
using namespace swss; | ||
using namespace std; | ||
|
||
void SWSSSonicDBConfig_initialize(const char *path) { | ||
SWSSTry(SonicDBConfig::initialize(path)); | ||
} | ||
|
||
void SWSSSonicDBConfig_initializeGlobalConfig(const char *path) { | ||
SWSSTry(SonicDBConfig::initializeGlobalConfig(path)); | ||
} | ||
|
||
SWSSDBConnector SWSSDBConnector_new_tcp(int32_t dbId, const char *hostname, uint16_t port, | ||
uint32_t timeout) { | ||
SWSSTry(return (SWSSDBConnector) new DBConnector(dbId, string(hostname), port, timeout)); | ||
} | ||
|
||
SWSSDBConnector SWSSDBConnector_new_unix(int32_t dbId, const char *sock_path, uint32_t timeout) { | ||
SWSSTry(return (SWSSDBConnector) new DBConnector(dbId, string(sock_path), timeout)); | ||
} | ||
|
||
SWSSDBConnector SWSSDBConnector_new_named(const char *dbName, uint32_t timeout_ms, uint8_t isTcpConn) { | ||
SWSSTry(return (SWSSDBConnector) new DBConnector(string(dbName), timeout_ms, isTcpConn)); | ||
} | ||
|
||
void SWSSDBConnector_free(SWSSDBConnector db) { | ||
delete (DBConnector *)db; | ||
} | ||
|
||
int8_t SWSSDBConnector_del(SWSSDBConnector db, const char *key) { | ||
SWSSTry(return ((DBConnector *)db)->del(string(key)) ? 1 : 0); | ||
} | ||
|
||
void SWSSDBConnector_set(SWSSDBConnector db, const char *key, const char *value) { | ||
SWSSTry(((DBConnector *)db)->set(string(key), string(value))); | ||
} | ||
|
||
char *SWSSDBConnector_get(SWSSDBConnector db, const char *key) { | ||
SWSSTry({ | ||
shared_ptr<string> s = ((DBConnector *)db)->get(string(key)); | ||
return s ? strdup(s->c_str()) : nullptr; | ||
}); | ||
} | ||
|
||
int8_t SWSSDBConnector_exists(SWSSDBConnector db, const char *key) { | ||
SWSSTry(return ((DBConnector *)db)->exists(string(key)) ? 1 : 0); | ||
} | ||
|
||
int8_t SWSSDBConnector_hdel(SWSSDBConnector db, const char *key, const char *field) { | ||
SWSSTry(return ((DBConnector *)db)->hdel(string(key), string(field)) ? 1 : 0); | ||
} | ||
|
||
void SWSSDBConnector_hset(SWSSDBConnector db, const char *key, const char *field, | ||
const char *value) { | ||
SWSSTry(((DBConnector *)db)->hset(string(key), string(field), string(value))); | ||
} | ||
|
||
char *SWSSDBConnector_hget(SWSSDBConnector db, const char *key, const char *field) { | ||
SWSSTry({ | ||
shared_ptr<string> s = ((DBConnector *)db)->hget(string(key), string(field)); | ||
return s ? strdup(s->c_str()) : nullptr; | ||
}); | ||
} | ||
|
||
SWSSFieldValueArray SWSSDBConnector_hgetall(SWSSDBConnector db, const char *key) { | ||
SWSSTry({ | ||
auto map = ((DBConnector *)db)->hgetall(key); | ||
return makeFieldValueArray(map); | ||
}); | ||
} | ||
|
||
int8_t SWSSDBConnector_hexists(SWSSDBConnector db, const char *key, const char *field) { | ||
SWSSTry(return ((DBConnector *)db)->hexists(string(key), string(field)) ? 1 : 0); | ||
} | ||
|
||
int8_t SWSSDBConnector_flushdb(SWSSDBConnector db) { | ||
SWSSTry(return ((DBConnector *)db)->flushdb() ? 1 : 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#ifndef SWSS_COMMON_C_API_DBCONNECTOR_H | ||
#define SWSS_COMMON_C_API_DBCONNECTOR_H | ||
|
||
#include "util.h" | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
void SWSSSonicDBConfig_initialize(const char *path); | ||
|
||
void SWSSSonicDBConfig_initializeGlobalConfig(const char *path); | ||
|
||
typedef struct SWSSDBConnectorOpaque *SWSSDBConnector; | ||
|
||
// Pass 0 to timeout for infinity | ||
SWSSDBConnector SWSSDBConnector_new_tcp(int32_t dbId, const char *hostname, uint16_t port, | ||
uint32_t timeout_ms); | ||
|
||
// Pass 0 to timeout for infinity | ||
SWSSDBConnector SWSSDBConnector_new_unix(int32_t dbId, const char *sock_path, uint32_t timeout_ms); | ||
|
||
// Pass 0 to timeout for infinity | ||
SWSSDBConnector SWSSDBConnector_new_named(const char *dbName, uint32_t timeout_ms, uint8_t isTcpConn); | ||
|
||
void SWSSDBConnector_free(SWSSDBConnector db); | ||
|
||
// Returns 0 when key doesn't exist, 1 when key was deleted | ||
int8_t SWSSDBConnector_del(SWSSDBConnector db, const char *key); | ||
|
||
void SWSSDBConnector_set(SWSSDBConnector db, const char *key, const char *value); | ||
|
||
// Returns NULL if key doesn't exist. | ||
// Result must be freed using free() | ||
char *SWSSDBConnector_get(SWSSDBConnector db, const char *key); | ||
|
||
// Returns 0 for false, 1 for true | ||
int8_t SWSSDBConnector_exists(SWSSDBConnector db, const char *key); | ||
|
||
// Returns 0 when key or field doesn't exist, 1 when field was deleted | ||
int8_t SWSSDBConnector_hdel(SWSSDBConnector db, const char *key, const char *field); | ||
|
||
void SWSSDBConnector_hset(SWSSDBConnector db, const char *key, const char *field, | ||
const char *value); | ||
|
||
// Returns NULL if key or field doesn't exist. | ||
// Result must be freed using free() | ||
char *SWSSDBConnector_hget(SWSSDBConnector db, const char *key, const char *field); | ||
|
||
// Returns an empty map when the key doesn't exist. | ||
// Result array and all of its elements must be freed using free() | ||
SWSSFieldValueArray SWSSDBConnector_hgetall(SWSSDBConnector db, const char *key); | ||
|
||
// Returns 0 when key or field doesn't exist, 1 when field exists | ||
int8_t SWSSDBConnector_hexists(SWSSDBConnector db, const char *key, const char *field); | ||
|
||
// std::vector<std::string> keys(const std::string &key); | ||
|
||
// std::pair<int, std::vector<std::string>> scan(int cursor = 0, const char | ||
// *match = "", uint32_t count = 10); | ||
|
||
// template<typename InputIterator> | ||
// void hmset(const std::string &key, InputIterator start, InputIterator stop); | ||
|
||
// void hmset(const std::unordered_map<std::string, | ||
// std::vector<std::pair<std::string, std::string>>>& multiHash); | ||
|
||
// std::shared_ptr<std::string> get(const std::string &key); | ||
|
||
// std::shared_ptr<std::string> hget(const std::string &key, const std::string | ||
// &field); | ||
|
||
// int64_t incr(const std::string &key); | ||
|
||
// int64_t decr(const std::string &key); | ||
|
||
// int64_t rpush(const std::string &list, const std::string &item); | ||
|
||
// std::shared_ptr<std::string> blpop(const std::string &list, int timeout); | ||
|
||
// void subscribe(const std::string &pattern); | ||
|
||
// void psubscribe(const std::string &pattern); | ||
|
||
// void punsubscribe(const std::string &pattern); | ||
|
||
// int64_t publish(const std::string &channel, const std::string &message); | ||
|
||
// void config_set(const std::string &key, const std::string &value); | ||
|
||
// Returns 1 on success, 0 on failure | ||
int8_t SWSSDBConnector_flushdb(SWSSDBConnector db); | ||
|
||
// std::map<std::string, std::map<std::string, std::map<std::string, | ||
// std::string>>> getall(); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <cstring> | ||
#include <string> | ||
|
||
#include "../dbconnector.h" | ||
#include "../producerstatetable.h" | ||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "util.h" | ||
|
||
using namespace swss; | ||
using namespace std; | ||
|
||
SWSSProducerStateTable SWSSProducerStateTable_new(SWSSDBConnector db, const char *tableName) { | ||
SWSSTry(return (SWSSProducerStateTable) new ProducerStateTable((DBConnector *)db, | ||
string(tableName))); | ||
} | ||
|
||
void SWSSProducerStateTable_free(SWSSProducerStateTable tbl) { | ||
SWSSTry(delete ((ProducerStateTable *)tbl)); | ||
} | ||
|
||
void SWSSProducerStateTable_setBuffered(SWSSProducerStateTable tbl, uint8_t buffered) { | ||
SWSSTry(((ProducerStateTable *)tbl)->setBuffered((bool)buffered)) | ||
} | ||
|
||
void SWSSProducerStateTable_set(SWSSProducerStateTable tbl, const char *key, | ||
SWSSFieldValueArray values) { | ||
SWSSTry(((ProducerStateTable *)tbl)->set(string(key), takeFieldValueArray(values))); | ||
} | ||
|
||
void SWSSProducerStateTable_del(SWSSProducerStateTable tbl, const char *key) { | ||
SWSSTry(((ProducerStateTable *)tbl)->del(string(key))); | ||
} | ||
|
||
void SWSSProducerStateTable_flush(SWSSProducerStateTable tbl) { | ||
SWSSTry(((ProducerStateTable *)tbl)->flush()); | ||
} | ||
|
||
int64_t SWSSProducerStateTable_count(SWSSProducerStateTable tbl) { | ||
SWSSTry(return ((ProducerStateTable *)tbl)->count()); | ||
} | ||
|
||
void SWSSProducerStateTable_clear(SWSSProducerStateTable tbl) { | ||
SWSSTry(((ProducerStateTable *)tbl)->clear()); | ||
} | ||
|
||
void SWSSProducerStateTable_create_temp_view(SWSSProducerStateTable tbl) { | ||
SWSSTry(((ProducerStateTable *)tbl)->create_temp_view()); | ||
} | ||
|
||
void SWSSProducerStateTable_apply_temp_view(SWSSProducerStateTable tbl) { | ||
SWSSTry(((ProducerStateTable *)tbl)->apply_temp_view()); | ||
} |
Oops, something went wrong.