Пример #1
0
int main(int argc, char **argv)
{
  struct katcp_dispatch *d;
  int status;

  if(argc <= 1){
    fprintf(stderr, "usage: %s [bind-ip:]listen-port\n", argv[0]);
    return 1;
  }

  d = startup_katcp();
  if(d == NULL){
    fprintf(stderr, "%s: unable to allocate state\n", argv[0]);
    return 1;
  }

  version_katcp(d, "echo-test", 0, 1);
  build_katcp(d, BUILD);

  if(register_katcp(d, "?echo", "echo returns its parameters", &echo_cmd)){
    fprintf(stderr, "server: unable to enroll command\n");
    return 1;
  }

  if(run_server_katcp(d, argv[1], 0) < 0){
    fprintf(stderr, "server: run failed\n");
    return 1;
  }

  status = exited_katcp(d);

  shutdown_katcp(d);

  return status;
}
Пример #2
0
int main(int argc, char *argv[])
{
  struct katcp_dispatch *d;
  int rtn;

  d = startup_katcp();
  if (d == NULL){
    fprintf(stderr, "unable to create dispatch\n");
    return 1;
  }
  
  rtn = 0;

  rtn += register_name_type_katcp(d, "test", NULL, NULL, NULL, NULL, NULL);
  rtn += register_name_type_katcp(d, "test", NULL, NULL, NULL, NULL, NULL);
  
  rtn += store_data_type_katcp(d, "names", "john", NULL, NULL, NULL, NULL, NULL, NULL);
  
  rtn += store_data_type_katcp(d, "string", "test1", NULL, NULL, NULL, NULL, NULL, NULL);
  rtn += store_data_type_katcp(d, "string", "test2", NULL, NULL, NULL, NULL, NULL, NULL);

  rtn += store_data_type_katcp(d, "names", "adam", NULL, NULL, NULL, NULL, NULL, NULL);
  rtn += store_data_type_katcp(d, "names", "perry", NULL, NULL, NULL, NULL, NULL, NULL);
 
  rtn += store_data_type_katcp(d, "string", "thisisalongstring", NULL, NULL, NULL, NULL, NULL, NULL);
  
  fprintf(stderr, "katcp_type: cumulative rtn in main: %d\n", rtn);
  
  fprintf(stderr,"\n");
  print_types_katcp(d);
  fprintf(stderr,"\n");
  
  destroy_type_list_katcp(d);

  shutdown_katcp(d);
  return 0;
} 
Пример #3
0
int main(int argc, char **argv)
{
  struct katcp_dispatch *d;
#if 0
  struct cached_sensor_state local_data;
  struct fifo_sensor_state *fss;
#endif
  int status, result;

  if(argc <= 1){
    fprintf(stderr, "usage: %s [bind-ip:]listen-port\n", argv[0]);
    return 1;
  }

  /* create a state handle */
  d = startup_katcp();
  if(d == NULL){
    fprintf(stderr, "%s: unable to allocate state\n", argv[0]);
    return 1;
  }

  /* load up build and version information */
  add_version_katcp(d, "mylabel", 0, "myversion", "mybuildtime");

  /* example sensor */
  if(register_integer_sensor_katcp(d, 0, "check.integer.simple", "unix time in decaseconds", "Ds", &simple_integer_check_sensor, NULL, NULL, 0, INT_MAX)){
    fprintf(stderr, "server: unable to register sensors\n");
    return 1;
  }

  /* register example commands */

  result = 0;

  result += register_katcp(d, "?check-own",   "return self generated code", &own_check_cmd);
  result += register_katcp(d, "?check-ok",    "return ok", &ok_check_cmd);
  result += register_katcp(d, "?check-fail",  "return fail", &fail_check_cmd);
  result += register_katcp(d, "?check-pause", "pauses", &pause_check_cmd);
  result += register_katcp(d, "?check-subprocess", "runs sleep 10 as a subprocess and waits for completion", &subprocess_check_cmd);

  if(result < 0){
    fprintf(stderr, "server: unable to register commands\n");
    return 1;
  }


#if 1
  /* alternative - run with more than one client */
  #define CLIENT_COUNT 3

  if(run_multi_server_katcp(d, CLIENT_COUNT, argv[1], 0) < 0){
    fprintf(stderr, "server: run failed\n");
  }
#else
  if(run_server_katcp(d, argv[1], 0) < 0){
    fprintf(stderr, "server: run failed\n");
  }
#endif

  status = exited_katcp(d);

  shutdown_katcp(d);
#if 0
  fifo_boolean_destroy_sensor(fss);
#endif

  return status;
}