60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
/*
|
|
* 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 "state_machine.h"
|
|
#include <thread>
|
|
bool CreateStateMachine(void)
|
|
{
|
|
auto instance = std::make_shared<IStateMachine>();
|
|
StatusCode code = StateMachineMakePtr::GetInstance()->CreateStateMachine(instance);
|
|
if (IsCodeOK(code)) {
|
|
LogInfo("State machine instance is ok.\n");
|
|
IStateMachine::GetInstance(&instance);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
std::shared_ptr<StateMachineMakePtr> &StateMachineMakePtr::GetInstance(std::shared_ptr<StateMachineMakePtr> *impl)
|
|
{
|
|
static auto instance = std::make_shared<StateMachineMakePtr>();
|
|
if (impl) {
|
|
instance = *impl;
|
|
}
|
|
return instance;
|
|
}
|
|
StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr<VStateMachineHandle> &stateMachine)
|
|
{
|
|
// TODO: need a name ?
|
|
auto tmp = std::make_shared<StateMachine>("TODO");
|
|
if (tmp) {
|
|
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<IStateMachine> &instance)
|
|
{
|
|
auto tmp = std::make_shared<StateMachineImpl>();
|
|
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);
|
|
} |