From 5a42ff8c0301cd13463e42860497912e504ce147 Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Thu, 23 Oct 2014 10:13:55 +0200 Subject: [PATCH] Add AgentTalker class This class will be used as interface for plugin<->agent communication. Change-Id: Id6d6c439d531a8ff7e0b2b96005c12c5a5ab63b7 --- src/service/CMakeLists.txt | 1 + src/service/agent/AgentTalker.cpp | 52 ++++++++++++++++++++++++++++ src/service/agent/AgentTalker.h | 71 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 src/service/agent/AgentTalker.cpp create mode 100644 src/service/agent/AgentTalker.h diff --git a/src/service/CMakeLists.txt b/src/service/CMakeLists.txt index c317d8e..d6fd025 100644 --- a/src/service/CMakeLists.txt +++ b/src/service/CMakeLists.txt @@ -19,6 +19,7 @@ SET(CYNARA_SERVICE_PATH ${CYNARA_PATH}/service) SET(CYNARA_SOURCES + ${CYNARA_SERVICE_PATH}/agent/AgentTalker.cpp ${CYNARA_SERVICE_PATH}/logic/Logic.cpp ${CYNARA_SERVICE_PATH}/main/Cynara.cpp ${CYNARA_SERVICE_PATH}/main/main.cpp diff --git a/src/service/agent/AgentTalker.cpp b/src/service/agent/AgentTalker.cpp new file mode 100644 index 0000000..45f8a50 --- /dev/null +++ b/src/service/agent/AgentTalker.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file src/service/agent/AgentTalker.cpp + * @author Adam Malinowski + * @version 1.0 + * @brief Definition of AgentTalker class + */ + +#include +#include +#include +#include +#include + +#include + +#include "AgentTalker.h" + +namespace Cynara { + +void AgentTalker::sendMessage(const AgentResponseType type, const RawBuffer &data) { + ResponseTakerPtr responseTaker = std::make_shared(); + auto context = std::make_shared(responseTaker, m_linkId); + context->returnResponse(context, + std::make_shared(type, data, m_checkId)); +} + +void AgentTalker::send(const PluginData &agentData) { + RawBuffer data(agentData.begin(), agentData.end()); + sendMessage(CYNARA_MSG_TYPE_ACTION, data); +} + +void AgentTalker::cancel(void) { + RawBuffer data; + sendMessage(CYNARA_MSG_TYPE_CANCEL, data); +} + +} // namespace Cynara diff --git a/src/service/agent/AgentTalker.h b/src/service/agent/AgentTalker.h new file mode 100644 index 0000000..fd45af1 --- /dev/null +++ b/src/service/agent/AgentTalker.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +/** + * @file src/service/agent/AgentTalker.h + * @author Adam Malinowski + * @version 1.0 + * @brief Declaration of AgentTalker class + */ + +#ifndef SRC_SERVICE_AGENT_AGENTTALKER_H_ +#define SRC_SERVICE_AGENT_AGENTTALKER_H_ + +#include + +#include +#include +#include +#include + +#include + +namespace Cynara { + +class AgentTalker { +public: + AgentTalker(const AgentType &agentType, const LinkId &linkId, + const ProtocolFrameSequenceNumber checkId) : m_agentType(agentType), + m_checkId(checkId), m_linkId (linkId) {} + ~AgentTalker() {} + + void send(const PluginData &agentData); + void cancel(void); + + const AgentType &agentType(void) const { + return m_agentType; + } + + const LinkId linkId(void) const { + return m_linkId; + } + + ProtocolFrameSequenceNumber checkId(void) const { + return m_checkId; + } + +private: + const AgentType m_agentType; + const ProtocolFrameSequenceNumber m_checkId; + const LinkId m_linkId; + + void sendMessage(const AgentResponseType type, const RawBuffer &data); +}; + +typedef std::shared_ptr AgentTalkerPtr; + +} // namespace Cynara + +#endif /* SRC_SERVICE_AGENT_AGENTTALKER_H_ */ -- 2.7.4