示例#1
0
void *_GalSS_init_server(GalIO_ServerStruct *server, int argc, char **argv)
{
  char *data_file = (char *) NULL;
  AudioDevice *a;
  AudioPkg *p;
  int num_batch = 0;
  
  if (GalUtil_OACheckUsage(argc, argv, oas, NULL) == 0)	
    exit(1);
  
  if (GalUtil_OAExtract(argc, argv, oas, "-audio_data",
			GAL_OA_STRING, &data_file) == 0) {
    GalUtil_Warn("No -audio_data argument. Exiting.");
    exit(1);
  }
  GalUtil_OAExtract(argc, argv, oas, "-batch",
		    GAL_OA_INT, &num_batch);
  a = InitializeAudio(data_file, __AudioPoll, num_batch);
  free(data_file);
  if (!a) {
    GalUtil_Warn("Can't initialize audio device. Exiting.");
    exit(1);
  }
  p = (AudioPkg *) calloc(1, sizeof(AudioPkg));
  p->device = a;
  a->client_data = (void *) p;
  return (void *) p;
}
示例#2
0
void *_GalSS_init_server(Gal_Server *s, int argc, char **argv)
{
    char *config_file = NULL;

    if (GalUtil_OACheckUsage(argc, argv, oas, NULL) == 0)
       exit(1);
    GalUtil_OAExtract(argc, argv, oas, "-config", GAL_OA_STRING, &config_file);
    if (config_file == NULL){
       printf("No config file specified... exiting\n");
       exit(1);
    }

    /* set config file parms */
    config(argc, argv);

    /* initialize parser, malloc space, etc */
    init_parse(dir, dict_file, grammar_file, frames_file, priority_file);

    return (void *) NULL;
}
GalSS_ServerArgs *GalSS_ExtractCmdlineServerArgs(GalSS_ServerArgs *arg_pkg,
						 int argc, char **argv,
						 int *new_argc_ptr,
						 char ***new_argv_ptr)
{
  int new_argc, our_new_argc;
  char **new_argv,**our_new_argv;
  int use_ttloop;
  int use_threads = 0;
  char *hub_location = (char *) NULL;
  GalSS_ServerArgs *initial_arg_pkg = arg_pkg;
  char **local_oas;

  Gal_InitializeStatics();

  if (!arg_pkg) {
    arg_pkg = GalSS_DefaultServerArgs();
  }
  local_oas = arg_pkg->oas_descr->oas;
  
  if (!GalUtil_OASplitArgs(argc, argv, local_oas, NULL, &our_new_argc,
		     &our_new_argv, &new_argc, &new_argv)) {
    if (!initial_arg_pkg)
      GalSS_FreeArgPkg(arg_pkg);
    return (GalSS_ServerArgs *) NULL;
  }

  if (GalUtil_OACheckUsage(our_new_argc, our_new_argv, local_oas, NULL) == 0) {
    _GalSS_print_usage(argc, argv);    
    if (!initial_arg_pkg)
      GalSS_FreeArgPkg(arg_pkg);
    return (GalSS_ServerArgs *) NULL;
  }
    
  /* If we don't get a server port, make sure it uses the default. */
  if (!arg_pkg->port_disabled) {
    if (GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas, "-port",
			  GAL_OA_SHORT, &(arg_pkg->server_port))) {
      /* Make sure it's a listener on top of whatever else. */
      arg_pkg->server_listen_status = arg_pkg->server_listen_status | GAL_LISTENING_SERVER;
    }
  }
  
  /* Now that we've extracted the port, extract the hub location. This
     will override the port if necessary. */
  if (!arg_pkg->contact_hub_info_disabled) {
    if (GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas,
			  "-contact_hub",
			  GAL_OA_STRING, &hub_location)) {
      /* SAM 2/28/02: Now OAExtract is guaranteed to copy the string. */
      arg_pkg->client_pair_string = hub_location;
      if (!arg_pkg->server_listen_status_disabled) {
	if (arg_pkg->server_port != 0) {
	  /* The server port has been set on the command line. */
	  arg_pkg->server_listen_status = arg_pkg->server_listen_status | GAL_HUB_CLIENT | GAL_LISTENING_SERVER;
	} else {
	  /* DISABLE LISTENING. */
	  arg_pkg->server_listen_status = (arg_pkg->server_listen_status & ~GAL_LISTENING_SERVER) | GAL_HUB_CLIENT;
	}
      }
    }
  }

  if (!arg_pkg->server_locations_disabled) {
    /* SAM 2/28/02: OAExtract is now guaranteed to copy the string. */
    GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas,
		      "-server_locations_file", GAL_OA_STRING,
		      &(arg_pkg->server_locations_file));
  }

  if (!arg_pkg->slf_disabled) {
    GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas,
		      "-slf_name", GAL_OA_STRING,
		      &(arg_pkg->slf_name));
  } 

  if (!arg_pkg->maxconns_disabled) {
    GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas, "-maxconns",
		      GAL_OA_INT, &(arg_pkg->max_conns));
  }

  if (!arg_pkg->color_disabled) {
    if (GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas, "-color", GAL_OA_INT, NULL))
      arg_pkg->use_color = 1;
  }

  if (!arg_pkg->verbosity_disabled) {
    GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas, "-verbosity",
	       GAL_OA_INT, &(arg_pkg->verbosity));
  }

  if (!arg_pkg->contact_hub_info_disabled) {
    /* SAM 2/28/02: OAExtract is now guaranteed to copy the string. */
    GalUtil_OAExtract(our_new_argc, our_new_argv, local_oas, "-session_id",
		      GAL_OA_STRING, &(arg_pkg->session_id));   
  }

  if (!arg_pkg->assert_disabled) {
    arg_pkg->do_assert = GalUtil_OAExtract(our_new_argc, our_new_argv,
				    local_oas, "-assert", GAL_OA_INT, NULL);
  }
  if (!arg_pkg->validate_disabled) {
    arg_pkg->validate = GalUtil_OAExtract(our_new_argc, our_new_argv,
				   local_oas, "-validate", GAL_OA_INT, NULL);
  }
  if (!arg_pkg->loop_type_disabled) {
    use_ttloop = !GalUtil_OAExtract(our_new_argc, our_new_argv,
			     local_oas, "-nottloop", GAL_OA_INT, NULL);
#ifdef GAL_THREADS
    use_threads = GalUtil_OAExtract(our_new_argc, our_new_argv,
			     local_oas, "-thread", GAL_OA_INT, NULL);
#endif /* GAL_THREADS */
    if (use_threads) {
      arg_pkg->loop_type = GAL_LOOP_THREADS;
    } else if (use_ttloop) {
      arg_pkg->loop_type = GAL_LOOP_TT;
    } else {
      arg_pkg->loop_type = GAL_LOOP_EXTERNAL;
    }
  }

  GalSS_FreeArgv(our_new_argc, our_new_argv);
  
  *new_argc_ptr = new_argc;
  *new_argv_ptr = new_argv;

  __GalSS_PostprocessContactInfo(arg_pkg);
  
  return arg_pkg;
}