/* 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"); }
// Display Results void EqlCmd_DisplayResults (EqlCmdPtr self) { if (self) { int i; for (i = 0; i < self->results->size; i++) { EsifDataPtr data = &self->results->elements[i]; char *strdata = EsifData_ToString(data); if (strdata) { CMD_OUT("%s\n", strdata); esif_ccb_free(strdata); } } CMD_OUT("\n"); } }
void EsifLogFile_DisplayList(void) { int j; for (j = 0; j < MAX_ESIFLOG; j++) { if (g_EsifLogFile[j].handle != NULL && g_EsifLogFile[j].name != NULL) { CMD_OUT("%s log: %s\n", g_EsifLogFile[j].name, (g_EsifLogFile[j].filename ? g_EsifLogFile[j].filename : "NA")); } } }
eEsifError esif_uf_init() { eEsifError rc = ESIF_OK; ESIF_TRACE_ENTRY_INFO(); #ifdef ESIF_ATTR_SHELL_LOCK esif_ccb_mutex_init(&g_shellLock); #endif ESIF_TRACE_DEBUG("Init Upper Framework (UF)"); esif_ccb_mempool_init_tracking(); // Get Home directory CMD_OUT("Home: %s\n", esif_pathlist_get(ESIF_PATHTYPE_HOME)); /* OS Agnostic */ EsifLogMgrInit(); esif_link_list_init(); esif_ht_init(); esif_ccb_tmrm_init(); EsifCfgMgrInit(); EsifEventMgr_Init(); EsifCnjMgrInit(); EsifUpPm_Init(); EsifDspMgrInit(); EsifActMgrInit(); /* Web Server optionally started by shell scripts in esif_init */ /* OS Specific */ rc = esif_uf_os_init(); if (ESIF_OK != rc) { goto exit; } /* Start App Manager after all dependent components started * This does not actually start any apps. */ EsifAppMgrInit(); #ifdef ESIF_FEAT_OPT_ACTION_SYSFS SysfsRegisterParticipants(); #else ipc_connect(); sync_lf_participants(); #endif exit: ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
void esif_memtrace_exit() { struct memalloc_s *mem = NULL; char tracefile[MAX_PATH] = {0}; FILE *tracelog = NULL; esif_build_path(tracefile, sizeof(tracefile), ESIF_PATHTYPE_LOG, "memtrace.txt", NULL); esif_pathlist_exit(); esif_ccb_write_lock(&g_memtrace.lock); mem = g_memtrace.allocated; g_memtrace.allocated = NULL; esif_ccb_write_unlock(&g_memtrace.lock); CMD_OUT("MemTrace: Allocs=" ATOMIC_FMT " Frees=" ATOMIC_FMT "\n", atomic_read(&g_memtrace.allocs), atomic_read(&g_memtrace.frees)); if (!mem) { goto exit; } CMD_OUT("\n*** MEMORY LEAKS DETECTED ***\nFor details see %s\n", tracefile); esif_ccb_fopen(&tracelog, tracefile, "a"); if (tracelog) { time_t now = time(NULL); char timestamp[MAX_CTIME_LEN] = {0}; esif_ccb_ctime(timestamp, sizeof(timestamp), &now); fprintf(tracelog, "\n*** %.24s: MEMORY LEAKS DETECTED (%s) ***\n", timestamp, ESIF_UF_VERSION); } while (mem) { struct memalloc_s *node = mem; if (tracelog) { fprintf(tracelog, "[%s @%s:%d]: (%lld bytes) %p\n", mem->func, mem->file, mem->line, (long long)mem->size, mem->mem_ptr); } mem = mem->next; native_free(node->mem_ptr); native_free(node); } if (tracelog) { esif_ccb_fclose(tracelog); } exit: esif_ccb_lock_uninit(&g_memtrace.lock); }
// Event Worker Thread // Processes ESIF Events void *esif_event_worker_thread(void *ptr) { int rc = 0; fd_set rfds = {0}; struct timeval tv = {0}; UNREFERENCED_PARAMETER(ptr); ESIF_TRACE_ENTRY_INFO(); CMD_OUT("Start ESIF Event Thread\n"); // Connect To Kernel IPC with infinite timeout ipc_autoconnect(0); // Run Until Told To Quit while (!g_quit) { #ifdef ESIF_FEAT_OPT_ACTION_SYSFS esif_ccb_sleep_msec(250); #else if (g_ipc_handle == ESIF_INVALID_HANDLE) { break; } if (rc > 0) { EsifEvent_GetAndSignalIpcEvent(); } FD_ZERO(&rfds); FD_SET((esif_ccb_socket_t)g_ipc_handle, &rfds); tv.tv_sec = 0; tv.tv_usec = 50000; /* 50 msec */ #ifdef ESIF_ATTR_OS_LINUX rc = select(g_ipc_handle + 1, &rfds, NULL, NULL, &tv); #endif #ifdef ESIF_ATTR_OS_WINDOWS // Windows does not support select/poll so we simulate here esif_ccb_sleep_msec(50); rc = 1; #endif #endif } if (g_ipc_handle != ESIF_INVALID_HANDLE) { ipc_disconnect(); } ESIF_TRACE_EXIT_INFO(); return 0; }
static char* get_cmd_line(GameContext* pGame, GameEventContext* pEvent, const char* prompt, char* buf, int len) { int mode; RESULT ret; if(is_test_mode()) { // contiue test proc mode = CMD_LINE_MODE_NORMAL; MSG_OUT("%s", prompt); ret = script_test_continue(s_out_messages,s_out_len, buf, len, &mode); if(R_SUCC == ret) { s_out_len = 0; s_out_messages[0] = 0; if(mode == CMD_LINE_MODE_SCRIPT) { if(R_SUCC != cmd_do_script(pGame, pEvent)) { s_test_mode = 0; buf[0] = 0; CMD_OUT(buf); script_test_error(); if(pGame->status != Status_None) { //longjmp(pContext->__jb__, R_EXIT); //pGame->status = Status_GameAbort; luaL_error(get_game_script(), "Run test error!"); } return buf; } } CMD_OUT(buf); return buf; } s_out_len = 0; s_out_messages[0] = 0; // 失败退出测试模式 s_test_mode = 0; buf[0] = 0; CMD_OUT(buf); if(R_CANCEL == ret) { // test finished } else if(pGame->status != Status_None) { //longjmp(pContext->__jb__, R_EXIT); //pGame->status = Status_GameAbort; luaL_error(get_game_script(), "Run test error!"); } return buf; } else { mode = CMD_LINE_MODE_NORMAL; return logic_wait_cmd(prompt, buf, len); } }
static eEsifError ActionCreate( EsifActPtr actionPtr, GetIfaceFuncPtr ifaceFuncPtr ) { eEsifError rc = ESIF_OK; EsifActTypePtr action_type_ptr = NULL; EsifData p1 = {ESIF_DATA_STRING, "action_iD", sizeof("action_id")}; EsifData p2 = {ESIF_DATA_STRING, "domain_qualifier", sizeof("domain_qaulifier")}; EsifData p3 = {ESIF_DATA_UINT32, "kernel_abi_type", sizeof("Kernel_abi_type")}; EsifData p4 = {ESIF_DATA_UINT8, "mode", sizeof("mode")}; char name[ESIF_NAME_LEN] = {0}; ESIF_DATA(data_name, ESIF_DATA_STRING, name, ESIF_NAME_LEN); char desc[ESIF_DESC_LEN] = {0}; ESIF_DATA(data_desc, ESIF_DATA_STRING, desc, ESIF_DESC_LEN); char version[ESIF_DESC_LEN] = {0}; ESIF_DATA(data_version, ESIF_DATA_STRING, version, ESIF_DESC_LEN); UInt32 action_type_id = 0; EsifData action_type = {ESIF_DATA_UINT32, &action_type_id, sizeof(action_type_id), 0}; esif_guid_t guid = {0}; EsifData data_guid = {ESIF_DATA_GUID, &guid, sizeof(guid), 0}; EsifString act_type_ptr = NULL; EsifInterface act_service_iface; ESIF_ASSERT(actionPtr != NULL); ESIF_ASSERT(ifaceFuncPtr != NULL); /* Assign the EsifInterface Functions */ act_service_iface.fIfaceType = eIfaceTypeEsifService; act_service_iface.fIfaceVersion = 1; act_service_iface.fIfaceSize = (UInt16)sizeof(EsifInterface); act_service_iface.fGetConfigFuncPtr = EsifSvcConfigGet; act_service_iface.fSetConfigFuncPtr = EsifSvcConfigSet; act_service_iface.fPrimitiveFuncPtr = EsifSvcPrimitiveExec; act_service_iface.fWriteLogFuncPtr = EsifSvcWriteLog; act_service_iface.fRegisterEventFuncPtr = EsifSvcEventRegister; act_service_iface.fUnregisterEventFuncPtr = EsifSvcEventUnregister; /* GetApplicationInterface Handleshake send ESIF receive APP Interface */ rc = ifaceFuncPtr(&actionPtr->fInterface); if (ESIF_OK != rc) { goto exit; } /* Check EsifAppInterface */ if (actionPtr->fInterface.fIfaceType != eIfaceTypeAction || actionPtr->fInterface.fIfaceSize != (UInt16)sizeof(EsifActInterface) || actionPtr->fInterface.fIfaceVersion != 1 || /* Functions Pointers */ actionPtr->fInterface.fActCreateFuncPtr == NULL || actionPtr->fInterface.fActDestroyFuncPtr == NULL || actionPtr->fInterface.fActGetAboutFuncPtr == NULL || actionPtr->fInterface.fActGetDescriptionFuncPtr == NULL || actionPtr->fInterface.fActGetFuncPtr == NULL || actionPtr->fInterface.fActGetIDFuncPtr == NULL || actionPtr->fInterface.fActGetGuidFuncPtr == NULL || actionPtr->fInterface.fActGetNameFuncPtr == NULL || actionPtr->fInterface.fActGetStateFuncPtr == NULL || actionPtr->fInterface.fActGetStatusFuncPtr == NULL || actionPtr->fInterface.fActGetVersionFuncPtr == NULL || actionPtr->fInterface.fActSetFuncPtr == NULL || actionPtr->fInterface.fActSetStateFuncPtr == NULL) { ESIF_TRACE_ERROR("The required function pointer in EsifActInterface is NULL\n"); goto exit; } /* Callback for application information */ rc = actionPtr->fInterface.fActGetNameFuncPtr(&data_name); if (ESIF_OK != rc) { goto exit; } rc = actionPtr->fInterface.fActGetDescriptionFuncPtr(&data_desc); if (ESIF_OK != rc) { goto exit; } rc = actionPtr->fInterface.fActGetVersionFuncPtr(&data_version); if (ESIF_OK != rc) { goto exit; } rc = actionPtr->fInterface.fActGetIDFuncPtr(&action_type); if (ESIF_OK != rc) { goto exit; } rc = actionPtr->fInterface.fActGetGuidFuncPtr(&data_guid); if (ESIF_OK != rc) { goto exit; } act_type_ptr = "plugin"; ESIF_TRACE_DEBUG("%s\n\n" "Action Name : %s\n" "Action Desc : %s\n" "Action Type : %s\n" "Action Version: %s\n\n", ESIF_FUNC, (EsifString)data_name.buf_ptr, (EsifString)data_desc.buf_ptr, (EsifString)act_type_ptr, (EsifString)data_version.buf_ptr); /* Create The Application */ CMD_OUT("create action\n"); rc = actionPtr->fInterface.fActCreateFuncPtr( &act_service_iface, NULL, &actionPtr->fHandle, eEsifActStateEnabled, &p1, &p2, &p3, &p4, NULL); if (ESIF_OK != rc) { goto exit; } /* Append New Action To Linked List */ action_type_ptr = (EsifActTypePtr)esif_ccb_malloc(sizeof(EsifActType)); if (NULL == action_type_ptr) { ESIF_TRACE_ERROR("Fail to allocate EsifActType\n"); rc = ESIF_E_NO_MEMORY; goto exit; } action_type_ptr->fHandle = actionPtr->fHandle; action_type_ptr->fType = *(UInt8 *)action_type.buf_ptr; esif_ccb_strcpy(action_type_ptr->fName, (EsifString)data_name.buf_ptr, ESIF_NAME_LEN); esif_ccb_strcpy(action_type_ptr->fDesc, (EsifString)data_desc.buf_ptr, ESIF_DESC_LEN); esif_ccb_strcpy(action_type_ptr->fOsType, ESIF_ATTR_OS, ESIF_NAME_LEN); action_type_ptr->fGetFuncPtr = actionPtr->fInterface.fActGetFuncPtr; action_type_ptr->fSetFuncPtr = actionPtr->fInterface.fActSetFuncPtr; esif_ccb_memcpy(action_type_ptr->fGuid, data_guid.buf_ptr, ESIF_GUID_LEN); action_type_ptr->fIsKernel = ESIF_FALSE; action_type_ptr->fIsPlugin = ESIF_TRUE; /* Register Action */ if (NULL != g_actMgr.AddActType) { rc = g_actMgr.AddActType(&g_actMgr, action_type_ptr); } else { ESIF_TRACE_ERROR("Fail to add action type since g_actMrg.AddActType is NULL\n"); esif_ccb_free(action_type_ptr); rc = ESIF_E_NO_CREATE; } exit: return rc; }
void done(const void *context) { CMD_OUT("Context = %p %s\n", context, (char *)context); }
static eEsifError AppCreate( EsifAppPtr appPtr, GetIfaceFuncPtr ifaceFuncPtr ) { eEsifError rc = ESIF_OK; AppDataPtr app_data_ptr = NULL; char path_buf[ESIF_PATH_LEN]; char name[ESIF_NAME_LEN]; ESIF_DATA(data_name, ESIF_DATA_STRING, name, ESIF_NAME_LEN); char desc[ESIF_DESC_LEN]; ESIF_DATA(data_desc, ESIF_DATA_STRING, desc, ESIF_DESC_LEN); char version[ESIF_DESC_LEN]; ESIF_DATA(data_version, ESIF_DATA_STRING, version, ESIF_DESC_LEN); #define BANNER_LEN 1024 char banner[BANNER_LEN]; ESIF_DATA(data_banner, ESIF_DATA_STRING, banner, BANNER_LEN); esif_string app_type_ptr = NULL; EsifInterface app_service_iface; ESIF_ASSERT(appPtr != NULL); ESIF_ASSERT(ifaceFuncPtr != NULL); /* Assign the EsifInterface Functions */ app_service_iface.fIfaceType = eIfaceTypeEsifService; app_service_iface.fIfaceVersion = ESIF_INTERFACE_VERSION; app_service_iface.fIfaceSize = (UInt16)sizeof(EsifInterface); app_service_iface.fGetConfigFuncPtr = EsifSvcConfigGet; app_service_iface.fSetConfigFuncPtr = EsifSvcConfigSet; app_service_iface.fPrimitiveFuncPtr = EsifSvcPrimitiveExec; app_service_iface.fWriteLogFuncPtr = EsifSvcWriteLog; app_service_iface.fRegisterEventFuncPtr = EsifSvcEventRegister; app_service_iface.fUnregisterEventFuncPtr = EsifSvcEventUnregister; /* GetApplicationInterface Handleshake send ESIF receive APP Interface */ rc = ifaceFuncPtr(&appPtr->fInterface); if (ESIF_OK != rc) { goto exit; } /* Check EsifAppInterface */ if (appPtr->fInterface.fIfaceType != eIfaceTypeApplication || appPtr->fInterface.fIfaceSize != (UInt16)sizeof(AppInterface) || appPtr->fInterface.fIfaceVersion != APP_INTERFACE_VERSION || /* Functions Pointers */ appPtr->fInterface.fAppAllocateHandleFuncPtr == NULL || appPtr->fInterface.fAppCreateFuncPtr == NULL || appPtr->fInterface.fAppDestroyFuncPtr == NULL || appPtr->fInterface.fAppCommandFuncPtr == NULL || appPtr->fInterface.fAppEventFuncPtr == NULL || appPtr->fInterface.fAppGetAboutFuncPtr == NULL || appPtr->fInterface.fAppGetBannerFuncPtr == NULL || appPtr->fInterface.fAppGetDescriptionFuncPtr == NULL || appPtr->fInterface.fAppGetGuidFuncPtr == NULL || appPtr->fInterface.fAppGetNameFuncPtr == NULL || appPtr->fInterface.fAppGetStatusFuncPtr == NULL || appPtr->fInterface.fAppGetVersionFuncPtr == NULL || appPtr->fInterface.fParticipantAllocateHandleFuncPtr == NULL || appPtr->fInterface.fParticipantCreateFuncPtr == NULL || appPtr->fInterface.fParticipantDestroyFuncPtr == NULL || appPtr->fInterface.fParticipantSetStateFuncPtr == NULL || appPtr->fInterface.fDomainAllocateHandleFuncPtr == NULL || appPtr->fInterface.fDomainCreateFuncPtr == NULL || appPtr->fInterface.fDomainDestroyFuncPtr == NULL || appPtr->fInterface.fDomainSetStateFuncPtr == NULL || appPtr->fInterface.fAppSetStateFuncPtr == NULL) { rc = ESIF_E_PARAMETER_IS_NULL; goto exit; } /* Callback for application information */ rc = appPtr->fInterface.fAppGetNameFuncPtr(&data_name); if (ESIF_OK != rc) { goto exit; } rc = appPtr->fInterface.fAppGetDescriptionFuncPtr(&data_desc); if (ESIF_OK != rc) { goto exit; } rc = appPtr->fInterface.fAppGetVersionFuncPtr(&data_version); if (ESIF_OK != rc) { goto exit; } app_type_ptr = "plugin"; ESIF_TRACE_DEBUG("\n\n" "Application Name : %s\n" "Application Desc : %s\n" "Application Type : %s\n" "Application Version: %s\n\n", (esif_string)data_name.buf_ptr, (esif_string)data_desc.buf_ptr, (esif_string)app_type_ptr, (esif_string)data_version.buf_ptr); /* Ask for the application handle to be allocated */ rc = appPtr->fInterface.fAppAllocateHandleFuncPtr(&appPtr->fHandle); if (ESIF_OK != rc) { goto exit; } app_data_ptr = CreateAppData(path_buf); if (NULL == app_data_ptr) { rc = ESIF_E_NO_MEMORY; goto exit; } /* Create the application */ rc = appPtr->fInterface.fAppCreateFuncPtr(&app_service_iface, appPtr, appPtr->fHandle, app_data_ptr, eAppStateEnabled); esif_ccb_free(app_data_ptr); if (ESIF_OK != rc) { goto exit; } rc = appPtr->fInterface.fAppGetBannerFuncPtr(appPtr->fHandle, &data_banner); if (ESIF_OK != rc) { goto exit; } CMD_OUT("%s\n", (esif_string)data_banner.buf_ptr); exit: return rc; }
int esif_ws_init(void) { int index=0; int retVal=0; char *ipaddr = (char*)g_ws_ipaddr; char *portPtr = g_ws_port; struct sockaddr_in addrSrvr = {0}; struct sockaddr_in addrClient = {0}; socklen_t len_inet = 0; esif_ccb_socket_t client_socket = INVALID_SOCKET; int option = 1; eEsifError req_results = ESIF_OK; ClientRecordPtr clientPtr = NULL; int selRetVal = 0; int maxfd = 0; int setsize = 0; struct timeval tv={0}; /* Timeout value */ fd_set workingSet = {0}; esif_ccb_mutex_init(&g_web_socket_lock); atomic_inc(&g_ws_threads); atomic_set(&g_ws_quit, 0); CMD_OUT("Starting WebServer %s %s\n", ipaddr, portPtr); esif_ccb_socket_init(); // Allocate pool of Client Records and HTTP input buffer g_clients = (ClientRecordPtr )esif_ccb_malloc(MAX_CLIENTS * sizeof(*g_clients)); g_ws_http_buffer = (char *)esif_ccb_malloc(WS_BUFFER_LENGTH); if (NULL == g_clients || NULL == g_ws_http_buffer) { ESIF_TRACE_DEBUG("Out of memory"); goto exit; } esif_ws_server_initialize_clients(); len_inet = sizeof(addrSrvr); retVal = esif_ws_server_create_inet_addr(&addrSrvr, &len_inet, ipaddr, portPtr, (char*)"top"); if (retVal < 0 && !addrSrvr.sin_port) { ESIF_TRACE_DEBUG("Invalid server address/port number"); goto exit; } g_listen = socket(PF_INET, SOCK_STREAM, 0); if (g_listen == SOCKET_ERROR) { ESIF_TRACE_DEBUG("open socket error"); goto exit; } retVal = setsockopt(g_listen, SOL_SOCKET, SO_REUSEADDR, (char*)&option, sizeof(option)); if (retVal < 0) { esif_ccb_socket_close(g_listen); g_listen = INVALID_SOCKET; ESIF_TRACE_DEBUG("setsockopt failed"); goto exit; } retVal = bind(g_listen, (struct sockaddr*)&addrSrvr, len_inet); if (retVal < -1) { esif_ccb_socket_close(g_listen); g_listen = INVALID_SOCKET; ESIF_TRACE_DEBUG("bind sysem call failed"); goto exit; } retVal = listen(g_listen, MAX_CLIENTS); if (retVal < 0) { ESIF_TRACE_DEBUG("listen system call failed"); goto exit; } /* Accept client requests and new connections until told to quit */ while (!atomic_read(&g_ws_quit)) { /* Build file descriptor set of active sockets */ maxfd = 0; setsize = 0; /* Clear the FD set we will check after each iteration */ FD_ZERO(&workingSet); /* Add our listner to the FD set to check */ if (g_listen != INVALID_SOCKET) { FD_SET((u_int)g_listen, &workingSet); maxfd = (int)g_listen + 1; setsize++; } /* Add our current clients to the FD set to check */ for (index = 0; index < MAX_CLIENTS && setsize < FD_SETSIZE; index++) { if (g_clients[index].socket != INVALID_SOCKET) { FD_SET((u_int)g_clients[index].socket, &workingSet); maxfd = esif_ccb_max(maxfd, (int)g_clients[index].socket + 1); setsize++; } } /* If we have nothing functional in te FD set to check; break */ if (maxfd == 0) { break; } /* * timeout of N + 0.05 secs */ tv.tv_sec = 2; tv.tv_usec = 50000; /* Check our FD set for sockets ready to be accepted (listener) or read (others already accepted) */ selRetVal = select(maxfd, &workingSet, NULL, NULL, &tv); if (selRetVal == SOCKET_ERROR) { break; } else if (!selRetVal) { continue; } /* Accept any new connections on the listening socket */ if (FD_ISSET(g_listen, &workingSet)) { int sockets = (g_listen == INVALID_SOCKET ? 0 : 1); len_inet = sizeof addrClient; client_socket = (int)accept(g_listen, (struct sockaddr*)&addrClient, &len_inet); if (client_socket == SOCKET_ERROR) { ESIF_TRACE_DEBUG("accept(2)"); goto exit; } /* Find the first empty client in our list */ for (index = 0; index < MAX_CLIENTS && sockets < FD_SETSIZE; index++) { if (g_clients[index].socket == INVALID_SOCKET) { esif_ws_client_initialize_client(&g_clients[index]); g_clients[index].socket = client_socket; break; } sockets++; } /* If all clients are in use, close the new client */ if (index >= MAX_CLIENTS || sockets >= FD_SETSIZE) { ESIF_TRACE_DEBUG("Connection Limit Exceeded (%d)", MAX_CLIENTS); esif_ccb_socket_close(client_socket); client_socket = INVALID_SOCKET; continue; } } /* Go through our client list and check if the FD set indicates any have activity */ for (index = 0; index < MAX_CLIENTS; index++) { client_socket = g_clients[index].socket; if (client_socket == INVALID_SOCKET || client_socket == g_listen) { continue; } /* Process client if it is in the set of active file descriptors */ if (FD_ISSET(client_socket, &workingSet)) { ESIF_TRACE_DEBUG("Client %d connected\n", client_socket); /******************** Process the client request ********************/ clientPtr = &g_clients[index]; req_results = esif_ws_client_process_request(clientPtr); if (req_results == ESIF_E_WS_DISC) { ESIF_TRACE_DEBUG("Client %d disconnected\n", client_socket); esif_ws_client_initialize_client(clientPtr); /* reset */ } else if (req_results == ESIF_E_NO_MEMORY) { ESIF_TRACE_DEBUG("Out of memory\n"); esif_ws_client_initialize_client(clientPtr); /* reset */ } /* Clear everything after use */ esif_ws_protocol_initialize(&clientPtr->prot); } } } exit: /* cleanup */ if (g_listen != INVALID_SOCKET) { esif_ccb_socket_close(g_listen); g_listen = INVALID_SOCKET; } if (g_clients) { for (index = 0; index < MAX_CLIENTS; index++) { esif_ws_client_close_client(&g_clients[index]); } esif_ccb_free(g_clients); g_clients = NULL; } esif_ccb_free(g_rest_out); esif_ccb_free(g_ws_http_buffer); g_rest_out = NULL; g_ws_http_buffer = NULL; esif_ccb_socket_exit(); atomic_dec(&g_ws_threads); return 0; }
static eEsifError EsifActMgr_LoadDelayLoadAction( enum esif_action_type type, UInt8 upInstance ) { eEsifError rc = ESIF_OK; struct esif_link_list_node *curNodePtr = NULL; struct esif_link_list_node *nextNodePtr = NULL; EsifActMgrEntryPtr entryPtr = NULL; enum esif_action_type possType = 0; UNREFERENCED_PARAMETER(type); esif_ccb_write_lock(&g_actMgr.mgrLock); /* If the "Possible Actions List" has not been created; create it */ if (NULL == g_actMgr.possibleActions) { rc = EsifActMgr_CreatePossActList_Locked(); if (rc != ESIF_OK) { goto lockExit; } if (NULL == g_actMgr.possibleActions) { rc = ESIF_E_NO_MEMORY; goto lockExit; } } /* Search through the listed actions until we find one that is the type */ nextNodePtr = g_actMgr.possibleActions->head_ptr; while (nextNodePtr) { curNodePtr = nextNodePtr; nextNodePtr = curNodePtr->next_ptr; entryPtr = (EsifActMgrEntryPtr)curNodePtr->data_ptr; ESIF_ASSERT(entryPtr != NULL); /* * Get the type of the possible action, if it fails; remove the entry as there * is no point in ever looking at it again */ rc = EsifActMgr_GetTypeFromPossAct_Locked(entryPtr, &possType); if (rc != ESIF_OK) { esif_link_list_node_remove(g_actMgr.possibleActions, curNodePtr); EsifActMgr_DestroyEntry(entryPtr); continue; } /* * If the library supports the action, load the action and remove the * entry from the possible action list */ if (entryPtr->type == type) { esif_link_list_node_remove(g_actMgr.possibleActions, curNodePtr); esif_ccb_write_unlock(&g_actMgr.mgrLock); rc = EsifActMgr_StartUpe(entryPtr->libName, upInstance); if (rc == ESIF_OK) { CMD_OUT("Started UPE: %s\n", entryPtr->libName); } EsifActMgr_DestroyEntry(entryPtr); goto exit; } } lockExit: esif_ccb_write_unlock(&g_actMgr.mgrLock); exit: return rc; }