feat(infra/exdata): exdata as independent component

This commit is contained in:
yangwei
2024-09-06 18:36:24 +08:00
parent 3de8bbdabc
commit a24214cbee
12 changed files with 270 additions and 177 deletions

View File

@@ -1,4 +1,4 @@
set(INFRA tuple packet_parser packet_io ip_reassembly tcp_reassembly session_manager plugin_manager) set(INFRA exdata tuple packet_parser packet_io ip_reassembly tcp_reassembly session_manager plugin_manager)
set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml) set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml)
#set(DECODERS http lpi) #set(DECODERS http lpi)
set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS}) set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS})

View File

@@ -0,0 +1,3 @@
add_library(exdata exdata.c)
#add_subdirectory(test)

154
infra/exdata/exdata.c Normal file
View File

@@ -0,0 +1,154 @@
#include "stellar/utils.h"
#include "exdata_internal.h"
/*******************************
* STELLAR EXDATA SCHEMA API*
*******************************/
struct exdata_schema *exdata_schema_new()
{
struct exdata_schema *s = CALLOC(struct exdata_schema, 1);
return s;
}
void exdata_schema_free(struct exdata_schema *s)
{
if(s==NULL)return;
if(s->exdata_meta_array)
{
utarray_free(s->exdata_meta_array);
}
FREE(s);
}
int exdata_schema_get_idx_by_name(struct exdata_schema *schema, const char *name)
{
if(schema==NULL || schema->exdata_meta_array == NULL || name == NULL)return -1;
unsigned int len = utarray_len(schema->exdata_meta_array);
struct exdata_meta *t_schema;
for(unsigned int i = 0; i < len; i++)
{
t_schema = (struct exdata_meta *)utarray_eltptr(schema->exdata_meta_array, i);
if(strcmp(t_schema->name, name) == 0)
{
return t_schema->idx;
}
}
return -1;
}
static void stellar_exdata_met_copy(void *_dst, const void *_src)
{
struct exdata_meta *dst = (struct exdata_meta *)_dst, *src = (struct exdata_meta *)_src;
dst->free_func = src->free_func;
dst->free_arg = src->free_arg;
dst->idx = src->idx;
dst->name = src->name ? strdup(src->name) : NULL;
}
static void stellar_exdata_met_dtor(void *_elt)
{
struct exdata_meta *elt = (struct exdata_meta *)_elt;
if (elt->name)
FREE(elt->name);
}
UT_icd stellar_exdata_meta_icd = {sizeof(struct exdata_meta), NULL, stellar_exdata_met_copy, stellar_exdata_met_dtor};
int exdata_new_index(struct exdata_schema *s, const char *name, exdata_free *free_func,void *free_arg)
{
if(s==NULL || name==NULL)return -1;
if(s->exdata_meta_array == NULL)
{
utarray_new(s->exdata_meta_array, &stellar_exdata_meta_icd);
}
if(s->exdata_meta_array == NULL)return -1;
unsigned int len = utarray_len(s->exdata_meta_array);
struct exdata_meta *t_schema;
for(unsigned int i = 0; i < len; i++)
{
t_schema = (struct exdata_meta *)utarray_eltptr(s->exdata_meta_array, i);
if(strcmp(t_schema->name, name) == 0)
{
t_schema->free_func=free_func;
t_schema->free_arg=free_arg;
return t_schema->idx;
}
}
struct exdata_meta new_schema;
memset(&new_schema, 0, sizeof(struct exdata_schema));
new_schema.free_func=free_func;
new_schema.name=(char *)name;
new_schema.idx=len;
new_schema.free_arg=free_arg;
utarray_push_back(s->exdata_meta_array, &new_schema);
return new_schema.idx;
}
/*******************************
* STELLAR EXDATA HANDLE API *
*******************************/
struct exdata_handle *exdata_handle_new(struct exdata_schema *s)
{
if(s==NULL || s->exdata_meta_array==NULL)return NULL;
struct exdata_handle *h = CALLOC(struct exdata_handle, 1);
h->schema=s;
unsigned int len = utarray_len(s->exdata_meta_array);
if(len > 0)
{
h->exdata_array=CALLOC(struct exdata, len);
}
return h;
}
void exdata_handle_reset(struct exdata_handle *h)
{
if(h==NULL||h->schema==NULL||h->exdata_array==NULL)return;
unsigned int len=utarray_len(h->schema->exdata_meta_array);
for (unsigned int i = 0; i < len; i++)
{
void *exdata = (h->exdata_array + i)->exdata;
(h->exdata_array + i)->state=EXIT;
struct exdata_meta *schema = (struct exdata_meta *)utarray_eltptr(h->schema->exdata_meta_array, i);
if (exdata)
{
if (schema->free_func)
{
schema->free_func(i, exdata, schema->free_arg);
(h->exdata_array + i)->exdata=NULL;
}
}
(h->exdata_array + i)->state=INIT;
}
return;
}
void exdata_handle_free(struct exdata_handle *h)
{
if(h==NULL)return;
exdata_handle_reset(h);
if(h->exdata_array)FREE(h->exdata_array);
FREE(h);
}
int exdata_set(struct exdata_handle *h, int idx, void *ex_ptr)
{
if(h==NULL || h->schema == NULL|| h->exdata_array == NULL)return -1;
unsigned int len=utarray_len(h->schema->exdata_meta_array);
if(len < (unsigned int)idx)return -1;
if((h->exdata_array+idx)->state == EXIT)return -1;
(h->exdata_array+idx)->exdata=ex_ptr;
return 0;
}
void *exdata_get(struct exdata_handle *h, int idx)
{
if(h==NULL || h->schema == NULL|| h->exdata_array == NULL)return NULL;
unsigned int len = utarray_len(h->schema->exdata_meta_array);
if(len < (unsigned int)idx)return NULL;
if((h->exdata_array+idx)->state == EXIT)return NULL;
return (h->exdata_array+idx)->exdata;
}

22
infra/exdata/exdata.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
typedef void exdata_free(int idx, void *ex_ptr, void *arg);
struct exdata_schema;
struct exdata_schema *exdata_schema_new();
void exdata_schema_free(struct exdata_schema *s);
int exdata_new_index(struct exdata_schema *schema, const char *name, exdata_free *free_func,void *free_arg);
int exdata_schema_get_idx_by_name(struct exdata_schema *schema, const char *name);
struct exdata_handle;
struct exdata_handle *exdata_handle_new(struct exdata_schema *h);
void exdata_handle_free(struct exdata_handle *h);
void exdata_handle_reset(struct exdata_handle *h);
int exdata_set(struct exdata_handle *h, int idx, void *ex_ptr);
void *exdata_get(struct exdata_handle *h, int idx);

View File

@@ -0,0 +1,35 @@
#pragma once
#include "uthash/utarray.h"
#include "exdata.h"
struct exdata_schema
{
UT_array *exdata_meta_array;
};
struct exdata_meta
{
char *name;
exdata_free *free_func;
void *free_arg;
int idx;
}__attribute__((aligned(sizeof(void*))));
enum exdata_state
{ INIT, ACTIVE, EXIT };
struct exdata
{
void *exdata;
enum exdata_state state;
};
struct exdata_handle
{
struct exdata_schema *schema;
struct exdata *exdata_array;
};

View File

@@ -6,6 +6,6 @@ target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/packe
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/session_manager) target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/session_manager)
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/tuple) target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/infra/tuple)
target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/deps/) target_include_directories(plugin_manager PUBLIC ${CMAKE_SOURCE_DIR}/deps/)
target_link_libraries(plugin_manager session_manager bitmap toml ${CMAKE_DL_LIBS}) target_link_libraries(plugin_manager PUBLIC session_manager bitmap toml exdata ${CMAKE_DL_LIBS})
add_subdirectory(test) add_subdirectory(test)

View File

@@ -1,5 +1,5 @@
#include "plugin_manager_interna.h" #include "plugin_manager_interna.h"
#include "stellar/session.h" #include "stellar/stellar_exdata.h"
#include "stellar/utils.h" #include "stellar/utils.h"
#include "toml/toml.h" #include "toml/toml.h"
#include "uthash/utlist.h" #include "uthash/utlist.h"
@@ -10,7 +10,6 @@
#include "packet_private.h" #include "packet_private.h"
#include "session_private.h" #include "session_private.h"
#include <stdbool.h>
void stellar_per_stage_message_counter_incby(struct plugin_manager_schema *plug_mgr, int tid, long long increment) void stellar_per_stage_message_counter_incby(struct plugin_manager_schema *plug_mgr, int tid, long long increment)
{ {
@@ -104,7 +103,7 @@ static void plugin_manager_per_thread_data_free(struct plugin_manager_per_thread
for (int i = 0; i < thread_num; i++) for (int i = 0; i < thread_num; i++)
{ {
p_data=per_thread_data+i; p_data=per_thread_data+i;
if(p_data->per_thread_pkt_exdata_array.exdata_array)FREE(p_data->per_thread_pkt_exdata_array.exdata_array); exdata_handle_free(p_data->exdata_array);
} }
FREE(per_thread_data); FREE(per_thread_data);
return; return;
@@ -129,6 +128,8 @@ struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char
plug_mgr->st = st; plug_mgr->st = st;
stellar_set_plugin_manger(st, plug_mgr); stellar_set_plugin_manger(st, plug_mgr);
plug_mgr->exdata_schema=exdata_schema_new();
for(int i = 0; i < spec_num; i++) for(int i = 0; i < spec_num; i++)
{ {
if (specs[i].load_cb != NULL) if (specs[i].load_cb != NULL)
@@ -163,7 +164,7 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
} }
utarray_free(plug_mgr->stellar_mq_schema_array); utarray_free(plug_mgr->stellar_mq_schema_array);
} }
if(plug_mgr->stellar_exdata_schema_array)utarray_free(plug_mgr->stellar_exdata_schema_array); //if(plug_mgr->stellar_exdata_schema_array)utarray_free(plug_mgr->stellar_exdata_schema_array);
if(plug_mgr->registered_polling_plugin_array)utarray_free(plug_mgr->registered_polling_plugin_array); if(plug_mgr->registered_polling_plugin_array)utarray_free(plug_mgr->registered_polling_plugin_array);
if(plug_mgr->registered_packet_plugin_array) if(plug_mgr->registered_packet_plugin_array)
{ {
@@ -175,6 +176,7 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
utarray_free(plug_mgr->registered_packet_plugin_array); utarray_free(plug_mgr->registered_packet_plugin_array);
} }
plugin_manager_per_thread_data_free(plug_mgr->per_thread_data, plug_mgr->st); plugin_manager_per_thread_data_free(plug_mgr->per_thread_data, plug_mgr->st);
exdata_schema_free(plug_mgr->exdata_schema);
FREE(plug_mgr); FREE(plug_mgr);
return; return;
} }
@@ -183,124 +185,47 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
* STELLAR EXDATA * * STELLAR EXDATA *
*******************************/ *******************************/
static void stellar_exdata_met_copy(void *_dst, const void *_src)
{
struct stellar_exdata_schema *dst = (struct stellar_exdata_schema *)_dst, *src = (struct stellar_exdata_schema *)_src;
dst->free_func = src->free_func;
dst->free_arg = src->free_arg;
dst->idx = src->idx;
dst->name = src->name ? strdup(src->name) : NULL;
}
static void stellar_exdata_met_dtor(void *_elt)
{
struct stellar_exdata_schema *elt = (struct stellar_exdata_schema *)_elt;
if (elt->name)
FREE(elt->name);
}
UT_icd stellar_exdata_meta_icd = {sizeof(struct stellar_exdata_schema), NULL, stellar_exdata_met_copy, stellar_exdata_met_dtor};
int stellar_exdata_new_index(struct stellar *st, const char *name, stellar_exdata_free *free_func,void *free_arg) int stellar_exdata_new_index(struct stellar *st, const char *name, stellar_exdata_free *free_func,void *free_arg)
{ {
if(st==NULL || name==NULL)return -1; if(st==NULL || name==NULL)return -1;
struct plugin_manager_schema *plug_mgr = stellar_get_plugin_manager(st); struct plugin_manager_schema *plug_mgr = stellar_get_plugin_manager(st);
if(plug_mgr->stellar_exdata_schema_array == NULL) if(plug_mgr->exdata_schema==NULL)return -1;
{ return exdata_new_index(plug_mgr->exdata_schema, name, free_func, free_arg);
utarray_new(plug_mgr->stellar_exdata_schema_array, &stellar_exdata_meta_icd);
}
if(plug_mgr->stellar_exdata_schema_array == NULL)return -1;
unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array);
struct stellar_exdata_schema *t_schema;
for(unsigned int i = 0; i < len; i++)
{
t_schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->stellar_exdata_schema_array, i);
if(strcmp(t_schema->name, name) == 0)
{
t_schema->free_func=free_func;
t_schema->free_arg=free_arg;
return t_schema->idx;
}
}
struct stellar_exdata_schema new_schema;
memset(&new_schema, 0, sizeof(struct stellar_exdata_schema));
new_schema.free_func=free_func;
new_schema.name=(char *)name;
new_schema.idx=len;
new_schema.free_arg=free_arg;
utarray_push_back(plug_mgr->stellar_exdata_schema_array, &new_schema);
return new_schema.idx;
}
int stellar_exdata_set(UT_array *exdata_schema, struct stellar_exdata *exdata_array, int idx, void *ex_ptr)
{
if(exdata_schema == NULL|| exdata_array == NULL)return -1;
unsigned int len=utarray_len(exdata_schema);
if(len < (unsigned int)idx)return -1;
if((exdata_array+idx)->state == EXIT)return -1;
(exdata_array+idx)->exdata=ex_ptr;
return 0;
}
void *stellar_exdata_get(UT_array *exdata_schema, struct stellar_exdata *exdata_array, int idx)
{
if(exdata_schema == NULL|| exdata_array == NULL)return NULL;
unsigned int len = utarray_len(exdata_schema);
if(len < (unsigned int)idx)return NULL;
if((exdata_array+idx)->state == EXIT)return NULL;
return (exdata_array+idx)->exdata;
} }
/******************************* /*******************************
* PACKET EXDATA * * PACKET EXDATA *
*******************************/ *******************************/
static struct stellar_exdata *per_thread_packet_exdata_arrary_get(struct plugin_manager_schema *plug_mgr) static struct exdata_handle *per_thread_packet_exdata_arrary_get(struct plugin_manager_schema *plug_mgr)
{ {
if(plug_mgr==NULL || plug_mgr->stellar_exdata_schema_array == NULL)return NULL; if(plug_mgr==NULL || plug_mgr->exdata_schema == NULL)return NULL;
int tid=stellar_get_current_thread_index(); int tid=stellar_get_current_thread_index();
if(plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array == NULL) if(plug_mgr->per_thread_data[tid].exdata_array == NULL)
{ {
unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array); plug_mgr->per_thread_data[tid].exdata_array = exdata_handle_new(plug_mgr->exdata_schema);
plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array = CALLOC(struct stellar_exdata, len);
} }
return plug_mgr->per_thread_data[tid].per_thread_pkt_exdata_array.exdata_array; return plug_mgr->per_thread_data[tid].exdata_array;
} }
static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr) static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr)
{ {
if(plug_mgr==NULL || plug_mgr->stellar_exdata_schema_array == NULL)return; if(plug_mgr==NULL || plug_mgr->exdata_schema == NULL)return;
unsigned int len=utarray_len(plug_mgr->stellar_exdata_schema_array); struct exdata_handle *per_thread_exdata_handle = per_thread_packet_exdata_arrary_get(plug_mgr);
struct stellar_exdata *per_thread_pkt_exdata_arrary = per_thread_packet_exdata_arrary_get(plug_mgr); return exdata_handle_reset(per_thread_exdata_handle);
if(per_thread_pkt_exdata_arrary == NULL)return;
for (unsigned int i = 0; i < len; i++)
{
void *exdata = (per_thread_pkt_exdata_arrary + i)->exdata;
(per_thread_pkt_exdata_arrary + i)->state=EXIT;
struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(plug_mgr->stellar_exdata_schema_array, i);
if (exdata)
{
if (schema->free_func)
{
schema->free_func(i, exdata, schema->free_arg);
}
(per_thread_pkt_exdata_arrary + i)->exdata=NULL;
}
(per_thread_pkt_exdata_arrary + i)->state=INIT;
}
} }
int packet_exdata_set(struct packet *pkt, int idx, void *ex_ptr) int packet_exdata_set(struct packet *pkt, int idx, void *ex_ptr)
{ {
if(pkt == NULL)return -1; if(pkt == NULL)return -1;
struct plugin_manager_schema *plug_mgr = (struct plugin_manager_schema *)packet_get_user_data(pkt); struct plugin_manager_schema *plug_mgr = (struct plugin_manager_schema *)packet_get_user_data(pkt);
return stellar_exdata_set(plug_mgr->stellar_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx, ex_ptr); return exdata_set(per_thread_packet_exdata_arrary_get(plug_mgr), idx, ex_ptr);
} }
void *packet_exdata_get(struct packet *pkt, int idx) void *packet_exdata_get(struct packet *pkt, int idx)
{ {
if(pkt == NULL)return NULL; if(pkt == NULL)return NULL;
struct plugin_manager_schema *plug_mgr = (struct plugin_manager_schema *)packet_get_user_data(pkt); struct plugin_manager_schema *plug_mgr = (struct plugin_manager_schema *)packet_get_user_data(pkt);
return stellar_exdata_get( plug_mgr->stellar_exdata_schema_array, per_thread_packet_exdata_arrary_get(plug_mgr), idx); return exdata_get( per_thread_packet_exdata_arrary_get(plug_mgr), idx);
} }
/******************************* /*******************************
@@ -309,18 +234,16 @@ void *packet_exdata_get(struct packet *pkt, int idx)
int session_exdata_set(struct session *sess, int idx, void *ex_ptr) int session_exdata_set(struct session *sess, int idx, void *ex_ptr)
{ {
struct stellar_exdata *sess_exdata_array = (struct stellar_exdata *)session_get_user_data(sess); struct exdata_handle *sess_exdata = (struct exdata_handle *)session_get_user_data(sess);
if(sess_exdata_array == NULL)return -1; if(sess_exdata == NULL)return -1;
if(sess_exdata_array->plug_mgr->stellar_exdata_schema_array == NULL)return -1; return exdata_set(sess_exdata,idx, ex_ptr);
return stellar_exdata_set(sess_exdata_array->plug_mgr->stellar_exdata_schema_array, sess_exdata_array, idx, ex_ptr);
} }
void *session_exdata_get(struct session *sess, int idx) void *session_exdata_get(struct session *sess, int idx)
{ {
struct stellar_exdata *sess_exdata_array = (struct stellar_exdata *)session_get_user_data(sess); struct exdata_handle *sess_exdata = (struct exdata_handle *)session_get_user_data(sess);
if(sess_exdata_array == NULL)return NULL; if(sess_exdata == NULL)return NULL;
if(sess_exdata_array->plug_mgr->stellar_exdata_schema_array==NULL)return NULL; return exdata_get(sess_exdata, idx);
return stellar_exdata_get(sess_exdata_array->plug_mgr->stellar_exdata_schema_array, sess_exdata_array, idx);
} }
/******************************* /*******************************
@@ -588,39 +511,15 @@ int stellar_mq_publish_message(struct stellar *st, int topic_id, void *data)
/******************************* /*******************************
* PLUGIN MANAGER SESSION RUNTIME * * PLUGIN MANAGER SESSION RUNTIME *
*******************************/ *******************************/
struct stellar_exdata *session_exdata_runtime_new(struct stellar *st) struct exdata_handle *session_exdata_runtime_new(struct stellar *st)
{ {
struct stellar_exdata *exdata_rt = NULL;
struct plugin_manager_schema *plug_mgr=stellar_get_plugin_manager(st); struct plugin_manager_schema *plug_mgr=stellar_get_plugin_manager(st);
if(plug_mgr->stellar_exdata_schema_array==NULL)return NULL; return exdata_handle_new(plug_mgr->exdata_schema);
unsigned int len = utarray_len(plug_mgr->stellar_exdata_schema_array);
if(len > 0)
{
exdata_rt=CALLOC(struct stellar_exdata, len);
exdata_rt->plug_mgr=plug_mgr; // TODO: temporarily set plug_mgr in exdata[0]
}
return exdata_rt;
} }
void session_exdata_runtime_free(struct stellar_exdata *exdata_rt) void session_exdata_runtime_free(struct exdata_handle *exdata_h)
{ {
if(exdata_rt==NULL || exdata_rt->plug_mgr == NULL)return; return exdata_handle_free(exdata_h);
if(exdata_rt->plug_mgr->stellar_exdata_schema_array==NULL)return;
unsigned int len=utarray_len(exdata_rt->plug_mgr->stellar_exdata_schema_array);
for (unsigned int i = 0; i < len; i++)
{
void *exdata = (exdata_rt + i)->exdata;
(exdata_rt + i)->state=EXIT;
struct stellar_exdata_schema *schema = (struct stellar_exdata_schema *)utarray_eltptr(exdata_rt->plug_mgr->stellar_exdata_schema_array, i);
if (exdata)
{
if (schema->free_func)
{
schema->free_func(i, exdata, schema->free_arg);
}
}
}
FREE(exdata_rt);
} }

View File

@@ -20,9 +20,9 @@ void plugin_manager_on_packet_output(struct plugin_manager_schema *plug_mgr, str
//return polling work state, 0: idle, 1: working //return polling work state, 0: idle, 1: working
int plugin_manager_on_polling(struct plugin_manager_schema *plug_mgr); int plugin_manager_on_polling(struct plugin_manager_schema *plug_mgr);
struct stellar_exdata; struct exdata_handle;
struct stellar_exdata *session_exdata_runtime_new(struct stellar *st); struct exdata_handle *session_exdata_runtime_new(struct stellar *st);
void session_exdata_runtime_free(struct stellar_exdata *exdata_rt); void session_exdata_runtime_free(struct exdata_handle *exdata_h);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -9,20 +9,16 @@ extern "C"
#include "stellar/stellar.h" #include "stellar/stellar.h"
#include "stellar/stellar_mq.h" #include "stellar/stellar_mq.h"
#include "stellar/stellar_exdata.h"
#include "uthash/utarray.h" #include "uthash/utarray.h"
#include "exdata/exdata.h"
struct stellar_message; struct stellar_message;
struct per_thread_exdata_array
{
struct stellar_exdata *exdata_array;
};
struct plugin_manager_per_thread_data struct plugin_manager_per_thread_data
{ {
struct per_thread_exdata_array per_thread_pkt_exdata_array; struct exdata_handle *exdata_array;
struct stellar_message *priority_mq[STELLAR_MQ_PRIORITY_MAX];// message list struct stellar_message *priority_mq[STELLAR_MQ_PRIORITY_MAX];// message list
struct stellar_message *dealth_letter_queue;// dlq list struct stellar_message *dealth_letter_queue;// dlq list
unsigned long long pub_packet_msg_cnt; unsigned long long pub_packet_msg_cnt;
@@ -32,7 +28,7 @@ struct plugin_manager_schema
{ {
struct stellar *st; struct stellar *st;
UT_array *plugin_load_specs_array; UT_array *plugin_load_specs_array;
UT_array *stellar_exdata_schema_array; struct exdata_schema *exdata_schema;
UT_array *stellar_mq_schema_array; UT_array *stellar_mq_schema_array;
UT_array *registered_packet_plugin_array; UT_array *registered_packet_plugin_array;
UT_array *registered_polling_plugin_array; UT_array *registered_polling_plugin_array;
@@ -43,26 +39,6 @@ struct plugin_manager_schema
}__attribute__((aligned(sizeof(void*)))); }__attribute__((aligned(sizeof(void*))));
enum plugin_exdata_state
{ INIT, ACTIVE, EXIT };
struct stellar_exdata
{
struct plugin_manager_schema *plug_mgr;
void *exdata;
enum plugin_exdata_state state;
};
struct stellar_exdata_schema
{
char *name;
stellar_exdata_free *free_func;
void *free_arg;
int idx;
}__attribute__((aligned(sizeof(void*))));
struct stellar_message struct stellar_message
{ {
struct stellar *st; struct stellar *st;

View File

@@ -2,6 +2,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "stellar/utils.h" #include "stellar/utils.h"
#include "stellar/stellar_exdata.h"
#include "exdata/exdata_internal.h"
#include "plugin_manager_gtest_mock.h" #include "plugin_manager_gtest_mock.h"
@@ -20,7 +23,7 @@ void whitebox_test_plugin_manager_intrisic_metadata(struct stellar *st, struct p
EXPECT_TRUE(plug_mgr->plugin_load_specs_array==NULL); EXPECT_TRUE(plug_mgr->plugin_load_specs_array==NULL);
//session exdata schema null //session exdata schema null
EXPECT_TRUE(plug_mgr->stellar_exdata_schema_array==NULL); EXPECT_TRUE(plug_mgr->exdata_schema!=NULL);
//stellar mq schema null //stellar mq schema null
EXPECT_TRUE(plug_mgr->stellar_mq_schema_array==NULL); EXPECT_TRUE(plug_mgr->stellar_mq_schema_array==NULL);
@@ -33,7 +36,7 @@ void whitebox_test_plugin_manager_intrisic_metadata(struct stellar *st, struct p
int thread_num=stellar_get_worker_thread_num(st); int thread_num=stellar_get_worker_thread_num(st);
for(int i=0; i<thread_num; i++) for(int i=0; i<thread_num; i++)
{ {
EXPECT_TRUE(plug_mgr->per_thread_data[i].per_thread_pkt_exdata_array.exdata_array==NULL); EXPECT_TRUE(plug_mgr->per_thread_data[i].exdata_array==NULL);
EXPECT_TRUE(plug_mgr->per_thread_data[i].dealth_letter_queue==NULL); EXPECT_TRUE(plug_mgr->per_thread_data[i].dealth_letter_queue==NULL);
for(int j=0; j<STELLAR_MQ_PRIORITY_MAX; j++) for(int j=0; j<STELLAR_MQ_PRIORITY_MAX; j++)
EXPECT_TRUE(plug_mgr->per_thread_data[i].priority_mq[j]==NULL); EXPECT_TRUE(plug_mgr->per_thread_data[i].priority_mq[j]==NULL);
@@ -76,14 +79,14 @@ TEST(plugin_manager_init, packet_exdata_new_index_overwrite) {
{ {
SCOPED_TRACE("White-box test, check stellar internal schema"); SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr( struct exdata_meta *exdata_schema = (struct exdata_meta *)utarray_eltptr(
plug_mgr->stellar_exdata_schema_array, (unsigned int)exdata_idx); plug_mgr->exdata_schema->exdata_meta_array, (unsigned int)exdata_idx);
EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_packet_exdata_free); EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_packet_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, plug_mgr); EXPECT_EQ(exdata_schema->free_arg, plug_mgr);
EXPECT_EQ(exdata_schema->idx, exdata_idx); EXPECT_EQ(exdata_schema->idx, exdata_idx);
EXPECT_STREQ(exdata_schema->name, exdata_name); EXPECT_STREQ(exdata_schema->name, exdata_name);
int exdata_num = utarray_len(plug_mgr->stellar_exdata_schema_array); int exdata_num = utarray_len(plug_mgr->exdata_schema->exdata_meta_array);
EXPECT_EQ(exdata_num, 1); EXPECT_EQ(exdata_num, 1);
} }
@@ -210,14 +213,14 @@ TEST(plugin_manager_init, session_exdata_new_index_overwrite) {
{ {
SCOPED_TRACE("White-box test, check stellar internal schema"); SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr( struct exdata_meta *exdata_schema = (struct exdata_meta *)utarray_eltptr(
plug_mgr->stellar_exdata_schema_array, (unsigned int)exdata_idx); plug_mgr->exdata_schema->exdata_meta_array, (unsigned int)exdata_idx);
EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_session_exdata_free); EXPECT_EQ(exdata_schema->free_func, (void *)test_mock_overwrite_session_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, plug_mgr); EXPECT_EQ(exdata_schema->free_arg, plug_mgr);
EXPECT_EQ(exdata_schema->idx, exdata_idx); EXPECT_EQ(exdata_schema->idx, exdata_idx);
EXPECT_STREQ(exdata_schema->name, exdata_name); EXPECT_STREQ(exdata_schema->name, exdata_name);
int exdata_num = utarray_len(plug_mgr->stellar_exdata_schema_array); int exdata_num = utarray_len(plug_mgr->exdata_schema->exdata_meta_array);
EXPECT_EQ(exdata_num, 1); EXPECT_EQ(exdata_num, 1);
} }
plugin_manager_exit(plug_mgr); plugin_manager_exit(plug_mgr);
@@ -497,8 +500,8 @@ TEST(plugin_manager, packet_plugins_share_exdata) {
env.packet_exdata_idx[i]=stellar_exdata_new_index(&st, exdata_name[i], test_packet_exdata_free, &env); env.packet_exdata_idx[i]=stellar_exdata_new_index(&st, exdata_name[i], test_packet_exdata_free, &env);
{ {
SCOPED_TRACE("White-box test, check stellar internal schema"); SCOPED_TRACE("White-box test, check stellar internal schema");
struct stellar_exdata_schema *exdata_schema = (struct stellar_exdata_schema *)utarray_eltptr( struct exdata_meta *exdata_schema = (struct exdata_meta *)utarray_eltptr(
plug_mgr->stellar_exdata_schema_array, env.packet_exdata_idx[i]); plug_mgr->exdata_schema->exdata_meta_array, env.packet_exdata_idx[i]);
EXPECT_EQ(exdata_schema->free_func, (void *)test_packet_exdata_free); EXPECT_EQ(exdata_schema->free_func, (void *)test_packet_exdata_free);
EXPECT_EQ(exdata_schema->free_arg, &env); EXPECT_EQ(exdata_schema->free_arg, &env);
@@ -509,7 +512,7 @@ TEST(plugin_manager, packet_plugins_share_exdata) {
{ {
SCOPED_TRACE("White-box test, check stellar internal schema"); SCOPED_TRACE("White-box test, check stellar internal schema");
EXPECT_EQ(utarray_len(plug_mgr->stellar_exdata_schema_array), exdata_idx_len); EXPECT_EQ(utarray_len(plug_mgr->exdata_schema->exdata_meta_array), exdata_idx_len);
} }
int exdata_set_plugin_id=stellar_plugin_register(&st, test_exdata_set_on_packet, NULL,&env); int exdata_set_plugin_id=stellar_plugin_register(&st, test_exdata_set_on_packet, NULL,&env);

View File

@@ -9,6 +9,7 @@ extern "C"
#include "stellar/session.h" #include "stellar/session.h"
#include "tuple.h" #include "tuple.h"
#include "exdata/exdata.h"
//mock stellar //mock stellar
struct stellar struct stellar
@@ -37,7 +38,7 @@ struct packet
struct session struct session
{ {
struct stellar_exdata *session_exdat_rt; struct exdata_handle *session_exdat_rt;
enum session_type type; enum session_type type;
enum session_state state; enum session_state state;
int sess_pkt_cnt; int sess_pkt_cnt;
@@ -77,7 +78,7 @@ enum session_type session_get_type(const struct session *sess)
void session_set_user_data(struct session *sess, void *user_data) void session_set_user_data(struct session *sess, void *user_data)
{ {
sess->session_exdat_rt = (struct stellar_exdata *)user_data; sess->session_exdat_rt = (struct exdata_handle *)user_data;
} }
void *session_get_user_data(const struct session *sess) void *session_get_user_data(const struct session *sess)

View File

@@ -206,8 +206,8 @@ static void *worker_thread(void *arg)
{ {
goto fast_path; goto fast_path;
} }
struct stellar_exdata *per_sess_exdata_rt=session_exdata_runtime_new(plug_mgr); struct exdata_handle *per_sess_exdata=session_exdata_runtime_new(st);
session_set_user_data(sess, per_sess_exdata_rt); session_set_user_data(sess, per_sess_exdata);
} }
else else
{ {
@@ -448,7 +448,7 @@ struct stellar *stellar_new(const char *stellar_cfg_file, const char *plugin_cfg
CORE_LOG_ERROR("unable to create stellar stat"); CORE_LOG_ERROR("unable to create stellar stat");
goto error_out; goto error_out;
} }
runtime->plug_mgr = plugin_manager_init(st, plugin_cfg_file); runtime->plug_mgr = plugin_manager_init(st, plugin_cfg_file, MAX_MSG_PER_STAGE);
if (runtime->plug_mgr == NULL) if (runtime->plug_mgr == NULL)
{ {
CORE_LOG_ERROR("unable to create plugin manager"); CORE_LOG_ERROR("unable to create plugin manager");