📄 macedon-declares.c
字号:
#ifdef ALLINONEHDR while (temp) { field = temp->fields; while (field) { if (!field->field_dupe) { if (!strcmp(field->field_size, "1")) fprintf(hfile, " %s %s%s;\n", field->field_type, field->field_name, field->field_init); else fprintf(hfile, " %s %s%s[%s];\n", field->field_type, field->field_name, field->field_init, field->field_size); } field = field->next; } temp = temp->next; }#endif fprintf(hfile, " static int offset_;\n"); fprintf(hfile, " inline static int& offset() { return offset_; }\n"); fprintf(hfile, " inline static hdr_%s* access(const Packet* p) {\n",protocol_name); fprintf(hfile, " return (hdr_%s*) p->access(offset_);\n", protocol_name); fprintf(hfile, " }\n"); fprintf(hfile, "};\n\n"); #ifndef ALLINONEHDR while (temp) { fprintf(hfile, "struct hdr_%s_%s\n", protocol_name, temp->simple_name); fprintf(hfile, "{\n"); fprintf(hfile, " struct macedon_fields %s_mf_;\n", protocol_name); fprintf(hfile, " static int offset_;\n"); fprintf(hfile, " inline static int& offset() { return offset_; }\n"); fprintf(hfile, " inline static hdr_%s* access(const Packet* p) {\n",protocol_name); fprintf(hfile, " return (hdr_%s*) p->access(offset_);\n", protocol_name); fprintf(hfile, " }\n"); field = temp->fields; while (field) { if (!strcmp(field->field_size, "1")) fprintf(hfile, " %s %s%s;\n", field->field_type, field->field_name, field->field_init); else fprintf(hfile, " %s %s%s[%s];\n", field->field_type, field->field_name, field->field_init, field->field_size); field = field->next; } temp = temp->next; fprintf(hfile, "};\n\n"); }#endif fprintf(hfile, "class %s_Agent;\n", protocol_name); /* fprintf(hfile, "typedef int ( %s_Agent::*%s_agent_handler)(Event *);\n", protocol_name, protocol_name); */ /* fprintf(hfile, "class %s_Timer : public TimerHandler {\n", protocol_name); */ /* fprintf(hfile, "public:\n"); */ /* fprintf(hfile, " %s_Timer(class %s_Agent *a, %s_agent_handler handler) : TimerHandler() { a_ = a; handler_= handler; }\n", protocol_name, protocol_name, protocol_name); */ /* fprintf(hfile, " virtual void expire(Event *e);\n"); */ /* fprintf(hfile, "protected:\n"); */ /* fprintf(hfile, " class %s_Agent *a_;\n", protocol_name); */ /* fprintf(hfile, " %s_agent_handler handler_;\n", protocol_name); */ /* fprintf(hfile, "};\n\n"); */ temp = my_messages; while (temp) { int i; for(i=0; i<API_num_types; i++) { if(!API_sendsdata[i]) continue; /************** API calls ****************/ fprintf(hfilemacros,"#define %s_%s(dest", API_types[i], temp->simple_name); field = temp->fields; while (field) { fprintf(hfilemacros,", %s", field->field_nickname); field = field->next; } fprintf(hfilemacros,", msg, size, importance) \\\n"); alloc_and_fill_pkt(temp); if (base_name) { fprintf(hfilemacros, " int rel;\\\n"); fprintf(hfilemacros, " rel=%s;\\\n", temp->message_transport->under); fprintf(hfilemacros, " if (importance >= PRIORITY_BEST_EFFORT && importance <= PRIORITY_HIGHEST)\\\n"); fprintf(hfilemacros, " rel = importance;\\\n"); fprintf(hfilemacros, " hdr_ip * iphdr = gethdrip( send_pkt ); \\\n"); fprintf(hfilemacros, " char *outbuf; \\\n"); fprintf(hfilemacros, " outbuf = (char *) malloc (send_pkt->hdrlen_+ size+100); \\\n"); fprintf(hfilemacros, " if (outbuf == 0) {\\\n"); fprintf(hfilemacros, " printf(\"Malloc exception 3!\\n\"); \\\n"); fprintf(hfilemacros, " exit(72);\\\n"); fprintf(hfilemacros, " }\\\n");#ifdef VARIABLE_HEADERS fprintf(hfilemacros, " if (size) {\\\n"); fprintf(hfilemacros, " ((macedon_fields*)gethdr%s( send_pkt ))->mh_expanded_size_+=size; \\\n", protocol_name, protocol_name, temp->simple_name); fprintf(hfilemacros, " }\\\n");#endif fprintf(hfilemacros, " bcopy(send_pkt->bits_, outbuf, send_pkt->hdrlen_); \\\n"); fprintf(hfilemacros, " if (size) {\\\n"); fprintf(hfilemacros, " bcopy(msg, (char *)(outbuf+send_pkt->hdrlen_), size); \\\n"); if (tracing) { fprintf(hfilemacros, " send_pkt->data_ = (unsigned char *)outbuf+send_pkt->hdrlen_;\\\n"); fprintf(hfilemacros, " send_pkt->size_ = size;\\\n"); } fprintf(hfilemacros, " }\\\n"); if (tracing) { fprintf(hfilemacros, " dump_packet(send_pkt, \"%s\", 0); \\\n", temp->message_name); fprintf(hfilemacros, " send_pkt->data_ = NULL;\\\n"); fprintf(hfilemacros, " send_pkt->size_ = 0;\\\n"); } //fprintf(hfilemacros, " debug_macro(\"%s: about to call base layer macedon_%s\\n\");\\\n",protocol_name,API_types[i]); fprintf(hfilemacros, " macedon_sendret = base_agent->macedon_%s(dest, outbuf+sizeof(hdr_ip)+sizeof(hdr_cmn), send_pkt->hdrlen_+size-sizeof(hdr_ip)-sizeof(hdr_cmn), rel); \\\n",API_types[i]); fprintf(hfilemacros, " ::free(outbuf); \\\n"); fprintf(hfilemacros, " macedon_pkt_free(send_pkt); \\\n"); } else if(API_unicast[i]) // must go directly to IP { fprintf(hfilemacros, " char *outbuf = 0; \\\n"); fprintf(hfilemacros, " if (size) \\\n"); fprintf(hfilemacros, " { \\\n");#ifdef VARIABLE_HEADERS fprintf(hfilemacros, " ((macedon_fields*)gethdr%s( send_pkt ))->mh_expanded_size_+=size; \\\n", protocol_name, protocol_name, temp->simple_name);#endif fprintf(hfilemacros, " hdr_cmn* hdrcmn = (hdr_cmn *)send_pkt->bits_; \\\n"); fprintf(hfilemacros, " outbuf = (char *) malloc (size+100); \\\n"); fprintf(hfilemacros, " if (outbuf == 0) {\\\n"); fprintf(hfilemacros, " printf(\"Malloc exception 3!\\n\"); \\\n"); fprintf(hfilemacros, " exit(72);\\\n"); fprintf(hfilemacros, " }\\\n"); fprintf(hfilemacros, " bcopy(msg, outbuf, size); \\\n"); fprintf(hfilemacros, " send_pkt->data_ = (unsigned char *)outbuf; \\\n"); fprintf(hfilemacros, " hdrcmn->size_ = size; \\\n"); fprintf(hfilemacros, " send_pkt->size_ = size; \\\n"); fprintf(hfilemacros, " } \\\n"); /* Adolfo reworking priority stuff if (temp->message_transport->type) { fprintf(hfilemacros, " hdr_ip* dest_hdrip = gethdrip( send_pkt ); \\\n"); fprintf(hfilemacros, " macedon_sendret=%s->send (dest_hdrip->dst_.addr_, send_pkt->bits_, send_pkt->hdrlen_, send_pkt->data_, send_pkt->size_); \\\n", temp->message_transport->over); fprintf(hfilemacros, " macedon_pkt_free(send_pkt); \\\n"); } else { fprintf(hfilemacros, " macedon_sendret = reliab_send(send_pkt); \\\n"); } */ temptran = my_transports; if (tracing) fprintf(hfilemacros, " dump_packet(send_pkt, \"%s\", 0); \\\n", temp->message_name); fprintf(hfilemacros, " hdr_ip* dest_hdrip = gethdrip( send_pkt ); \\\n"); fprintf(hfilemacros, " if (0) {}\\\n"); while (temptran) { if (strcmp(temptran->over, "UDP") && strcmp(temptran->over, "SWP") && strcmp(temptran->over, "TCP")) { fprintf(hfilemacros, " else if (importance == PRIORITY_%s) {\\\n", temptran->over); if (temptran->type) { fprintf(hfilemacros, " macedon_sendret=%s->send (dest_hdrip->dst_.addr_, send_pkt->bits_, send_pkt->hdrlen_, send_pkt->data_, send_pkt->size_); \\\n", temptran->over); fprintf(hfilemacros, " macedon_pkt_free(send_pkt); \\\n"); } else { fprintf(hfilemacros, " macedon_sendret = reliab_send(send_pkt); \\\n"); } fprintf(hfilemacros, " }\\\n"); } temptran = temptran->next; } fprintf(hfilemacros, " else {\\\n"); if (temp->message_transport->type) { fprintf(hfilemacros, " hdr_ip* dest_hdrip = gethdrip( send_pkt ); \\\n"); fprintf(hfilemacros, " macedon_sendret=%s->send (dest_hdrip->dst_.addr_, send_pkt->bits_, send_pkt->hdrlen_, send_pkt->data_, send_pkt->size_); \\\n", temp->message_transport->over); fprintf(hfilemacros, " macedon_pkt_free(send_pkt); \\\n"); } else { fprintf(hfilemacros, " macedon_sendret = reliab_send(send_pkt); \\\n"); } fprintf(hfilemacros, " }\\\n"); } fprintf(hfilemacros,"}\n\n"); } temp = temp->next; } fprintf(hfilemacros,"#endif \n");}add_message_field (char *message_name, char *type, char *field, char *size, char *init){ message *lookup; neighbor_type *temp = my_neighbor_types; message_field *new = (message_field *) malloc (sizeof(message_field)); message_field *prev; int skip_dcl = 0; int isconst = 0; constant *tempc; char *real_name = (char *)malloc(400); char *real_field = (char *)malloc(400); sprintf(real_name, "%s_message_%s", protocol_name, message_name); sprintf(real_field, "%s_header_%s", protocol_name, field); lookup = my_messages; while (lookup) { prev = lookup->fields; while (prev) { if (strcmp(real_field, prev->field_name)==0) skip_dcl = 1; prev = prev->next; } lookup = lookup->next; } lookup = lookup_message(real_name); if (lookup==0) { printf("message %s not found!\n", real_name); exit(4); } lookup->num_fields++; new->field_name = real_field; new->field_nickname = strdup(field); new->field_type = (char *) malloc (400); sprintf(new->field_type, "%s", type); new->neighbor = 0; while(temp) { if (strcmp(temp->name, type)==0) new->neighbor = temp; temp = temp->next; } new->field_size = (char *) malloc (400); new->field_dupe = skip_dcl; if (init) { new->field_init = (char *) malloc (100); sprintf (new->field_init, "(%s)", init); } else new->field_init = empty; tempc = my_constants; while (tempc) { if (!strcmp(size, tempc->constant_simple_name)) isconst = 1; tempc = tempc->next; } if (strlen(size) > 1 && isconst==0) sprintf(new->field_size, "%s_%s", protocol_name, size); else sprintf(new->field_size, "%s", size); new->next = 0; if (lookup == 0) { printf ("Message %s not found!\n", message_name); exit(4); } if (lookup->fields == 0) lookup->fields = new; else { prev = lookup->fields; while (prev->next != 0) prev = prev->next; prev->next = new; }}add_neighbor_type (char *name, char *size){ neighbor_type *new = (neighbor_type *)malloc (sizeof(neighbor_type)); neighbor_type *old; new->size = (char *) malloc (400); sprintf(new->size, "%s", size); new->name = (char *) malloc (400); sprintf(new->name, "%s", name); new->simple_name = (char *) malloc (400); sprintf(new->simple_name, "%s", name); new->fields = 0; new->class = 0; if (my_neighbor_types) { old = my_neighbor_types; while (old->next) { old = old->next; } old->next = new; new->next = 0; } else { new->next = 0; my_neighbor_types = new; }#ifdef GEN_TRACE printf("Added neighbor type %s\n", new->name);#endif}add_neighbor_type_field (char *type, char *name){ declare *my_field; neighbor_type *old; my_field = (declare *) malloc(sizeof(declare)); my_field->name = (char *) malloc (400); sprintf(my_field->name, "%s", name); my_field->type = (char *) malloc (400); sprintf(my_field->type, "%s", type); my_field->size = (char *) malloc (400); sprintf(my_field->size, "1"); my_field->exported = 0; my_field->array = 0; my_field->neighbor = NULL; old = my_neighbor_types; while(old != NULL) { if(!strcmp(old->name,type)) { my_field->neighbor = old; } old = old->next; } old = my_neighbor_types; while (old->next) { old = old->next; } my_field->next = old->fields; old->fields = my_field;#ifdef GEN_TRACE printf("Added neighbor type field %s %s %s\n", my_field->type, my_field->name, my_field->size);#endif}add_neighbor_type_field_array (char *type, char *name, char *size){ declare *my_field; neighbor_type *old; my_field = (declare *) malloc(sizeof(declare)); my_field->name = (char *) malloc (400); sprintf(my_field->name, "%s", name); my_field->type = (char *) malloc (400); sprintf(my_field->type, "%s", type); my_field->type = (char *) malloc (400); sprintf(my_field->size, "%s", size); my_field->exported = 0; my_field->array = 1; old = my_neighbor_types; while (old->next) { old = old->next; } my_field->next = old->fields; old->fields = my_field;}done_node_types(){ node_type *temp = my_node_types; int count = 10; while (temp) { fprintf(hfile, "#define %s %d\n", temp->type_name, count); count+=10; temp = temp->next; } fprintf(hfile, "\n");}done_states(){ int count; state *temps = my_states; temps = my_states; count = 10; while (temps) { fprintf(hfile, "#define %s %d\n", temps->state_name, count); fprintf(hfile, "#define %s %d\n", temps->state_hint_name, temps->status); temps = temps->next; count+=10; } fprintf(hfile, "\n");}add_type (char *type){ node_type *new = (node_type *) malloc (sizeof (node_type)); new->type_name = (char *) malloc (400); sprintf(new->type_name, "%s_node_type_%s", protocol_name, type); new->simple_name = (char *) malloc (400); sprintf(new->simple_name, "%s", type); new->next = my_node_types; my_node_types = new;}done_neighbor_types(){ neighbor_type *temp = my_neighbor_types; neighbor_type *temp2 = my_neighbor_types; declare *tempntfields; declare *temp_field; fprintf(hfile,"namespace %s_namespace {\n\n", protocol_name); temp = my_neighbor_types; while (temp) { fprintf(hfile, "class neighbor_%s;\n",temp->name); temp = temp->next; } temp = my_neighbor_types; while (temp) { fprintf(hfile, "typedef neighbor_set<neighbor_%s,%s> %s;\n", temp->name, temp->size, temp->name); temp = temp->next; } temp = my_neighbor_types; while (temp) { fprintf(hfile, "class neighbor_%s : public neighbor\n", temp->name); fprintf(hfile, "{\n"); fprintf(hfile, "public:\n"); temp_field = temp->fields; while (temp_field) { if(!strcmp(temp_field->type, "int") || !strcmp(temp_field->type, "double")) fprintf(hfile, " %s %s;\n", temp_field->type, temp_field->name); else fprintf(hfile, " %s %s;\n", temp_field->type, temp_field->name); temp_field = temp_field->next; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -