Skip to content

Commit

Permalink
Refactor eventpublisher deinit (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbud-msft authored Jan 6, 2023
1 parent b9a9dbb commit 9e1176d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions common/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ void
EventPublisher::drop_publisher(event_handle_t handle)
{
lst_publishers_t::iterator it;
EventPublisher_ptr_t p;

for(it=s_publishers.begin(); it != s_publishers.end(); ++it) {
if (it->second.get() == handle) {
p = it->second;
s_publishers.erase(it);
break;
}
}

if(p != NULL) {
p->remove_runtime_id();
}
}

int
Expand Down Expand Up @@ -114,17 +120,21 @@ int EventPublisher::init(const string event_source)

EventPublisher::~EventPublisher()
{
if (!m_runtime_id.empty()) {
/* Retire the runtime ID */
send_evt(EVENT_STR_CTRL_DEINIT);
}
m_event_service.close_service();
if (m_socket != NULL) {
zmq_close(m_socket);
}
zmq_ctx_term(m_zmq_ctx);
}

void
EventPublisher::remove_runtime_id()
{
if (!m_runtime_id.empty()) {
/* Retire the runtime ID */
send_evt(EVENT_STR_CTRL_DEINIT);
}
}

int
EventPublisher::send_evt(const string str_data)
Expand Down
1 change: 1 addition & 0 deletions common/events_pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class EventPublisher : public events_base
int publish(const string event_tag,
const event_params_t *params);
int send_evt(const string str_data);
void remove_runtime_id();

void *m_zmq_ctx;
void *m_socket;
Expand Down

0 comments on commit 9e1176d

Please sign in to comment.