/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(wget_process, ev, data) { static char name[32]; static unsigned char i; PROCESS_BEGIN(); /* Allow other processes to initialize properly. */ for(i = 0; i < 10; ++i) { PROCESS_PAUSE(); } fputs("Get url:", stdout); if(contiki_argc > 1) { strcpy(url, contiki_argv[1]); puts(url); } else { gets(url); } fputs("Save as:", stdout); if(contiki_argc > 2) { strcpy(name, contiki_argv[2]); puts(name); } else { gets(name); } file = cfs_open(name, CFS_WRITE); if(file == -1) { printf("Open error with '%s'\n", name); app_quit(); } else { petsciiconv_toascii(url, sizeof(url)); start_get(); } while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); #if UIP_UDP } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) { start_get(); } else { puts("Host not found"); app_quit(); } #endif /* UIP_UDP */ } } PROCESS_END(); }
static struct result dispatch_events(struct app *app) { struct result result = result_success(); app->is_running = true; do { int key = view_read_key(app->active_view); if (ERR == key) { result = result_ncurses_err(); app_quit(app); break; } result = app->active_view->on_key(app->active_view, app, key); if (!result_is_success(result)) { app_quit(app); break; } } while (app->is_running); return result; }
void quit_callb(GtkWidget *wdg, gpointer callb_data) { // Quit the application, after closing all opened documents // Scan documents wrappers app_struct *app; app = (app_struct *) callb_data; if (app) commit_or_reset (app->stack); // Check for document needing saving // If so: ask to save (modal), then save with the save function for this type // If not: destroy document window app_quit(wdg, callb_data); }
/* Callback function. Called from the webclient module when HTTP data * has arrived. */ void webclient_datahandler(char *data, uint16_t len) { static unsigned long dload_bytes; int ret; if(len > 0) { dload_bytes += len; printf("Downloading (%lu bytes)\n", dload_bytes); if(file != -1) { ret = cfs_write(file, data, len); if(ret != len) { printf("Wrote only %d bytes\n", ret); } } } if(data == NULL) { printf("Finished downloading %lu bytes.\n", dload_bytes); app_quit(); } }
/*-----------------------------------------------------------------------------------*/ PROCESS_THREAD(dhcp_process, ev, data) { PROCESS_BEGIN(); ctk_window_new(&window, 29, 14, "DHCP client"); CTK_WIDGET_ADD(&window, &requestbutton); CTK_WIDGET_ADD(&window, &statuslabel); CTK_WIDGET_ADD(&window, &ipaddrlabel); CTK_WIDGET_ADD(&window, &ipaddrtextentry); CTK_WIDGET_ADD(&window, &netmasklabel); CTK_WIDGET_ADD(&window, &netmasktextentry); CTK_WIDGET_ADD(&window, &gatewaylabel); CTK_WIDGET_ADD(&window, &gatewaytextentry); #if WITH_DNS CTK_WIDGET_ADD(&window, &dnsserverlabel); CTK_WIDGET_ADD(&window, &dnsservertextentry); #endif /* WITH_DNS */ CTK_WIDGET_ADD(&window, &savebutton); CTK_WIDGET_ADD(&window, &cancelbutton); CTK_WIDGET_FOCUS(&window, &requestbutton); ctk_window_open(&window); /* Allow resolver to set DNS server address. */ process_post(PROCESS_CURRENT(), PROCESS_EVENT_MSG, NULL); dhcpc_init(uip_ethaddr.addr, sizeof(uip_ethaddr.addr)); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_MSG) { makestrings(); ctk_window_redraw(&window); } else if(ev == tcpip_event) { dhcpc_appcall(ev, data); } else if(ev == ctk_signal_button_activate) { if(data == (process_data_t)&requestbutton) { dhcpc_request(); set_statustext("Requesting..."); } if(data == (process_data_t)&savebutton) { apply_tcpipconfig(); app_quit(); } if(data == (process_data_t)&cancelbutton) { app_quit(); } } else if( #if CTK_CONF_WINDOWCLOSE ev == ctk_signal_window_close || #endif ev == PROCESS_EVENT_EXIT) { app_quit(); } } PROCESS_END(); }
gint app_menu_delete (GtkWidget *wdg, GdkEvent *event, gpointer data) { return app_quit (wdg, data); }
/* Callback function. Called from the webclient when the HTTP * connection was closed after a request from the "webclient_close()" * function. . */ void webclient_closed(void) { puts("Done."); app_quit(); }
/* Callback function. Called from the webclient when the HTTP * connection timed out. */ void webclient_timedout(void) { puts("Connection timed out"); app_quit(); }
/* Callback function. Called from the webclient when the HTTP * connection was abruptly aborted. */ void webclient_aborted(void) { puts("Connection reset by peer"); app_quit(); }
/** * QUIT ARexx command * * @param rxmsg the message defining the ARexx context * @param args the command's arguments */ static void arexx_quit(struct RexxMsg *rxmsg, STRPTR args) { app_quit(); }
bool handle_events( void ) { SDL_Event _event; reset_events(); //DebugPrintf("processing events\n"); while( SDL_PollEvent( &_event ) ) { switch( _event.type ) { // previously mouse wheel was a button code // now it's an x/y axis since it supports mouse wheel balls #if SDL_VERSION_ATLEAST(2,0,0) case SDL_MOUSEWHEEL: app_mouse_wheel( &_event ); break; #endif // this event name has changed #if SDL_VERSION_ATLEAST(2,0,0) // TODO - we should call something like app_window // which then delegates to app_active in correct case case SDL_WINDOWEVENT: app_active( &_event ); break; #else case SDL_ACTIVEEVENT: app_active( &_event.active ); break; #endif // these have been moved into the window event above #if !SDL_VERSION_ATLEAST(2,0,0) case SDL_VIDEORESIZE: app_resize( &_event.resize ); break; case SDL_VIDEOEXPOSE: // need redraw render_flip(&render_info); break; #endif // the newer sdl now uses a union instead of sub structures #if SDL_VERSION_ATLEAST(2,0,0) case SDL_KEYDOWN: case SDL_KEYUP: app_keyboard( &_event ); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: app_mouse_button( &_event ); break; case SDL_MOUSEMOTION: app_mouse_motion( &_event ); break; case SDL_JOYAXISMOTION: app_joy_axis( &_event ); break; case SDL_JOYBALLMOTION: app_joy_ball( &_event ); break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: app_joy_button( &_event ); break; case SDL_JOYHATMOTION: app_joy_hat( &_event ); break; #else case SDL_KEYDOWN: case SDL_KEYUP: app_keyboard( &_event.key ); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: app_mouse_button( &_event.button ); break; case SDL_MOUSEMOTION: app_mouse_motion( &_event.motion ); break; case SDL_JOYAXISMOTION: app_joy_axis( &_event.jaxis ); break; case SDL_JOYBALLMOTION: app_joy_ball( &_event.jball ); break; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: app_joy_button( &_event.jbutton ); break; case SDL_JOYHATMOTION: app_joy_hat( &_event.jhat ); break; #endif case SDL_QUIT: app_quit(); break; // platform specific _event type // must be enabled using SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE) case SDL_SYSWMEVENT: DebugPrintf("recived a platform specific _event type\n"); break; // to avoid threading issues timers will add an event to the queue // so that we can call the callbacks from the same thread case SDL_USEREVENT: { void (*p) (void*) = _event.user.data1; // callback p(_event.user.data2); // callback( data ) } break; // TODO default: printf("Unknown event type: %d\n",_event.type); break; } } //DebugPrintf("DONE processing events\n"); if ( quitting ) { DebugPrintf("about to CleanUpAndPostQuit ( from WindowProc )\n"); quitting = false; CleanUpAndPostQuit(); } return true; }