new message_set functions

FossilOrigin-Name: 8cdf87be9882ec0526b09102abf4e54cbfb944aac8eae0ca0e47af66b80b0b9a
This commit is contained in:
7u83@mail.ru 2018-02-23 23:30:44 +00:00
parent fbbc21b728
commit dcbbaf28a6
9 changed files with 162 additions and 7 deletions

View File

@ -21,6 +21,7 @@
<File Name="src/ac/ac.h"/>
<File Name="src/ac/dataman.h"/>
<File Name="src/ac/socklist.h"/>
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

View File

@ -303,6 +303,8 @@
<File Name="src/cw/avltree_foreach_rl.c"/>
<File Name="src/cw/cw_out_radio_info.c"/>
<File Name="src/cw/capwap_items.c"/>
<File Name="src/cw/message_set.c"/>
<File Name="src/cw/message_set.h"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

View File

@ -6,7 +6,6 @@
<File Name="src/mod/capwap/capwap_out_ac_ip_list.c"/>
<File Name="src/mod/capwap/capwap_out_wtp_descriptor.c"/>
<File Name="src/mod/capwap/capwap_actions.h"/>
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
<File Name="src/mod/capwap/mod_capwap_ac.c"/>
<File Name="src/mod/capwap/capwap_in_wtp_board_data.c"/>
<File Name="src/mod/capwap/capwap_actions_wtp.c"/>

View File

@ -92,9 +92,17 @@ extern struct mod_ac * cw_get_mod_ac(const char *name);
#include "cw/mlist.h"
extern void test_sets();
int main(int argc, char *argv[])
{
int rc = 0;
/* parse arguments */
@ -117,6 +125,10 @@ int main(int argc, char *argv[])
developers is turned on ;) */
DBGX("Attention! %s", "DBG X is ON!");
test_sets();
exit(0);
/* Initialize the database */
if (!db_init())

View File

@ -85,6 +85,7 @@ MAVLOBJS= \
mlist.o \
cw_load_file.o \
cw_save_file.o \
message_set.o

View File

@ -115,6 +115,7 @@ typedef struct {
int type;
int * states;
cw_messagedef_t * elements;
const char * name;
}cw_message_t;
typedef struct {
@ -127,10 +128,10 @@ typedef struct {
const char * name;
}cw_message_element_t;
typefe struct {
}cw_message_set;
typedef struct {
mavl_t messages;
mavl_t all_elems;
}cw_message_set_t;

View File

@ -1,5 +1,118 @@
#include "cw.h"
#include "mavl.h"
#include "message_set.h"
struct message_search_elem{
cw_messagedef_t *message;
mavl_t elements_tree;
mlist_t elements_list;
};
void cw_message_set_create(){
static inline int cmp_cw_message_element(const void *elem1, const void *elem2){
cw_message_element_t * e1 = (cw_message_element_t*)elem1;
cw_message_element_t * e2 = (cw_message_element_t*)elem2;
int r;
r = e1->id - e2->id;
if (r!=0)
return r;
r = e1->vendor - e2->vendor;
if (r!=0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
return 0;
}
static inline int msg_cmp(const void *elem1, const void *elem2)
{
/* struct cw_action_in *e1 = (struct cw_action_in *) elem1;
struct cw_action_in *e2 = (struct cw_action_in *) elem2;
int r;
r = e1->capwap_state - e2->capwap_state;
if (r != 0)
return r;
r = e1->msg_id - e2->msg_id;
if (r != 0)
return r;
r = e1->elem_id - e2->elem_id;
if (r != 0)
return r;
r = e1->vendor_id - e2->vendor_id;
if (r != 0)
return r;
r = e1->proto - e2->proto;
if (r != 0)
return r;
*/
return 0;
}
void cw_message_set_destroy(cw_message_set_t * set){
if (set->messages){
mavl_destroy(set->messages);
}
if (set->all_elems){
mavl_destroy(set->all_elems);
}
free(set);
}
cw_message_set_t * cw_message_set_create(){
/* allocate memory for a message_set */
cw_message_set_t * set = malloc(sizeof(cw_message_set_t));
if (set==NULL)
return NULL;
memset(set,0,sizeof(cw_message_set_t));
/* create mavl for all_elems */
set->all_elems = mavl_create(cmp_cw_message_element,NULL);
if (set->all_elems==NULL){
cw_message_set_destroy(set);
return NULL;
}
/* create mavl for messages */
set->messages = mavl_create(msg_cmp,NULL);
if (set->messages==NULL){
cw_message_set_destroy(set);
return NULL;
}
return set;
}
void cw_message_set_add(cw_message_set_t * set,
cw_message_t * messages,
cw_message_element_t * elements[]){
cw_message_element_t ** e;
for (e=elements; e->id!=0; e++){
// mavl_add(set->all_elems, e);
printf("Add: %d %d %d %s\n",
e->proto,
e->vendor,
e->id,
e->name
);
}
}

View File

@ -0,0 +1,11 @@
#ifndef __MESSAGE_SET_H
#define __MESSAGE_SET_H
#include "cw.h"
extern void cw_message_set_destroy(cw_message_set_t * set);
extern cw_message_set_t * cw_message_set_create();
extern void cw_message_set_add(cw_message_set_t * set,
cw_message_t * messages,
cw_message_element_t * elements[]);
#endif

View File

@ -18,11 +18,13 @@
#include "cw/cw.h"
#include "cw/log.h"
#include "cw/action.h"
#include "cw/capwap_items.h"
#include "cw/strheap.h"
#include "cw/radio.h"
#include "cw/message_set.h"
#include "mod_capwap.h"
@ -37,12 +39,14 @@ static cw_message_element_t elements[] = {
},
{
.id = CAPWAP_ELEM_WTP_BOARD_DATA,
.name = "WTP Board Data",
// .start = cw_in_wtp_board_data,
// .item_id = CW_ITEM_WTP_BOARD_DATA,
},
{
.id = CAPWAP_ELEM_WTP_DESCRIPTOR,
.name = "WTP Descriptor",
//.start = capwap_in_wtp_descriptor,
//.item_id = "wtp_descriptor",
@ -50,12 +54,14 @@ static cw_message_element_t elements[] = {
,
{
.id = CW_ELEM_WTP_FRAME_TUNNEL_MODE,
.name = "WTP Frame Tunnel Mode",
// .start = cw_in_generic2,
// .item_id = CW_ITEM_WTP_FRAME_TUNNEL_MODE,
.min_len = 1,
.max_len = 1
}
,
{.id=0}
};
static cw_message_t messages[] = {
@ -73,7 +79,16 @@ static cw_message_t messages[] = {
}
};
void test_sets(){
cw_message_set_t * set = cw_message_set_create();
if (set==NULL){
cw_log(LOG_ERR,"No mem");
return;
}
cw_message_set_add(set,messages,&elements);
}