static void ntetris_thread(CYG_ADDRWORD data) { int argc = 1; char *argv[] = {"ntetris" }; INIT_PER_THREAD_DATA(); ntetris_main(argc, argv); }
int world_thread(CYG_ADDRWORD data) { int argc = 1; char *argv[] = {"world" }; cyg_thread_delay(10*100); INIT_PER_THREAD_DATA(); world_main(argc, argv); }
int landmine_thread(CYG_ADDRWORD data) { int argc = 5; char *argv[] = {"landmine", "-m", "15", "-s", "10"}; INIT_PER_THREAD_DATA(); landmine_main(argc, argv); }
int img_demo_thread(CYG_ADDRWORD data) { int err, s, client, client_len; struct sockaddr client_addr; struct sockaddr_in my_addr; struct addrinfo *ai, *addrs, hints; char buf[256], addr_buf[256]; int one = 1; fd_set in_fds, src_fds; int num, len; struct timeval tv; INIT_PER_THREAD_DATA(); printf("Image demo here\n"); #ifdef CYGPKG_FS_RAM // Stage files from JFFS2 image into RAM err = mount("", "/ramfs", "ramfs"); if (err >= 0) { do_copy_all("/", "/ramfs"); } else { pexit("Can't mount RAMfs\n"); } chdir("/ramfs"); #endif if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } // Set up as a generic server, listening on TCP/7734 #if 0 bzero(&hints, sizeof(hints)); hints.ai_family = PF_UNSPEC;b hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if ((err = getaddrinfo(NULL, "7734", &hints, &addrs)) != EAI_NONE) { diag_printf("can't getaddrinfo(): %s\n", gai_strerror(err)); pexit("getaddrinfo"); } s = socket(ai->ai_family, ai->ai_socktype, 0); if (s < 0) { pexit("stream socket"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { pexit("setsockopt SO_REUSEADDR"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { pexit("setsockopt SO_REUSEPORT"); } if(bind(s, ai->ai_addr, ai->ai_addr->sa_len) < 0) { pexit("bind error"); } listen(s, SOMAXCONN); #else s = socket(AF_INET, SOCK_STREAM, 0); if (s < 0) { pexit("stream socket"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { pexit("setsockopt SO_REUSEADDR"); } if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one))) { pexit("setsockopt SO_REUSEPORT"); } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_len = sizeof(my_addr); my_addr.sin_port = htons(7734); my_addr.sin_addr.s_addr = INADDR_ANY; if(bind(s, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) { pexit("bind error"); } listen(s, SOMAXCONN); #endif while (true) { // Wait for a connection FD_ZERO(&src_fds); FD_SET(s, &src_fds); tv.tv_sec = 15; tv.tv_usec = 0; num = select(s+1, &src_fds, 0, 0, &tv); if (num > 0) { client_len = sizeof(client_addr); if ((client = accept(s, (struct sockaddr *)&client_addr, &client_len)) < 0) { pexit("accept"); } client_len = sizeof(client_addr); getpeername(client, &client_addr, &client_len); _inet_ntop(&client_addr, addr_buf, sizeof(addr_buf)); diag_printf("connection from %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); fdprintf(client, "Hello %s(%d)\n", addr_buf, ntohs(_inet_port(&client_addr))); while (true) { fdprintf(client, "// Ready\n"); tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&in_fds); FD_SET(client, &in_fds); num = select(client+1, &in_fds, 0, 0, &tv); if (num > 0) { len = read(client, buf, sizeof(buf)-1); if (len <= 0) { diag_printf("Client read error: %s\n", strerror(errno)); break; } buf[len-1] = '\0'; do_cmd(client, buf); } else if (num == 0) { fdprintf(client, "<IDLE> show_all\n"); do_show_all(client, "show_all ."); } else { perror("select"); } } close(client); diag_printf("Connection with %s closed\n", addr_buf); } else if (num == 0) { // No connection within 15 seconds do_show_all(0, "show_all ."); } else { diag_printf("select returned: %d\n", num); pexit("bad select"); } } }
void ecos_nx_init(CYG_ADDRWORD data) { GR_SCREEN_INFO si; /* window information */ GR_FONT_INFO fi; /* font information */ GR_WINDOW_ID mainwid; /* main window id */ GR_WM_PROPERTIES props; GR_GC_ID gct = 0; #if 0 NWIDGET *w; NBUTTON *b; NTEXTFIELD *t; #endif cyg_thread_delay(50); INIT_PER_THREAD_DATA(); test_file_io(); if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } #if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS) GrSetPortraitMode(MWPORTRAIT_RIGHT); #endif GrGetScreenInfo(&si); GrGetFontInfo(0, &fi); #if 1 mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.cols, si.rows, 0, RED, WHITE); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER; GrSetWMProperties(mainwid, &props); GrMapWindow(mainwid); GrFlush(); cyg_thread_delay(50); gct = GrNewGC(); GrSetGCForeground(gct, WHITE); #ifdef CYGPKG_IO_FILEIO { struct stat stat_data; if (0 == stat("/redhat.logo", &stat_data)) { GrDrawImageFromFile(mainwid, gct, 0, 0, si.cols, si.rows, "/redhat.logo", 0); } } #endif #if (defined CYGPKG_HAL_ARM) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS) // Touch sensitive screen calibration, only relevant on some // platforms. GrSetGCFont(gct, GrCreateFont(GR_FONT_GUI_VAR, 0, NULL)); GrText(mainwid, gct, 80, 350, "Tap all 4 corners", 17, GR_TFTOP); GrFlush(); printf("Tap all four corners\n"); cyg_thread_delay(10*100); #endif #else n_init_button_class(); n_init_textfield_class(); w = NEW_NOBJECT(widget); n_widget_init(w, 0); n_widget_resize(w, si.cols - 10, si.rows - 30); n_widget_background(w, "/redhat.logo"); n_widget_show(w); b = NEW_NOBJECT(button); n_button_init(b, w, "Close"); n_button_onclick(b, do_close); n_widget_resize(b, 40, 20); n_widget_move(b,180,260); n_widget_show(b); t = NEW_NOBJECT(textfield); n_textfield_init(t,w,"Tap all 4 corners"); n_widget_move(t,45,220); n_widget_resize(t,120,20); n_widget_show(t); t = NEW_NOBJECT(textfield); n_textfield_init(t,w,"Then press close"); n_widget_move(t,45,250); n_widget_resize(t,120,20); n_widget_show(t); while (!closed) { n_handle_event(); } n_widget_hide(w); n_object_cleanup(w); #endif GrClose(); }