PUBLIC void setupDevices(void) { //inicializa informaçoes do equipamento. info_init(); //inicializa e configura mecanismo de controle das teclas buttons_init(); button_attach(1, 9); button_attach(2, 28); //configura e inicializa pinos que serao usados pela biblioteca LCD. lcd_attach(14, 15, 22, 23, 24, 25); lcd_gotoxy(1, 1); uint8_t buff[] = {"Modulo JAGA! "}; lcd_print(&buff); //configura mecanismo de controle dos leds pinMode(0, INPUT); leds_init(); leds_attach(0, 4); leds_attach(1, 5); leds_set(LD1G, LED_BLINK_FAST); leds_set(LD2G, LED_BLINK_SLOW); }
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); info_init(); bathstr = ("E:/git/my_qt/wl_tcpServer/data.db"); }
void rtgui_startup() { rtgui_rect_t rect; /* GUI系统初始化 */ rtgui_system_server_init(); /* register dock panel */ rect.x1 = 0; rect.y1 = 0; rect.x2 = 128; rect.y2 = 64; rtgui_panel_register("info", &rect); rtgui_panel_set_default_focused("info"); /* 启动info workbench */ info_init(); }
/* Set the card object to the requested card */ int set_card(int number) { if(!set_card_info(number)) return 0; info_init(); if(nv_card->arch & NV3X) ;//nv30_init(); else if(nv_card->arch & NV4X) nv40_init(); else if(nv_card->arch & NV5X) nv50_init(); else nv_init(); return 1; }
void main(void) { bit test_radio = 0; bit bounce_radio = 0; /* Initialize app modules. Not reinitialized upon reset. */ message_init(); compose_init(); inbox_init(); info_init(); reset: sleepy_ = 0; state_ = STATE_VIEW; if (bounce_radio) { repeater_mode(); } /* Initialize system modules. */ clock_init(); setIOPorts(); configureSPI(); LCDReset(); radio_init(); random_init(); inbox_draw(); if (test_radio) { run_test_radio(); } /* Main loop. */ radio_listen(); while (1) { poll_keyboard(); /* Send and receive messages. */ message_tick(); /* Handle background tasks (like progress bar) */ if (compose_tick() && state_ == STATE_COMPOSE) { compose_draw(); } if (info_tick() && state_ == STATE_INFO) { info_draw(); } /* go to sleep (more or less a shutdown) if power button pressed */ if (sleepy_) { clear(); clock_delayms(1000); SSN = LOW; LCDPowerSave(); SSN = HIGH; sleep(); /* reset on wake */ goto reset; } } }
void main_bsp(void) { // Print header screen_write("Hydrogen v0.2b - http://github.com/farok/H2", 0, 0); screen_write("Copyright (c) 2012 by Lukas Heidemann", 0, 1); screen_write("-------------------------------------------------", 0, 2); // Load the IDT idt_load(idt_address, IDT_LENGTH); idt_setup_loader(); // Initialize Hydrogen info tables and parse the multiboot tables info_init(); multiboot_parse(); // Setup the heap heap_init(); // Now parse the ACPI tables and analyze the IO APICs acpi_parse(); ioapic_analyze(); // Find, check and load the kernel binary kernel_find(); kernel_check(); elf64_load(kernel_binary); kernel_analyze(); // Initialize interrupt controllers lapic_detect(); lapic_setup(); ioapic_setup_loader(); pic_setup(); // Calibrate the LAPIC timer lapic_timer_calibrate(); // Boot APs info_cpu[lapic_id()].flags |= HY_INFO_CPU_FLAG_BSP; smp_setup(); // Setup IDT and IOAPIC according to kernel header idt_setup_kernel(); ioapic_setup_kernel(); // Setup fast syscall support syscall_init(); // Setup mapping kernel_map_info(); kernel_map_stack(); kernel_map_idt(); kernel_map_gdt(); // Set free address info_root->free_paddr = (heap_top + 0xFFF) & ~0xFFF; // Lower main entry barrier and jump to the kernel entry point main_entry_barrier = 0; kernel_enter_bsp(); }
__task void main_task(void) { // State processing uint16_t flags = 0; // LED gpio_led_state_t hid_led_value = GPIO_LED_ON; gpio_led_state_t cdc_led_value = GPIO_LED_ON; gpio_led_state_t msc_led_value = GPIO_LED_ON; // USB uint32_t usb_state_count = USB_BUSY_TIME; // thread running after usb connected started uint8_t thread_started = 0; // button state main_reset_state_t main_reset_button_state = MAIN_RESET_RELEASED; // Initialize settings config_init(); // Initialize our serial mailbox os_mbx_init(&serial_mailbox, sizeof(serial_mailbox)); // Get a reference to this task main_task_id = os_tsk_self(); // leds gpio_init(); // Turn off LED gpio_set_hid_led(GPIO_LED_ON); gpio_set_cdc_led(GPIO_LED_ON); gpio_set_msc_led(GPIO_LED_ON); // do some init with the target before USB and files are configured prerun_target_config(); // Update versions and IDs info_init(); // USB usbd_init(); vfs_user_enable(true); usbd_connect(0); usb_state = USB_CONNECTING; usb_state_count = USB_CONNECT_DELAY; // Start timer tasks os_tsk_create_user(timer_task_30mS, TIMER_TASK_30_PRIORITY, (void *)stk_timer_30_task, TIMER_TASK_30_STACK); // Target running target_set_state(RESET_RUN); while(1) { os_evt_wait_or( FLAGS_MAIN_RESET // Put target in reset state | FLAGS_MAIN_90MS // 90mS tick | FLAGS_MAIN_30MS // 30mS tick | FLAGS_MAIN_POWERDOWN // Power down interface | FLAGS_MAIN_DISABLEDEBUG // Disable target debug | FLAGS_MAIN_PROC_USB // process usb events ,NO_TIMEOUT); // Find out what event happened flags = os_evt_get(); if (flags & FLAGS_MAIN_PROC_USB) { USBD_Handler(); } if (flags & FLAGS_MAIN_RESET) { target_set_state(RESET_RUN); } if (flags & FLAGS_MAIN_POWERDOWN) { // Disable debug target_set_state(NO_DEBUG); // Disconnect USB usbd_connect(0); // Turn off LED gpio_set_hid_led(GPIO_LED_OFF); gpio_set_cdc_led(GPIO_LED_OFF); gpio_set_msc_led(GPIO_LED_OFF); // TODO: put the interface chip in sleep mode while(1); } if (flags & FLAGS_MAIN_DISABLEDEBUG) { // Disable debug target_set_state(NO_DEBUG); } if (flags & FLAGS_MAIN_90MS) { // Update USB busy status vfs_user_periodic(90); // FLAGS_MAIN_90MS // Update USB connect status switch (usb_state) { case USB_DISCONNECTING: usb_state = USB_DISCONNECTED; usbd_connect(0); break; case USB_CONNECTING: // Wait before connecting if (DECZERO(usb_state_count) == 0) { usbd_connect(1); usb_state = USB_CHECK_CONNECTED; } break; case USB_CHECK_CONNECTED: if(usbd_configured()) { if (!thread_started) { os_tsk_create_user(hid_process, DAP_TASK_PRIORITY, (void *)stk_dap_task, DAP_TASK_STACK); serial_task_id = os_tsk_create_user(serial_process, SERIAL_TASK_PRIORITY, (void *)stk_serial_task, SERIAL_TASK_STACK); thread_started = 1; } usb_state = USB_CONNECTED; } break; case USB_CONNECTED: case USB_DISCONNECTED: default: break; } } // 30mS tick used for flashing LED when USB is busy if (flags & FLAGS_MAIN_30MS) { // handle reset button without eventing switch (main_reset_button_state) { default: case MAIN_RESET_RELEASED: if (0 == gpio_get_sw_reset()) { main_reset_button_state = MAIN_RESET_PRESSED; target_forward_reset(true); } break; case MAIN_RESET_PRESSED: // ToDo: add a counter to do a mass erase or target recovery after xxx seconds of being held if (1 == gpio_get_sw_reset()) { main_reset_button_state = MAIN_RESET_TARGET; } break; case MAIN_RESET_TARGET: target_forward_reset(false); main_reset_button_state = MAIN_RESET_RELEASED; break; } if (hid_led_usb_activity && ((hid_led_state == MAIN_LED_FLASH) || (hid_led_state == MAIN_LED_FLASH_PERMANENT))) { // Flash DAP LED ONCE if (hid_led_value) { hid_led_value = GPIO_LED_OFF; } else { hid_led_value = GPIO_LED_ON; // Turn on if (hid_led_state == MAIN_LED_FLASH) { hid_led_usb_activity = 0; } } // Update hardware gpio_set_hid_led(hid_led_value); } if (msc_led_usb_activity && ((msc_led_state == MAIN_LED_FLASH) || (msc_led_state == MAIN_LED_FLASH_PERMANENT))) { // Flash MSD LED ONCE if (msc_led_value) { msc_led_value = GPIO_LED_OFF; } else { msc_led_value = GPIO_LED_ON; // Turn on if (msc_led_state == MAIN_LED_FLASH) { msc_led_usb_activity = 0; } } // Update hardware gpio_set_msc_led(msc_led_value); } if (cdc_led_usb_activity && ((cdc_led_state == MAIN_LED_FLASH) || (cdc_led_state == MAIN_LED_FLASH_PERMANENT))) { // Flash CDC LED ONCE if (cdc_led_value) { cdc_led_value = GPIO_LED_OFF; } else { cdc_led_value = GPIO_LED_ON; // Turn on if (cdc_led_state == MAIN_LED_FLASH) { cdc_led_usb_activity = 0; } } // Update hardware gpio_set_cdc_led(cdc_led_value); } } } }
void radio_rtgui_init(void) { rtgui_rect_t rect; rtgui_system_server_init(); /* register dock panel */ rect.x1 = 0; rect.y1 = 0; rect.x2 = 240; rect.y2 = 25; rtgui_panel_register("info", &rect); rtgui_panel_set_nofocused("info"); /* register main panel */ rect.x1 = 0; rect.y1 = 25; rect.x2 = 240; rect.y2 = 320; rtgui_panel_register("main", &rect); rtgui_panel_set_default_focused("main"); //rt_hw_lcd_init(); { #if LCD_VERSION == 1 #include "fmt0371/FMT0371.h" _rtgui_lcd_driver.name = "lcd"; _rtgui_lcd_driver.byte_per_pixel = 2; _rtgui_lcd_driver.width = 240; _rtgui_lcd_driver.height = 320; _rtgui_lcd_driver.draw_hline = fmt_lcd_draw_hline; _rtgui_lcd_driver.draw_raw_hline = fmt_lcd_draw_raw_hline; _rtgui_lcd_driver.draw_vline = fmt_lcd_draw_vline; _rtgui_lcd_driver.get_pixel = fmt_lcd_get_pixel; _rtgui_lcd_driver.set_pixel = fmt_lcd_set_pixel; _rtgui_lcd_driver.screen_update = fmt_lcd_update; _rtgui_lcd_driver.get_framebuffer = fmt_lcd_get_framebuffer; fmt_lcd_init(); #elif LCD_VERSION == 2 #include "ili_lcd_general.h" _rtgui_lcd_driver.name = "lcd"; _rtgui_lcd_driver.byte_per_pixel = 2; _rtgui_lcd_driver.width = 240; _rtgui_lcd_driver.height = 320; _rtgui_lcd_driver.draw_hline = rt_hw_lcd_draw_hline; _rtgui_lcd_driver.draw_raw_hline = rt_hw_lcd_draw_raw_hline; _rtgui_lcd_driver.draw_vline = rt_hw_lcd_draw_vline; _rtgui_lcd_driver.get_pixel = rt_hw_lcd_get_pixel; _rtgui_lcd_driver.set_pixel = rt_hw_lcd_set_pixel; _rtgui_lcd_driver.screen_update = rt_hw_lcd_update; _rtgui_lcd_driver.get_framebuffer = rt_hw_lcd_get_framebuffer; lcd_Initializtion(); #elif LCD_VERSION == 3 #include "ssd1289.h" _rtgui_lcd_driver.name = "lcd"; _rtgui_lcd_driver.byte_per_pixel = 2; _rtgui_lcd_driver.width = 240; _rtgui_lcd_driver.height = 320; _rtgui_lcd_driver.draw_hline = ssd1289_lcd_draw_hline; _rtgui_lcd_driver.draw_raw_hline = ssd1289_lcd_draw_raw_hline; _rtgui_lcd_driver.draw_vline = ssd1289_lcd_draw_vline; _rtgui_lcd_driver.get_pixel = ssd1289_lcd_get_pixel; _rtgui_lcd_driver.set_pixel = ssd1289_lcd_set_pixel; _rtgui_lcd_driver.screen_update = ssd1289_lcd_update; _rtgui_lcd_driver.get_framebuffer = ssd1289_lcd_get_framebuffer; ssd1289_init(); #endif }//rt_hw_lcd_init /* add lcd driver into graphic driver */ rtgui_graphic_driver_add(&_rtgui_lcd_driver); info_init(); player_init(); lcd_backlight_init(); }
int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *table1; GtkWidget *menuBar; GtkWidget *noteBook; GtkWidget *MenuItemTask; const char *title[3] = {"总体信息","进程信息","系统信息"}; GtkWidget *label[Nsize];//页面标题 GtkWidget *frame[Nsize];//页面框架 gtk_init(&argc, &argv);//初始化命令行参数 虽不使用但是必需 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window),"任务管理器"); gtk_widget_set_usize(window, 600, 600); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (window), TRUE); gtk_container_set_border_width(GTK_CONTAINER(window),5); table1 = gtk_table_new(11,11,TRUE); gtk_container_add(GTK_CONTAINER(window),table1); menuBar = gtk_menu_bar_new(); gtk_table_attach_defaults(GTK_TABLE(table1), menuBar,0,11,0,1); MenuItemTask = CreateMenuItem(menuBar, "进程"); CreateMenuTask(MenuItemTask); noteBook = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(noteBook),GTK_POS_TOP);//设置notebook的格式 gtk_table_attach_defaults(GTK_TABLE(table1), noteBook, 0, 11, 1, 10); gint i; for(i = 0; i < Nsize; i++) { label[i] = gtk_label_new(title[i]); frame[i] = gtk_frame_new(NULL); gtk_container_set_border_width(GTK_CONTAINER(frame[i]), 5); gtk_widget_set_size_request(frame[i],450,450); gtk_notebook_append_page(GTK_NOTEBOOK(noteBook),frame[i],label[i]); table2[i] = gtk_table_new(12,12,TRUE); gtk_container_add(GTK_CONTAINER(frame[i]),table2[i]); } time_label = gtk_label_new(""); gtk_timeout_add(1000, (GtkFunction)get_time, NULL); gtk_table_attach_defaults(GTK_TABLE(table1), time_label, 8,10,1,2); cpu_label = gtk_label_new(""); gtk_timeout_add(3000, (GtkFunction)get_cpu_rate, NULL); gtk_table_attach_defaults(GTK_TABLE(table1), cpu_label, 1,3,10,11); mem_label = gtk_label_new(""); gtk_timeout_add(3000, (GtkFunction)get_mem_rate, NULL); gtk_table_attach_defaults(GTK_TABLE(table1), mem_label, 8,10,10,11); process_num_label = gtk_label_new(""); gtk_timeout_add(1000, (GtkFunction)get_process_num, NULL); gtk_table_attach_defaults(GTK_TABLE(table1), process_num_label, 4,7,10,11); pro_init(); gtk_timeout_add(3000, (GtkFunction)pro_fill, NULL); info_init(); drawlines_init(); gtk_timeout_add(1000, (GtkFunction)lines_refresh, NULL); g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);//可关闭 gtk_widget_show_all(window); gtk_main();//主事件循环 return 0; }
int stream_info(struct play_s *play) { /* Info uses following pipeline: file -(uncompressed_buffer)-> reads data from stream file unpack -(uncompressed_buffer)-> decompresses lzo/quicklz packets info -(rgb)-> shows stream information */ ps_bufferattr_t attr; ps_buffer_t uncompressed_buffer, compressed_buffer; info_t info; unpack_t unpack; int ret = 0; if ((ret = ps_bufferattr_init(&attr))) goto err; /* initialize buffers */ if ((ret = ps_bufferattr_setsize(&attr, play->compressed_size))) goto err; if ((ret = ps_buffer_init(&compressed_buffer, &attr))) goto err; if ((ret = ps_bufferattr_setsize(&attr, play->uncompressed_size))) goto err; if ((ret = ps_buffer_init(&uncompressed_buffer, &attr))) goto err; if ((ret = ps_bufferattr_destroy(&attr))) goto err; /* and filters */ if ((ret = unpack_init(&unpack, &play->glc))) goto err; if ((ret = info_init(&info, &play->glc))) goto err; info_set_level(info, play->info_level); /* run it */ if ((ret = unpack_process_start(unpack, &compressed_buffer, &uncompressed_buffer))) goto err; if ((ret = info_process_start(info, &uncompressed_buffer))) goto err; if ((ret = file_read(play->file, &compressed_buffer))) goto err; /* wait for threads and do cleanup */ if ((ret = info_process_wait(info))) goto err; if ((ret = unpack_process_wait(unpack))) goto err; unpack_destroy(unpack); info_destroy(info); ps_buffer_destroy(&compressed_buffer); ps_buffer_destroy(&uncompressed_buffer); return 0; err: fprintf(stderr, "extracting stream information failed: %s (%d)\n", strerror(ret), ret); return ret; }
/************************************************************************* main ==== **************************************************************************/ int main(void) { int x = 0; const int interval = 200000; FIO_ENABLE; vic_disableIRQ(); pllstart_seventytwomhz() ; // pllstart_sixtymhz() ; // pllstart_fourtyeightmhz() ; mam_enable(); info_init(); uart0_init_115200() ; uart0_putstring("\n***Starting gfe color led test***\n\n"); uart0_putstring("\n***Board is defined as: "); uart0_putstring( infoquery_gfe_boardtag() ); uart0_putstring(" ***\n"); init_color_led(); RED_LED_OFF; BLUE_LED_OFF; GREEN_LED_OFF; printf_lpc(UART0,"5 FAST flashes...red, blue then green\n"); color_led_flash(5, RED_LED, FLASH_FAST ) ; RED_LED_OFF; color_led_flash(5, BLUE_LED, FLASH_FAST ) ; BLUE_LED_OFF; color_led_flash(5, GREEN_LED, FLASH_FAST ) ; GREEN_LED_OFF; uart0_putstring(" ** END OF TEST ""\n"); printf_lpc(UART0, "Initialising USB stack\n"); // initialize stack USBInit(); // register descriptors USBRegisterDescriptors(abDescriptors); // register class request handler USBRegisterRequestHandler(REQTYPE_TYPE_CLASS, HandleClassRequest, abClassReqData); // register endpoint handlers USBHwRegisterEPIntHandler(INT_IN_EP, NULL); // register frame handler USBHwRegisterFrameHandler(USBFrameHandler); // register device event handler USBHwRegisterDevIntHandler(USBDevIntHandler); inputIsocDataBuffer[0] = 0; printf_lpc(UART0, "Starting USB communication\n"); VICVectPriority22 = 0x01; // 0x0 is highest priority, 0xF is lowest VICVectAddr22 = (unsigned int)USBIntHandler; VICAddress = 0x0; printf_lpc(UART0, "addresses entered\n"); ENABLE_USB_IRQ; printf_lpc(UART0, "USB IRQ Enabled\n"); vic_enableIRQ(); printf_lpc(UART0, "vic_enable\n"); ENABLE_USB_INT; printf_lpc(UART0, "USB INT Enabled\n"); //printf_lpc(UART0, "connect to bus\n"); // // // connect to bus USBHwConnect(TRUE); // for(;;) { x++; if (x == interval) { RED_LED_ON; } else if (x >= (interval*2)) { x = 0; RED_LED_OFF; } } return 0; }
void create_view(void) { // Window win, ewin; Evas *evas; Ecore_Evas * ee; int x, y, w, h, res; int maxcol; int engine; char *fontdir; int font_cache, image_cache; char buf[4096]; char *s; E_DB_INT_GET(shell->rcfile, "/main_win/win_x", x, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_y", y, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_w", w, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/main_win/win_h", h, res); ENGY_ASSERT(res); E_DB_STR_GET(shell->rcfile, "/aliases", (shell->aliases), res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/maxcolors", maxcol, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/rendermethod", engine, res); ENGY_ASSERT(res); if (render_method != -1) engine = render_method; E_DB_INT_GET(shell->rcfile, "/maximagecache", image_cache, res); ENGY_ASSERT(res); E_DB_INT_GET(shell->rcfile, "/maxfontcache", font_cache, res); ENGY_ASSERT(res); E_DB_STR_GET(shell->rcfile, "/fontdir", s, res); ENGY_ASSERT(res); if (s[0] != '/') { snprintf(buf, 4000,"%s/%s", shell->home, s); imlib_add_path_to_font_path(buf); fontdir = DUP(buf); } else { imlib_add_path_to_font_path(s); fontdir = DUP(s); } FREE(s); /* win = ecore_window_new(0, x, y, w, h); ecore_window_set_events(win, XEV_CONFIGURE | XEV_KEY); evas = evas_new_all(ecore_display_get(), win, 0, 0, w, h, engine, maxcol, font_cache, image_cache, fontdir); ENGY_ASSERTS(evas, "evas_new"); FREE(fontdir); evas_set_output_viewport(evas, 0, 0, w, h); ewin = evas_get_window(evas); ecore_window_set_events(ewin, XEV_EXPOSE | XEV_BUTTON | XEV_MOUSE_MOVE); */ if (!ecore_x_init(NULL)) exit(-1); //LOG_AND_RETURN (ERR_EFL); if (!ecore_evas_init()) exit(-1); //LOG_AND_RETURN (ERR_EFL); ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 640, 480); if (!ee) exit(-1); //LOG_AND_RETURN (ERR_EFL); evas = ecore_evas_get(ee); evas_font_path_prepend(evas, fontdir); FREE(fontdir); ecore_evas_callback_delete_request_set(ee, engy_delete_request); ecore_evas_callback_pre_render_set(ee, engy_pre_rend); ecore_evas_callback_post_render_set(ee, engy_post_rend); ecore_evas_callback_resize_set(ee, engy_resize); ecore_evas_name_class_set(ee, "engy", "main"); ecore_evas_show(ee); _get_title_dcd(); shell->title = my_iconv(shell->title_dcd, TITLE); ecore_evas_title_set(ee, shell->title); shell->evas = evas; shell->win = ecore_evas_software_x11_window_get(ee); shell->ee = ee; shell->w = w; shell->h = h; // GLS // ecore_set_blank_pointer(win); // ecore_window_set_title(win, shell->title); // my_evas_init(); _shell_bg_create(); menu_init(); // GLS engy_cl_init(); cl_configure(w, h); log_init(); info_init(); info_sync(); panel_init(); pointer_init(); serv_init(); logo_init(); alias_init(); // evas_render(shell->evas); }
int main(int argc, char **argv) { bstring info_page; info_t info; yajl_gen yajl; const unsigned char *json; size_t json_len; curl_global_init(CURL_GLOBAL_NOTHING); for (size_t i = 0; argv[i]; i += 1) { if (strcmp(argv[i], "-r") == 0) { modem_touch(MODEM_RESTART_URL); return EXIT_SUCCESS; } } info_page = modem_fetch(MODEM_INFO_URL); if (!info_page) { fprintf(stderr, "hektor: Couldn't fetch '%s'\n", MODEM_INFO_URL); return EXIT_FAILURE; } info_init(&info, info_page); yajl = yajl_gen_alloc(NULL); assert(yajl); yajl_gen_config(yajl, yajl_gen_beautify, true); #define yajl_gen_strst(y, s) yajl_gen_string((y), (s), sizeof(s) - 1) yajl_gen_map_open(yajl); yajl_gen_strst(yajl, "connection"); yajl_gen_integer(yajl, info.conn); yajl_gen_strst(yajl, "fapped"); yajl_gen_bool(yajl, info.fap == FAP_ACTIVE); yajl_gen_strst(yajl, "refill_secs"); yajl_gen_integer(yajl, info.refill_secs); yajl_gen_strst(yajl, "refill_ts"); yajl_gen_integer(yajl, info.refill_ts); yajl_gen_strst(yajl, "usage_allowed"); yajl_gen_integer(yajl, info.usage_allowed); yajl_gen_strst(yajl, "usage_remain"); yajl_gen_integer(yajl, info.usage_remain); yajl_gen_map_close(yajl); #undef yajl_gen_strst yajl_gen_get_buf(yajl, &json, &json_len); printf("%s", json); bdestroy(info_page); yajl_gen_free(yajl); curl_global_cleanup(); return EXIT_SUCCESS; }
static void init_from_browser(struct ev_loop*loop,struct ev_io*watcher,int revents) { if (revents&EV_ERROR){ printf("revent error at init_from_browser\n"); return; } int browser_fd ,browser_len; struct sockaddr_in browser_addr; browser_len=sizeof(browser_addr); if ( (browser_fd=accept(watcher->fd,(struct sockaddr*)&browser_addr,&browser_len)) <0 ){ printf("accept browser connect fail\n"); return; } //-----initial the proxy connection----- struct timeval time_opt={0}; struct sockaddr_in outside_addr; int option=1 , hostname_len ,result,ret; char buff[MAXBUFF]; time_opt.tv_sec=2; time_opt.tv_usec=0; #ifdef SO_NOSIGPIPE setsockopt(browser_fd, SOL_SOCKET, SO_NOSIGPIPE, &option, sizeof(option)); #endif if ( (setsockopt(browser_fd,SOL_SOCKET,SO_RCVTIMEO,(char*)&time_opt,sizeof(time_opt)) == -1) || ( setsockopt(browser_fd,SOL_SOCKET,SO_SNDTIMEO,(char*)&time_opt,sizeof(time_opt)) ==-1) ){ printf("setsockopt error at init_from_browser\n"); return; } if ( setsockopt(browser_fd,SOL_SOCKET,SO_REUSEADDR,(uint*)&option,sizeof(option)) ==-1 ){ printf("setsockopt reuse error at init_from_browser"); return; } //-----proxy auth , step one----- if ( recv(browser_fd, buff, 2, 0)==-1){ error_report(0,1,browser_fd); return; } if ( ((socks5_method_req_t *)buff)->ver != 0x05 ){ printf("This is not sock5 , disconnect\n"); close(browser_fd); return; } ret = ((socks5_method_req_t *)buff)->nmethods; if ( recv(browser_fd, buff, ret, 0) ==-1){ error_report(0,2,browser_fd); return; } // no auth memcpy(buff, "\x05\x00", 2); if (send(browser_fd, buff, 2, 0)==-1){ error_report(1,3,browser_fd); return; } // REQUEST and REPLY if (recv(browser_fd, buff, 4, 0)==-1){ error_report(0,4,browser_fd); return; } if ( ((socks5_request_t *)buff)->ver != 0x05 || ((socks5_request_t *)buff)->cmd !=0x01 ) { ((socks5_request_t *)buff)->ver = 0x05; ((socks5_request_t *)buff)->cmd = 0x07; ((socks5_request_t *)buff)->rsv = 0; // cmd not supported send(browser_fd, buff, 4, 0); close(browser_fd); return; } if ( ((socks5_request_t *)buff)->addrtype ==0x01 ) { bzero((char *)&outside_addr, sizeof(outside_addr)); outside_addr.sin_family = AF_INET; if ( recv(browser_fd, buff, 4, 0)==-1){ error_report(0,5,browser_fd); return; } memcpy(&(outside_addr.sin_addr.s_addr), buff, 4); if ( recv(browser_fd, buff, 2, 0)==-1){ error_report(0,6,browser_fd); return; } memcpy(&(outside_addr.sin_port), buff, 2); printf("type : IP, %s:%d\n", inet_ntoa(outside_addr.sin_addr), htons(outside_addr.sin_port)); } else if ( ((socks5_request_t *)buff)->addrtype ==0x03) { struct hostent *hptr; bzero((char *)&outside_addr, sizeof(outside_addr)); outside_addr.sin_family = AF_INET; if (recv(browser_fd, buff, 1, 0)==-1){ error_report(0,7,browser_fd); return; } ret = buff[0]; buff[ret] = 0; if (recv(browser_fd, buff, ret, 0)==-1){ error_report(0,8,browser_fd); return; } //hptr = gethostbyname(buff); printf("type : domain [%s].\n", buff); if (NULL == hptr){ printf("error at initial the proxy connection , hostent is NULL\n"); close(browser_fd); return; } if (AF_INET != hptr->h_addrtype){ printf("error at initial the proxy connection , it is not tcp\n"); close(browser_fd); return; } if (NULL == *(hptr->h_addr_list)){ printf("error at initial the proxy connection , h_add_list is NULL\n"); close(browser_fd); return; } memcpy(&(outside_addr.sin_addr.s_addr), *(hptr->h_addr_list), 4); if (recv(browser_fd, buff, 2, 0)==-1){ error_report(0,9,browser_fd); return; } memcpy(&(outside_addr.sin_port), buff, 2); } else { ((socks5_request_t *)buff)->ver = 0x05; ((socks5_request_t *)buff)->cmd = 0x08; ((socks5_request_t *)buff)->rsv = 0; // cmd not supported send(browser_fd, buff, 4, 0); printf("error at initial the proxy connection , the connection command is not support\n"); close(browser_fd); return; } //-----send the new address to entry server----- CONN_INFO*ptr=(CONN_INFO*)malloc(sizeof(CONN_INFO)); struct ev_io*browser_watcher=(struct ev_io*)malloc(sizeof(struct ev_io)); uint32_t streamid,thread_id,len=6; streamid=get_streamid(); thread_id=connection_distribute(streamid); ptr=info_init(browser_fd,streamid,thread_id,browser_watcher); info_insert(&info_head[thread_id],ptr); browser_watcher->data=(void*)ptr; memcpy(buff,&streamid,4); memcpy(buff+4,&len,4); memcpy(buff+8,&(outside_addr.sin_addr.s_addr),4); memcpy(buff+12,&(outside_addr.sin_port),2); my_send(browser_fd,buff,14,"init_from_browser"); ev_io_init(browser_watcher,handle_from_browser,browser_fd,EV_READ); ev_io_start(my_loop,browser_watcher); }
int main(int argc, char **argv) { const char *ptr; int server_mode = -1; int i; int rc = 0; FILE *xmlf; #if !defined(HPUX) setlinebuf(stdout); #endif ptr = strrchr(argv[0], '/'); if (ptr == NULL) { strncpy(prog_name, argv[0], PROG_NAME_LEN); } else { strncpy(prog_name, ptr + 1, PROG_NAME_LEN); } pagesize = getpagesize(); printf("pagesize = %d\n", pagesize); cache_line_size = OPT_CACHE_LINE_EST; #ifdef TBB_KINFO int kinfo_fd = 0; #endif /* TBB_KINFO */ #ifdef TBB_KINFO if (options.kinfo) { kinfo_fd = pre_kinfo_init(); } #endif /* TBB_KINFO */ init_print_time(&tnow, &tprev); /* must happen before processing arguments */ options_set(); /* Process command line arguments */ process_args(argc, argv); /* Check for conflicts in the specified cmd line options */ check_options(); printf("INIT START\n"); num_idle = maxconns; printf("main: num_idle = %d\n", num_idle); printf("main: maxconns = %d\n", maxconns); printf("main: max_fds = %d\n", max_fds); #ifdef DEBUG_ON printf("Debugging is on debugging messages mask = 0x%x\n", MSG_MASK); #else printf("Compiled without debugging\n"); #endif /* DEBUG_ON */ if (options.use_socket_aio) { // for now leave some room for a few open files and // a few listening sockets (unfortunately we need to call this before // we know how many listening sockets there will be // max_sock_sd = maxconns + 20; // For now we just pick a value that _SHOULD_ avoid // collisions with future tests. // Note that if there were sd/fd collisions things // _should_ likely work just fine but this may // make finding problems easier - since there is // potential to control which range of values the // underlying aio layer is returning. #ifdef HAVE_AIO_LAYER /* These are just estimates !!! */ int aio_lowest_sock_sd = OPT_AIO_LOWEST_SD; int aio_highest_sock_sd = (maxconns + aio_lowest_sock_sd - 1) + OPT_AIO_MAX_LISTENERS; max_sock_sd = aio_highest_sock_sd; if (max_sock_sd > max_fds) { printf("main: max_sock_sd = %d > max_fds = %d\n", max_sock_sd, max_fds); exit(1); } printf("main: aio_lowest_sock_sd = %d\n", aio_lowest_sock_sd); printf("main: aio_highest_sock_sd = %d\n", aio_highest_sock_sd); PRINT_TIME(NOFD, &tnow, &tprev, "main: calling aio_sock_init with " "max_sock_sd = %d", max_sock_sd); rc = aio_sock_init(aio_lowest_sock_sd, aio_highest_sock_sd); if (rc < 0) { printf("main: aio_sock_init failed rc = %d\n", rc); exit(1); } #endif /* HAVE_AIO_LAYER */ } else { max_sock_sd = max_fds; } printf("main: max_sock_sd = %d\n", max_sock_sd); printf("main: FD_SETSIZE = %d\n", FD_SETSIZE); printf("main: sizeof(fd_set) = %d\n", (int) sizeof(fd_set)); #ifdef TBB_KINFO if (options.kinfo) { kinfo_fd = pre_kinfo_init(); } #endif /* TBB_KINFO */ rc = info_init(); info_listener_init(); /* must happen after processing arguments */ init_app_queues(); create_pidfile(); options_valid(); options_print(); xmlf = fopen("options.xml", "w"); if (!xmlf) { printf("main: failed to create options.xml\n"); exit(1); } options_print_xml(xmlf); fclose(xmlf); #ifndef AIO_WORKAROUND_BUGS print_extra_info(); #endif /* AIO_WORKAROUND_BUGS */ #ifdef HAVE_NETSTAT netstat_init(); #endif /* HAVE_NETSTAT */ sock_special_init(); /* initialize the event dispatch mechanism */ if (options.use_poll) { PRINT_TIME(NOFD, &tnow, &tprev, "userver: calling poll_loop_init"); poll_loop_init(); #ifdef HAVE_EPOLL } else if (options.use_epoll || options.use_epoll2) { PRINT_TIME(NOFD, &tnow, &tprev, "userver: calling epoll_loop_init"); epoll_loop_init(); #endif /* HAVE_EPOLL */ #ifdef HAVE_AIO_LAYER } else if (options.use_socket_aio) { PRINT_TIME(NOFD, &tnow, &tprev, "userver: calling aio_loop_init"); aio_loop_init(); #endif /* HAVE_AIO_LAYER */ } else if (!options.send_loop) { assert(options.send_loop == 0); PRINT_TIME(NOFD, &tnow, &tprev, "userver: calling select_loop_init"); select_loop_init(); } else { #ifdef SEND assert(options.send_loop == 1); PRINT_TIME(NOFD, &tnow, &tprev, "userver: calling send_loop_init"); send_loop_init(); #endif } switch (options.get_connections) { case OPT_CONN_WITH_SELECT_POLL_EPOLL: server_mode = LISTENER_NOT_ASYNC_INIT; break; #ifdef SEND case OPT_CONN_WITH_SEND_SELECT: server_mode = LISTENER_NOT_ASYNC_INIT | LISTENER_SEND_INIT; break; #endif /* SEND */ case OPT_CONN_WITH_SIGIO: server_mode = LISTENER_DO_ASYNC_INIT; break; case OPT_CONN_WITH_SEND_EVTS: server_mode = LISTENER_SEND_INIT; break; case OPT_CONN_WITH_AIO_ACCEPT: server_mode = LISTENER_AIO_INIT; break; default: printf("%s: options.get_connections = %d not handled\n", argv[0], options.get_connections); exit(1); break; } /* switch */ printf("Calling server_init with mode = 0x%x = %d\n", server_mode, server_mode); server_init(server_mode); for (i = sock_listener_min; i <= sock_listener_max; i++) { if (sock_is_listener(i)) { printf("listen_sd = %d\n", i); if (i > max_sd) { max_sd = i; } } } switch (options.process_sds_order) { case OPT_PROCESS_SDS_LRU: lru_copy_init(); break; case OPT_PROCESS_SDS_LIFO: q_init(max_fds + 1); if (options.get_connections == OPT_CONN_WITH_SELECT_POLL_EPOLL) { for (i = sock_listener_min; i <= sock_listener_max; i++) { if (sock_is_listener(i)) { q_add_to_front(i); } } } break; case OPT_PROCESS_SDS_FIFO: q_init(max_fds + 1); if (options.get_connections == OPT_CONN_WITH_SELECT_POLL_EPOLL) { for (i = sock_listener_min; i <= sock_listener_max; i++) { if (sock_is_listener(i)) { q_add_to_rear(i); } } } break; default: /* do nothing */ break; } if (options.caching_on) { initCache(options.cache_table_size, options.cache_max_bytes, options.cache_max_file_size, options.cache_max_load_factor, options.cache_lock_pages); #ifdef CACHE_MAPPED_NEW if (options.cache_warm) { cache_warm(options.cache_warm_file, (options.doc_root[0] != '\0') ? options.doc_root : NULL, options.cache_table_print); } #endif } rusage_init(); fork_servers(numprocs); return 0; }