Modify the implementation of the plugin manager take over
A plugin that is taken over, if the plugin was called before being taken over
and has a registered SESSION_EVENT_CLOSING event,
it will be called again when the SESSION_EVENT_CLOSING event comes.
Otherwise, the plugin will not be called.
This commit is contained in:
14
readme.md
14
readme.md
@@ -48,12 +48,18 @@ Plugin Management APIs
|
||||
pm_session_dettach_me(session);
|
||||
|
||||
/*
|
||||
* The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* The current plugin(cb2) takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event.
|
||||
*
|
||||
* The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING),
|
||||
* other plugins event_cb is not called, the session pme on other plugins is NULL,
|
||||
* When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL.
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* Plugin runtime callback list: | cb1 |-->| cb2 |-->| cb3 |-->| cb4 |
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* /|\
|
||||
* |
|
||||
* plugin cb2 run pm_session_take_over
|
||||
*
|
||||
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
|
||||
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
|
||||
*/
|
||||
pm_session_take_over(session);
|
||||
```
|
||||
|
||||
@@ -22,12 +22,18 @@ typedef void plugin_exit_callback(void);
|
||||
void pm_session_dettach_me(const struct stellar_session *session);
|
||||
|
||||
/*
|
||||
* The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* The current plugin(cb2) takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event.
|
||||
*
|
||||
* The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING),
|
||||
* other plugins event_cb is not called, the session pme on other plugins is NULL,
|
||||
* When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL.
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* Plugin runtime callback list: | cb1 |-->| cb2 |-->| cb3 |-->| cb4 |
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* /|\
|
||||
* |
|
||||
* plugin cb2 run pm_session_take_over
|
||||
*
|
||||
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
|
||||
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
|
||||
*/
|
||||
void pm_session_take_over(const struct stellar_session *session);
|
||||
|
||||
|
||||
@@ -19,11 +19,12 @@ enum plugin_status
|
||||
|
||||
struct callback_runtime
|
||||
{
|
||||
enum plugin_status status;
|
||||
void *cb_args;
|
||||
fn_session_event_callback *event_cb;
|
||||
|
||||
enum session_event_type event;
|
||||
fn_session_event_callback *event_cb;
|
||||
enum plugin_status status;
|
||||
int is_be_called;
|
||||
};
|
||||
|
||||
struct session_plugin_ctx
|
||||
@@ -95,6 +96,7 @@ static struct session_plugin_ctx *plugin_manager_create_plugin_ctx(struct plugin
|
||||
|
||||
for (int i = 0; i < plug_ctx->callback_num; i++)
|
||||
{
|
||||
plug_ctx->callbacks[i].is_be_called = 0;
|
||||
plug_ctx->callbacks[i].status = PLUGIN_STATUS_NORMAL;
|
||||
plug_ctx->callbacks[i].event = elem->callbacks[i].event;
|
||||
plug_ctx->callbacks[i].event_cb = elem->callbacks[i].event_cb;
|
||||
@@ -435,12 +437,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
|
||||
}
|
||||
else if (runtime->status == PLUGIN_STATUS_TAKEN_OVER)
|
||||
{
|
||||
/*
|
||||
* This plugin may be taken over when the session is open (SESSION_EVENT_OPENING),
|
||||
* and the pme may be NULL when event_cb() is run to free memory with the session is closed (SESSION_EVENT_CLOSING).
|
||||
* So, The plugin must check whether the pme is NULL before freeing memory.
|
||||
*/
|
||||
if (event_type & SESSION_EVENT_CLOSING)
|
||||
if ((event_type & SESSION_EVENT_CLOSING) && (runtime->event & SESSION_EVENT_CLOSING) && runtime->is_be_called)
|
||||
{
|
||||
plug_ctx->callback_index = i;
|
||||
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'taken over', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
@@ -459,6 +456,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve
|
||||
plug_ctx->callback_index = i;
|
||||
plugin_manager_log(DEBUG, "dispatch, run event_cb: %p, plugin status: 'normal', session: %s, event: (%d, %s)", runtime->event_cb, session_name, event_type, event_str_buffer);
|
||||
runtime->event_cb(seesion, event_type, packet, payload, payload_len, &runtime->cb_args);
|
||||
runtime->is_be_called = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -499,12 +497,18 @@ void pm_session_dettach_me(const struct stellar_session *session)
|
||||
}
|
||||
|
||||
/*
|
||||
* The current plugin takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* The current plugin(cb2) takes over the current session, the pm_session_take_over setting flag disables other plugins,
|
||||
* and the current session does not call other plugins except for the SESSION_EVENT_CLOSING event.
|
||||
*
|
||||
* The current plugin may be taken over while the session is open (SESSION_EVENT_OPENING),
|
||||
* other plugins event_cb is not called, the session pme on other plugins is NULL,
|
||||
* When the session is closed (SESSION_EVENT_CLOSING), call other plugin even_cb to destroy pme must check if pme is NULL
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* Plugin runtime callback list: | cb1 |-->| cb2 |-->| cb3 |-->| cb4 |
|
||||
* +-----+ +-----+ +-----+ +-----+
|
||||
* /|\
|
||||
* |
|
||||
* plugin cb2 run pm_session_take_over
|
||||
*
|
||||
* A plugin(cb1/cb3/cb4) that is taken over, if the plugin was called before being taken over and has a registered SESSION_EVENT_CLOSING event,
|
||||
* it will be called again when the SESSION_EVENT_CLOSING event comes. Otherwise, the plugin will not be called.
|
||||
*/
|
||||
void pm_session_take_over(const struct stellar_session *session)
|
||||
{
|
||||
|
||||
@@ -149,6 +149,10 @@ static int toml_parse_session_section(toml_table_t *root, struct plugin_manager_
|
||||
(config->session_section[config->session_section_num].event) = (enum session_event_type)((config->session_section[config->session_section_num].event) | type_int);
|
||||
safe_free(type_str.u.s);
|
||||
}
|
||||
if ((config->session_section[config->session_section_num].event & SESSION_EVENT_CLOSING) == 0)
|
||||
{
|
||||
plugin_manager_log(WARN, "can't find 'SESSION_EVENT_CLOSING' value for 'SESSION_EVENT_TYPE' configuration item in '[SESSION_NAME.%s]' section of %s", session_name, file);
|
||||
}
|
||||
|
||||
config->session_section_num++;
|
||||
}
|
||||
|
||||
@@ -29,15 +29,14 @@ struct event_type_map
|
||||
enum session_event_type type_int;
|
||||
};
|
||||
|
||||
static struct event_type_map evtype_map[] =
|
||||
{
|
||||
{"SESSION_EVENT_UNKNOWN", SESSION_EVENT_UNKNOWN},
|
||||
{"SESSION_EVENT_OPENING", SESSION_EVENT_OPENING},
|
||||
{"SESSION_EVENT_RAWPKT", SESSION_EVENT_RAWPKT},
|
||||
{"SESSION_EVENT_ORDPKT", SESSION_EVENT_ORDPKT},
|
||||
{"SESSION_EVENT_META", SESSION_EVENT_META},
|
||||
{"SESSION_EVENT_CLOSING", SESSION_EVENT_CLOSING},
|
||||
{"SESSION_EVENT_ALL", SESSION_EVENT_ALL},
|
||||
static struct event_type_map evtype_map[] = {
|
||||
{"SESSION_EVENT_UNKNOWN", SESSION_EVENT_UNKNOWN},
|
||||
{"SESSION_EVENT_OPENING", SESSION_EVENT_OPENING},
|
||||
{"SESSION_EVENT_RAWPKT", SESSION_EVENT_RAWPKT},
|
||||
{"SESSION_EVENT_ORDPKT", SESSION_EVENT_ORDPKT},
|
||||
{"SESSION_EVENT_META", SESSION_EVENT_META},
|
||||
{"SESSION_EVENT_CLOSING", SESSION_EVENT_CLOSING},
|
||||
{"SESSION_EVENT_ALL", SESSION_EVENT_ALL},
|
||||
};
|
||||
|
||||
enum session_event_type session_event_type_str2int(const char *evtype_str)
|
||||
|
||||
@@ -38,8 +38,9 @@ char *safe_dup(const char *str);
|
||||
enum plugin_manager_log_level
|
||||
{
|
||||
DEBUG = 0x11,
|
||||
INFO = 0x12,
|
||||
ERROR = 0x13,
|
||||
WARN = 0x12,
|
||||
INFO = 0x13,
|
||||
ERROR = 0x14,
|
||||
};
|
||||
|
||||
#ifndef plugin_manager_log
|
||||
@@ -51,6 +52,10 @@ enum plugin_manager_log_level
|
||||
fprintf(stdout, "PLUGIN_MANAGER [DEBUG] " format "\n", ##__VA_ARGS__); \
|
||||
fflush(stdout); \
|
||||
break; \
|
||||
case WARN: \
|
||||
fprintf(stdout, "PLUGIN_MANAGER [WARN] " format "\n", ##__VA_ARGS__); \
|
||||
fflush(stdout); \
|
||||
break; \
|
||||
case INFO: \
|
||||
fprintf(stdout, "PLUGIN_MANAGER [INFO] " format "\n", ##__VA_ARGS__); \
|
||||
fflush(stdout); \
|
||||
|
||||
Reference in New Issue
Block a user