📄 macedon-conv.c
字号:
dumpstate_function(){ declare *temp = my_periphs; fprintf(cfile, "void %s_Agent::dump_state()\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " char *temp_trace = trace_buf_;\n"); while (temp) { dumpsomestate(temp, ""); temp = temp->next; } fprintf(cfile, " return;\n"); fprintf(cfile, "}\n\n");}dumpsomestate(declare *temp, char *pred) { char *entryname; declare *mytempfields; char *tempname = (char *)malloc (400); if (temp->nodump) return; if ( strcmp(pred, "") ) sprintf(tempname, "%s.%s", pred, temp->name); else sprintf(tempname, "%s", temp->name); if (!strcmp(temp->size, "1")) { if (!strcmp(temp->type, "int")) { fprintf(cfile, " debug_macro(\"St: %s %%.8x\\n\", %s);\n", tempname, tempname); } else if (!strcmp(temp->type, "double")) { fprintf(cfile, " debug_macro(\"St: %s %%f\\n\", %s);\n", tempname, tempname); } else if (!strcmp(temp->type, "char *")) { fprintf(cfile, " debug_macro(\"St: %s %%s\\n\", %s);\n", tempname, tempname); } else if (!strncmp(temp->type, "candidate_set", strlen("candidate_set"))) { fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " sprintf(trace_buf_,\"St: %s \");\n", tempname); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " %s.dumpem(temp_trace); \n", tempname); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); } else if (temp->neighbor != 0) { fprintf(cfile, " if (%s.count > 0)\n", tempname); fprintf(cfile, " {\n"); fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " sprintf(trace_buf_,\"St: neigh %s [%%d]: \", %s.count);\n", tempname, tempname); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); foreachcount++; fprintf(cfile, " int i%d;\n", foreachcount); fprintf(cfile, " int j%d;\n", foreachcount); fprintf(cfile, " for(i%d=0; i%d<%s.count; i%d++)\n", foreachcount, foreachcount, tempname, foreachcount); fprintf(cfile, " {\n"); fprintf(cfile, " sprintf(temp_trace,\"[%%.8x] %%f \", %s.entries[i%d].ipaddr, %s.entries[i%d].delay);\n", tempname, foreachcount, tempname, foreachcount); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); mytempfields = temp->neighbor->fields; while (mytempfields) { if (!strcmp(mytempfields->type, "int")) fprintf(cfile, " sprintf(temp_trace,\"%%.8x \", %s.entries[i%d].%s);\n", tempname, foreachcount, mytempfields->name); mytempfields = mytempfields->next; fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); } fprintf(cfile, " }\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); fprintf(cfile, " temp_trace = trace_buf_;\n"); if (temp->neighbor) { declare *tempfields = temp->neighbor->fields; fprintf(cfile, " for(j%d=0; j%d<%s.count; j%d++)\n", foreachcount, foreachcount, tempname, foreachcount); fprintf(cfile, " {\n"); fprintf(cfile, " temp_trace = trace_buf_;\n"); //FIXME: What does this code do? while (tempfields) { char *tempname2 = (char *) malloc(500); sprintf(tempname2, "%s.entries[j%d]", tempname, foreachcount); dumpsomestate(tempfields, tempname2); free(tempname2); tempfields = tempfields->next; } fprintf(cfile, " }\n"); } fprintf(cfile, " }\n"); foreachcount--; } else {} } else // temp->size != "1" { foreachcount++; fprintf(cfile, " int i%d,i%d_2,i%d_3;\n", foreachcount, foreachcount, foreachcount); fprintf(cfile, " int j%d;\n", foreachcount); entryname = (char*) malloc(500); fprintf(cfile, " for(i%d=0; i%d<%s; i%d++)\n", foreachcount, foreachcount, temp->size, foreachcount); sprintf(entryname, "%s[i%d]", tempname, foreachcount); if (temp->array >= 2) { fprintf(cfile, " for(i%d_2=0; i%d_2<%s; i%d_2++)\n", foreachcount, foreachcount, temp->size2, foreachcount); sprintf(entryname, "%s[i%d][i%d_2]", tempname, foreachcount, foreachcount); } if (temp->array >= 3) { fprintf(cfile, " for(i%d_3=0; i%d_3<%s; i%d_3++)\n", foreachcount, foreachcount, temp->size3, foreachcount); sprintf(entryname, "%s[i%d][i%d_2][i%d_3]", tempname, foreachcount, foreachcount, foreachcount); } fprintf(cfile, " {\n"); if (!strcmp(temp->type, "int")) { fprintf(cfile, " debug_macro(\"St: %s[%%d] %%d\\n\", i%d, %s);\n", tempname, foreachcount, entryname); } else if (!strcmp(temp->type, "double")) { fprintf(cfile, " debug_macro(\"St: %s[%%d] %%f\\n\", i%d, %s);\n", tempname, foreachcount, entryname); } else if (temp->neighbor != 0) { fprintf(cfile, " temp_trace = trace_buf_;\n"); fprintf(cfile, " pthread_mutex_lock(&debug_lock);\n"); fprintf(cfile, " if (%s.count > 0)\n", entryname, foreachcount); fprintf(cfile, " {\n"); if (temp->array == 1) fprintf(cfile, " sprintf(temp_trace,\"St: neigh %s[%%d] [%%d]: \", i%d, %s.count);\n", tempname, foreachcount, entryname); else if (temp->array == 2) fprintf(cfile, " sprintf(temp_trace,\"St: neigh %s[%%d][%%d] [%%d]: \", i%d, i%d_2, %s.count);\n", tempname, foreachcount, foreachcount, entryname); else if (temp->array == 3) fprintf(cfile, " sprintf(temp_trace,\"St: neigh %s[%%d][%%d][%%d] [%%d]: \", i%d, i%d_2, i%d_3, %s.count);\n", tempname, foreachcount, foreachcount, foreachcount, entryname); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); fprintf(cfile, " for(j%d=0; j%d<%s.count; j%d++)\n", foreachcount, foreachcount, entryname, foreachcount); fprintf(cfile, " {\n"); fprintf(cfile, " sprintf(temp_trace,\"[%%d] %%.8x %%f \", j%d, %s.entries[j%d].ipaddr, %s.entries[j%d].delay);\n", foreachcount, entryname, foreachcount, entryname, foreachcount); fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); mytempfields = temp->neighbor->fields; while (mytempfields) { if (!strcmp(mytempfields->type, "int")) fprintf(cfile, " sprintf(temp_trace,\"%%.8x \", %s.entries[j%d].%s);\n", entryname, foreachcount, mytempfields->name); mytempfields = mytempfields->next; fprintf(cfile, " temp_trace = trace_buf_ + strlen(trace_buf_);\n"); } fprintf(cfile, " }\n"); fprintf(cfile, " sprintf(temp_trace,\"\\n\");\n"); fprintf(cfile, " trace_print();\n"); fprintf(cfile, " pthread_mutex_unlock(&debug_lock);\n"); fprintf(cfile, " temp_trace = trace_buf_;\n"); if (temp->neighbor) { declare *tempfields = temp->neighbor->fields; fprintf(cfile, " for(j%d=0; j%d<%s.count; j%d++)\n", foreachcount, foreachcount, entryname, foreachcount); fprintf(cfile, " {\n"); fprintf(cfile, " temp_trace = trace_buf_;\n"); while (tempfields) { char *tempname2 = (char *) malloc(500); sprintf(tempname2, "%s.entries[j%d]", entryname, foreachcount); dumpsomestate(tempfields, tempname2); free(tempname2); tempfields = tempfields->next; } fprintf(cfile, " }\n"); } fprintf(cfile, " }\n"); } else {} fprintf(cfile, " }\n"); free(entryname); } free(tempname);}recv_functions(){ declare *temp = my_periphs; if (!base_name) { fprintf(cfile, "void %s_Agent::recv_from_pipe(int from, unsigned char * hdata, int hsize, unsigned char * data, int size)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " Packet *pkt;\n"); fprintf(cfile, " char *buffer;\n"); fprintf(cfile, " pkt = new Packet();\n");#ifndef VARIABLE_HEADERS fprintf(cfile, " pkt->bits_ = (unsigned char *)malloc(hsize+size+100);\n"); fprintf(cfile, " buffer = (char*)pkt->bits_;\n");#else fprintf(cfile, " buffer = (char *)malloc(hsize+size+100);\n");#endif fprintf(cfile, " if (buffer == 0) {\n"); fprintf(cfile, " printf(\"Malloc exception 2!\\n\"); \n"); fprintf(cfile, " exit(72);\n"); fprintf(cfile, " }\n");#ifndef VARIABLE_HEADERS fprintf(cfile, " pkt->hdrlen_ = hsize;\n");#endif fprintf(cfile, " bcopy( hdata, buffer, hsize );\n"); fprintf(cfile, " if (size>0)\n"); fprintf(cfile, " {\n");#ifndef VARIABLE_HEADERS fprintf(cfile, " pkt->data_ = (unsigned char *)(pkt->bits_ + hsize);\n"); fprintf(cfile, " pkt->size_ = size;\n");#endif fprintf(cfile, " bcopy( data, buffer+hsize, size );\n"); fprintf(cfile, " }\n");#ifdef VARIABLE_HEADERS fprintf(cfile, " pkt = %s_prep_delivery(buffer, hsize+size, COMM_TYPE_UNICAST, 0, 0, 1);\n",protocol_name);#endif fprintf(cfile, " recv(pkt, (Handler *)34);\n"); fprintf(cfile, " return;\n"); fprintf(cfile, "}\n"); fprintf(cfile, "\n"); } fprintf(cfile, "void %s_Agent::recv(Packet* pkt, Handler* myhand)\n", protocol_name); fprintf(cfile, "{\n"); fprintf(cfile, " double curtime = Scheduler::instance().clock();\n"); fprintf(cfile, " int processed=0;\n"); fprintf(cfile, " hdr_ip* recv_hdrip = gethdrip( pkt );\n"); fprintf(cfile, " hdr_%s* recv_hdr%s = gethdr%s( pkt );\n", protocol_name, protocol_name, protocol_name);// if (!base_name) {// fprintf(cfile, " if ( recv_hdr%s->%s_mf_.mh_type_ == MH_TYPE_ACK )\n", protocol_name, protocol_name);// fprintf(cfile, " {\n");// if (tracing >= 3) {// fprintf(cfile, " dump_packet(pkt, 0, 1);\n"); // }// fprintf(cfile, " ack_in(pkt); \n");// fprintf(cfile, " macedon_pkt_free(pkt);\n"); // fprintf(cfile, " return;\n");// fprintf(cfile, " }\n");// } if (tracing >= 3 ) fprintf(cfile, " dump_state();\n"); fprintf(cfile, " hdr_%s* hdr = (hdr_%s*)gethdr%s( pkt ); \n", protocol_name, protocol_name, protocol_name); fprintf(cfile, " int from = hdr->%s_mf_.mh_src_addr_;\n", protocol_name); if(temp) { fprintf(cfile, " Lock_Write();\n"); while (temp) { if (temp->failure) { if (!strcmp(temp->size, "1")) { fprintf(cfile, " if(neighbor_query(%s, from)) {\n", temp->name); fprintf(cfile, " neighbor_%s *temp_%s = neighbor_entry(%s, from);\n", temp->type, temp->name, temp->name); fprintf(cfile, " temp_%s->time_last_heard = curtime;\n", temp->name); fprintf(cfile, " }\n"); } else { fprintf(cfile, " for (int i=0; i<%s; i++) {\n", temp->size); fprintf(cfile, " if(neighbor_query(%s[i], from)) {\n", temp->name); fprintf(cfile, " neighbor_%s *temp_%s = neighbor_entry(%s[i], from);\n", temp->type, temp->name, temp->name); fprintf(cfile, " temp_%s->time_last_heard = curtime;\n", temp->name); fprintf(cfile, " }\n"); fprintf(cfile, " }\n"); } } temp = temp->next; } fprintf(cfile, " Unlock();\n"); } fprintf(cfile, " if(hdr->%s_mf_.mh_type_ == %s_message_pulse)\n", protocol_name, protocol_name); fprintf(cfile, " {\n"); fprintf(cfile, " processed = 1;\n"); if (tracing >= 1) fprintf(cfile, " dump_packet(pkt, 0, 1);\n"); fprintf(cfile, " if (((hdr_%s_pulse *)hdr)->%s_header_request == 0)\n", protocol_name, protocol_name); fprintf(cfile, " route_pulse(from, 1, 0, 0, -1);\n"); fprintf(cfile, " }\n"); fprintf(cfile2, "int %s_Agent::forward(Packet* pkt)\n", protocol_name); fprintf(cfile2, "{\n"); fprintf(cfile2, " int processed=0;\n"); fprintf(cfile2, " int retval=0;\n"); fprintf(cfile2, " hdr_ip* recv_hdrip = gethdrip( pkt );\n"); fprintf(cfile2, " hdr_%s* recv_hdr%s = gethdr%s( pkt );\n", protocol_name, protocol_name, protocol_name);/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -