// IPC Auto Connect eEsifError ipc_autoconnect(UInt32 max_retries) { eEsifError rc = ESIF_OK; UInt32 connect_retries = 0; ESIF_TRACE_ENTRY_INFO(); if (g_ipc_handle != ESIF_INVALID_HANDLE) { return rc; } // Attempt to connect to LF indefinitely until ESIF exits (unless the LF version is unsupported) while (!g_quit) { rc = ipc_connect(); if (rc == ESIF_OK || rc == ESIF_E_NOT_SUPPORTED) { break; } if (max_retries > 0 && ++connect_retries >= max_retries) { ESIF_TRACE_ERROR("Unable to do an IPC connect\n"); break; } esif_ccb_sleep(1); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
/* stop web server and wait for worker threads to exit */ void esif_ws_exit(esif_thread_t *threadPtr) { CMD_OUT("Stopping WebServer...\n"); atomic_set(&g_ws_quit, 1); esif_ccb_thread_join(threadPtr); /* join to close child thread, clean up handle */ // Wait for worker thread to finish while (atomic_read(&g_ws_threads) > 0) { esif_ccb_sleep(1); } esif_ccb_mutex_uninit(&g_web_socket_lock); atomic_set(&g_ws_quit, 0); CMD_OUT("WebServer Stopped\n"); }
// IPC Auto Connect void ipc_autoconnect () { if (g_ipc_handle != ESIF_INVALID_HANDLE) { return; } while (!g_quit) { ipc_connect(); if (g_ipc_handle != ESIF_INVALID_HANDLE) { break; } esif_ccb_sleep(1); } }
int main (int argc, char **argv) { int c = 0; FILE *fp = stdin; char command[MAX_LINE + 1] = {0}; int quit_after_command = ESIF_FALSE; #if defined(ESIF_ATTR_DAEMON) int start_as_server = ESIF_FALSE; int start_with_pipe = ESIF_FALSE; int start_with_log = ESIF_FALSE; #else int start_as_server = ESIF_TRUE; #endif // Init ESIF int rc = chdir(".."); optind = 1; // Rest To 1 Restart Vector Scan while ((c = getopt(argc, argv, "d:f:c:b:nxhq?spl")) != -1) { switch (c) { case 'd': g_dst = (u8)esif_atoi(optarg); break; case 'n': g_autocpc = ESIF_FALSE; break; case 'x': g_format = FORMAT_XML; break; case 'b': g_binary_buf_size = (int)esif_atoi(optarg); break; case 'f': fp = fopen(optarg, "r"); break; case 'c': sprintf(command, "%s", optarg); break; case 'q': quit_after_command = ESIF_TRUE; break; #if defined (ESIF_ATTR_DAEMON) case 's': start_as_server = ESIF_TRUE; break; case 'p': start_with_pipe = ESIF_TRUE; break; case 'l': start_with_log = ESIF_TRUE; break; #endif case 'h': case '?': printf( "EsiF Eco-System Independent Framework Shell\n" "(c) 2013 Intel Corp\n\n" "-d [*id] Set Destination\n" "-f [*filename] Load Filename\n" "-n No Auto CPC Assignment\n" "-x XML Output Data Format\n" "-c [*command] Issue Shell Command\n" "-q Quit After Command\n" "-b [*size] Set Binary Buffer Size\n" #if defined (ESIF_ATTR_DAEMON) "-s Run As Server\n" "-p Use Pipe For Input\n" "-l Use Log For Output\n" #endif "-h or -? This Help\n\n"); exit(0); break; default: break; } } #if defined (ESIF_ATTR_DAEMON) if (start_as_server) { run_as_server(fp, command, quit_after_command); } else { run_as_daemon(start_with_pipe, start_with_log); } #else run_as_server(fp, command, quit_after_command); #endif if (fp && fp != stdin) { fclose(fp); } /* NICE Wait For Worker Thread To Exit */ printf("Waiting For EVENT Thread To Exit...\n"); while (!g_quit2) { esif_ccb_sleep(1); } printf("Errorlevel Returned: %d\n", g_errorlevel); /* Exit ESIF */ esif_uf_exit(); exit(g_errorlevel); }
static int run_as_server(FILE* input, char* command, int quit_after_command) { char *ptr = NULL; char line[MAX_LINE + 1] = {0}; char line2[MAX_LINE + 1] = {0}; g_debuglog = stdin; /* Prompt */ #define PROMPT_LEN 64 char *prompt = NULL; char full_prompt[MAX_LINE + 1] = {0}; char prompt_buf[PROMPT_LEN] = {0}; ESIF_DATA(data_prompt, ESIF_DATA_STRING, prompt_buf, PROMPT_LEN); esif_uf_init(""); esif_ccb_thread_create(&g_thread, esif_event_worker_thread, "Server"); sleep(1); cmd_app_subsystem(SUBSYSTEM_ESIF); while (!g_quit) { int count = 0; // Startup Command? if (command) { parse_cmd(command, ESIF_FALSE); if (ESIF_TRUE == quit_after_command) { g_quit = 1; continue; } } // Get User Input g_appMgr.GetPrompt(&g_appMgr, &data_prompt); prompt = (esif_string)data_prompt.buf_ptr; #ifdef ESIF_ATTR_OS_LINUX_HAVE_READLINE // Use Readline With History sprintf(full_prompt, "%s ", prompt); ptr = readline(full_prompt); // Add To History NO NUL's if (ptr[0] != 0) { add_history(ptr); } strcpy(line, ptr); free(ptr); #else // No History So Sorry printf("%s ", prompt); if (fgets(line, MAX_LINE, input) == NULL) { break; } ptr = line; while (*ptr != '\0') { if (*ptr == '\r' || *ptr == '\n' || *ptr == '#') { *ptr = '\0'; } ptr++; } #endif if (1 == g_repeat || !strncmp(line, "repeat", 6)) { parse_cmd(line, ESIF_FALSE); } else { for (count = 0; count < g_repeat; count++) { strcpy(line2, line); parse_cmd(line2, ESIF_FALSE); /* parse destroys command line */ if (kbhit()) { break; } if (g_soe && g_errorlevel != 0) { break; } if (g_repeat_delay && count + 1 < g_repeat) { esif_ccb_sleep(g_repeat_delay / 1000); } } g_repeat = 1; } } }