/** * @brief init */ static void init(){ /*int k = 0, k1 = random_int(100); for(k = 0; k < 100; k++){ random_rand(); }*/ ///initialize setting must be called before neighbors init bcz initialize_settings(); ///initialize list of neighbors neighs_init(); //on(); PT_INIT(&pt); /** start the node discovery process NOTE: ONLY USED FOR COOJA SIMULATIONS*/ process_start(&autotrigger_process, NULL); process_start(&output_process, NULL); ///START UP PROTOCOL...INDRIYA ONLY..... ///@todo..comment this code afterwards.. //cc2420_set_channel(i3e154_channels[random_int(num_channels)]); cc2420_set_channel(i3e154_channels[0]); }
// Returns the singleton instance of the app object. // If it is being created for the first time, it // does application initialization. AppUtil* AppUtil::instance() { if (instance_ == NULL) { instance_ = new AppUtil(); if ( !instance_ ) { PRINT_ERROR(" *** Unable to initialize application ***\n"); exit(1); } // Initialize interrupted flag to false. cubit_intr = CUBIT_FALSE; cubit_update_terminal_size(0); initialize_settings(); } return instance_; }
void initgraph(int *graphdriver,int *graphmode,char *pathtodriver) { int x=640, y; int _initflag=SDL_SWSURFACE; if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(-1); } atexit(closegraph); /* Register closegraph() as the default exit function in case user forgets to call it. */ _pid = fork(); // Don't bother with this. if //The process forks a child to check for Ctrl-C. (!_pid) ctrlbreak(); else { signal(SIGUSR1, inthandler); signal (SIGUSR2, refresh_interrupt); } if (*graphdriver == DETECT) *graphmode = VGAHI; //Default mode 640*480*8 if (*graphdriver == USER) { y = *graphmode % 1000; x = (*graphmode / 1000) % 1000; *graphmode = USERMODE; } else switch(*graphmode){ case VGALO : y = 200; break; case VGAMED : y = 350; break; case VGAMAX : x = 800,y = 600; /*Special extension 800*600*8 windowed*/ break; case VGA640 : /* Special extension 640x480x8 fullscreen */ y = 480; /* WARNING : may cause virtual screen */ _initflag |= SDL_FULLSCREEN; break; case VGA800 : /* Special extension 800x600x8 fullscreen */ x = 800, y = 600; /* WARNING : may cause virtual screen */ _initflag |= SDL_FULLSCREEN; break; case VGA1024 : /* Special extension 1024x768x8 fullscreen */ x = 1024, y = 768; /* WARNING : may cause virtual screen */ _initflag |= SDL_FULLSCREEN; break; case VGAHI : default : y = 480; break; } { /* Setup the custom libgraph icon */ char *iconpath; asprintf (&iconpath, "%s%s", FONTDIR, "icon.bmp"); SDL_WM_SetIcon (SDL_LoadBMP (iconpath), NULL); free (iconpath); } SDL_WM_SetCaption("SDL-libgraph -- Graphics on GNU/Linux", 0); /* Set the default libgraph window caption */ screen = SDL_SetVideoMode(x, y, 8, _initflag); if ( screen == NULL ) { fprintf(stderr, "Unable to set video: %s\n", SDL_GetError()); exit(-1); } initialize_settings (); /* Initialize global variables */ }
/* @brief The main function. Initialization happens here. * * @return 0 on success and 1 on failure. */ int main(int argc, char **argv) { int32_t exit_code = 0; atexit(kill_zombie); int c; char *config_file = CONFIG_FILE; while ((c = getopt(argc, argv, "c:")) != -1) { switch (c) { case 'c': config_file = optarg; break; default: break; } } if (initialize_settings(config_file)) { return 1; } int i; enum { MAX_ARGS = 64 }; int nargs = 0; char *cmdargs[MAX_ARGS]; /* one extra for the NULL */ nargs = (argc - optind) + 2; if (nargs > 63) nargs = 63; for (i=optind; i < argc; i++) { if ((i - optind) + 1 > 62) break; cmdargs[(i - optind) + 1] = strdup(argv[i]); } cmdargs[nargs - 1] = NULL; /* Set up the remote process. */ int32_t to_child_fd, from_child_fd; char *exec_file = settings.cmd; if (spawn_piped_process(exec_file, &to_child_fd, &from_child_fd, (char **)cmdargs)) { fprintf(stderr, "Failed to spawn piped process.\n"); exit_code = 1; return exit_code; } /* Don't free #0, it is filled in by spawn_piped_process() and isn't memory that we own */ for (i=1; i < nargs - 1 ; i++) free(cmdargs[i]); /* The main way to communicate with our remote process. */ FILE *to_child = fdopen(to_child_fd, "w"); /* Connect to the X server. */ xcb_connection_t *connection = xcb_connect(NULL, NULL); /* Setup keyboard stuff. Thanks Apple! */ xcb_key_symbols_t *keysyms = xcb_key_symbols_alloc(connection); /* Get the first screen. */ const xcb_setup_t *setup = xcb_get_setup(connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_t *screen = iter.data; /* Create a window. */ xcb_window_t window = xcb_generate_id(connection); uint32_t values[2]; values[0] = screen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS; xcb_void_cookie_t window_cookie = xcb_create_window_checked(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, settings.width, settings.height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, values); if (check_xcb_cookie(window_cookie, connection, "Failed to initialize window.")) { exit_code = 1; goto cleanup; } /* Get the atoms to create a dock window type. */ xcb_atom_t window_type_atom, window_type_dock_atom; xcb_intern_atom_cookie_t atom_cookie = xcb_intern_atom(connection, 0, strlen("_NET_WM_WINDOW_TYPE"), "_NET_WM_WINDOW_TYPE"); xcb_intern_atom_reply_t *atom_reply = xcb_intern_atom_reply(connection, atom_cookie, NULL); if (!atom_reply) { fprintf(stderr, "Unable to set window type. You will need to manually set your window manager to run lighthouse as you'd like.\n"); } else { window_type_atom = atom_reply->atom; free(atom_reply); atom_cookie = xcb_intern_atom(connection, 0, strlen("_NET_WM_WINDOW_TYPE_DOCK"), "_NET_WM_WINDOW_TYPE_DOCK"); atom_reply = xcb_intern_atom_reply(connection, atom_cookie, NULL); if (atom_reply) { window_type_dock_atom = atom_reply->atom; free(atom_reply); xcb_change_property_checked(connection, XCB_PROP_MODE_REPLACE, window, window_type_atom, XCB_ATOM_ATOM, 32, 1, &window_type_dock_atom); } else { fprintf(stderr, "Unable to set window type. You will need to manually set your window manager to run lighthouse as you'd like.\n"); } } /* Now set which desktop to run on. */ xcb_atom_t desktop_atom; atom_cookie = xcb_intern_atom(connection, 0, strlen("_NET_WM_DESKTOP"), "_NET_WM_DESKTOP"); atom_reply = xcb_intern_atom_reply(connection, atom_cookie, NULL); if (!atom_reply) { fprintf(stderr, "Unable to set a specific desktop to launch on.\n"); } else { desktop_atom = atom_reply->atom; free(atom_reply); xcb_change_property_checked(connection, XCB_PROP_MODE_REPLACE, window, desktop_atom, XCB_ATOM_ATOM, 32, 1, (const uint32_t []){ settings.desktop }); }
/** * Initializes the required resources. * * Should only be called once, right after starting. */ Code initialize(Window **window, Renderer **renderer) { char log_buffer[MAXIMUM_STRING_SIZE]; Uint32 renderer_flags = 0; initialize_logger(); initialize_profiler(); initialize_settings(); if (SDL_Init(SDL_INIT_FLAGS)) { sprintf(log_buffer, "SDL initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } SDL_ShowCursor(SDL_DISABLE); initialize_joystick(); if (!TTF_WasInit()) { if (TTF_Init()) { sprintf(log_buffer, "TTF initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } } if ((IMG_Init(IMG_FLAGS) & IMG_FLAGS) != IMG_FLAGS) { sprintf(log_buffer, "Failed to initialize required image support."); log_message(log_buffer); return CODE_ERROR; } /** * The number of columns and the number of lines are fixed. However, the * number of pixels we need for the screen is not. We find this number by * experimenting before creating the window. */ /* Log the size of the window we are going to create. */ *window = create_window(&window_width, &window_height); sprintf(log_buffer, "Created a %dx%d window.", window_width, window_height); log_message(log_buffer); if (*window == NULL) { sprintf(log_buffer, "SDL initialization error: %s.", SDL_GetError()); log_message(log_buffer); return CODE_ERROR; } if (initialize_fonts()) { sprintf(log_buffer, "Failed to initialize fonts."); log_message(log_buffer); return CODE_ERROR; } if (initialize_font_metrics()) { sprintf(log_buffer, "Failed to initialize font metrics."); log_message(log_buffer); return CODE_ERROR; } /* Must disable text input to prevent a name capture bug. */ SDL_StopTextInput(); set_window_title_and_icon(*window); if (get_renderer_type() == RENDERER_HARDWARE) { renderer_flags = SDL_RENDERER_ACCELERATED; } else { renderer_flags = SDL_RENDERER_SOFTWARE; } *renderer = SDL_CreateRenderer(*window, -1, renderer_flags); set_color(*renderer, COLOR_DEFAULT_BACKGROUND); clear(*renderer); return CODE_OK; }