This class will be used as interface for plugin<->agent communication.
Change-Id: Id6d6c439d531a8ff7e0b2b96005c12c5a5ab63b7
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
--- /dev/null
+/*
+ * 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 <a.malinowsk2@partner.samsung.com>
+ * @version 1.0
+ * @brief Definition of AgentTalker class
+ */
+
+#include <log/log.h>
+#include <protocol/ProtocolAgent.h>
+#include <request/RequestContext.h>
+#include <response/AgentActionResponse.h>
+#include <response/pointers.h>
+
+#include <cynara-agent.h>
+
+#include "AgentTalker.h"
+
+namespace Cynara {
+
+void AgentTalker::sendMessage(const AgentResponseType type, const RawBuffer &data) {
+ ResponseTakerPtr responseTaker = std::make_shared<ProtocolAgent>();
+ auto context = std::make_shared<RequestContext>(responseTaker, m_linkId);
+ context->returnResponse(context,
+ std::make_shared<AgentActionResponse>(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
--- /dev/null
+/*
+ * 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 <a.malinowsk2@partner.samsung.com>
+ * @version 1.0
+ * @brief Declaration of AgentTalker class
+ */
+
+#ifndef SRC_SERVICE_AGENT_AGENTTALKER_H_
+#define SRC_SERVICE_AGENT_AGENTTALKER_H_
+
+#include <memory>
+
+#include <containers/RawBuffer.h>
+#include <types/Agent.h>
+#include <types/Link.h>
+#include <types/ProtocolFields.h>
+
+#include <cynara-plugin.h>
+
+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<AgentTalker> AgentTalkerPtr;
+
+} // namespace Cynara
+
+#endif /* SRC_SERVICE_AGENT_AGENTTALKER_H_ */