123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- #ifndef RVC_MOD_BOOT_MANAGER_H_
- #define RVC_MOD_BOOT_MANAGER_H_
- #include "SpBase.h"
- #include "SpTest.h"
- #include "modVer.h"
- #include <vector>
- #include <memory>
- #define ISSUCCEEDED(hr) ((hr) == Error_Succeed)
- #define FAILURED(hr) (!(ISSUCCEEDED(hr)))
- enum EntityBootType
- {
- IgnoreResult,
- VerifyInAsync,
- VerifyInSync
- };
- enum EntityBootStep
- {
- NotInit,
- CoreBoot,
- SafeLoad,
- IEBrowser,
- Operating
- };
- class BootManager;
- struct EntityBootInfo
- {
- CSimpleStringA entityName;
- EntityBootType bootType;
- ErrorCodeEnum bootResult;
- EntityBootInfo(const char* name, EntityBootType type)
- :entityName(name)
- , bootType(type)
- ,bootResult(Error_NotInit)
- {
- }
- };
- struct BootStep
- {
- CSimpleStringA strSectionName;
- std::vector< EntityBootInfo> entityList;
- BootStep() :strSectionName(true) {}
- BootStep(const char* stepName) :strSectionName(stepName) { }
- virtual ~BootStep() {}
- ErrorCodeEnum LoadConfig(const CSimpleStringA& configPath);
- bool HasEntity() const {
- return(!entityList.empty());
- }
- ErrorCodeEnum StartStartupEntities(BootManager* pTrigger);
- };
- struct CoreBootStep : public BootStep
- {
- CoreBootStep(const CSimpleStringA& sectionPosix)
- :BootStep(CSimpleStringA("CoreBoot.") + sectionPosix)
- { }
- };
- struct SafeLoadStep : public BootStep
- {
- SafeLoadStep(const CSimpleStringA& sectionPosix)
- :BootStep(CSimpleStringA("SafeLoad.") + sectionPosix)
- { }
- };
- struct BrowserShowStep : public BootStep
- {
- BrowserShowStep(const CSimpleStringA& sectionPosix)
- :BootStep(CSimpleStringA("IEBrowser.") + sectionPosix + ".Url")
- { }
- };
- struct OperatingStep : public BootStep
- {
- OperatingStep(const CSimpleStringA& sectionPosix)
- : BootStep(CSimpleStringA("Operating.") + sectionPosix)
- { }
- };
- struct StartEntityBaseContext : public IReleasable
- {
- CEntityBase* theEntity;
- virtual bool IsFinished(ErrorCodeEnum* retrieveResult) const { return true; }
- StartEntityBaseContext(CEntityBase* pEntity) :theEntity(pEntity) {}
- virtual ~StartEntityBaseContext() {}
- ErrorCodeEnum StartEntity(const char* entityName, const char* cmdLine, CSmartPointer<IAsynWaitSp>& spWait)
- {
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = theEntity->GetFunction()
- .ConvertCase<IEntityFunctionPrivilege>();
- ErrorCodeEnum result = pFuncPrivilege->StartEntity(entityName, cmdLine, spWait);
- return result;
- }
- virtual ErrorCodeEnum BootEntity(const EntityBootInfo* entityInfo) { return Error_NotImpl; }
- };
- struct StartEntitySyncContenxt : public StartEntityBaseContext
- {
- using StartEntityBaseContext::StartEntityBaseContext;
- ErrorCodeEnum BootEntity(const EntityBootInfo* entityInfo)
- {
- ErrorCodeEnum result(Error_Succeed);
- CSmartPointer<IAsynWaitSp> spWait;
- result = StartEntity(entityInfo->entityName, nullptr, spWait);
- if (ISSUCCEEDED(result) && spWait != nullptr) {
- result = spWait->WaitAnswer(60 * 1000);
- }
- return result;
- }
- };
- struct StartEntityIgnoreContenxt : public StartEntityBaseContext
- {
- using StartEntityBaseContext::StartEntityBaseContext;
- ErrorCodeEnum BootEntity(const EntityBootInfo* entityInfo)
- {
- CSmartPointer<IAsynWaitSp> spWait;
- StartEntity(entityInfo->entityName, nullptr, spWait);
- if (spWait != nullptr) {
- spWait->WaitAnswer(100);
- }
- return Error_Succeed;
- }
- };
- struct StartEntityOperation;
- struct StartEntityAsyncContenxt : public StartEntityBaseContext, public ICallbackListener
- {
- enum FinishedState
- {
- Pending,
- End
- } theFinishedState;
- StartEntityAsyncContenxt(CEntityBase* pEntity)
- : StartEntityBaseContext(pEntity)
- ,theFinishedState(End)
- ,asyncResult(Error_NotInit){ }
- virtual bool IsFinished(ErrorCodeEnum* retrieveResult) const
- {
- if (retrieveResult) { *retrieveResult = asyncResult; }
- return (theFinishedState == End);
- }
- ErrorCodeEnum BootEntity(const EntityBootInfo* entityInfo)
- {
- LOG_FUNCTION();
- ErrorCodeEnum result(Error_Succeed);
- CSmartPointer<IAsynWaitSp> spWait;
- theFinishedState = Pending;
- result = StartEntity(entityInfo->entityName, nullptr, spWait);
- if (ISSUCCEEDED(result) && spWait != nullptr) {
- spWait->SetCallback(this, nullptr);
- result = Error_Pending;
- } else {
- theFinishedState = End;
- Dbg("return directly: %s", SpStrError(result));
- }
- asyncResult = result;
- return result;
- }
- void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp)
- {
- LOG_FUNCTION();
- asyncResult = pAsynWaitSp->AsyncGetAnswer();
- theFinishedState = End;
- }
- ErrorCodeEnum asyncResult;
- };
- struct StartEntityOperation
- {
- StartEntityOperation(CEntityBase* pEntity, EntityBootInfo& entityInfo)
- :entInfo(entityInfo)
- {
- switch (entityInfo.bootType) {
- case VerifyInAsync:
- theContext = std::make_shared<StartEntityAsyncContenxt>(pEntity);
- break;
- case VerifyInSync:
- theContext = std::make_shared<StartEntitySyncContenxt>(pEntity);
- break;
- default:
- theContext = std::make_shared<StartEntityIgnoreContenxt>(pEntity);
- break;
- }
- }
- bool IsDone() { return theContext->IsFinished(&entInfo.bootResult); }
- ErrorCodeEnum StartEntity()
- {
- ErrorCodeEnum result = theContext->BootEntity(&entInfo);
- entInfo.bootResult = result;
- return result;
- }
- std::shared_ptr< StartEntityBaseContext> theContext;
- EntityBootInfo& entInfo;
- };
- class BootManager : public CEntityBase
- {
- public:
- BootManager()
- {
- }
- ~BootManager()
- {
- }
- const char* GetEntityName() const override
- {
- return "BootManager";
- }
- const char* GetEntityVersion() const override
- {
- return MODULE_VERSION_FULL;
- }
- ON_ENTITYT_TEST()
- void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Init());
- }
- void OnStarted() override;
- ErrorCodeEnum LoadBootConfigInfo();
- ErrorCodeEnum BootStartupEntity();
- void SendEntityBootMessage(const char* entityName);
- void SendEntityBootResultMessage(const char* entityName, ErrorCodeEnum result);
- private:
- void QtUIShow();
- ErrorCodeEnum Init();
- std::shared_ptr<CoreBootStep> mCoreBootSteper;
- std::shared_ptr<SafeLoadStep> mSafeLoadSteper;
- std::shared_ptr<BrowserShowStep> mBrowserShowSteper;
- std::shared_ptr<OperatingStep> mOperatingSteper;
- };
- class BootEntityTask : public ITaskSp
- {
- public:
- BootEntityTask(BootManager* entity) :pEntity(entity) {}
- ~BootEntityTask() {}
- void Process() override
- {
- LOG_FUNCTION();
- ErrorCodeEnum result = pEntity->LoadBootConfigInfo();
- if (ISSUCCEEDED(result)) {
- result = pEntity->BootStartupEntity();
- }
- }
- private:
- BootManager* pEntity;
- };
- #endif //RVC_MOD_BOOT_MANAGER_H_
|