-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dev-reset-local-users-password
- Loading branch information
Showing
49 changed files
with
2,001 additions
and
85 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
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,45 @@ | ||
#include <boost/numeric/conversion/cast.hpp> | ||
#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; | ||
using boost::numeric_cast; | ||
|
||
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); | ||
}); | ||
} | ||
|
||
uint32_t SWSSConsumerStateTable_getFd(SWSSConsumerStateTable tbl) { | ||
SWSSTry(return numeric_cast<uint32_t>(((ConsumerStateTable *)tbl)->getFd())); | ||
} | ||
|
||
SWSSSelectResult SWSSConsumerStateTable_readData(SWSSConsumerStateTable tbl, uint32_t timeout_ms, | ||
uint8_t interrupt_on_signal) { | ||
SWSSTry(return selectOne((ConsumerStateTable *)tbl, timeout_ms, interrupt_on_signal)); | ||
} |
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,39 @@ | ||
#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); | ||
|
||
// Return the underlying fd for polling/selecting on. | ||
// Callers must NOT read/write on fd, it may only be used for epoll or similar. | ||
// After the fd becomes readable, SWSSConsumerStateTable_readData must be used to | ||
// reset the fd and read data into internal data structures. | ||
uint32_t SWSSConsumerStateTable_getFd(SWSSConsumerStateTable tbl); | ||
|
||
// Block until data is available to read or until a timeout elapses. | ||
// A timeout of 0 means the call will return immediately. | ||
SWSSSelectResult SWSSConsumerStateTable_readData(SWSSConsumerStateTable tbl, uint32_t timeout_ms, | ||
uint8_t interrupt_on_signal); | ||
|
||
#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,93 @@ | ||
#include <cstring> | ||
#include <string> | ||
#include <utility> | ||
|
||
#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, SWSSStrRef value) { | ||
SWSSTry(((DBConnector *)db)->set(string(key), takeStrRef(value))); | ||
} | ||
|
||
SWSSString SWSSDBConnector_get(SWSSDBConnector db, const char *key) { | ||
SWSSTry({ | ||
shared_ptr<string> s = ((DBConnector *)db)->get(string(key)); | ||
return s ? makeString(move(*s)) : 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, | ||
SWSSStrRef value) { | ||
SWSSTry(((DBConnector *)db)->hset(string(key), string(field), takeStrRef(value))); | ||
} | ||
|
||
SWSSString SWSSDBConnector_hget(SWSSDBConnector db, const char *key, const char *field) { | ||
SWSSTry({ | ||
shared_ptr<string> s = ((DBConnector *)db)->hget(string(key), string(field)); | ||
return s ? makeString(move(*s)) : nullptr; | ||
}); | ||
} | ||
|
||
SWSSFieldValueArray SWSSDBConnector_hgetall(SWSSDBConnector db, const char *key) { | ||
SWSSTry({ | ||
auto map = ((DBConnector *)db)->hgetall(string(key)); | ||
|
||
// We can't move keys out of the map, we have to copy them, until C++17 map::extract so we | ||
// copy them here into a vector to avoid needing an overload on makeFieldValueArray | ||
vector<pair<string, string>> pairs; | ||
pairs.reserve(map.size()); | ||
for (auto &pair : map) | ||
pairs.push_back(make_pair(pair.first, move(pair.second))); | ||
|
||
return makeFieldValueArray(std::move(pairs)); | ||
}); | ||
} | ||
|
||
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,64 @@ | ||
#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, SWSSStrRef value); | ||
|
||
// Returns NULL if key doesn't exist | ||
// Result must be freed using SWSSString_free() | ||
SWSSString 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, SWSSStrRef value); | ||
|
||
// Returns NULL if key or field doesn't exist | ||
// Result must be freed using SWSSString_free() | ||
SWSSString 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 appropriate free functions | ||
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); | ||
|
||
// Returns 1 on success, 0 on failure | ||
int8_t SWSSDBConnector_flushdb(SWSSDBConnector db); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.