コード例 #1
0
ファイル: statemachine_base.c プロジェクト: gitj/katcp_devel
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;
}
コード例 #2
0
ファイル: ktype.c プロジェクト: gitj/katcp_devel
void *search_type_katcp(struct katcp_dispatch *d, struct katcp_type *t, char *key, void *data)
{
  //struct katcp_type *t;
  void *o;
  
  if (t == NULL || key == NULL)
    return NULL;
#if 0
  t = find_name_type_katcp(d, type);
  if (t == NULL)
    return NULL;
#endif

  o = get_node_data_avltree(find_name_node_avltree(t->t_tree, key));
  if (o == NULL){
    if (data != NULL){
      if (store_data_at_type_katcp(d, t, 0, key, data,
                                      t->t_print,
                                      t->t_free,
                                      t->t_copy,
                                      t->t_compare,
                                      t->t_parse,
                                      t->t_getkey) < 0){
#ifdef DEBUG
        fprintf(stderr, "ktype: search store data fail calling process must manage data at (%p)\n", data);
#endif

        return NULL;
      }
    }
  }
  else {
#if 0
    def DEBUG
    fprintf(stderr, "ktype: search found key: <%s> managing data at (%p)\n", key, data);
#endif
    
    if (t->t_free != NULL && data != o)
      (*t->t_free)(data);

    data = o;
  }

  return data;
}
コード例 #3
0
ファイル: ktype.c プロジェクト: gitj/katcp_devel
int del_data_type_katcp(struct katcp_dispatch *d, char *type, char *key)
{
  struct katcp_type *t;
  struct avl_node *n;

  if (type == NULL || key == NULL)
    return -1;

  t = find_name_type_katcp(d, type);
  if (t == NULL)
    return -1;

  n = find_name_node_avltree(t->t_tree, key);
  if (n == NULL)
    return -1;

  return del_node_avltree(t->t_tree, n, t->t_free);
}
コード例 #4
0
ファイル: ktype.c プロジェクト: gitj/katcp_devel
void *get_key_data_type_katcp(struct katcp_dispatch *d, char *type, char *key)
{
  struct katcp_type *t;
  struct avl_node *n;

  if (type == NULL || key == NULL)
    return NULL;

  t = find_name_type_katcp(d, type);
  if (t == NULL)
    return NULL;

  n = find_name_node_avltree(t->t_tree, key);
  if (n == NULL)
    return NULL;
  
  return get_node_data_avltree(n);
}
コード例 #5
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);
}
コード例 #6
0
ファイル: statemachine_base.c プロジェクト: gitj/katcp_devel
struct kcs_sm_op *pushstack_setup_statemachine_kcs(struct katcp_dispatch *d, struct kcs_sm_state *s)
{
#define ARG_BASE 5
  struct katcp_type *t;
  struct katcp_tobject *o;
  struct kcs_sm_op *op;
  char **data, *type;
  void *ptemp, *stemp;
  int num, i;

  stemp = NULL;

  type = arg_string_katcp(d, 4);

  if (type == NULL || s == NULL)
    return NULL;
  
  t = find_name_type_katcp(d, type);
  if (t == NULL){
    log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "invalid type: %s\n", type); 
    return NULL;
  }
  
  num = arg_count_katcp(d) - ARG_BASE;
  
  data = malloc(sizeof(char *) * (num + 1));
  if (data == NULL)
    return NULL;
  
  for (i=0; i<num; i++){
    data[i] = arg_string_katcp(d, ARG_BASE + i);
#ifdef DEBUG
    fprintf(stderr, "statemachine: pushsetup data[%d of %d]: %s\n", i+1, num, data[i]);
#endif
  }
  data[num] = NULL; 
  
#ifdef DEBUG
  fprintf(stderr, "statemachine: call type parse function\n");
#endif
  ptemp = (*t->t_parse)(d, data);
  
  if (data[0] != NULL)
    stemp = search_type_katcp(d, t, data[0], ptemp);

  free(data);

  if (ptemp == NULL){
#ifdef DEBUG
    fprintf(stderr, "statemachine: type parse fn failed\n");
#endif
    //return NULL;  
  }

  if (stemp == NULL){
#ifdef DEBUG
    fprintf(stderr, "statemachine: type search fn failed\n");
#endif
    (*t->t_free)(ptemp);
    return NULL;
  }

  o = create_tobject_katcp(stemp, t, 0);
  if (o == NULL){
    (*t->t_free)(stemp);
#ifdef DEBUG
    fprintf(stderr, "statemachine: pushsetup could not create stack obj\n");
#endif
    return NULL;
  }
  
  op = create_sm_op_kcs(&pushstack_statemachine_kcs, o);
  if (op == NULL){
    (*t->t_free)(stemp);
    destroy_tobject_katcp(o);
    return NULL;
  }

#ifdef DEBUG
  fprintf(stderr, "statemachine: pushsetup created op (%p)\n", op);
#endif

  return op;
#undef ARG_BASE
}
コード例 #7
0
ファイル: ktype.c プロジェクト: gitj/katcp_devel
void *search_named_type_katcp(struct katcp_dispatch *d, char *type, char *key, void *data)
{ 
  return search_type_katcp(d, find_name_type_katcp(d, type), key, data);
}