예제 #1
0
main()
{
   INT status, port;

   /* register RPC server under port 1750 */
   port = 1750;
   status = rpc_register_server(ST_REMOTE, "", &port, NULL);
   if (status != RPC_SUCCESS) {
      printf("Cannot start server");
      return 0;
   }

   /* Register function list. Calls get forwarded to rpc_dispatch */
   rpc_register_functions(rpc_list, rpc_dispatch);

   /* Print debugging messages */
   rpc_set_debug((void (*)(char *)) puts, 0);

   /* Server loop */
   while (cm_yield(1000) != RPC_SHUTDOWN);

   /* Shutdown server */
   rpc_server_shutdown();

   return 1;
}
예제 #2
0
파일: odb_test.c 프로젝트: wuchen1106/DAQ
int main()
{
   int status, size;
   HNDLE hDB, hKey;

   /* connect to experiment */
   status = cm_connect_experiment("", "", "ODBTest", NULL);
   if (status != CM_SUCCESS)
      return 1;

   /* get handle to online database */
   cm_get_experiment_database(&hDB, &hKey);

   /* read key "runinfo/run number" */
   size = sizeof(run_number);
   status =
       db_get_value(hDB, 0, "/runinfo/run number", &run_number, &size, TID_INT, TRUE);
   if (status != DB_SUCCESS) {
      printf("Cannot read run number");
      return 0;
   }

   printf("Current run number is %d\n", run_number);

   /* set new run number */
   run_number++;
   db_set_value(hDB, 0, "/runinfo/run number", &run_number, size, 1, TID_INT);


   /* now open run_number with automatic updates */
   db_find_key(hDB, 0, "/runinfo/run number", &hKey);
   db_open_record(hDB, hKey, &run_number, sizeof(run_number),
                  MODE_READ, run_number_changed, NULL);

   printf("Waiting for run number to change. Hit RETURN to abort\n");

   do {
      cm_yield(1000);
   } while (!ss_kbhit());

   db_close_record(hDB, hKey);

   /* disconnect from experiment */
   cm_disconnect_experiment();

   return 1;
}
예제 #3
0
INT rpc_master_poll_live()
{
  if(!enable_rpc_master) {
    return SUCCESS;
  }

  // Yield to receive any pending RPCs
  cm_yield(0);

  // Have we received a request to end the event?
  if(request_stop_event == event_number) {
    // diag_print(2, "Stopping event.\n");
    return FE_NEED_STOP; 
  } 

  return SUCCESS;
}
예제 #4
0
/** 
 * If frontend_call_loop is true, this routine gets called when
 * the frontend is idle or once between every event
 * 
 * @return SUCCESS. Other options are RPC_SHUTDOWN, SS_ABORT
 */
INT frontend_loop()
{
   /* if frontend_call_loop is true, this routine gets called when
      the frontend is idle or once between every event */
  static int count = 0;
  INT prescale = 10;
  INT status = SUCCESS;

  // allow access to mutex_midas lock
  pthread_mutex_unlock( &mutex_midas );
  usleep(1);
  pthread_mutex_lock( &mutex_midas );
  
  if ( !count%prescale ) status = cm_yield(1);
  count++;

  return status;
}
예제 #5
0
/* ********************************************************************* */
INT rpc_slave_poll_live()
{
  if(!enable_rpc_slave) {
    return SUCCESS;
  }

  // Yield to receive any pending RPCs
  cm_yield(1000);

  // Have we received an end-of-event notice?
  if(event_ended) {
    event_ended = FALSE;
    diag_print(2, "event ended\n");
    return FE_END_BLOCK;
  } else {
    return SUCCESS;
  }
}
예제 #6
0
/** 
 * If frontend_call_loop is true, this routine gets called when
 * the frontend is idle or once between every event
 * 
 * @return SUCCESS. Other options are RPC_SHUTDOWN, SS_ABORT
 */
INT frontend_loop()
{
   /* if frontend_call_loop is true, this routine gets called when
      the frontend is idle or once between every event */

  INT status = SUCCESS;

  /*TG  
  pthread_mutex_unlock( &mutex_midas );
  usleep(1);
  pthread_mutex_lock( &mutex_midas );
  */


#if 1
  //dm_area_flush();
  //printf("frontend loop\n");
  status = cm_yield(10);
  //sched_yield();
#endif 
  
  return status;
}
예제 #7
0
INT rpc_master_poll_dead()
{
  if(!enable_rpc_master) {
    return SUCCESS;
  }

  // Yield to receive any pending RPCs
  cm_yield(0);

  // Have we received notice from each of the enabled crates that
  // it is ready to start? 

  BOOL ready_to_start = TRUE;

  INT ram = cycle_ram(); 

  for(int i = 0; i < MAX_CRATES; i++) {
    if(i != crate_number && crate[i].enabled && crate[i].synchronous && 
       !(crate[i].ready[ram] || crate[i].ready[0])) {
      ready_to_start = FALSE; 
      break;
    }
  }

  if(ready_to_start) {
    for(int i = 0; i < MAX_CRATES; i++) {
      crate[i].participating = (crate[i].ready[ram] || crate[i].ready[0]);

      crate[i].ready[ram] = FALSE;
      crate[i].ready[0] = FALSE;
    }

    return FE_NEED_START;
  } else {
    return SUCCESS;
  }
}
예제 #8
0
main()
{
   INT status, size, trans, run_number;
   char host_name[256], str[32];
   INT event_id, request_id;
   DWORD last_time;
   BOOL via_callback;

   /* get parameters */

   printf("ID of event to request: ");
   ss_gets(str, 32);
   event_id = atoi(str);

   printf("Host to connect: ");
   ss_gets(host_name, 256);

   printf("Get all events (0/1): ");
   ss_gets(str, 32);
   all_flag = atoi(str);

   printf("Receive via callback ([y]/n): ");
   ss_gets(str, 32);
   via_callback = str[0] != 'n';

   /* connect to experiment */
   status = cm_connect_experiment(host_name, "",
                                  all_flag ? "Power Consumer" : "Consumer", NULL);
   if (status != CM_SUCCESS)
      return 1;

   /* open the "system" buffer, 1M size */
   bm_open_buffer("SYSTEM", EVENT_BUFFER_SIZE, &hBufEvent);

   /* set the buffer cache size */
   bm_set_cache_size(hBufEvent, 100000, 0);

   /* place a request for a specific event id */
   bm_request_event(hBufEvent, (WORD) event_id, TRIGGER_ALL,
                    all_flag ? GET_ALL : GET_SOME, &request_id,
                    via_callback ? process_event : NULL);

   /* place a request for system messages */
   cm_msg_register(process_message);

   /* place a request for transition notification */
   cm_register_transition(TR_START, via_callback? transition : NULL);

   last_time = 0;

   do {
      if (via_callback)
         status = cm_yield(1000);
      else {
         /* receive event "manually" and call receive_event */
         size = sizeof(event_buffer);
         status = bm_receive_event(hBufEvent, event_buffer, &size, ASYNC);
         if (status == BM_SUCCESS)
            process_event(hBufEvent, request_id, (EVENT_HEADER *) event_buffer,
                          (void *) (((EVENT_HEADER *) event_buffer) + 1));

         /* receive transitions "manually" */
         if (cm_query_transition(&trans, &run_number, NULL))
            transition(run_number, NULL);

         /* call yield once every 100 ms */
         if (ss_millitime() - last_time > 100) {
            last_time = ss_millitime();
            status = cm_yield(0);
         }
      }

   } while (status != RPC_SHUTDOWN && status != SS_ABORT);

   cm_disconnect_experiment();

   return 1;
}
예제 #9
0
파일: mlxspeaker.c 프로젝트: cjpl/midas
int main(int argc, char *argv[])
{
   BOOL daemon = FALSE;
   INT status, i, ch;
   char host_name[HOST_NAME_LENGTH];
   char exp_name[NAME_LENGTH];
   char *speech_program = SPEECH_PROGRAM;

   /* get default from environment */
   cm_get_environment(host_name, sizeof(host_name), exp_name, sizeof(exp_name));

#ifdef OS_DARWIN
   strlcpy(mtTalkStr, "afplay $MIDASSYS/utils/notify.wav", sizeof(mtTalkStr));
   strlcpy(mtUserStr, "afplay $MIDASSYS/utils/notify.wav", sizeof(mtTalkStr));
#endif   

   /* parse command line parameters */
   for (i = 1; i < argc; i++) {
      if (argv[i][0] == '-' && argv[i][1] == 'D')
         daemon = TRUE;
      else if (argv[i][0] == '-') {
         if (i + 1 >= argc || argv[i + 1][0] == '-')
            goto usage;
         if (argv[i][1] == 'e')
            strcpy(exp_name, argv[++i]);
         else if (argv[i][1] == 'h')
            strcpy(host_name, argv[++i]);
         else if (argv[i][1] == 'c')
            speech_program = argv[++i];
         else if (argv[i][1] == 't')
            strcpy(mtTalkStr, argv[++i]);
         else if (argv[i][1] == 'u')
            strcpy(mtUserStr, argv[++i]);
         else if (argv[i][1] == 's')
            shutupTime = atoi(argv[++i]);
         else {
          usage:
            printf
                ("usage: mlxspeaker [-h Hostname] [-e Experiment] [-c command] [-D] daemon\n");
            printf("                  [-t mt_talk] Specify the mt_talk alert command\n");
            printf("                  [-u mt_user] Specify the mt_user alert command\n");
            printf("                  [-s shut up time] Specify the min time interval between alert [s]\n");
            printf("                  The -t & -u switch require a command equivalent to:\n");
            printf("                  '-t play --volume=0.3 file.wav'\n");
            printf("                  [-c command] Used to start the speech synthesizer,\n");
            printf("                              which should read text from it's standard input.\n");
            printf("                              eg: mlxspeaker -c 'festival --tts -'\n\n");
            return 0;
         }
      }
   }

   if (daemon) {
      printf("Becoming a daemon...\n");
      ss_daemon_init(FALSE);
   }

   /* Handle SIGPIPE signals generated from errors on the pipe */
   signal(SIGPIPE, sigpipehandler);
   signal(SIGINT, siginthandler);
   
   fp = popen(speech_program, "w");
   if (fp == NULL) {
      cm_msg(MERROR, "Speaker", "Unable to start \"%s\": %s\n",
             speech_program, strerror(errno));
      cm_disconnect_experiment();
      exit(2);
   }
   
   /* now connect to server */
   status = cm_connect_experiment(host_name, exp_name, "Speaker", NULL);
   if (status != CM_SUCCESS)
      return 1;

   cm_msg_register(receive_message);

   printf("Midas Message Speaker connected to %s. Press \"!\" to exit.\n", host_name[0] ? host_name : "local host");

   /* initialize terminal */
   ss_getchar(0);
   
   do {
      status = cm_yield(1000);
      while (ss_kbhit()) {
         ch = ss_getchar(0);
         if (ch == -1)
            ch = getchar();
         if (ch == '!')
            status = RPC_SHUTDOWN;
      }
            
   } while (status != SS_ABORT && status != RPC_SHUTDOWN);

   /* reset terminal */
   ss_getchar(TRUE);
   
   pclose(fp);

   cm_disconnect_experiment();
   return 1;
}