rename fn_session_event_callback to plugin_event_callback and update API parameters
* plugin_event_callback delete 'struct stellar_packet *p'
* plugin_event_callback rename 'uint16_t len' to 'size_t len'
* plugin_event_callback rename 'void **pme' to 'void **ctx'
This commit is contained in:
@@ -9,72 +9,72 @@
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
static void *custom_decode(const char *payload, uint16_t len, void **pme)
|
||||
static void *custom_decode(const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct tcp_session_pme
|
||||
struct tcp_session_ctx
|
||||
{
|
||||
char data[16];
|
||||
/* data */
|
||||
};
|
||||
|
||||
struct custom_session_pme
|
||||
struct custom_session_ctx
|
||||
{
|
||||
char data[16];
|
||||
/* data */
|
||||
};
|
||||
|
||||
static struct tcp_session_pme *tcp_session_pme_create()
|
||||
static struct tcp_session_ctx *tcp_session_ctx_create()
|
||||
{
|
||||
struct tcp_session_pme *pme = (struct tcp_session_pme *)calloc(1, sizeof(struct tcp_session_pme));
|
||||
return pme;
|
||||
struct tcp_session_ctx *ctx = (struct tcp_session_ctx *)calloc(1, sizeof(struct tcp_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void tcp_session_pme_destory(struct tcp_session_pme *pme)
|
||||
static void tcp_session_ctx_destory(struct tcp_session_ctx *ctx)
|
||||
{
|
||||
if (pme)
|
||||
if (ctx)
|
||||
{
|
||||
free(pme);
|
||||
pme = NULL;
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static struct custom_session_pme *custom_session_pme_create()
|
||||
static struct custom_session_ctx *custom_session_ctx_create()
|
||||
{
|
||||
struct custom_session_pme *pme = (struct custom_session_pme *)calloc(1, sizeof(struct custom_session_pme));
|
||||
return pme;
|
||||
struct custom_session_ctx *ctx = (struct custom_session_ctx *)calloc(1, sizeof(struct custom_session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void custom_session_pme_destory(struct custom_session_pme *pme)
|
||||
static void custom_session_ctx_destory(struct custom_session_ctx *ctx)
|
||||
{
|
||||
if (pme)
|
||||
if (ctx)
|
||||
{
|
||||
free(pme);
|
||||
pme = NULL;
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme;
|
||||
struct tcp_session_ctx **per_tcp_session_ctx = (struct tcp_session_ctx **)ctx;
|
||||
|
||||
printf("RUN custom_event_plugin_tcp_entry, event: %d\n", event);
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_tcp_session_pme == NULL)
|
||||
if (*per_tcp_session_ctx == NULL)
|
||||
{
|
||||
struct tcp_session_pme *cur_ctx = tcp_session_pme_create();
|
||||
struct tcp_session_ctx *cur_ctx = tcp_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry"));
|
||||
*per_tcp_session_pme = *&cur_ctx;
|
||||
*per_tcp_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
|
||||
struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, ctx);
|
||||
struct stellar_session *new_session = session_manager_session_derive(session, "CUSTOM");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
@@ -83,29 +83,29 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
tcp_session_pme_destory(*per_tcp_session_pme);
|
||||
tcp_session_ctx_destory(*per_tcp_session_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx)
|
||||
{
|
||||
struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme;
|
||||
struct custom_session_ctx **per_custom_session_ctx = (struct custom_session_ctx **)ctx;
|
||||
|
||||
printf("RUN custom_event_plugin_custom_entry, event: %d\n", event);
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_custom_session_pme == NULL)
|
||||
if (*per_custom_session_ctx == NULL)
|
||||
{
|
||||
struct custom_session_pme *cur_ctx = custom_session_pme_create();
|
||||
struct custom_session_ctx *cur_ctx = custom_session_ctx_create();
|
||||
memcpy(cur_ctx->data, "custom_event_plugin_custom_entry", strlen("custom_event_plugin_custom_entry"));
|
||||
*per_custom_session_pme = *&cur_ctx;
|
||||
*per_custom_session_ctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
custom_session_pme_destory(*per_custom_session_pme);
|
||||
custom_session_ctx_destory(*per_custom_session_ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user