This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/sdk/example/custom_event_plugin.cpp
2022-08-02 18:50:17 +08:00

58 lines
1.5 KiB
C++

#include "session.h"
#include "packet.h"
#include "plugin.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
static char *g_handler = NULL;
static void *custom_decode(const char *payload, uint16_t len, void **pme)
{
return NULL;
}
extern "C" void custom_plugin_tcp_entry(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
{
char **per_session_pme = (char **)pme;
printf("RUN custom_plugin_tcp_entry, event: %d\n", event);
struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
struct stellar_session *new_session = session_manager_session_derive(s, "CUSTOM");
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
}
extern "C" void custom_plugin_custom_entry(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
{
char **per_session_pme = (char **)pme;
printf("RUN custom_plugin_custom_entry, event: %d\n", event);
}
extern "C" int custom_plugin_init(void)
{
printf("RUN custom_plugin_init\n");
if (g_handler == NULL)
{
g_handler = (char *)malloc(1024);
snprintf(g_handler, 1024, "222222");
}
return 0;
}
extern "C" void custom_plugin_exit(void)
{
printf("RUN custom_plugin_exit\n");
if (g_handler)
{
free(g_handler);
g_handler = NULL;
}
}