static eEsifError GetPrompt( EsifAppMgr *THIS, EsifDataPtr promptPtr ) { enum esif_rc rc = ESIF_OK; EsifAppPtr a_app_ptr = THIS->fSelectedAppPtr; if (NULL == a_app_ptr) { esif_ccb_sprintf(promptPtr->buf_len, (esif_string)promptPtr->buf_ptr, "esif(%u)->", g_dst); } else { ESIF_DATA(data_prompt, ESIF_DATA_STRING, promptPtr->buf_ptr, promptPtr->buf_len); rc = a_app_ptr->fInterface.fAppGetPromptFuncPtr(a_app_ptr->fHandle, &data_prompt); } return rc; }
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; }
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; }
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; } } }
/* Create A Conjure Library */ static eEsifError ConjureCreate( EsifCnjPtr conjurePtr, GetIfaceFuncPtr ifaceFuncPtr ) { eEsifError rc = ESIF_OK; EsifConjureServiceInterface conjure_service_iface; 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); ESIF_ASSERT(conjurePtr != NULL); ESIF_ASSERT(ifaceFuncPtr != NULL); /* Assign the EsifInterface Functions */ conjure_service_iface.fIfaceType = eIfaceTypeConjureService; conjure_service_iface.fIfaceVersion = 1; conjure_service_iface.fIfaceSize = (UInt16)sizeof(EsifConjureServiceInterface); conjure_service_iface.fRegisterParticipantFuncPtr = RegisterParticipant; conjure_service_iface.fUnRegisterParticipantFuncPtr = UnRegisterParticipant; /* GetConjureInterface Handleshake send ESIF receive APP Interface */ rc = ifaceFuncPtr(&conjurePtr->fInterface); if (ESIF_OK != rc) { goto exit; } /* Check EsifAppInterface */ if (conjurePtr->fInterface.fIfaceType != eIfaceTypeConjure || conjurePtr->fInterface.fIfaceSize != (UInt16)sizeof(EsifConjureInterface) || conjurePtr->fInterface.fIfaceVersion != 1 || /* Functions Pointers */ conjurePtr->fInterface.fConjureCreateFuncPtr == NULL || conjurePtr->fInterface.fConjureDestroyFuncPtr == NULL || conjurePtr->fInterface.fConjureGetAboutFuncPtr == NULL || conjurePtr->fInterface.fConjureGetDescriptionFuncPtr == NULL || conjurePtr->fInterface.fConjureGetGuidFuncPtr == NULL || conjurePtr->fInterface.fConjureGetNameFuncPtr == NULL || conjurePtr->fInterface.fConjureGetVersionFuncPtr == NULL) { ESIF_TRACE_ERROR("The required function pointer of EsifConjureInterface is NULL\n"); goto exit; } /* Callback for application information */ rc = conjurePtr->fInterface.fConjureGetNameFuncPtr(&data_name); if (ESIF_OK != rc) { goto exit; } rc = conjurePtr->fInterface.fConjureGetDescriptionFuncPtr(&data_desc); if (ESIF_OK != rc) { goto exit; } rc = conjurePtr->fInterface.fConjureGetVersionFuncPtr(&data_version); if (ESIF_OK != rc) { goto exit; } ESIF_TRACE_DEBUG("%s\n\n" "Conjure Lib Name : %s\n" "Conjure Lib Desc : %s\n" "Conjure Lib Type : %s\n" "Conjure Lib Version: %s\n\n", ESIF_FUNC, (EsifString)data_name.buf_ptr, (EsifString)data_desc.buf_ptr, (EsifString)"plugin", (EsifString)data_version.buf_ptr); /* Create The Conjure */ rc = conjurePtr->fInterface.fConjureCreateFuncPtr( &conjure_service_iface, NULL, &conjurePtr->fHandle); if (ESIF_OK != rc) { goto exit; } exit: ESIF_TRACE_EXIT_INFO(); return ESIF_OK; }