⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macedon-conv.c

📁 这是一个著名的应用层组播中间件的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
}ext_functions() {  int i;  fprintf(cfile, "int %s_my_upcall_ext(int operation, void *arg)\n", protocol_name);  fprintf(cfile, "{\n");  //  fprintf(cfile, "  printf(\"%s_my_upcall_ext called\\n\");\n", protocol_name);  fprintf(cfile, "  return global%s->macedon_upcall_ext(operation, arg);\n", protocol_name);  fprintf(cfile, "}\n");  fprintf(cfile, "\n");  fprintf(cfile, "int %s_Agent::macedon_upcall_ext(int operation, void* arg) {\n",protocol_name);  fprintf(cfile, "  int return_code;\n");  for(i=0; i<AUTOEXT_num_types; i++) {    if(ext_direction[i]==UP || ext_direction[i]==BOTH) {      fprintf(cfile, "  if(operation == %s) { Lock_Write(); return_code = %s; Unlock(); return return_code; }\n", ext_function_numbers[i], ext_commands[i]);    }  }  fprintf(cfile, "  Lock_Write();\n");  fprintf(cfile, "  return_code = actual_upcall_ext(operation, arg);\n");  fprintf(cfile, "  Unlock();\n");  fprintf(cfile, "  return return_code;\n");  fprintf(cfile, "}\n");  fprintf(cfile, "\n");  fprintf(cfile, "int %s_Agent::macedon_downcall_ext(int operation, void* arg) {\n",protocol_name);  fprintf(cfile, "  int return_code;\n");  for(i=0; i<AUTOEXT_num_types; i++) {    if(ext_direction[i]==DOWN || ext_direction[i]==BOTH) {      fprintf(cfile, "  if(operation == %s) { Lock_Write(); return_code = %s; Unlock(); return return_code; }\n", ext_function_numbers[i], ext_commands[i]);    }  }  fprintf(cfile, "  Lock_Write();\n");  fprintf(cfile, "  return_code = actual_downcall_ext(operation, arg);\n");  fprintf(cfile, "  Unlock();\n");  fprintf(cfile, "  return return_code;\n");  fprintf(cfile, "}\n");}init_function(){  declare *tempp;  timer *tempt;  message *temp = my_messages;  char *entryname; // for array stuff, see below  fprintf(cfile, "extern int big_hdr_size;\n");  fprintf(cfile, "%s_Agent::%s_Agent() : MACEDON_Agent(PT_%s),\n", protocol_name, protocol_name, protocol_name);   fprintf(cfile, "			   utility_timer_(this,(int (MACEDON_Agent::*)(int))& %s_Agent::utility_expire, 0)\n", protocol_name);  fprintf(cfile, "{\n");  fprintf(cfile, "  int i, j, j2, j3;\n");  fprintf(cfile, "  forward_handler = 0;\n");  fprintf(cfile, "  deliver_handler = 0;\n");  fprintf(cfile, "  upcall_handler = 0;\n");  fprintf(cfile, "  notify_handler = 0;\n");  fprintf(cfile, "global%s = this;\n", protocol_name);  if (!base_name) {    transport *temptr = my_transports;    fprintf(cfile, "  int base_port = parameters.getint(\"port\");\n");    while (temptr) {      if (temptr->type) {#ifdef ADOLFO_TRANSPORTS        if (!strcmp(temptr->type, "tfrc")) #endif          fprintf(cfile, "  %s = new %s_transport(here_.addr_,base_port+%d, %d, %d);\n", temptr->over, temptr->type, temptr->port, temptr->threads, temptr->queue);#ifdef ADOLFO_TRANSPORTS        else           fprintf(cfile, "  %s = new %s_transport(here_.addr_,base_port+%d, %d);\n", temptr->over, temptr->type, temptr->port, temptr->queue);#endif      }      temptr = temptr->next;    }  }#ifndef ALLINONEHDR    while (temp)  {    fprintf(cfile, "printf(\"Header size of %s_%s (type %%d) is %%d\\n\", %s_message_%s, sizeof(hdr_%s_%s));\n", protocol_name, temp->simple_name, protocol_name, temp->simple_name, protocol_name, temp->simple_name);    fprintf(cfile, "if (big_hdr_size < sizeof(hdr_%s_%s))\n", protocol_name, temp->simple_name);    fprintf(cfile, "  big_hdr_size = sizeof(hdr_%s_%s);\n", protocol_name, temp->simple_name);    temp = temp->next;  }#else  fprintf(cfile, "big_hdr_size = sizeof(hdr_%s);\n", protocol_name);#endif  fprintf(cfile, "  fsm = %s_state_init;\n", protocol_name);  fprintf(cfile, "  fsm_hint = %s_state_hint_init;\n", protocol_name);  fprintf(cfile, "  bytes_sent = 0;\n");  if (my_node_types)    fprintf(cfile, "  node_type = %s;\n", my_node_types->type_name);  tempp = my_periphs;  while (tempp)  {    if (tempp->neighbor)    {      if (!strcmp(tempp->size, "1"))      {        fprintf(cfile, " %s.neighbor_clearit();\n",tempp->name);        /** unnecessary...          fprintf(cfile, "  for (i=0; i<%s; i++)\n", tempp->neighbor->size);          fprintf(cfile, "    {\n");          fprintf(cfile, "      ((%s).entries[i]).neighbor_clearit();\n", tempp->name);          fprintf(cfile, "    }\n");          fprintf(cfile, "  %s.count = 0;\n", tempp->name);         **/      }	         else // tempp->size != "1"      {        entryname = (char*) malloc(500);        fprintf(cfile, "  for (j=0; j<%s; j++)\n", tempp->size);	              sprintf(entryname, "%s[j]", tempp->name);        if (tempp->array >= 2)        {          fprintf(cfile, "  for (j2=0; j2<%s; j2++)\n", tempp->size2);          sprintf(entryname, "%s[j][j2]", tempp->name);        }        if (tempp->array >= 3)        {          fprintf(cfile, "  for (j3=0; j3<%s; j3++)\n", tempp->size3);          sprintf(entryname, "%s[j][j2][j3]", tempp->name);        }        fprintf(cfile, "    {\n");        fprintf(cfile, " %s.neighbor_clearit();\n",entryname);        /** unnecessary...          fprintf(cfile, "      for (i=0; i<%s; i++)\n", tempp->neighbor->size);          fprintf(cfile, "      {\n");          fprintf(cfile, "        ((%s).entries[i]).neighbor_clearit();\n", entryname);          fprintf(cfile, "      }\n");          fprintf(cfile, "      %s.count = 0;\n", entryname);         **/        fprintf(cfile, "    }\n");        free(entryname);      }    }    else    {      if (!strcmp(tempp->type, "int") || !strcmp(tempp->type, "double")          || !strcmp(tempp->type, "char *"))       {        if (!strcmp(tempp->size, "1"))        {          fprintf(cfile, "  %s = 0;\n", tempp->name);        }        else // array        {          entryname = (char*) malloc(500);          fprintf(cfile, "  for (j=0; j<%s; j++)\n", tempp->size);	                sprintf(entryname, "%s[j]", tempp->name);          if (tempp->array >= 2)          {            fprintf(cfile, "  for (j2=0; j2<%s; j2++)\n", tempp->size2);            sprintf(entryname, "%s[j][j2]", tempp->name);          }          if (tempp->array >= 3)          {            fprintf(cfile, "  for (j3=0; j3<%s; j3++)\n", tempp->size3);            sprintf(entryname, "%s[j][j2][j3]", tempp->name);          }          fprintf(cfile, "    {\n");          fprintf(cfile, "  %s = 0;\n", entryname);          fprintf(cfile, "    }\n");          free(entryname);        }      }    }    if (tempp->exported)      fprintf(cfile, "  bind(\"%s\", &%s);\n", tempp->name, tempp->name);    tempp = tempp->next;  }  tempt = my_timers;  fprintf(cfile, "  debug_macro(\"utility timer addr %%x\\n\", &utility_timer_);\n");  while (tempt)  {    fprintf(cfile, "  %s = new MACEDON_Timer (this, (int (MACEDON_Agent::*)(int))& %s_Agent::expire_%s, 0);\n", tempt->timer_name, protocol_name, tempt->timer_name);    fprintf(cfile, "  debug_macro(\"%s timer addr %%x\\n\", %s);\n", tempt->timer_name, tempt->timer_name);    tempt = tempt->next;  }  if (base_name != 0)  {    fprintf(cfile, "base_agent = (MACEDON_Agent *) new %s_Agent;\n", base_name);    fprintf(cfile, "base_agent->macedon_register_handlers((macedon_forward_handler)&%s_my_forward, (macedon_deliver_handler)&%s_my_deliver, (macedon_notify_handler)&%s_my_notify, (macedon_upcall_handler)&%s_my_upcall_ext);\n", protocol_name, protocol_name, protocol_name, protocol_name);  } else {    fprintf(cfile, "base_agent = NULL;\n");  }  fprintf(cfile, "}\n");  fprintf(cfile, "\n");}multicast_functions(){  fprintf(cfile, "void %s_Agent::sendmsg(int nbytes, AppData *data, const char* )\n", protocol_name);  fprintf(cfile, "{\n");  fprintf(cfile, "}\n");  fprintf(cfile, "\n");  }exit_function(){  timer* tempt;  timer_demux* temptd;  api_demux* tempad;  msg_demux* msgd;  fprintf(cfile, "void %s_Agent::dump_timings()\n", protocol_name);  fprintf(cfile, "{\n");#ifdef PROFILE_AGENTS  fprintf(cfile, "printf(\"Transition Statistics: (transition total count average)\\n\");\n");  tempt = my_timers;  while(tempt)  {    temptd = tempt->demux;    while (temptd)    {        fprintf(cfile, "  printf(\"%30s %%f %%d %%f\\n\",%s_total,%s_count,%s_total/(double)%s_count );\n", temptd->func, temptd->func, temptd->func, temptd->func, temptd->func);      temptd = temptd->next;    }    tempt = tempt->next;  }  fprintf(stderr, "apidemux==%.8x", apidemux);  tempad = apidemux;  while(tempad) {    fprintf(cfile, "  printf(\"%30s %%f %%d %%f\\n\",%s_total, %s_count, %s_total/(double)%s_count );\n", tempad->func2,tempad->func2,tempad->func2,tempad->func2,tempad->func2);    tempad = tempad->next;  }  msgd = msglist;  while(msgd) {    fprintf(cfile, "  printf(\"%30s %%f %%d %%f\\n\",%s_total,%s_count,%s_total/(double)%s_count );\n", msgd->msgfunc, msgd->msgfunc, msgd->msgfunc, msgd->msgfunc, msgd->msgfunc);    msgd = msgd->next;  }#endif  fprintf(cfile, "}\n");    fprintf(cfile, "void %s_Agent::exit_agent()\n", protocol_name);  fprintf(cfile, "{\n");  fprintf(cfile, "  debug_macro(\"exit_agent for %s\\n\");\n", protocol_name);  if (!base_name) {    transport *temptr = my_transports;    while (temptr) {      if (temptr->type)  {        fprintf(cfile, "  debug_macro(\"cancelling %s timer\\n\");\n", temptr->over);        fprintf(cfile, "  if(%s)\n", temptr->over);        fprintf(cfile, "    pthread_cancel(%s->thread_id);\n", temptr->over);      }      temptr = temptr->next;    }  }  fprintf(cfile, " dump_timings();\n");  fprintf(cfile, " if(base_agent != NULL) { base_agent->exit_agent(); }\n");  fprintf(cfile, "}\n");}check_function(){  declare *temp = my_periphs;  fprintf(cfile, "void %s_Agent::check_neighbors(double curtime)\n", protocol_name);  fprintf(cfile, "{\n");  fprintf(cfile, "  Lock_Write();\n");  /*   if(strcmp(protocol_name, "bullet")) { */  /*     fprintf(cfile, "  #ifdef PIP_MESSAGING\n"); */  /*     fprintf(cfile, "  char pathId[40];\n"); */  /*     fprintf(cfile, "  static int num = 0;\n"); */  /*     fprintf(cfile, "  sprintf(pathId, \"check_nbr-%%.8x-%%d\", me, num++);\n"); */  /*     fprintf(cfile, "  ANNOTATE_SET_PATH_ID(NULL, 0, pathId, strlen(pathId));\n"); */  /*     fprintf(cfile, "  #endif\n"); */  /*   } */  while (temp) {    if (temp->failure) {      if (!strcmp(temp->size, "1")) {        fprintf(cfile, "  foreach_neighbor(neighbor_%s *, dude, %s) {\n", temp->type, temp->name);         fprintf(cfile, "    if (dude->ipaddr != me && dude->time_last_heard !=0.0 && dude->time_last_heard + HEARTBEAT_TIMEOUT < curtime)\n");         fprintf(cfile, "      {\n");        fprintf(cfile, "        debug_macro(\"neighbor %%.8x timed out %%f\\n\", dude->ipaddr, dude->time_last_heard);\n");        fprintf(cfile, "        macedon_error(ERROR_NEIGHBOR_FAILURE, dude->ipaddr);\n");        fprintf(cfile, "      }\n");        fprintf(cfile, "    else if (dude->ipaddr != me && dude->time_last_heard + HEARTBEAT_SEND < curtime && fmod((curtime-dude->time_last_heard), 10*MACEDON_UTIL_TIMER_VALUE) < 2*MACEDON_UTIL_TIMER_VALUE)\n");         fprintf(cfile, "      {\n");        fprintf(cfile, "        route_pulse(dude->ipaddr, 0, 0, 0, -1);\n");        fprintf(cfile, "      }\n");        fprintf(cfile, "  }\n");       }      else {        fprintf(cfile, "  for (int i=0; i<%s; i++) {\n", temp->size);        fprintf(cfile, "    foreach_neighbor(neighbor_%s *, dude, %s[i]) {\n", temp->type, temp->name);         fprintf(cfile, "      if (dude->ipaddr != me && dude->time_last_heard !=0.0 && dude->time_last_heard + HEARTBEAT_TIMEOUT < curtime)\n");         fprintf(cfile, "      {\n");        fprintf(cfile, "        debug_macro(\"neighbor %%.8x timed out %%f\\n\", dude->ipaddr, dude->time_last_heard);\n");        fprintf(cfile, "        macedon_error(ERROR_NEIGHBOR_FAILURE, dude->ipaddr);\n");        fprintf(cfile, "      }\n");        fprintf(cfile, "      else if (dude->ipaddr != me && dude->time_last_heard + HEARTBEAT_SEND < curtime && std::fmod((curtime-dude->time_last_heard),10*MACEDON_UTIL_TIMER_VALUE) < 2*MACEDON_UTIL_TIMER_VALUE)\n");         fprintf(cfile, "        route_pulse(dude->ipaddr, 0, 0, 0, -1);\n");        fprintf(cfile, "    }\n");         fprintf(cfile, "  }\n");      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -