82 lines
3.2 KiB
C++
82 lines
3.2 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 "DataProcessing.h"
|
|
#include "ILog.h"
|
|
#include "IMissionManager.h"
|
|
#include "IStateMachine.h"
|
|
#include "KeyControl.h"
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
const bool NOT_EXECUTED = false;
|
|
const bool EXECUTED = true;
|
|
key_event_data::key_event_data(const std::string &keyName, const KeyEvent &keyEvent, const unsigned int &holdTime)
|
|
: mKeyName(keyName), mKeyEvent(keyEvent), mHoldTime(holdTime)
|
|
{
|
|
}
|
|
MissionData::MissionData(const std::shared_ptr<VMissionData> &data) : mMissionData(data)
|
|
{
|
|
}
|
|
MissionMessage::MissionMessage(const std::shared_ptr<VMissionData> &message) : mMissionData(message)
|
|
{
|
|
}
|
|
DataProcessing::DataProcessing()
|
|
{
|
|
mEventHandle[InternalStateEvent::KEY_EVENT_HANDLE] = std::bind(&DataProcessing::KeyEventHandle, this, _1);
|
|
}
|
|
bool DataProcessing::EventHandle(VStateMachineData *msg)
|
|
{
|
|
if (nullptr == msg) {
|
|
LogError("nullptr pointer.\n");
|
|
return NOT_EXECUTED;
|
|
}
|
|
std::map<InternalStateEvent, DataProcessingFunc>::iterator iter;
|
|
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
|
InternalStateEvent event = static_cast<InternalStateEvent>(message->mMissionData->mEvent);
|
|
iter = mEventHandle.find(event);
|
|
if (iter != mEventHandle.end()) {
|
|
return mEventHandle[event](msg);
|
|
}
|
|
return NOT_EXECUTED;
|
|
}
|
|
bool DataProcessing::KeyEventHandle(VStateMachineData *msg)
|
|
{
|
|
if (nullptr == msg) {
|
|
LogError("nullptr pointer.\n");
|
|
return NOT_EXECUTED;
|
|
}
|
|
std::map<std::string, KeyHandleFunc>::iterator iter;
|
|
std::shared_ptr<MissionMessage> message = std::dynamic_pointer_cast<MissionMessage>(msg->GetMessageObj());
|
|
std::shared_ptr<VMissionDataV2<KeyEventData>> data =
|
|
std::dynamic_pointer_cast<VMissionDataV2<KeyEventData>>(message->mMissionData);
|
|
if (!data) {
|
|
LogError("nullptr pointer.\n");
|
|
return NOT_EXECUTED;
|
|
}
|
|
iter = mKeyClickHandle.find(data->mData.mKeyName);
|
|
if (iter != mKeyClickHandle.end() && KeyEvent::SHORT_CLICK == data->mData.mKeyEvent) {
|
|
return mKeyClickHandle[data->mData.mKeyName](data->mData);
|
|
}
|
|
iter = mKeyHoldDownHandle.find(data->mData.mKeyName);
|
|
if (iter != mKeyHoldDownHandle.end() && KeyEvent::HOLD_DOWN == data->mData.mKeyEvent) {
|
|
return mKeyHoldDownHandle[data->mData.mKeyName](data->mData);
|
|
}
|
|
iter = mKeyHoldUpHandle.find(data->mData.mKeyName);
|
|
if (iter != mKeyHoldUpHandle.end() && KeyEvent::HOLD_UP == data->mData.mKeyEvent) {
|
|
return mKeyHoldUpHandle[data->mData.mKeyName](data->mData);
|
|
}
|
|
return NOT_EXECUTED;
|
|
} |