int run_chassis_tbs(struct katcp_dispatch *d, struct katcp_arb *a, unsigned int mode) { struct input_event event; int rr, fd; fd = fileno_arb_katcp(d, a); if(mode & KATCP_ARB_READ){ rr = read(fd, &event, sizeof(struct input_event)); if(rr == sizeof(struct input_event)){ log_message_katcp(d, KATCP_LEVEL_TRACE, NULL, "input event type=%d, code=%d, value=%d", event.type, event.code, event.value); if(event.type == EV_KEY && (event.value > 0)){ switch(event.code){ case KEY_POWER : case KEY_SYSRQ : log_message_katcp(d, KATCP_LEVEL_WARN, NULL, "power button pressed, shutting down"); terminate_katcp(d, KATCP_EXIT_HALT); break; } } } } return 0; }
int start_chassis_cmd(struct katcp_dispatch *d, int argc) { char *match; struct tbs_raw *tr; tr = get_mode_katcp(d, TBS_MODE_RAW); if(tr == NULL){ log_message_katcp(d, KATCP_LEVEL_FATAL, NULL, "unable to get raw state"); return KATCP_RESULT_FAIL; } if(tr->r_chassis){ log_message_katcp(d, KATCP_LEVEL_WARN, NULL, "chassis logic already registered"); return KATCP_RESULT_FAIL; } if(argc <= 1){ match = TBS_ROACH_CHASSIS; } else { match = arg_string_katcp(d, 1); if(match == NULL){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to acquire valid match"); return KATCP_RESULT_FAIL; } } tr->r_chassis = chassis_init_tbs(d, match); if(tr->r_chassis == NULL){ return KATCP_RESULT_FAIL; } return KATCP_RESULT_OK; }
void dump_variable_sensor_katcp(struct katcp_dispatch *d, struct katcp_vrbl *vx, int level) { unsigned int i; struct katcp_wit *w; if(is_vrbl_sensor_katcp(d, vx) <= 0){ log_message_katcp(d, level, NULL, "variable at %p does not appear to be a reasonable sensor", vx); return; } if(vx->v_extra == NULL){ log_message_katcp(d, level, NULL, "no extra variable state found for %p", vx->v_extra); return; } w = vx->v_extra; sane_wit(w); for(i = 0; i < w->w_size; i++){ log_message_katcp(d, level, NULL, "subscriber[%u] uses strategy %d with endpoint %p", i, w->w_vector[i]->s_strategy, w->w_vector[i]->s_endpoint); if(w->w_vector[i]->s_variable != vx){ log_message_katcp(d, (w->w_vector[i]->s_variable == NULL) ? level : KATCP_LEVEL_FATAL, NULL, "subscriber[%u] variable mismatch: cached value %p does not match top-level %p", i, w->w_vector[i]->s_variable, vx); } } log_message_katcp(d, level, NULL, "variable %p has %u subscribers", vx, w->w_size); }
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; }
int write_event_tbs(struct katcp_dispatch *d, struct katcp_arb *a, int type, int code, int value) { int fd, result; struct input_event event; fd = fileno_arb_katcp(d, a); if(fd < 0){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "no valid file descriptor as event target"); return -1; } event.type = type; event.code = code; event.value = value; result = write(fd, &event, sizeof(struct input_event)); if(result == sizeof(struct input_event)){ return 0; } if(result < 0){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "event write failed: %s", strerror(errno)); } else { log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "logic problem, short event write"); } return -1; }
int connect_udp(struct katcp_dispatch *d, struct udp_state *ud, int port) { int fd; struct sockaddr_in sa; /* Prepare UDP socket */ memset(&sa, 0, sizeof sa); sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_ANY); sa.sin_port = htons(port); fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(fd < 0){ fprintf(stderr, "unable to create udp socket:\n "); log_message_katcp(d, KATCP_LEVEL_ERROR, DMON_MODULE_NAME, "unable to create udp socket: %s", strerror(errno)); return -1; } if(bind(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0){ fprintf(stderr, "unable to bind udp:\n "); log_message_katcp(d, KATCP_LEVEL_ERROR, DMON_MODULE_NAME, "unable to connect to udp: %s", strerror(errno)); close(fd); fd = (-1); return -1; } ud->u_fd = fd; log_message_katcp(d, KATCP_LEVEL_INFO, DMON_MODULE_NAME, "digitiser destination,%s:%d", ip_addr, port); fprintf(stderr, "digitiser destination,%s:%d\n", ip_addr, port); return 0; }
int parser_save(struct katcp_dispatch *d, char *filename, int force){ struct kcs_basic *kb; struct p_parser *p; kb = get_mode_katcp(d,KCS_MODE_BASIC); if (kb == NULL) return KATCP_RESULT_FAIL; p = kb->b_parser; if (p != NULL) { int rtn; if (filename == NULL && !force){ rtn = save_tree(p,p->filename,force); if (rtn == KATCP_RESULT_FAIL){ log_message_katcp(d,KATCP_LEVEL_WARN,NULL,"File has been edited behind your back!!! use ?parser save newfilename or force save ?parser forcesave"); return KATCP_RESULT_FAIL; } } else if (force) rtn = save_tree(p,p->filename,force); else rtn = save_tree(p,filename,force); if (rtn == KATCP_RESULT_OK){ log_message_katcp(d,KATCP_LEVEL_INFO,NULL,"Saved configuration file as %s",(filename == NULL)?p->filename:filename); return rtn; } } log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"No configuration file loaded yet, use ?parser load [filename]"); return KATCP_RESULT_FAIL; }
int subprocess_check_cmd(struct katcp_dispatch *d, int argc) { struct katcp_notice *n; struct katcp_job *j; char *arguments[3] = { "SLEEP", "10", NULL }; log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "starting child process sleep 10"); /* check if somebody else is busy */ n = find_notice_katcp(d, "sleep-notice"); if(n != NULL){ log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "another instance already active"); return KATCP_RESULT_FAIL; } /* create a notice, an entity which can invoke the callback when triggered */ n = register_notice_katcp(d, "sleep-notice", 0, &subprocess_check_callback, NULL); if(n == NULL){ log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "unable to create notice object"); return KATCP_RESULT_FAIL; } /* create a job, something which isn't a timer or a client issuing commands, give it the notice so that it can trigger it when it needs to */ j = process_name_create_job_katcp(d, arguments[0], arguments, n, NULL); if(j == NULL){ log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "unable to create a subprocess handling job"); return KATCP_RESULT_FAIL; } /* suspend, rely on the call back to resume this task */ return KATCP_RESULT_PAUSE; }
int load_pattern_walsh_cmd(struct katcp_dispatch *d, int argc){ int i, j, s, input; time_t timeStamp; char walshBytes[2][64]; uint32_t *ind, value, patval; struct tbs_raw *tr; struct tbs_entry *te; /* Grab the mode pointer */ tr = get_mode_katcp(d, TBS_MODE_RAW); if(tr == NULL){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to acquire raw mode state"); return KATCP_RESULT_FAIL; } /* Make sure we're programmed */ if(tr->r_fpga != TBS_FPGA_MAPPED){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "fpga not programmed"); return KATCP_RESULT_FAIL; } /* Get the pointer to the Walsh table block memory */ te = find_data_avltree(tr->r_registers, WALSH_TABLE_BRAM); if(te == NULL){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "register %s not defined", WALSH_TABLE_BRAM); return KATCP_RESULT_FAIL; } /* Grab the Walsh pattern using DSM */ s = dsm_read(DDS_HOST, DSM_WALSH_VAR, &walshBytes, &timeStamp); if (s != DSM_SUCCESS) { dsm_error_message(s, "dsm_read()"); log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "dsm_read('%s', '%s'): failed with %d", DDS_HOST, DSM_WALSH_VAR, s); return KATCP_RESULT_FAIL; } /* For each input ... */ for (input=0; input<DSM_WALSH_INP; input++) { /* Repeat the pattern to fill the block */ for (i=0; i<WALSH_LEN/(DSM_WALSH_LEN/DSM_WALSH_SKIP); i++) { for (j=0; j<(DSM_WALSH_LEN/DSM_WALSH_SKIP); j++) { /* Get current value of WALSH_TABLE_BRAM[i*DSM_WALSH_LEN + j] */ ind = tr->r_map + te->e_pos_base + 4*(i*(DSM_WALSH_LEN/DSM_WALSH_SKIP) + j); value = *((uint32_t *)ind); /* Mask in the requested values */ patval = ((uint32_t)walshBytes[input][j*2] & 0xf) << (input*4); *((uint32_t *)ind) = (value & ~(0xf << (input*4))) | patval; /* mysnc to update the memory map */ msync(tr->r_map, tr->r_map_size, MS_SYNC); } } } return KATCP_RESULT_OK; }
int print_stack_statemachine_kcs(struct katcp_dispatch *d, struct katcp_stack *stack, struct katcp_tobject *o) { #ifdef DEBUG fprintf(stderr, "statemachine: about to runtime print stack\n"); #endif log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "----STACK PRINT START----"); print_stack_katcp(d, stack); log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "-----STACK PRINT END-----"); return 0; }
int perform_sensor_update_katcp(struct katcp_dispatch *d, void *data) { struct katcp_shared *s; unsigned int i, j, count; struct katcp_flat *fx; struct katcp_group *gx; struct katcl_parse *px; s = d->d_shared; if(s == NULL){ return -1; } if(s->s_changes <= 0){ log_message_katcp(d, KATCP_LEVEL_WARN, NULL, "logic problem: scheduled device update, but nothing requires updating"); return -1; } px = create_referenced_parse_katcl(); if(px == NULL){ return -1; } add_string_parse_katcl(px, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, KATCP_DEVICE_CHANGED_INFORM); add_string_parse_katcl(px, KATCP_FLAG_LAST | KATCP_FLAG_STRING, "sensor-list"); count = 0; for(j = 0; j < s->s_members; j++){ gx = s->s_groups[j]; for(i = 0; i < gx->g_count; i++){ fx = is_ready_flat_katcp(d, gx->g_flats[i]); if(fx){ if((fx->f_stale & KATCP_STALE_MASK_SENSOR) == KATCP_STALE_SENSOR_STALE){ fx->f_stale = KATCP_STALE_SENSOR_NAIVE; if((fx->f_flags & KATCP_FLAT_TOCLIENT) && (fx->f_flags & KATCP_FLAT_SEESKATCP)){ /* TODO: shouldn't we use the fancy queue infrastructure ? */ append_parse_katcl(fx->f_line, px); count++; } } } } } log_message_katcp(d, KATCP_LEVEL_DEBUG, NULL, "notified %u clients of %u sensor %s", count, s->s_changes, (s->s_changes == 1) ? "change" : "changes"); destroy_parse_katcl(px); s->s_changes = 0; return 0; }
int rcv_udp(struct katcp_dispatch *d, struct udp_state *ud) { struct udp_message buffer, *uv; int rr; uv = &buffer; fprintf(stderr, "receive udp start:\n "); rr = recvfrom(ud->u_fd, uv, sizeof(buffer), 0, NULL, NULL); if(rr < 0){ switch(errno){ case EAGAIN : case EINTR : return 0; default : log_message_katcp(d, KATCP_LEVEL_ERROR, DMON_MODULE_NAME, "udp receive failed with %s", strerror(errno)); close(ud->u_fd); ud->u_fd = (-1); return 0; } } uv->u_sequence = ntohs(uv->u_sequence); uv->u_addr_errcode = ntohl(uv->u_addr_errcode); if(ud->u_rw){ uv->u_data_length = ntohl(uv->u_data_length); } log_message_katcp(d, KATCP_LEVEL_TRACE, DMON_MODULE_NAME, "udp reply with sequence number %d", uv->u_sequence); fprintf(stderr, "udp reply with sequence number %d\n", uv->u_sequence); uv->u_addr_errcode = ((0xFF000000 & uv->u_addr_errcode) >> 24); if(uv->u_addr_errcode != 0){ log_message_katcp(d, KATCP_LEVEL_WARN, DMON_MODULE_NAME, "udp receive: something is not right, error code: %d", uv->u_addr_errcode); fprintf(stderr,"udp receive: something is not right, error code: %d", uv->u_addr_errcode); return -1; } if(uv->u_sequence != ud->u_sequence){ log_message_katcp(d, KATCP_LEVEL_WARN, DMON_MODULE_NAME, "udp received sequence number %d not %d", uv->u_sequence, ud->u_sequence); fprintf(stderr,"udp received sequence number %d not %d", uv->u_sequence, ud->u_sequence); return -1; } if(ud->u_rw){ log_message_katcp(d, KATCP_LEVEL_TRACE, DMON_MODULE_NAME, "udp data 0x%x", uv->u_data_length); fprintf(stderr,"udp data 0x%08x\n", uv->u_data_length); } return 0; }
int schedule_sensor_update_katcp(struct katcp_dispatch *d, char *name) { struct timeval tv; struct katcp_shared *s; struct katcp_flat *fx; s = d->d_shared; if(s == NULL){ return -1; } fx = this_flat_katcp(d); for_all_flats_vrbl_katcp(d, fx, name, NULL, &mark_stale_flat_katcp); tv.tv_sec = 0; tv.tv_usec = KATCP_NAGLE_CHANGE; if(register_in_tv_katcp(d, &tv, &perform_sensor_update_katcp, &(s->s_changes)) < 0){ return -1; } log_message_katcp(d, KATCP_LEVEL_DEBUG, NULL, "scheduled change notification"); s->s_changes++; return 0; }
int hook_led_cmd(struct katcp_dispatch *d, int argc, int value) { struct tbs_raw *tr; #if 0 log_message_katcp(d, KATCP_LEVEL_DEBUG, NULL, "running tbs hook function with value %d", value); #endif tr = get_mode_katcp(d, TBS_MODE_RAW); if(tr == NULL){ return -1; } if(tr->r_chassis == NULL){ return -1; } if(write_event_tbs(d, tr->r_chassis, EV_LED, LED_MISC, value) < 0){ return -1; } if(write_event_tbs(d, tr->r_chassis, EV_SYN, 0, 0) < 0){ return -1; } return 0; }
struct katcp_subscribe *attach_variable_katcp(struct katcp_dispatch *d, struct katcp_vrbl *vx, struct katcp_flat *fx) { struct katcp_wit *w; struct katcp_subscribe *sub; if((vx->v_flags & KATCP_VRF_SEN) == 0){ log_message_katcp(d, KATCP_LEVEL_WARN, NULL, "variable not declared as sensor, unwilling to monitor it"); return NULL; } /* TODO - could be more eleborate function pointer checking, in particular does it have a :value field */ if(vx->v_extra == NULL){ w = create_wit_katcp(d); if(w == NULL){ return NULL; } if(configure_vrbl_katcp(d, vx, vx->v_flags, w, NULL, &change_sensor_katcp, &release_sensor_katcp) < 0){ destroy_wit_katcp(d, w); return NULL; } } else { w = vx->v_extra; } sub = create_subscribe_katcp(d, w, fx); if(sub == NULL){ return NULL; } return sub; }
int pause_check_cmd(struct katcp_dispatch *d, int argc) { log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "ran pause check, will not return"); /* not useful on its own, but can use resume() to restart */ return KATCP_RESULT_PAUSE; }
int run_client_xlookup(struct katcp_dispatch *d, int argc) { struct mul_client *ci; ci = get_multi_katcp(d); if(ci == NULL){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "not a multiserver"); return KATCP_RESULT_FAIL; } return run_xlookup(ci, argc); }
void clear_ntp_poco(struct katcp_dispatch *d, struct ntp_sensor_poco *nt) { if(nt->n_magic != NTP_MAGIC){ log_message_katcp(d, KATCP_LEVEL_FATAL, NULL, "bad magic on ntp state"); } if(nt->n_fd >= 0){ close(nt->n_fd); nt->n_fd = (-1); } }
int subprocess_check_callback(struct katcp_dispatch *d, struct katcp_notice *n, void *data) { log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "was woken by child process exit"); /* a callback can not use KATCP_RESULT_* codes, it has to generate its messages by hand */ send_katcp(d, KATCP_FLAG_FIRST | KATCP_FLAG_STRING, "!check-subprocess", KATCP_FLAG_LAST | KATCP_FLAG_STRING, KATCP_OK); /* unpause the client instance, so that it can parse new commands */ resume_katcp(d); return 0; }
int parser_load(struct katcp_dispatch *d, char *filename){ int rtn; struct kcs_basic *kb; struct p_parser *p; kb = get_mode_katcp(d,KCS_MODE_BASIC); if (kb == NULL) return KATCP_RESULT_FAIL; p = kb->b_parser; if (p != NULL){ clean_up_parser(p); } p = malloc(sizeof(struct p_parser)); p->lcount = 0; p->labels = NULL; p->comments = NULL; p->comcount = 0; p->fsize = 0; rtn = start_parser(p,filename); if (rtn != 0){ log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"%s",strerror(rtn)); clean_up_parser(p); return KATCP_RESULT_FAIL; } p->filename = strdup(filename); kb->b_parser = p; log_message_katcp(d,KATCP_LEVEL_INFO,NULL,"Configuration file loaded"); return KATCP_RESULT_OK; }
int init_ntp_poco(struct katcp_dispatch *d, struct ntp_sensor_poco *nt) { int fd; struct sockaddr_in sa; nt->n_magic = NTP_MAGIC; if(nt->n_fd >= 0){ log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "closing previous ntp file descriptor"); close(nt->n_fd); nt->n_fd = (-1); } sa.sin_family = AF_INET; sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); sa.sin_port = htons(123); fd = socket(AF_INET, SOCK_DGRAM, 0); if(fd < 0){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to create ntp socket: %s", strerror(errno)); return -1; } if(connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "unable to connect to ntp: %s", strerror(errno)); close(fd); fd = (-1); return -1; } nt->n_fd = fd; nt->n_sequence = 1; send_ntp_poco(d, nt); return 0; }
int broadcast_subscribe_katcp(struct katcp_dispatch *d, struct katcp_wit *w, struct katcl_parse *px) { unsigned int i, inc; struct katcp_subscribe *sub; sane_wit(w); #ifdef DEBUG fprintf(stderr, "sensor: broadcasting sensor update to %u interested parties\n", w->w_size); #endif i = 0; while(i < w->w_size){ sub = w->w_vector[i]; inc = 1; #ifdef KATCP_CONSISTENCY_CHECKS if(sub == NULL){ fprintf(stderr, "major logic problem: null entry at %u in vector of subscribers\n", i); abort(); } #endif /* WARNING: for events: should we check that something actually has changed ? */ if(sub->s_strategy == KATCP_STRATEGY_EVENT){ if(send_message_endpoint_katcp(d, w->w_endpoint, sub->s_endpoint, px, 0) < 0){ #if 0 log_message_katcp(d, KATCP_LEVEL_DEBUG, NULL, "subscriber %u/%u unreachable at enpoint %p, retiring it", i, w->w_size, sub->s_endpoint); #endif /* other end could have gone away, notice it ... */ delete_subscribe_katcp(d, w, i); /* implies a w_size-- */ inc = 0; } #ifdef KATCP_CONSISTENCY_CHECKS } else { fprintf(stderr, "major logic problem: unimplemented sensor strategy %u\n", sub->s_strategy); abort(); #endif } i += inc; } return w->w_size; }
int parser_set(struct katcp_dispatch *d, char *srcl, char *srcs, unsigned long vidx, char *nv){ struct kcs_basic *kb; struct p_parser *p; kb = get_mode_katcp(d,KCS_MODE_BASIC); if (kb == NULL) return KATCP_RESULT_FAIL; p = kb->b_parser; if (p != NULL) { return set_label_setting_value(d,p,srcl,srcs,vidx,nv); } log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"No configuration file loaded yet, use ?parser load [filename]"); return KATCP_RESULT_FAIL; }
void destroy_udp(struct katcp_dispatch *d, struct udp_state *ud) { if(ud == NULL){ return; } if(ud->u_magic != UDP_MAGIC){ log_message_katcp(d, KATCP_LEVEL_FATAL, DMON_MODULE_NAME, "bad magic on udp state"); } if(ud->u_fd >= 0){ close(ud->u_fd); ud->u_fd = (-1); } free(ud); }
int init_mod(struct katcp_dispatch *d) { int rtn; if (check_code_version_katcp(d) != 0){ #ifdef DEBUG fprintf(stderr, "mod: ERROR was build against an incompatible katcp lib\n"); #endif log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "cannot load module katcp version mismatch"); return -1; } rtn = store_data_type_katcp(d, KATCP_TYPE_OPERATION, KATCP_DEP_BASE, KATCP_OPERATION_CONF_PARSE, &config_parser_setup_mod, NULL, NULL, NULL, NULL, NULL, NULL); #if 0 rtn = register_name_type_katcp(d, KATCP_TYPE_CONFIG_SETTING, KATCP_DEP_BASE, &print_config_setting_type_mod, &destroy_config_setting_type_mod, NULL, NULL, &parse_config_setting_type_mod, &getkey_config_setting_type_mod); #endif rtn += store_data_type_katcp(d, KATCP_TYPE_OPERATION, KATCP_DEP_BASE, KATCP_OPERATION_PARSE_CSV, &parse_csv_setup_mod, NULL, NULL, NULL, NULL, NULL, NULL); #if 0 rtn += store_data_type_katcp(d, KATCP_TYPE_EDGE, KATCP_DEP_BASE, KATCP_EDGE_CONF_SEARCH, &config_search_setup_mod, NULL, NULL, NULL, NULL, NULL, NULL); #endif log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "successfully loaded mod_config_parser"); #if 0 log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "added type:"); log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "%s", KATCP_TYPE_CONFIG_SETTING); #endif log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "added operations:"); log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "%s", KATCP_OPERATION_CONF_PARSE); log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "%s", KATCP_OPERATION_PARSE_CSV); #if 0 log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "added edges:"); log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "%s", KATCP_EDGE_CONF_SEARCH); #endif //log_message_katcp(d, KATCP_LEVEL_INFO, NULL, "to see the full operation list: ?sm oplist"); return rtn; }
int store_data_at_type_katcp(struct katcp_dispatch *d, struct katcp_type *t, int dep, char *d_name, void *d_data, void (*fn_print)(struct katcp_dispatch *, char *key, void *), void (*fn_free)(void *), int (*fn_copy)(void *, void *, int), int (*fn_compare)(const void *, const void *), void *(*fn_parse)(struct katcp_dispatch *d, char **), char *(*fn_getkey)(void *)) { struct avl_tree *at; struct avl_node *an; if (t == NULL) return -1; if (t->t_print != fn_print || t->t_free != fn_free || t->t_copy != fn_copy || t->t_compare != fn_compare || t->t_parse != fn_parse || t->t_getkey != fn_getkey){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "callbacks for data with key <%s> dont match type %s\n", d_name, t->t_name); #ifdef DEBUG fprintf(stderr, "katcp_type: callbacks for data with key <%s> dont match type %s\n", d_name, t->t_name); #endif return -1; } if (t->t_tree == NULL){ t->t_tree = create_avltree(); #if DEBUG >1 fprintf(stderr, "katcp_type: create avltree for type: <%s>\n", t->t_name); #endif } at = t->t_tree; if (at == NULL) return -1; an = create_node_avltree(d_name, d_data); if (an == NULL) return -1; if (add_node_avltree(at, an) < 0){ //free_node_avltree(an, fn_free); free_node_avltree(an, NULL); an = NULL; return -1; } #if DEBUG >1 fprintf(stderr, "katcp_type: inserted {%s} for type tree: <%s>\n", d_name, t->t_name); #endif return 0; }
int parser_list(struct katcp_dispatch *d){ struct kcs_basic *kb; struct p_parser *p; kb = get_mode_katcp(d,KCS_MODE_BASIC); if (kb == NULL) return KATCP_RESULT_FAIL; p = kb->b_parser; if (p != NULL) { show_tree(d,p); } else { log_message_katcp(d,KATCP_LEVEL_ERROR,NULL,"No configuration file loaded yet, use ?parser load [filename]"); return KATCP_RESULT_FAIL; } return KATCP_RESULT_OK; }
int store_data_type_katcp(struct katcp_dispatch *d, char *t_name, int dep, char *d_name, void *d_data, void (*fn_print)(struct katcp_dispatch *, char *key, void *), void (*fn_free)(void *), int (*fn_copy)(void *, void *, int), int (*fn_compare)(const void *, const void *), void *(*fn_parse)(struct katcp_dispatch *d, char **), char *(*fn_getkey)(void *)) { struct katcp_shared *s; struct katcp_type **ts; struct katcp_type *t; int size, pos; sane_shared_katcp(d); s = d->d_shared; if (s == NULL) return -1; ts = s->s_type; size = s->s_type_count; pos = binary_search_type_list_katcp(ts, size, t_name); if (pos < 0){ #if DEBUG>1 fprintf(stderr, "katcp_type: need to register new type for <%s> at %d which maps to %d\n", t_name, pos, (pos+1)*(-1)); #endif /*pos returned from bsearch is pos to insert new type of searched name but it needs to be decremented and flipped positive*/ pos = register_at_id_type_katcp(d, (pos+1)*(-1), t_name, dep, fn_print, fn_free, fn_copy, fn_compare, fn_parse, fn_getkey); if (pos < 0){ log_message_katcp(d, KATCP_LEVEL_ERROR, NULL, "could not create new type %s\n", t_name); #ifdef DEBUG fprintf(stderr, "katcp_type: could not create new type: %s\n", t_name); #endif return -1; } } /*now pos is the position of the type in the list*/ ts = s->s_type; size = s->s_type_count; t = ts[pos]; return store_data_at_type_katcp(d, t, dep, d_name, d_data, fn_print, fn_free, fn_copy, fn_compare, fn_parse, fn_getkey); }
void destroy_event_katcp(struct katcp_dispatch *d, struct katcp_event *e) { unsigned int i; struct katcp_interest *ki; if(e == NULL){ return; } #ifdef KATCP_CONSISTENCY_CHECKS if(e->e_use > 0){ log_message_katcp(d, KATCP_LEVEL_FATAL, NULL, "internal problem: attempting to destroy an event which is held by some parties"); abort(); } #endif for(i = 0; i < e->e_count; i++){ ki = &(e->e_vector[i]); /* TODO */ } e->e_count = 0; if(e->e_name){ free(e->e_name); e->e_name = NULL; } if(e->e_vector){ free(e->e_vector); e->e_vector = NULL; } if(e->e_queue){ destroy_queue_katcl(e->e_queue); e->e_queue = NULL; } e->e_count = 0; free(e); }
int send_udp(struct katcp_dispatch *d, struct udp_state *ud, char *ip_addr, int port, uint32_t address, uint32_t length) { struct udp_message buffer, *uv; int wr; struct sockaddr_in sa; /* Prepare UDP socket */ memset(&sa, 0, sizeof sa); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr(ip_addr); sa.sin_port = htons(port); uv = &buffer; ud->u_sequence = 0xffff & (ud->u_sequence + 1); uv->u_sequence = htons(ud->u_sequence); uv->u_addr_errcode = ((address & 0x7FFFFFFF) | (ud->u_rw << 31)); uv->u_addr_errcode = htonl(uv->u_addr_errcode); uv->u_data_length = (length & 0xFFFFFFFF); uv->u_data_length = htonl(uv->u_data_length); wr = sendto(ud->u_fd, uv, sizeof(buffer), 0,(struct sockaddr *)&sa, sizeof(struct sockaddr_in)); if(wr < 0){ switch(errno){ case EAGAIN : case EINTR : fprintf(stderr, "unable to send request, ERR:\n"); return 0; default : log_message_katcp(d, KATCP_LEVEL_ERROR, DMON_MODULE_NAME, "unable to send request: %s", strerror(errno)); fprintf(stderr, "unable to send request: \n"); break; } } fprintf(stderr, "send udp ok:\n "); return 0; }