Add AgentTalker class 98/29798/8
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Thu, 23 Oct 2014 08:13:55 +0000 (10:13 +0200)
committerAdam Malinowski <a.malinowsk2@partner.samsung.com>
Sat, 15 Nov 2014 01:19:59 +0000 (02:19 +0100)
This class will be used as interface for plugin<->agent communication.

Change-Id: Id6d6c439d531a8ff7e0b2b96005c12c5a5ab63b7

src/service/CMakeLists.txt
src/service/agent/AgentTalker.cpp [new file with mode: 0644]
src/service/agent/AgentTalker.h [new file with mode: 0644]

index c317d8e..d6fd025 100644 (file)
@@ -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 (file)
index 0000000..45f8a50
--- /dev/null
@@ -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 <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
diff --git a/src/service/agent/AgentTalker.h b/src/service/agent/AgentTalker.h
new file mode 100644 (file)
index 0000000..fd45af1
--- /dev/null
@@ -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 <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_ */