Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
d883c01
first cut
renukamanavalan May 13, 2022
c223d04
first cut lib code with unit test
renukamanavalan May 14, 2022
7fbdcf1
save it just in case, as VM under risk
renukamanavalan May 17, 2022
9763d3a
partial update, as vm at risk
renukamanavalan May 17, 2022
d9d24b6
intermediate saving
renukamanavalan May 18, 2022
d68c204
First run code complete
renukamanavalan May 19, 2022
d130b84
self review update
renukamanavalan May 20, 2022
63db87a
partial compile
renukamanavalan May 21, 2022
cc2bfe5
In middle of compilation
renukamanavalan May 23, 2022
d28399e
compiled OK
renukamanavalan May 23, 2022
f2694ea
common ut passes
renukamanavalan May 24, 2022
4c8373d
events_service unit tests complete
renukamanavalan May 24, 2022
2197e85
test code in progress
renukamanavalan May 25, 2022
67fbe19
evens publish covere by unit test
renukamanavalan May 26, 2022
9d64634
events 75% covered by UT
renukamanavalan May 27, 2022
e7f1bca
subscribe UT done
renukamanavalan May 31, 2022
2f13706
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into re…
renukamanavalan May 31, 2022
94153f5
Drop internal readme
renukamanavalan May 31, 2022
c4db46e
Update upon self review - mostly on comments
renukamanavalan May 31, 2022
e81160b
More on comments update
renukamanavalan May 31, 2022
9f7b2a8
minor fix of copy/paste error
renukamanavalan May 31, 2022
35a6030
Comments update
renukamanavalan May 31, 2022
6eb78d7
more comments
renukamanavalan May 31, 2022
3328970
minor updates; merged with master via shared
renukamanavalan May 31, 2022
66632f6
Per review comments
renukamanavalan Jun 2, 2022
c849258
Merge pull request #1 from renukamanavalan/remanava_events
renukamanavalan Jun 2, 2022
9ba11ed
minor updates
renukamanavalan Jun 7, 2022
d1a6f83
minor: name change for a typedef
renukamanavalan Jun 9, 2022
bd28ea8
Added EXIT code
renukamanavalan Jun 10, 2022
8f72258
Minor name change; Enabled py build for events
renukamanavalan Jun 14, 2022
2f9e3cc
Merge pull request #2 from renukamanavalan/remanava_events
renukamanavalan Jun 17, 2022
ce606d4
Minor signature update to adapt to SWIG generated python
renukamanavalan Jun 17, 2022
b0d7ee0
Made zmq send & receive thread safe
renukamanavalan Jun 20, 2022
c71e7f0
Merge pull request #3 from renukamanavalan/remanava_events
renukamanavalan Jun 21, 2022
ee8e79e
temp commit to enable merge
renukamanavalan Jul 5, 2022
302aba7
Merge remote-tracking branch 'upstream/master' into syslog_telemetry_…
renukamanavalan Jul 5, 2022
bcfb876
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into re…
renukamanavalan Jul 5, 2022
ca8d5b5
removed hacks; Added set log level API
renukamanavalan Jul 8, 2022
0365b3d
Minor signature change
renukamanavalan Jul 8, 2022
daf2ced
Added unit test for C wrap
renukamanavalan Jul 11, 2022
8c42e85
Corrected per review comments; Addede log message for published events
renukamanavalan Jul 12, 2022
089864e
Merge pull request #4 from renukamanavalan/remanava_events
renukamanavalan Jul 13, 2022
cf30d4b
minor updates;no logical code changes
renukamanavalan Jul 15, 2022
48a36ce
Merge pull request #5 from renukamanavalan/remanava_events
renukamanavalan Jul 15, 2022
b587963
corrected per review comments; Added accidentally removed test
renukamanavalan Jul 18, 2022
6bebad3
Added back accidentally removed test code file
renukamanavalan Jul 18, 2022
98fb238
Merge branch 'syslog_telemetry_shared' of https://github.com/renukama…
renukamanavalan Jul 18, 2022
94d9c23
retire runtime id on deinit
renukamanavalan Jul 19, 2022
87bee63
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into st…
renukamanavalan Jul 19, 2022
aa45b1b
restore accidental removal
renukamanavalan Jul 19, 2022
e083c42
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into st…
renukamanavalan Jul 19, 2022
d7cbbd8
Merge remote-tracking branch 'upstream/master' into syslog_telemetry_…
renukamanavalan Jul 20, 2022
f72d159
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into re…
renukamanavalan Jul 21, 2022
5e1e281
Switched to shared_ptr per review comments
renukamanavalan Jul 21, 2022
7bbce0a
minor non logical code changes
renukamanavalan Jul 21, 2022
00705eb
Merge pull request #6 from renukamanavalan/remanava_events
renukamanavalan Jul 21, 2022
a0587a0
fix syntax
renukamanavalan Jul 21, 2022
3169a4d
few follow up changes for bare ptr to shared ptr conversion
renukamanavalan Jul 21, 2022
509d536
merged with shared
renukamanavalan Jul 21, 2022
f1a6510
send event as JSON string
renukamanavalan Jul 22, 2022
72d079e
syntax
renukamanavalan Jul 22, 2022
9e4b7db
syntax
renukamanavalan Jul 22, 2022
1428c18
syntax
renukamanavalan Jul 22, 2022
3e330d7
syntax
renukamanavalan Jul 22, 2022
8e0553b
syntax
renukamanavalan Jul 22, 2022
8ff311f
compile fix
renukamanavalan Jul 22, 2022
a560586
compile fix
renukamanavalan Jul 22, 2022
8c99651
compile fix
renukamanavalan Jul 22, 2022
de179f3
compile fix
renukamanavalan Jul 22, 2022
100ece7
compile fix
renukamanavalan Jul 22, 2022
3887e61
compile fix
renukamanavalan Jul 22, 2022
c6fdd80
compile fix
renukamanavalan Jul 22, 2022
88156a1
compile fix
renukamanavalan Jul 22, 2022
9fcf2f0
changing wrap signature to use struct instead of JSON string
renukamanavalan Jul 26, 2022
f50f878
compile fix
renukamanavalan Jul 26, 2022
5e9b4c3
compile fix
renukamanavalan Jul 26, 2022
68da0df
compile fix
renukamanavalan Jul 26, 2022
c997fc5
compile fix
renukamanavalan Jul 26, 2022
6bb9f33
compile fix
renukamanavalan Jul 26, 2022
80eda6e
compile fix
renukamanavalan Jul 26, 2022
ed32576
compile fix
renukamanavalan Jul 26, 2022
d1f960c
compile fix
renukamanavalan Jul 26, 2022
00fa3a3
compile fix
renukamanavalan Jul 26, 2022
948ae40
compile fix
renukamanavalan Jul 26, 2022
96945eb
compile fix
renukamanavalan Jul 26, 2022
a6d38ad
compile fix
renukamanavalan Jul 26, 2022
f07adc4
compile fix
renukamanavalan Jul 26, 2022
c3f06cc
compile fix
renukamanavalan Jul 26, 2022
4d6f3f6
compile fix
renukamanavalan Jul 26, 2022
d3475cc
compile fix
renukamanavalan Jul 26, 2022
4ee2050
compile fix
renukamanavalan Jul 26, 2022
33cd34e
compile fix
renukamanavalan Jul 27, 2022
972fa62
compile fix
renukamanavalan Jul 28, 2022
3ccb824
compile fix
renukamanavalan Jul 28, 2022
540dc70
Merge remote-tracking branch 'upstream/master' into syslog_telemetry_…
renukamanavalan Jul 29, 2022
bb777f3
compile fix
renukamanavalan Jul 29, 2022
13a7f5c
compile fix
renukamanavalan Jul 30, 2022
07cff7e
compile fix
renukamanavalan Jul 30, 2022
aa9c3fe
Add libzmq5 as dependency for ubuntu-20.04 build (#7)
zbud-msft Aug 2, 2022
d81441b
Modify azp (#8)
zbud-msft Aug 2, 2022
6b79a20
Modify azp (#9)
zbud-msft Aug 2, 2022
40f0665
Modify azp (#10)
zbud-msft Aug 3, 2022
30f49d9
Merge branch 'sonic-net:master' into syslog_telemetry_shared
zbud-msft Aug 3, 2022
0f58397
Merge remote-tracking branch 'origin/syslog_telemetry_shared' into st…
renukamanavalan Aug 3, 2022
fe863a7
compile errors
renukamanavalan Aug 4, 2022
3c8e1f0
compile errors
renukamanavalan Aug 4, 2022
36e18f7
Compile error from Ubuntu
renukamanavalan Aug 4, 2022
fc65a91
drop unused macro
renukamanavalan Aug 4, 2022
0ff6c10
compile fix
renukamanavalan Aug 4, 2022
4d24e6f
compile fix
renukamanavalan Aug 4, 2022
e3db7b8
remove pedantic
renukamanavalan Aug 4, 2022
2dab4e8
restored ABORT_IF_NOT
renukamanavalan Aug 4, 2022
7546a87
revert flag add
renukamanavalan Aug 4, 2022
6de2566
comments correction
renukamanavalan Aug 6, 2022
fd18ca8
Merge pull request #13 from renukamanavalan/statistics
renukamanavalan Aug 8, 2022
7fd1e4a
Log every published event
renukamanavalan Aug 8, 2022
7976914
Merge pull request #14 from renukamanavalan/statistics
renukamanavalan Aug 8, 2022
ded4178
Install dependencies for vstest (#15)
zbud-msft Aug 9, 2022
3351061
Install deps vstest (#16)
zbud-msft Aug 9, 2022
7e8d47c
Install deps vstest (#17)
zbud-msft Aug 9, 2022
f21e647
Added LINGER timeout to service sockets
renukamanavalan Aug 12, 2022
8f95bda
Added heartbeat
renukamanavalan Aug 15, 2022
3f7aecd
compile fix
renukamanavalan Aug 15, 2022
c591b9d
compile fix
renukamanavalan Aug 15, 2022
f370ff6
compile fix
renukamanavalan Aug 15, 2022
47f471a
set LINGER_TIMEOUT before connect/bind
renukamanavalan Aug 15, 2022
4eb9631
Add global options
renukamanavalan Aug 16, 2022
dc9b9d1
Add global options
renukamanavalan Aug 16, 2022
295beda
Add global options
renukamanavalan Aug 16, 2022
5cf84ba
Add global options
renukamanavalan Aug 16, 2022
ba47b43
Add global options
renukamanavalan Aug 16, 2022
2484abe
Add global options
renukamanavalan Aug 16, 2022
7d0ea03
Add global options
renukamanavalan Aug 16, 2022
962f134
Add global options
renukamanavalan Aug 16, 2022
380ccc1
Add global options
renukamanavalan Aug 16, 2022
65f97cd
added define
renukamanavalan Aug 16, 2022
837925a
Moved C API to C header file
renukamanavalan Aug 16, 2022
836224b
minor upates
renukamanavalan Aug 18, 2022
066548d
minor upates
renukamanavalan Aug 18, 2022
ccc151a
Merge pull request #18 from renukamanavalan/statistics
renukamanavalan Aug 18, 2022
fb2959d
Merge remote-tracking branch 'upstream/master' into syslog_telemetry_…
renukamanavalan Aug 18, 2022
24c9743
Merge branch 'syslog_telemetry_shared' of https://github.com/renukama…
renukamanavalan Aug 18, 2022
e122a5e
Updated comments
renukamanavalan Aug 18, 2022
7b75ef3
comments update
renukamanavalan Aug 19, 2022
f382698
comments update
renukamanavalan Aug 19, 2022
26a9e70
Fix build issue
zbud-msft Aug 19, 2022
9803be0
Modify comment
zbud-msft Aug 22, 2022
fc1bfb7
Modify comment
zbud-msft Aug 22, 2022
09b21a8
Modify comment
zbud-msft Aug 22, 2022
6cd6fb8
Modify comment
zbud-msft Aug 22, 2022
b0a5005
Modify comment
zbud-msft Aug 23, 2022
e3edc11
Modify comment
zbud-msft Aug 23, 2022
5b5af9f
Modify comment
zbud-msft Aug 23, 2022
9ce1113
Merge branch 'sonic-net:master' into fixBuildIssues
zbud-msft Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-pipelines/build_and_install_module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function build_and_install_kmodule()
apt-get install -y build-essential linux-headers-${KERNEL_RELEASE} autoconf pkg-config fakeroot
apt-get install -y flex bison libssl-dev libelf-dev
apt-get install -y libnl-route-3-200 libnl-route-3-dev libnl-cli-3-200 libnl-cli-3-dev libnl-3-dev
# Install libs required by libswsscommon
# Install libs required by libswsscommon for build
apt-get install -y libzmq3-dev libzmq5 libboost-serialization1.71.0 uuid-dev

# Add the apt source mirrors and download the linux image source code
Expand Down
63 changes: 58 additions & 5 deletions common/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

lst_publishers_t EventPublisher::s_publishers;
int EventPublisher::LINGER_TIMEOUT = 100; // In milliseconds

event_handle_t
EventPublisher::get_publisher(const string event_source)
Expand Down Expand Up @@ -73,15 +72,18 @@ get_uuid()

int EventPublisher::init(const string event_source)
{
int rc = -1;
m_zmq_ctx = zmq_ctx_new();
void *sock = zmq_socket (m_zmq_ctx, ZMQ_PUB);

int rc = zmq_connect (sock, get_config(XSUB_END_KEY).c_str());
RET_ON_ERR(rc == 0, "Publisher fails to connect %s", get_config(XSUB_END_KEY).c_str());
void *sock = zmq_socket (m_zmq_ctx, ZMQ_PUB);
RET_ON_ERR(sock != NULL, "Failed to ZMQ_PUB socket");

rc = zmq_setsockopt (sock, ZMQ_LINGER, &LINGER_TIMEOUT, sizeof (LINGER_TIMEOUT));
RET_ON_ERR(rc == 0, "Failed to ZMQ_LINGER to %d", LINGER_TIMEOUT);

rc = zmq_connect (sock, get_config(XSUB_END_KEY).c_str());
RET_ON_ERR(rc == 0, "Publisher fails to connect %s", get_config(XSUB_END_KEY).c_str());

/*
* Event service could be down. So have a timeout.
*
Expand Down Expand Up @@ -191,7 +193,7 @@ EventPublisher::publish(const string tag, const event_params_t *params)
}

str_data = convert_to_json(m_event_source + ":" + tag, *params);
SWSS_LOG_INFO("EVENT_PUBLISHED: %s", str_data.c_str());
SWSS_LOG_ERROR("EVENT_PUBLISHED: %s", str_data.c_str());

rc = send_evt(str_data);
RET_ON_ERR(rc == 0, "failed to send event str[%d]= %s", (int)str_data.size(),
Expand Down Expand Up @@ -681,8 +683,59 @@ event_receive_wrap(void *handle, event_receive_op_C_t *evt)

}


void swssSetLogPriority(int pri)
{
swss::Logger::setMinPrio((swss::Logger::Priority) pri);
}


int
event_set_global_options(const char *options)
{
int ret = -1, rc;
void *zmq_ctx;
event_service svc;

zmq_ctx = zmq_ctx_new();
RET_ON_ERR(zmq_ctx != NULL, "Failed to get zmq ctx");

rc = svc.init_client(zmq_ctx);
RET_ON_ERR (rc == 0, "Failed to init event service rc=%d", rc);

rc = svc.global_options_set(options);
RET_ON_ERR (rc == 0, "Failed to set options in event service rc=%d", rc);
ret = 0;
out:
svc.close_service();
zmq_ctx_term(zmq_ctx);

return ret;
}


int
event_get_global_options(char *options, int options_size)
{
int ret = -1, rc;
void *zmq_ctx;
event_service svc;

zmq_ctx = zmq_ctx_new();
RET_ON_ERR(zmq_ctx != NULL, "Failed to get zmq ctx");

rc = svc.init_client(zmq_ctx);
RET_ON_ERR (rc == 0, "Failed to init event service rc=%d", rc);

rc = svc.global_options_get(options, options_size);
RET_ON_ERR (rc >= 0, "Failed to set options in event service rc=%d", rc);

ret = rc;

out:
svc.close_service();
zmq_ctx_term(zmq_ctx);

return ret;
}

6 changes: 3 additions & 3 deletions common/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <map>

/*
* Events library
* Events library APIs.
*
* APIs are for publishing & receiving events with source, tag and params along with timestamp.
* Used by event publishers and those interested in receiving published events.
Expand All @@ -31,7 +31,7 @@ typedef void* event_handle_t;
* is complete. Hence recommend, do the init as soon as the process starts.
*
* Input:
* event_source
* event_source:
* The YANG module name for the event source. All events published with the handle
* returned by this call is tagged with this source, transparently. The receiver
* could subscribe with this source as filter.
Expand All @@ -47,7 +47,7 @@ event_handle_t events_init_publisher(const std::string event_source);
* De-init/free the publisher
*
* Input:
* Handle returned from events_init_publisher
* Handle returned from events_init_publisher.
*
* Output:
* Handle is nullified.
Expand Down
3 changes: 2 additions & 1 deletion common/events_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ using namespace chrono;
SWSS_LOG_ERROR("last:errno=%d", _e); \
goto out; }

static const int LINGER_TIMEOUT = 100; /* Linger timeout in milliseconds */

/* helper API to print variable type */
/*
Expand Down Expand Up @@ -210,7 +211,7 @@ typedef string runtime_id_t;
#define EVENT_STR_CTRL_PREFIX_SZ ((int)sizeof(EVENT_STR_CTRL_PREFIX) - 1)

/* The internal code that caches runtime-IDs could retire upon de-init */
#define EVENT_STR_CTRL_DEINIT "CONTROL_DEINIT"
#define EVENT_STR_CTRL_DEINIT EVENT_STR_CTRL_PREFIX "DEINIT"

typedef vector<internal_event_t> internal_events_lst_t;

Expand Down
1 change: 0 additions & 1 deletion common/events_pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ typedef map <string, EventPublisher_ptr_t> lst_publishers_t;
class EventPublisher : public events_base
{
static lst_publishers_t s_publishers;
static int LINGER_TIMEOUT;

public:
virtual ~EventPublisher();
Expand Down
44 changes: 44 additions & 0 deletions common/events_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ event_service::init_client(void *zmq_ctx, int block_ms)
void *sock = zmq_socket (zmq_ctx, ZMQ_REQ);
RET_ON_ERR(sock != NULL, "Failed to get ZMQ_REQ socket rc=%d", rc);

rc = zmq_setsockopt (sock, ZMQ_LINGER, &LINGER_TIMEOUT, sizeof (LINGER_TIMEOUT));
RET_ON_ERR(rc == 0, "Failed to ZMQ_LINGER to %d", LINGER_TIMEOUT);

rc = zmq_connect (sock, get_config(REQ_REP_END_KEY).c_str());
RET_ON_ERR(rc == 0, "Failed to connect to %s", get_config(REQ_REP_END_KEY).c_str());

Expand All @@ -60,6 +63,9 @@ event_service::init_server(void *zmq_ctx, int block_ms)
void *sock = zmq_socket (zmq_ctx, ZMQ_REP);
RET_ON_ERR(sock != NULL, "Failed to get ZMQ_REP socket rc=%d", rc);

rc = zmq_setsockopt (sock, ZMQ_LINGER, &LINGER_TIMEOUT, sizeof (LINGER_TIMEOUT));
RET_ON_ERR(rc == 0, "Failed to ZMQ_LINGER to %d", LINGER_TIMEOUT);

rc = zmq_bind (sock, get_config(REQ_REP_END_KEY).c_str());
RET_ON_ERR(rc == 0, "Failed to bind to %s", get_config(REQ_REP_END_KEY).c_str());

Expand Down Expand Up @@ -155,6 +161,44 @@ event_service::cache_read(event_serialized_lst_t &lst)
}


int
event_service::global_options_set(const char *val)
{
int rc;
event_serialized_lst_t lst;

lst.push_back(string(val));

RET_ON_ERR((rc = send_recv(EVENT_OPTIONS, &lst, NULL)) == 0,
"Failed to send global options request rc=%d", rc);
out:
return rc;
}


int
event_service::global_options_get(char *val, int sz)
{
int ret = -1, rc;
string s;
event_serialized_lst_t lst;

RET_ON_ERR((rc = send_recv(EVENT_OPTIONS, NULL, &lst)) == 0,
"Failed to receive global options request rc=%d", rc);

if (!lst.empty()) {
s = *lst.begin();
}

strncpy(val, s.c_str(), sz);

val[sz - 1] = 0;
ret = (int)s.size();
out:
return ret;
}


int
event_service::channel_read(int &code, event_serialized_lst_t &data)
{
Expand Down
33 changes: 33 additions & 0 deletions common/events_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef enum {
EVENT_CACHE_STOP, /* Stop the cache */
EVENT_CACHE_READ, /* Read cached events */
EVENT_ECHO, /* Echoes the received data in request via response */
EVENT_OPTIONS, /* global options Set/Get */
EVENT_EXIT /* Exit the eventd service -- Useful for unit test.*/
} event_req_type_t;

Expand Down Expand Up @@ -217,6 +218,38 @@ class event_service {
*/
int echo_receive(string &s);


/*
* Global options request set
*
* Input:
* val -- Put the interval for set
*
* Return:
* 0 - On Success
* -1 - On Failure
*/
int global_options_set(const char *val);


/*
* Global options request get.
*
* Input:
* val_sz -- Size of val buffer
*
* Output:
* val -- Get the current val
*
* Return:
* > 0 - Count of bytes to copied/to-be-copied.
* Result is truncated if given size <= this value.
* But copied string is *always* null termninated.
*
* -1 - On Failure
*/
int global_options_get(char *val, int val_sz);

/*
* The read for req/resp from client/server. The APIs above use this
* to read response and the server use this to read request.
Expand Down
71 changes: 71 additions & 0 deletions common/events_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,77 @@ int event_receive_wrap(void *handle, event_receive_op_C_t *evt);
*/
void swssSetLogPriority(int pri);


/*
* Global configurable options can be set via this API.
*
* The options are provided as JSON object with key/values as JSON string.
* key = <option name case insensitive>
* value = <option value>
*
* Supported options
*
* Option name: HEARTBEAT_INTERVAL_SECS
* Option Value: interval in seconds as int
* A value of -1 implies no heartbeat
* A value of 0 implies the lowest possible interval as possible/supported.
* This depends on implementation.
* Any non zero value implies count of seconds.
* NOTE: System will round it to the multiple of lowest interval supported.
* Any negative value other than -1 is treated as invalid.
*
*
* Option name: OFFLINE_CACHE_SIZE TODO/Not Yet Implemented
* Option Value: Size in count MBs as int
* A value of 0 implies the system default
* This depends on implementation.
* Any non zero value is accepted.
* This is constraint on available memory. Hence this is only a
* guideline to take if possible.
* Any negative value other than -1 is treated as invalid.
*
* Input:
* options - A c string holding JSON string of the options.
*
* Return:
* 0 - Implies success. It also implies that the provided options and
* their values were valid.
* < 0 - Implies failure. Either internal failure or invalid options or
* invalid values. Look at syslog for details.
*/

#define GLOBAL_OPTION_HEARTBEAT "HEARTBEAT_INTERVAL"

int event_set_global_options(const char *options);



/*
* A way to read the current values for global options.
* Refer above for details.
*
* Input:
* None
*
* Output:
* options - A buffer for c string holding JSON string of the options.
*
* options_size - Size of options buffer. The size must include space
* for terminating NULL character. If string to be copied
* is same or greater size, (options_size - 1) bytes
* are copied with a terminating NULL.
*
*
* Return:
* > 0 - Count of characters of the final JSON string to return. If given
* size is less/equal, then it implies the buffer carries truncated string.
* NOTE: The final copied string is always null terminated.
*
* < 0 - Implies failure to reach eventd service.
*
*/
int event_get_global_options(char *options, int options_size);

#ifdef __cplusplus
}
#endif
Expand Down
21 changes: 20 additions & 1 deletion tests/events_service_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static event_serialized_lst_t server_rd_lst, server_wr_lst;
void serve_commands()
{
int code;
event_serialized_lst_t lst;
event_serialized_lst_t lst, opt_lst;
EXPECT_EQ(0, service_svr.init_server(zmq_ctx, 1000));
while(!do_terminate) {
if (0 != service_svr.channel_read(code, lst)) {
Expand Down Expand Up @@ -51,6 +51,16 @@ void serve_commands()
server_ret = 0;
server_wr_lst = lst;
break;
case EVENT_OPTIONS:
server_ret = 0;
if (lst.empty()) {
server_wr_lst = opt_lst;
}
else {
opt_lst = lst;
server_wr_lst.clear();
}
break;
default:
EXPECT_TRUE(false);
server_ret = -1;
Expand Down Expand Up @@ -118,10 +128,19 @@ TEST(events_common, cache_cmds)
EXPECT_FALSE(server_rd_lst.empty());
EXPECT_EQ(s1, s);

string sopt("{\"HEARTBEAT_INTERVAL\": 2000, \"OFFLINE_CACHE_SIZE\": 500}");
char rd_opt[100];
rd_opt[0] = 0;
EXPECT_EQ(0, service_cl.global_options_set(sopt.c_str()));
EXPECT_LT(0, service_cl.global_options_get(rd_opt, (int)sizeof(rd_opt)));
EXPECT_EQ(EVENT_OPTIONS, server_rd_code);
EXPECT_EQ(sopt, string(rd_opt));

do_terminate = true;
service_cl.close_service();
EXPECT_FALSE(service_cl.is_active());
thr.join();
zmq_ctx_term(zmq_ctx);
}


Loading