int main(int argc, char** argv) { int rc; zlog_category_t *zc; rc = zlog_init("test_mdc.conf"); if (rc) { printf("init failed\n"); return -1; } zc = zlog_get_category("my_cat"); if (!zc) { printf("get cat fail\n"); zlog_fini(); return -2; } ZLOG_INFO(zc, "1.hello, zlog"); zlog_put_mdc("myname", "Zhang"); ZLOG_INFO(zc, "2.hello, zlog"); zlog_put_mdc("myname", "Li"); ZLOG_INFO(zc, "3.hello, zlog"); zlog_fini(); return 0; }
int mcp_recv_pppd_interface_info_ack(struct stream *data_s, int syn_flag) { struct pppd_interface_info *info; struct listnode *mm; struct list* multi_list; //char tmp_buf[256]; ZLOG_INFO("recv pppd interface info "); multi_list = mcp_pppd_interface_parse(data_s); if(multi_list == NULL) { PPPD_DEBUG_TCP("mcp ppp multilink info parse error"); return -1; } //if(multi_list->count == 0 && syn_flag == 1) { if(syn_flag == 1) { ppp_if_close_all_enalbe_channel(); ppp_init_db_file(); mcp_pppd_init_all_local_interface(); //这个一定要放ppp_if_close_all_enalbe_channel后面 } for(ALL_LIST_ELEMENTS_RO(multi_list, mm, info)) { mcp_printf_ppp_interface_info(info); if(syn_flag == 0 && mcp_pppd_interface_changed(info) == 1) pppd_interface_disable(info->interfaceid); ; mcp_ppp_interface_info_update_local(info); } list_delete(multi_list); return 0; }
int main(int argc, char** argv) { int rc; zlog_category_t *zc; rc = zlog_init("test_conf.conf"); if (rc) { printf("init failed, try zlog-chk-conf test_conf.conf for more detail\n"); return -1; } zc = zlog_get_category("my_cat"); if (!zc) { printf("get cat fail\n"); zlog_fini(); return -2; } ZLOG_INFO(zc, "hello, zlog"); zlog_fini(); printf("log end\n"); return 0; }
jobjectArray Java_com_zokama_androlirc_Lirc_getDeviceList( JNIEnv* env, jobject thiz) { if (!read_config_file(LIRCDCFGFILE)) return NULL; jstring str = NULL; jclass strCls = (*env)->FindClass(env,"java/lang/String"); if (strCls == NULL) { return; } int i, device_count=0; char msg[255]; struct ir_remote *all; all=devices; while(all) { all=all->next; device_count++; } sprintf(msg, "Device count: %d", device_count); ZLOG_INFO(msg); jobjectArray result = (*env)->NewObjectArray(env,device_count,strCls,NULL); if (result == NULL) { return; } all=devices; i=0; while(all) { if(all->name==NULL) return NULL; str = (*env)->NewStringUTF(env,all->name); (*env)->SetObjectArrayElement(env,result,i++,str); (*env)->DeleteLocalRef(env,str); all=all->next; } return result; }
void * work(void *ptr) { long j = loop_count; char category[20]; sprintf(category, "cat%ld", (long)ptr); zlog_category_t *zc; zc = zlog_get_category(category); while(j-- > 0) { ZLOG_INFO(zc, "loglog"); } return 0; }
int main(int argc, char** argv) { int rc; zlog_category_t *zc; rc = zlog_init("test_init.conf"); if (rc) { printf("init fail"); return -2; } zc = zlog_get_category("my_cat"); if (!zc) { printf("zlog_get_category fail\n"); zlog_fini(); return -1; } ZLOG_INFO(zc, "before update"); sleep(3); rc = zlog_reload("test_init.2.conf"); if (rc) { printf("update fail\n"); } ZLOG_INFO(zc, "after update"); zlog_profile(); zlog_fini(); return 0; }
int read_config_file(char * config_file) { if(initialized) return 1; FILE *fd; fd=fopen(config_file, "r"); char msg[255]; if(fd==NULL) { sprintf(msg, "could not open config file '%s'", config_file); ZLOG_INFO(msg); return 0; } devices=read_config(fd, config_file); fclose(fd); if(devices==(void *) -1) { ZLOG_INFO("reading of config file failed"); return 0; } else { ZLOG_INFO("config file read"); } if(devices==NULL) { ZLOG_INFO("config file contains no valid remote control definition"); return 0; } initialized = 1; return 1; }
jobjectArray Java_com_zokama_androlirc_Lirc_getCommandList( JNIEnv* env, jobject thiz, jstring dev) { char * remote_name = (char *)(*env)->GetStringUTFChars(env, dev, NULL); struct ir_remote * remote = get_ir_remote(devices, remote_name); jstring str = NULL; jclass strCls = (*env)->FindClass(env,"java/lang/String"); if (strCls == NULL) { return; } int i, command_count=0; char msg[255]; struct ir_ncode *all; all=remote->codes; while(all->name!=NULL) { command_count++; all++; } sprintf(msg, "Command count: %d", command_count); ZLOG_INFO(msg); jobjectArray result = (*env)->NewObjectArray(env,command_count,strCls,NULL); if (result == NULL) { return; } for(i=0;i<command_count;i++) { str = (*env)->NewStringUTF(env,remote->codes[i].name); (*env)->SetObjectArrayElement(env,result,i,str); (*env)->DeleteLocalRef(env,str); } return result; }
int mcp_recv_pppd_multilink_info_ack(struct stream *data_s) { struct pppd_multilink_info *multi_info; struct listnode *mm; struct list* multi_list; ZLOG_INFO("recv pppd multilink info "); multi_list = mcp_ppp_multilink_info_parse(data_s); if(multi_list == NULL) { PPPD_DEBUG_TCP("mcp ppp multilink info parse error"); return -1; } PPPD_DEBUG_TCP("mcp recv pppd remote MULTILINK config, info count:%u", multi_list->count); for(ALL_LIST_ELEMENTS_RO(multi_list, mm, multi_info)) { mcp_printf_ppp_multiinfo(multi_info); mcp_ppp_multlink_info_update_local(multi_info); } list_delete(multi_list); return 0; }
void output_rx_throughput(packet_t *pktt) { static dllist_node_t rx_tpt_list = { .prev = &rx_tpt_list, .next = &rx_tpt_list }; if (pktt && pktt->ptt != RX_OK) return; if (pktt == NULL) { /* output the result */ while (!DLLIST_EMPTY(&rx_tpt_list)) { rx_throughput_t *ttt = (rx_throughput_t*) DLLIST_HEAD(&rx_tpt_list); ZLOG_INFO("rx tpt: at [%d, %d)s, throughput %d bps\n", ttt->time, ttt->time + 1, ttt->throughput /* bps */); dllist_remove(&rx_tpt_list, &(ttt->node)); free(ttt); } return; } /* pktt != NULL, calcuate the rx *delivery* throughput */ u32 remainder = pktt->rx_deliver_timestamp % (u32) MS2US(S2MS(1)); u32 integer = (pktt->rx_deliver_timestamp - remainder) / MS2US(S2MS(1)); rx_throughput_t * ttt = (rx_throughput_t*) DLLIST_TAIL(&rx_tpt_list); if (DLLIST_IS_HEAD(&rx_tpt_list, ttt) || ttt->time != integer) { /* new one */ rx_throughput_t *new_ttt = (rx_throughput_t*) malloc(sizeof(rx_throughput_t)); assert(new_ttt); new_ttt->time = integer; new_ttt->throughput = pktt->packet_size; dllist_append(&rx_tpt_list, &(new_ttt->node)); } else { /* already existed, update it */ ttt->throughput += (pktt->packet_size * OCTET); } }
int main(int argc, char** argv) { int rc; zlog_category_t *zc; rc = zlog_init("test_hello.conf"); if (rc) { printf("init failed\n"); return -1; } zc = zlog_get_category("my_cat"); if (!zc) { printf("get cat fail\n"); zlog_fini(); return -2; } ZLOG_INFO(zc, "hello, zlog"); zlog_fini(); return 0; }
//运行函数 int Comm_SvrdApp_NonCtrl::run_instance() { ZLOG_INFO("[framework] app %s class [%s] run_instance start.", get_app_basename(), typeid(*this).name()); // size_t size_io_event = 0 , size_timer_expire = 0; size_t prc_frame = 0, idle = 0, proc_data_num = 0; ZCE_Time_Value select_interval(0, 0); ZCE_Timer_Queue *time_queue = ZCE_Timer_Queue::instance(); ZCE_Reactor *reactor = ZCE_Reactor::instance(); for (; app_run_;) { // 检查是否需要重新加载配置 if (app_reload_) { // 重新加载配置 reload_config(); } //处理收到的命令 popfront_recvpipe(prc_frame); size_timer_expire = time_queue->expire(); // 处理其他方式通信数据 proc_data_num = 0; proc(proc_data_num); //如果没有处理任何帧 // 处理管道的包少于要求处理的最大数则说明管道已经空了 if (prc_frame < MAX_ONCE_PROCESS_FRAME && size_timer_expire <= 0 && proc_data_num <= 0) { ++idle; } else { idle = 0; } // 如果空循环太多则会白白耗电不低碳 // 理论上这里睡眠最大时间是100毫秒 // 因此只要内存管道大小>=100毫秒最大系统处理包数*每个包字节数 // 则再睡醒以后能够正常处理数据而不至于管道满而丢数据 // 假设系统所有资源够用,那么网卡速率则决定了最大处理能力 // 网卡按1Gbit计算,则管道临界大小为1Gbit-per(S)/8/10≈12MByte,再加上管道自身的内存结构占用 // 考虑为16MByte也即足以,所以只要管道大小超过16MByte应该就顶的住。 // 所以这里就不用空跑那么多次了。 if (idle < 1) { continue; } //如果空闲很多,休息一下,如果你比较空闲,在这儿SELECT相当于Sleep, else if (idle >= HEAVY_IDLE_SLEEP_INTERVAL) { select_interval.usec(HEAVY_IDLE_INTERVAL_MICROSECOND); } //else 相当于 else if (idle >= LIGHT_IDLE_SELECT_INTERVAL) else { select_interval.usec(LIGHT_IDLE_INTERVAL_MICROSECOND); } // reactor->handle_events(&select_interval, &size_io_event); } ZLOG_INFO("[framework] app %s class [%s] run_instance end.", get_app_basename(), typeid(*this).name()); return SOAR_RET::SOAR_RET_SUCC; }
jintArray Java_com_zokama_androlirc_Lirc_getIrBuffer( JNIEnv* env, jobject thiz, jstring dev, jstring cmd, jint min_buf_size) { /* variables */ char * remote_name = (char *)(*env)->GetStringUTFChars(env, dev, NULL); char * code_name = (char *)(*env)->GetStringUTFChars(env, cmd, NULL); int length; lirc_t* signals; jbyteArray result; lirc_t freq; char msg[255]; /* Check config */ if(!read_config_file(LIRCDCFGFILE)) return 0; /* Prepare send - using lirc/daemons/transmit.h*/ struct ir_remote * remote = get_ir_remote(devices, remote_name); struct ir_ncode * code = get_code_by_name(remote, code_name); if(!init_send(remote, code)) return NULL; length = send_buffer.wptr; signals = send_buffer.data; if (length <= 0 || signals == NULL) { ZLOG_INFO("nothing to send"); return NULL; } /*carrier frequency */ freq = remote->freq ? remote->freq : DEFAULT_FREQ; sprintf(msg, "Using carrier frequency %i", freq); ZLOG_INFO(msg); /* Generate audio buffer - Derived from lirc/daemons/hw_audio.c */ int i, j=0, signalPhase=0, carrierPos=0, out; int currentSignal=0; unsigned char outptr[SAMPLERATE*5]; /* Insert space before the ir code */ for(j=0; j<5000; j++) { outptr[j] = 128; } for(i = 0; i<length; i++) { /* invert the phase */ signalPhase = signalPhase ? 0 : 1; for(currentSignal=signals[i]; currentSignal>0; currentSignal -= 1000000.0 / SAMPLERATE) { if (signalPhase) { /* write carrier */ out = rint(sin(carrierPos / (180.0 / PI)) * 127.0 + 128.0); } else { out = 128; } /* one channel is inverted, so both channels can be used to double the voltage */ outptr[j++] = out; outptr[j++] = 256 - out; /* increase carrier position */ /* carrier frequency is halved */ carrierPos += (double)freq / SAMPLERATE * 360.0 / 2.0; if (carrierPos >= 360.0) carrierPos -= 360.0; } } /* Fill with space if buffer is too small */ if (j < min_buf_size) { for (j; j<min_buf_size; j++) { outptr[j] = 128; sprintf(msg, "filling buffer: %d/%d",j, min_buf_size); ZLOG_INFO(msg); } } sprintf(msg, "Buffer size: %d bytes (min: %d)",j, min_buf_size); ZLOG_INFO(msg); /* Return audio buffer*/ result = (*env)->NewByteArray(env, j); if (result == NULL) { return NULL; } (*env)->SetByteArrayRegion(env, result, 0, j, outptr); return result; }
int main (int argc, char *argv[]) { /* 1. acquire all simulation parameters or use the default values 2. generate the simulation begin event @time = 0 3. add this event to the timer queue 4. while (simulatio not finished) { advance the simu time by 1 time unit (ms) } */ /* 1. */ simu_paras_t spt; spt.t.packet_size = PKT_SIZE; /* bytes */ spt.rl.link_distance = 0; spt.rl.prop_delay = MS2US(270); /* 270 ms */ spt.rl.link_bandwidth = BANDWIDTH; /* bps */ spt.rl.per = PER; /* x/10000 */ /* this should be set when the mac pdu is build (at the tx_begin_event) */ /* spt.tx_delay = ( (1e3 * OCTET * (spt.t.packet_size + MAC_HEADER_SIZE + PHY_HEADER_SIZE)) / spt.rl.link_bandwidth ); */ /* rlc params */ spt.rlc_paras.ump.t_Reordering = MS2US(T_REORDERING); /* ms */ spt.rlc_paras.ump.UM_Window_Size = UWSize; /* window size */ spt.rlc_paras.ump.sn_FieldLength = SN_LEN; /* sn length */ #define PTIMER_MEM_MAX 4096*16 spt.g_mem_ptimer_t = fastalloc_create(sizeof(ptimer_t), PTIMER_MEM_MAX, 0, 100); assert(spt.g_mem_ptimer_t); /* #define PACKET_MEM_MAX (4096*16*16*8) */ /* spt.g_mem_packet_t = fastalloc_create(sizeof(packet_t), PACKET_MEM_MAX, 0, 100); */ /* assert(spt.g_mem_packet_t); */ /* @transmitter */ /* @receiver */ /* leave these to be done at the simulatioin begin event */ /* init log */ zlog_default = openzlog(ZLOG_STDOUT); zlog_set_pri(zlog_default, LOG_INFO); zlog_reset_flag(zlog_default, ZLOG_LOGTIME); /* no time display */ ZLOG_DEBUG("pkt size = %d, prop delay = %d, link bandwidth = %d\n", spt.t.packet_size, spt.rl.prop_delay, spt.rl.link_bandwidth); /* 2. */ /* FIXME: simu time unit: 1us! */ ptimer_t simu_begin_timer = { .duration = 0, .onexpired_func = simu_begin_event, .param[0] = (void*) &spt, .param[1] = (void*) SIMU_BEGIN, }; time_t t; srand((unsigned) time(&t)); /* 3. */ rlc_init(); rlc_timer_start(&simu_begin_timer); /* 4. */ int step_in_us = 1; while (g_is_finished == NOT_FINISHED && g_time_elasped_in_us <= MS2US(S2MS(SIMU_TIME)) ) { rlc_timer_push(step_in_us); /* us */ g_time_elasped_in_us += step_in_us; if ( g_time_elasped_in_us % (int)MS2US(S2MS(1)) == 0 ) { ZLOG_INFO("simu time = %f\n", g_time_elasped_in_us/MS2US(S2MS(1))); } } /* output the simu result */ ZLOG_DEBUG("time_elasped_in_us = %d\n", g_time_elasped_in_us); int cnt = 0; int output_e2e_delay = 1; int n_rxok = 0, n_rxerr = 0; while (!DLLIST_EMPTY(&g_sink_packet_list)) { packet_t *pktt = (packet_t*) DLLIST_HEAD(&g_sink_packet_list); /* 1. tx throughput */ // output_tx_throughput(pktt); // output_rx_throughput(pktt); /* 2. e2e delay */ switch (pktt->ptt) { case RX_OK: n_rxok++; break; case RX_ERR: n_rxerr++; break; default: assert(0); break; } if( output_e2e_delay ) { if (pktt->ptt == RX_OK ) ZLOG_INFO("SN, buffering: %u, %u\n", pktt->sequence_no, pktt->rx_deliver_timestamp - pktt->rx_end_timestamp); } dllist_remove(&g_sink_packet_list, &(pktt->node)); cnt++; // FASTFREE(spt.g_mem_packet_t, pktt); free(pktt); pktt = NULL; } output_tx_throughput(NULL); output_rx_throughput(NULL); ZLOG_INFO("n_txed = %d, n_rxok = %d, n_rxerr = %d\n", cnt, n_rxok, n_rxerr); return 0; }
void output_tx_throughput(packet_t *pktt) { /* unit: second, based on the pktt->tx_begin_timestamp, the pktt->tx_end_timestamp */ static dllist_node_t tx_tpt_list = { .prev = &tx_tpt_list, .next = &tx_tpt_list }; if (pktt == NULL) { /* output the result */ while (!DLLIST_EMPTY(&tx_tpt_list)) { tx_throughput_t *ttt = (tx_throughput_t*) DLLIST_HEAD(&tx_tpt_list); ZLOG_INFO("tx tpt: at [%d, %d)s, throughput %d bps\n", ttt->time, ttt->time + 1, ttt->throughput /* bps */); dllist_remove(&tx_tpt_list, &(ttt->node)); free(ttt); } return; } /* pktt != NULL, calcuate the tx throughput */ u32 remainder_begin = pktt->tx_begin_timestamp % (u32) MS2US(S2MS(1)); u32 remainder_end = pktt->tx_end_timestamp % (u32) (MS2US(S2MS(1))); u32 integer_begin = (pktt->tx_begin_timestamp - remainder_begin) / MS2US(S2MS(1)); u32 integer_end = (pktt->tx_end_timestamp - remainder_end) / MS2US(S2MS(1)); tx_throughput_t * ttt = (tx_throughput_t*) DLLIST_TAIL(&tx_tpt_list); if ( integer_begin == integer_end ) { /* in the same time range */ /* if have, get it */ if (DLLIST_IS_HEAD(&tx_tpt_list, ttt) || ttt->time != integer_begin) { /* new one */ tx_throughput_t *new_ttt = (tx_throughput_t*) malloc(sizeof(tx_throughput_t)); assert(new_ttt); new_ttt->time = integer_begin; new_ttt->throughput = pktt->mac_pdu_size * OCTET; dllist_append(&tx_tpt_list, &(new_ttt->node)); } else { /* already existed, update it */ ttt->throughput += (pktt->mac_pdu_size * OCTET); } } else { /* not in the same time range, split it based on the pktt->mac_pdu_size */ assert(integer_end - integer_begin == 1); u32 total = pktt->tx_end_timestamp - pktt->tx_begin_timestamp; if (DLLIST_IS_HEAD(&tx_tpt_list, ttt)) { ttt = (tx_throughput_t*) malloc(sizeof(tx_throughput_t)); dllist_append(&tx_tpt_list, &(ttt->node)); } u32 part = (pktt->mac_pdu_size * OCTET) * remainder_end / total; tx_throughput_t *new_ttt = (tx_throughput_t*) malloc(sizeof(tx_throughput_t)); assert(new_ttt); new_ttt->time = integer_end; new_ttt->throughput = (pktt->mac_pdu_size * OCTET) * remainder_end / total; dllist_append(&tx_tpt_list, &(new_ttt->node)); ttt->time = integer_begin; ttt->throughput += (pktt->mac_pdu_size * OCTET) * (1 - remainder_end / total); ZLOG_DEBUG("begin %d, remainder %d, tpt: %d, end %d, remainder %d, tpt: %d\n", integer_begin, remainder_begin, pktt->mac_pdu_size * OCTET - part, integer_end, remainder_end, part); } }