Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor eventpublisher deinit #734

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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