Exemple #1
0
/* then read in global config file                                 */
void initialize_options(void)
{
    /* Initialize MathCards backend for math questions: */
    local_game = (MC_MathGame*) malloc(sizeof(MC_MathGame));
    if (local_game == NULL)
    {
        fprintf(stderr, "\nUnable to allocate MC_MathGame\n");
        exit(1);
    }
    local_game->math_opts = NULL;
    if (!MC_Initialize(local_game))
    {
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        exit(1);
    }


    lan_game_settings = (MC_MathGame*) malloc(sizeof(MC_MathGame));
    if (lan_game_settings == NULL)
    {
        fprintf(stderr, "\nUnable to allocate MC_MathGame\n");
        exit(1);
    }
    lan_game_settings->math_opts = NULL;
    if (!MC_Initialize(lan_game_settings))
    {
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        exit(1);
    }


    /* initialize game_options struct with defaults DSB */
    if (!Opts_Initialize())
    {
        fprintf(stderr, "\nUnable to initialize game_options\n");
        cleanup_on_error();
        exit(1);
    }

    /* Now that MathCards and game_options initialized using  */
    /* hard-coded defaults, read options from disk and mofify */
    /* as needed. First read in installation-wide settings:   */
    if (!read_global_config_file(local_game))
    {
        fprintf(stderr, "\nCould not find global config file.\n");
        /* can still proceed using hard-coded defaults.         */
    }
}
Exemple #2
0
int main()
{
  /* Init the agency */
  MCAgency_t agency;
  MCAgencyOptions_t options;
  int local_port=5051;

  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */
  agency = MC_Initialize(local_port, &options);

  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_SendAgentFile( agency, "comm_agent.xml");
#ifndef _WIN32
  sleep(1);
#else
  Sleep(1000);
#endif
  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_SendAgentFile( agency, "agent_1.xml");
#ifndef _WIN32
  sleep(1);
#else
  Sleep(1000);
#endif
  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_SendAgentFile( agency, "agent_2.xml");

  MC_End(agency);
  return 0;
}
int main(int argc,char *argv[])
{
    int i;
    MC_MathGame game;

    /* Initialize MathCards backend for math questions: */
    if (!MC_Initialize(&game))
    {
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        exit(1);
    }

    /* initialize game_options struct with defaults DSB */
    if (!Opts_Initialize())
    {
        fprintf(stderr, "\nUnable to initialize game_options\n");
        exit(1);
    }

    /* This next bit allows multiple config files to be read in sequence, since
       this is something that happens in the ordinary course of events
       in tuxmath itself. */
    for (i = 1; i < argc; i++) {
        fprintf(stderr, "Reading %s\n",argv[i]);
        read_named_config_file(&game, argv[i]);
    }
    fprintf(stderr, "All done reading!\n");

    MC_StartGame(&game);
    MC_PrintQuestionList(&game, stdout);
    return 0;
}
Exemple #4
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;
    int i;
    char buf[50];
    int local_port=5051;
    /* We want _all_ the threads on: including the command
     * prompt thread, which is off by default */
    MC_InitializeAgencyOptions(&options);
    for (i = 0; i < MC_THREAD_ALL; i++) {
        MC_SetThreadOn(&options, i);
    }
    
    /* We need to turn off MobileC's command prompt or it will interfere
     * with our custom command prompt. */
    MC_SetThreadOff(&options, MC_THREAD_CP); 

    agency = MC_Initialize(
        local_port,
        &options);
    printf("Welcome to the steer example command platform.\n");
    printf("----------------------------------------------\n");
    while( strcmp(buf, "quit")) {
      printf("What would you like to do?\n");
      printf("1: Restart the algorithm.\n");
      printf("2: Resume the algorithm.\n");
      printf("3: Stop the algorithm.\n");
      printf("4: Suspend the algorithm.\n");
      printf("q: Quit this program.\n");
      printf("  > ");
      scanf("%s", buf);

      switch(buf[0]) {
        case '1':
          MC_SendAgentFile ( agency, "restart.xml");
          break;
        case '2':
          MC_SendAgentFile ( agency, "resume.xml");
          break;
        case '3':
          MC_SendAgentFile ( agency, "stop.xml");
          break;
        case '4':
          MC_SendAgentFile ( agency, "suspend.xml");
          break;
        case 'q':
          strcpy(buf, "quit");
          break;
        default:
          printf("Invalid command.\n");
      }
    }
    MC_End(agency);
    return 0;
}
Exemple #5
0
int main() 
{
  MCAgency_t agency;
  int local_port = 5052;
  
  agency = MC_Initialize(local_port, NULL);

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #6
0
int main() 
{
  MCAgency_t agency;
  int local_port = 5051;

  printf("Initializing server...\n");  
  agency = MC_Initialize(local_port, NULL);

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #7
0
int main() {
    MCAgency_t agency;
    int local_port;

    local_port = 5053;

    agency = MC_Initialize(local_port, NULL);

    if(MC_MainLoop(agency) != 0) {
        MC_End(agency);
        return -1;
    }

    return 0;
}
Exemple #8
0
int main() 
{
  MCAgency_t agency;
  MCAgencyOptions_t options;
  int local_port = 5052;
 
  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */
  agency = MC_Initialize(local_port, &options);

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #9
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;

    MC_InitializeAgencyOptions(&options);
    MC_SetThreadOff(&options, MC_THREAD_CP);
    agency = MC_Initialize(5051, &options);

    /* Note: The third argument of the following function may also be a
       valid IP address in the form of a string. i.e. 192.168.0.1 */
    MC_SendAgentFile(agency, "message_box.xml");
    MC_End(agency);
    return 0;
}
Exemple #10
0
int main() 
{
    MCAgency_t agency;
    MCAgencyOptions_t options; 		
    int local_port=5127;

    printf("Hello I am task server 2 \n");

    MC_InitializeAgencyOptions(&options);
    strcpy(options.passphrase, "alpha1234");

    agency = MC_Initialize(local_port, &options);

    MC_MainLoop(agency);
    return 0;
}
Exemple #11
0
int main() 
{
  MCAgency_t agency;
  int local_port = 5126;
  //unsigned char passphrase[] = "alpha1234";
  MCAgencyOptions_t options;

  MC_InitializeAgencyOptions(&options);  
  strcpy(options.passphrase, "alpha1234");
   
  agency = MC_Initialize(local_port, &options);
  
  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #12
0
int main() 
{
  MCAgency_t agency;
  MCAgencyOptions_t options;
  int local_port=5050;

  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command_prompt */
  agency = MC_Initialize(local_port, &options);

  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_SendAgentFile(agency, "test1.xml");
  MC_MainLoop(agency);
  MC_End(agency);
  exit(0);
}
Exemple #13
0
int main(int argc, char** argv)
{
    int ret;
#ifdef HAVE_LIBSDL_NET
    //Initialize a copy of mathcards to hold settings:
    lan_game_settings = (MC_MathGame*) malloc(sizeof(MC_MathGame));
    if (lan_game_settings == NULL)
    {
        fprintf(stderr, "\nUnable to allocate MC_MathGame\n");
        exit(1);
    }
    lan_game_settings->math_opts = NULL;
    if (!MC_Initialize(lan_game_settings))
    {
        fprintf(stderr, "\nUnable to initialize MathCards\n");
        exit(1);
    }
    //Initialize SDL and SDL_net:
    if(SDL_Init(0) == -1)
    {
        fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
        return 0;;
    }
    if (SDLNet_Init() < 0)
    {
        fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
        return 0;
    }

    /* Run actual program: */
    ret = RunServer(argc, argv);
    /* cleanup */
    SDLNet_Quit();
    SDL_Quit();
    if (lan_game_settings)
    {
        MC_EndGame(lan_game_settings);
        free(lan_game_settings);
        lan_game_settings = NULL;
    }
    return ret;
#else
    return 0;
#endif
}
Exemple #14
0
int main() 
{
  MCAgency_t agency;
  MCAgencyOptions_t options;
  int local_port=5050;

  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */
  agency = MC_Initialize(local_port, &options);

  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_AddStationaryAgent(agency, stationary_agent_func, "agent2", NULL);

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #15
0
int main() 
{
  MCAgency_t agency;
  int local_port = 10; /* Bluetooth RFCOMM ports only go from 0 to 30 */

  MCAgencyOptions_t options;
  MC_InitializeAgencyOptions(&options);
  options.bluetooth = 1;
  options.initInterps = 2;

  printf("Initializing...\n");  
  agency = MC_Initialize(local_port, &options);
  printf("Done Initializing.\n");

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #16
0
int main() 
{
  MCAgency_t agency;
  MCAgencyOptions_t options;
  int local_port = 5051;

  MC_InitializeAgencyOptions(&options);
  /* If the following line is uncommented, the command prompt
   * will be disabled. */
  MC_SetThreadOff(&options, MC_THREAD_CP); 

  agency = MC_Initialize(local_port, &options);

  MC_AddStationaryAgent(agency, stationary_agent_func, "agent1", NULL);

  MC_MainLoop(agency);

  MC_End(agency);
  return 0;
}
Exemple #17
0
int main() {
    MCAgency_t agency;
    int local_port = 5050;
    MCAgencyOptions_t options;

    MC_InitializeAgencyOptions(&options);

    MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */

    agency = MC_Initialize(local_port, &options);

    printf("Starting algorithm...\n");
    MC_Steer(
        agency,
        &algorithm,
        NULL
        ); 

    MC_End(agency);
    return 0;
}
Exemple #18
0
int main() 
{
  MCAgency_t agency;
  MCAgencyOptions_t options;
  MCAgent_t agent;
  double *agent_return_value;
  int task_num;
  int local_port=5050;
  int remote_port=5051;

  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */
  agency = MC_Initialize(local_port, &options);

  /* Compose the agent from a task source file */
  agent = MC_ComposeAgentFromFile(
      "mobagent3",        /* Name */
      "localhost:5050",   /* Home - This is the host the agent will return to
                           * when it has finished its tasks. */
      "IEL",              /* Owner */
      "task1.c",          /* Code filename */
      "results_task1",     /* Return Variable Name */
      "localhost:5051",   /* server/destination host */
      0                   /* persistent */
      );

  /* Add one more task */
  MC_AgentAddTaskFromFile(
      agent,              /* Agent handle */
      "task2.c",          /* Task code file name */
      "results_task2",       /* Return Variable Name */
      "localhost:5052",   /* server/destination host */
      0 );                /* Persistent */
  
  /* Add the agent */
  MC_AddAgent(agency, agent);

  MC_End(agency);
  return 0;
}
Exemple #19
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;
    int i;
    int local_port=5051;

    MC_InitializeAgencyOptions(&options);

    /* We want _all_ the threads on: EXCEPT, the command prompt thread */
    for (i = 0; i < MC_THREAD_ALL; i++) {
        MC_SetThreadOn(&options, i);
    }
    MC_SetThreadOff(&options, MC_THREAD_CP);  

    agency = MC_Initialize(
            local_port,
            &options);

    MC_SyncInit(agency, MUTEX_ID);
    /* Now, lets perform a simulated task which accesses a shared resource
     * 20 times. */
    for(i = 0; i < 20; i++) {
        printf("C Space: Attempting to lock mutex...\n");
        MC_MutexLock(agency, MUTEX_ID);
        printf("C Space: Mutex Locked. Performing task.\n");
#ifndef _WIN32
        sleep(1);
#else
        Sleep(1000);
#endif
        printf("C Space: Unlocking Mutex...\n");
        MC_MutexUnlock(agency, MUTEX_ID);
        printf("C Space: Mutex Unlocked.\n");
    }

    MC_SyncDelete(agency, MUTEX_ID);
    MC_End(agency);
    return 0;
}
Exemple #20
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;
    int i;
    int local_port=5051;

    MC_InitializeAgencyOptions(&options);
    /* We want _all_ the threads on: EXCEPT, the command prompt thread */
    for (i = 0; i < MC_THREAD_ALL; i++) {
        MC_SetThreadOn(&options, i);
    }
    MC_SetThreadOff(&options, MC_THREAD_CP);  /* Turn off command prompt */

    agency = MC_Initialize(
                 local_port,
                 &options);

    /* Wait forever... */
    MC_MainLoop(agency);
    return 0;
}
Exemple #21
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;
    int local_port=5051;
    int i;
    /* We want _all_ the threads on: EXCEPT, the command prompt thread */
    MC_InitializeAgencyOptions(&options);
    for (i = 0; i < MC_THREAD_ALL; i++) {
        MC_SetThreadOn(&options, i); /* Turn all threads on */
    }
    /* If the following line is uncommented, the command prompt will be turned
     * off. */
    /*MC_SetThreadOff(&options, MC_THREAD_CP);  */ 

    agency = MC_Initialize(
            local_port,
            &options);

    /* Wait forever... */
    MC_MainLoop(agency);
    return 0;
}
Exemple #22
0
int main() {
  MCAgency_t agency;
  MCAgencyOptions_t options;

  char *file_name = "./test1.xml";

  /* If server is not running on localhost, replace 'localhost' with the
   * fully qualified hostname of your server. i.e., if the server is running
   * on iel2.engr.ucdavis.edu, use */
  /* char *server_name = "iel2.engr.ucdavis.edu"; */

  MC_InitializeAgencyOptions(&options);
  MC_SetThreadOff(&options, MC_THREAD_CP); /* Turn off command prompt */
  agency = MC_Initialize(5050, &options);

  /* Note: The third argument of the following function may also be a
     valid IP address in the form of a string. i.e. 192.168.0.1 */
  MC_SendAgentFile(agency, file_name);

  printf("Terminating...\n");
  MC_End(agency);

  return 0;
}
Exemple #23
0
int main()
{
    MCAgency_t agency;
    MCAgencyOptions_t options;
    int i;
    int local_port=5051;

    MC_InitializeAgencyOptions(&options);

    for (i = 0; i < MC_THREAD_ALL; i++) {
        MC_SetThreadOn(&options, i);
    }
    /* if the following line is uncommented, the command prompt
     * will be disabled. */
 /*   MC_SetThreadOff(&options, MC_THREAD_CP);  */

    agency = MC_Initialize(
            local_port,
            &options);

    /* Wait forever... */
    MC_MainLoop(agency);
    return 0;
}
int main(int argc, char *argv[]) {
  int num_teams;
  int agency_num;
  int local_port;
  int i, j, count = 0;
  ChOptions_t ch_options;

  struct timeval temp1, temp2;
  long elapsed_mtime[NUM_DATA];  // elapsed time in milliseconds
  long elapsed_seconds;          // time difference in seconds
  long elapsed_useconds;         // time difference in microseconds
  int num_hosts;

  FILE *fptr;

  MCAgency_t agency;
  MCAgencyOptions_t options;

  if(argc != 5 && argc != 6) {
    printf("Usage: %s <num_teams> <agency_num> <num_hosts> <local_port> [embed_ch_home] \n", argv[0]);
    exit(0);
  }

  num_teams = atoi(argv[1]);
  agency_num = atoi(argv[2]);
  num_hosts = atoi(argv[3]);
  local_port = atoi(argv[4]);
  ch_options.shelltype = CH_REGULARCH;

  MC_InitializeAgencyOptions(&options);
  //MC_SetThreadOff(&options, MC_THREAD_CP); // Turn off the command prompt
  options.stack_size[MC_THREAD_AGENT] = 400000;
  options.initInterps = num_teams*2; 

  if(argc == 6) {
    ch_options.chhome = (char*)malloc((strlen(argv[5]) + 1) * sizeof(char));
    strcpy(ch_options.chhome, argv[5]);
    //MC_ChInitializeOptions(agency, &ch_options);
    options.ch_options = &ch_options;
  }

  agency = MC_Initialize(local_port, &options);

  // initializing condition variable(s)
  for(i=1; i<=num_teams; i++) {
    for(j=0; j<=num_hosts; j++) {
      MC_SyncInit(agency, 100*i+j);
    }
  }

  if(agency_num == 1) {
    while(1) {
      while(count < NUM_DATA) {
        MC_BarrierInit(agency, 555, num_teams+1);
        MC_BarrierInit(agency, 556, num_teams+1);

        //printf("Waiting for %d trigger agent(s) ...\n", num_teams);
        MC_Barrier(agency, 555);
        gettimeofday(&temp1, NULL);

        //printf("Waiting for %d last-leg runner agent(s) ...\n", num_teams);
        MC_Barrier(agency, 556);
        gettimeofday(&temp2, NULL);

        elapsed_seconds = temp2.tv_sec - temp1.tv_sec;
        elapsed_useconds = temp2.tv_usec - temp1.tv_usec;

        // elapsed time in millisec is given by
        // 1000 * (difference in seconds) + (difference in microseconds)
        elapsed_mtime[count] = (elapsed_seconds) * 1000 + elapsed_useconds / 1000.0;
        //elapsed_utime = (elapsed_seconds) * 1000000 + elapsed_useconds;

        //printf("Elapsed time = %ld milliseconds\n", elapsed_mtime);
        //printf("Elapsed time = %ld microseconds\n", elapsed_utime);

        usleep(500000);
        MC_BarrierDelete(agency, 555);
        usleep(500000);
        MC_BarrierDelete(agency, 556);
        usleep(500000);
        count++;
      }
      fptr = fopen("./output", "w");
      for(i=0; i<NUM_DATA; i++) {
        fprintf(fptr, "%ld\n", elapsed_mtime[i]);
      }
      fclose(fptr);
      printf("Done!\n");
      count = 0;
    }
  }
  else { 
    MC_MainLoop(agency);
  }
  return 0;
}