/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "StateMachineMakePtr.h" #include "ILog.h" #include "IStateMachine.h" #include "StateMachineImpl.h" #include "StatusCode.h" #include "state_machine.h" #include #include bool CreateStateMachine(void) { auto instance = std::make_shared(); StatusCode code = StateMachineMakePtr::GetInstance()->CreateStateMachine(instance); if (IsCodeOK(code)) { LogInfo("State machine instance is ok.\n"); IStateMachine::GetInstance(&instance); return true; } return false; } bool DestroyStateMachine(void) { auto instance = std::make_shared(); IStateMachine::GetInstance(&instance); return true; } std::shared_ptr &StateMachineMakePtr::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); if (impl) { instance = *impl; } return instance; } StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr &stateMachine) { // TODO: need a name ? auto tmp = std::make_shared("TODO"); if (tmp) { LogInfo("Create state machine module successfully.\n"); stateMachine = std::move(tmp); return CreateStatusCode(STATUS_CODE_OK); } LogError("Create state machine module failed.\n"); return CreateStatusCode(STATUS_CODE_MAKE_SHARED_PTR_FAILED); } StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr &instance) { auto tmp = std::make_shared(); if (tmp) { instance = std::move(tmp); return CreateStatusCode(STATUS_CODE_OK); } LogError("Create state machine module failed.\n"); return CreateStatusCode(STATUS_CODE_MAKE_SHARED_PTR_FAILED); }