Esempio n. 1
0
int config_search_mod(struct katcp_dispatch *d, struct katcp_notice *n, void *data)
{
  struct katcp_stack *stack;
  char *string;
  struct config_setting *cs;

  stack = data;
 
  string = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_STRING);
  
  cs = search_config_settings_mod(d, string);
  
  if (cs == NULL){
    log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "config search not found!");
    return -1;
  }

  print_config_setting_type_mod(d, cs);
  
  if (push_named_stack_katcp(d, stack, cs, KATCP_TYPE_CONFIG_SETTING) < 0){
    log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "config search could not push return to stack!");
    return -1;
  }
  
  wake_notice_katcp(d, n, NULL);

  return 0;
}
Esempio n. 2
0
int peek_stack_type_statemachine_kcs(struct katcp_dispatch *d, struct katcp_notice *n, void *data)
{
  struct katcp_stack *stack;
  struct katcp_type *t;
  struct katcp_tobject *to;
  char *ctype;

  stack = data;
  if (stack == NULL)
    return -1;

  ctype = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_STRING);
  if (ctype == NULL)
    return -1;
  
  t = find_name_type_katcp(d, ctype);
  if (t == NULL)
    return -1;

  to = peek_stack_katcp(stack);
  if (to == NULL && to->o_type != t)
    return -1;

  wake_notice_katcp(d, n, NULL);
  
  return 0;
}
Esempio n. 3
0
int config_parser_mod(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *o)
{
  char *string;
  int rtn; 
  
  string = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_STRING);
  
  rtn = start_config_parser_mod(d, string);
  
  return rtn;
}
Esempio n. 4
0
int msleep_statemachine_kcs(struct katcp_dispatch *d, struct katcp_notice *n, void *data)
{
  struct katcp_stack *stack;
  int *time;
  struct timeval tv;

  stack = data;
  if (stack == NULL)
    return -1;

  time = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_INTEGER);
  if (time == NULL)
    return -1;
  
  component_time_katcp(&tv, (unsigned int) (*time));

  wake_notice_in_tv_katcp(d, n, &tv);

  return 0;
}
Esempio n. 5
0
int get_values_dbase_katcp(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *o)
{
  struct katcp_dbase *db;
  struct katcp_tobject *temp;
  struct katcp_stack *values;
  int count, i;

  db = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_DBASE);
  if (db == NULL)
    return -1;
  
  count = get_value_count_dbase_katcp(db);
  values = get_value_stack_dbase_katcp(db);

  for (i=0; i<count; i++){
    temp = index_stack_katcp(values, i);
    push_tobject_katcp(stack, copy_tobject_katcp(temp));
  }
  
  return 0;
}
Esempio n. 6
0
int parse_csv_mod(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *o)
{
#if 0
  struct config_setting *cs;
#endif
  struct katcp_type *strtype; 
  char *str, c, *temp[2];
  int len, pos, i, count;

  void *data;
  
  strtype = find_name_type_katcp(d, KATCP_TYPE_STRING);
  if (strtype == NULL || strtype->t_parse == NULL)
    return -1;
#if 0
  cs = pop_data_expecting_stack_katcp(d, stack, KATCP_TYPE_CONFIG_SETTING);
  if (cs == NULL)
    return -1;
#endif

  str = pop_data_type_stack_katcp(stack, strtype);
  if (str == NULL)
    return -1;

  len = strlen(str);
  pos = 0;
  temp[1] = NULL;
  count = 0;

  for (i=0; i<=len; i++){
    c = str[i];
    switch(c){
      case EOL:
      case CR:
      case LF:
      case VALUE:
        temp[0] = strndup(str + pos, i-pos);
        if (temp[0] != NULL){
#ifdef DEBUG
          fprintf(stderr, "csv: <%s>\n", temp[0]);
#endif
        
          data = search_type_katcp(d, strtype, temp[0], (*strtype->t_parse)(d, temp));
#if 0 
          if (push_named_stack_katcp(d, stack, data, KATCP_TYPE_STRING) < 0){
#endif
          if (push_stack_katcp(stack, data, strtype) < 0){
#ifdef DEBUG
            fprintf(stderr, "csv: push named stack katcp error\n");
#endif
          }
          count++;
          free(temp[0]);
        }
        pos = i+1;
        break;
    }
    
  }
#if 0
  if (count > 1){
    inttype = find_name_type_katcp(d, KATCP_TYPE_INTEGER);
    if (inttype == NULL || inttype->t_getkey == NULL)
      return -1;
      
    data = create_integer_type_kcs(count);
    if (data == NULL)
      return -1;

    str = (*inttype->t_getkey)(data);
    if (str == NULL)
      return -1;

#ifdef DEBUG
    fprintf(stderr, "csv: <%s>\n", str);
#endif
    data = search_type_katcp(d, inttype, str, data);
    push_named_stack_katcp(d, stack, data, KATCP_TYPE_INTEGER);

    free(str);
  }
#endif

  return 0;
}

struct kcs_sm_op *parse_csv_setup_mod(struct katcp_dispatch *d, struct kcs_sm_state *s)
{
  return create_sm_op_kcs(&parse_csv_mod, NULL);
}

#if 0
struct config_setting *search_config_settings_mod(struct katcp_dispatch *d, void *data)
{
  char *str;
  str = data;
  return get_key_data_type_katcp(d, KATCP_TYPE_CONFIG_SETTING, str);
}