Skip to content

Commit ce606d4

Browse files
Minor signature update to adapt to SWIG generated python
1 parent 8f72258 commit ce606d4

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

common/events.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ events_init_publisher(const string event_source)
149149
}
150150

151151
void
152-
events_deinit_publisher(event_handle_t &handle)
152+
events_deinit_publisher(event_handle_t handle)
153153
{
154154
lst_publishers_t::iterator it;
155155

@@ -160,8 +160,6 @@ events_deinit_publisher(event_handle_t &handle)
160160
break;
161161
}
162162
}
163-
handle = NULL;
164-
165163
}
166164

167165
int
@@ -413,13 +411,12 @@ events_init_subscriber(bool use_cache, int recv_timeout,
413411

414412

415413
void
416-
events_deinit_subscriber(event_handle_t &handle)
414+
events_deinit_subscriber(event_handle_t handle)
417415
{
418416
if ((handle == s_subscriber) && (s_subscriber != NULL)) {
419417
delete s_subscriber;
420418
s_subscriber = NULL;
421419
}
422-
handle = NULL;
423420
}
424421

425422

@@ -434,6 +431,16 @@ event_receive(event_handle_t handle, string &key,
434431
return -1;
435432
}
436433

434+
435+
event_receive_op_t
436+
event_receive_wrap(event_handle_t handle)
437+
{
438+
event_receive_op_t op;
439+
440+
op.rc = event_receive(handle, op.key, op.params, op.missed_cnt);
441+
return op;
442+
}
443+
437444
int event_last_error()
438445
{
439446
return zerrno;

common/events.h

+27-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ event_handle_t events_init_publisher(const std::string event_source);
5252
* Output:
5353
* Handle is nullified.
5454
*/
55-
void events_deinit_publisher(event_handle_t &handle);
55+
void events_deinit_publisher(event_handle_t handle);
5656

5757

5858
/*
@@ -147,7 +147,7 @@ event_handle_t events_init_subscriber(bool use_cache=false,
147147
* Output:
148148
* Handle is nullified.
149149
*/
150-
void events_deinit_subscriber(event_handle_t &handle);
150+
void events_deinit_subscriber(event_handle_t handle);
151151

152152

153153
/*
@@ -194,6 +194,31 @@ void events_deinit_subscriber(event_handle_t &handle);
194194
int event_receive(event_handle_t handle, std::string &key,
195195
event_params_t &params, int &missed_cnt);
196196

197+
/*
198+
* event_receive_wrap
199+
*
200+
* Returns o/p as structured.
201+
* This is handy for invocation via python.
202+
*
203+
* input:
204+
* handle - As obtained from events_init_subscriber
205+
*
206+
* output:
207+
* None
208+
*
209+
* Return:
210+
* struct that gets return value and all o/p params of event_receive
211+
*/
212+
typedef struct {
213+
int rc; /* Return value of event_receive */
214+
/* o/p params from event receive */
215+
std::string key;
216+
event_params_t params;
217+
int missed_cnt;
218+
} event_receive_op_t;
219+
220+
event_receive_op_t event_receive_wrap(event_handle_t handle);
221+
197222

198223
/*
199224
* Get error code for last receive

common/events_common.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,14 @@ string
9696
map_to_str(const Map &m)
9797
{
9898
stringstream _ss;
99+
string sep;
100+
99101
_ss << "{";
100102
for (const auto elem: m) {
101-
_ss << "{" << elem.first << "," << elem.second.substr(0,10) << "}";
103+
_ss << sep << "{" << elem.first << "," << elem.second.substr(0,10) << "}";
104+
if (sep.empty()) {
105+
sep = ", ";
106+
}
102107
}
103108
_ss << "}";
104109
return _ss.str();

pyext/swsscommon.i

+2
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,6 @@ T castSelectableObj(swss::Selectable *temp)
208208
%include "dbinterface.h"
209209
%include "logger.h"
210210
%include "events.h"
211+
%ignore event_receive(event_handle_t, std::string &, event_params_t &, int &);
212+
211213
%include "status_code_util.h"

0 commit comments

Comments
 (0)