plugin_manager adapt session_manager API and rewrite plugin_manger gtest
This commit is contained in:
70
sdk/example/http_plugin.cpp
Normal file
70
sdk/example/http_plugin.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "session.h"
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct session_ctx
|
||||
{
|
||||
char data[64];
|
||||
};
|
||||
|
||||
static struct session_ctx *session_ctx_create()
|
||||
{
|
||||
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static void session_ctx_destory(struct session_ctx *ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
free(ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void http_plugin_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
|
||||
{
|
||||
struct session_ctx **sctx = (struct session_ctx **)ctx;
|
||||
|
||||
if (state & SESSION_STATE_OPENING)
|
||||
{
|
||||
if (*sctx == NULL)
|
||||
{
|
||||
struct session_ctx *cur_ctx = session_ctx_create();
|
||||
memcpy(cur_ctx->data, "http_plugin_entry", 17);
|
||||
*sctx = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_ACTIVE)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
if (state & SESSION_STATE_CLOSING)
|
||||
{
|
||||
session_ctx_destory(*sctx);
|
||||
*sctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int http_plugin_init(void)
|
||||
{
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void http_plugin_exit(void)
|
||||
{
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user