Skip to content

Commit 6555057

Browse files
zbud-msftStormLiangMS
authored andcommitted
Refactor eventpublisher deinit (#734)
1 parent f4d6de7 commit 6555057

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

common/events.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@ void
3535
EventPublisher::drop_publisher(event_handle_t handle)
3636
{
3737
lst_publishers_t::iterator it;
38+
EventPublisher_ptr_t p;
3839

3940
for(it=s_publishers.begin(); it != s_publishers.end(); ++it) {
4041
if (it->second.get() == handle) {
42+
p = it->second;
4143
s_publishers.erase(it);
4244
break;
4345
}
4446
}
47+
48+
if(p != NULL) {
49+
p->remove_runtime_id();
50+
}
4551
}
4652

4753
int
@@ -114,17 +120,21 @@ int EventPublisher::init(const string event_source)
114120

115121
EventPublisher::~EventPublisher()
116122
{
117-
if (!m_runtime_id.empty()) {
118-
/* Retire the runtime ID */
119-
send_evt(EVENT_STR_CTRL_DEINIT);
120-
}
121123
m_event_service.close_service();
122124
if (m_socket != NULL) {
123125
zmq_close(m_socket);
124126
}
125127
zmq_ctx_term(m_zmq_ctx);
126128
}
127129

130+
void
131+
EventPublisher::remove_runtime_id()
132+
{
133+
if (!m_runtime_id.empty()) {
134+
/* Retire the runtime ID */
135+
send_evt(EVENT_STR_CTRL_DEINIT);
136+
}
137+
}
128138

129139
int
130140
EventPublisher::send_evt(const string str_data)

common/events_pi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EventPublisher : public events_base
6161
int publish(const string event_tag,
6262
const event_params_t *params);
6363
int send_evt(const string str_data);
64+
void remove_runtime_id();
6465

6566
void *m_zmq_ctx;
6667
void *m_socket;

0 commit comments

Comments
 (0)