Add agent library stub implementation 41/28541/13
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Thu, 2 Oct 2014 12:06:45 +0000 (14:06 +0200)
committerAdam Malinowski <a.malinowsk2@partner.samsung.com>
Fri, 14 Nov 2014 19:53:46 +0000 (20:53 +0100)
This patch introduces implementation of agent library. Connection
to cynara service is not yet implemented. Only basic structure of
library is created.

Change-Id: Iff771cbff35c1eb4f0c3842631f2fd65ea322ee8

21 files changed:
CMakeLists.txt
packaging/cynara.spec
packaging/libcynara-agent.manifest [new file with mode: 0644]
pkgconfig/CMakeLists.txt
pkgconfig/cynara-agent/CMakeLists.txt [new file with mode: 0644]
pkgconfig/cynara-agent/cynara-agent.pc.in [new file with mode: 0644]
src/CMakeLists.txt
src/agent/CMakeLists.txt [new file with mode: 0644]
src/agent/api/ApiInterface.h [new file with mode: 0644]
src/agent/api/agent-api.cpp [new file with mode: 0644]
src/agent/logic/Logic.cpp [new file with mode: 0644]
src/agent/logic/Logic.h [new file with mode: 0644]
src/common/CMakeLists.txt
src/common/request/pointers.h
src/common/response/AgentActionResponse.cpp [new file with mode: 0644]
src/common/response/AgentActionResponse.h [new file with mode: 0644]
src/common/response/ResponseTaker.cpp
src/common/response/ResponseTaker.h
src/common/response/pointers.h
src/common/types/Agent.h [new file with mode: 0644]
src/include/CMakeLists.txt

index 1c72d22..dc951bb 100644 (file)
@@ -86,6 +86,7 @@ SET(TARGET_LIB_CYNARA "cynara-client")
 SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async")
 SET(TARGET_LIB_CYNARA_COMMON "cynara-client-commons")
 SET(TARGET_LIB_CYNARA_ADMIN "cynara-admin")
+SET(TARGET_LIB_CYNARA_AGENT "cynara-agent")
 SET(TARGET_CYNARA_COMMON "cynara-commons")
 SET(TARGET_CYNARA_TESTS "cynara-tests")
 SET(TARGET_LIB_CREDS_COMMONS "cynara-creds-commons")
index 8a3e298..88e9209 100644 (file)
@@ -11,14 +11,15 @@ Source1002:    libcynara-client.manifest
 Source1003:    libcynara-client-async.manifest
 Source1004:    libcynara-admin.manifest
 Source1005:    cynara-tests.manifest
-Source1006:    libcynara-client-commons.manifest
-Source1007:    libcynara-commons.manifest
-Source1008:    libcynara-creds-commons.manifest
-Source1009:    libcynara-creds-dbus.manifest
-Source1010:    libcynara-creds-socket.manifest
-Source1011:    libcynara-session.manifest
-Source1012:    libcynara-storage.manifest
-Source1013:    cynara-db-migration.manifest
+Source1006:    libcynara-agent.manifest
+Source1007:    libcynara-client-commons.manifest
+Source1008:    libcynara-commons.manifest
+Source1009:    libcynara-creds-commons.manifest
+Source1010:    libcynara-creds-dbus.manifest
+Source1011:    libcynara-creds-socket.manifest
+Source1012:    libcynara-session.manifest
+Source1013:    libcynara-storage.manifest
+Source1014:    cynara-db-migration.manifest
 Requires:      default-ac-domains
 Requires(pre): pwdutils
 Requires(pre): cynara-db-migration >= %{version}-%{release}
@@ -51,9 +52,8 @@ BuildRequires: pkgconfig(libunwind)
 
 %description
 service, client libraries (libcynara-client, libcynara-client-async, libcynara-admin),
-helper libraries (libcynara-session, libcynara-creds-common, libcynara-creds-dbus,
-libcynara-creds-socket)
-and tests (cynara-tests)
+agent library, helper libraries (libcynara-session, libcynara-creds-common, libcynara-creds-dbus,
+libcynara-creds-socket) and tests (cynara-tests)
 
 #######################################################
 %package -n libcynara-client
@@ -118,6 +118,22 @@ Requires:   libcynara-commons-devel = %{version}-%{release}
 admin client library (devel) for setting, listing and removing policies
 
 #######################################################
+%package -n libcynara-agent
+Summary:    Cynara - agent client library
+Requires:   cynara = %{version}-%{release}
+
+%description -n libcynara-agent
+agent client library for communication with cynara service and plugins
+
+%package -n libcynara-agent-devel
+Summary:    Cynara - agent client library (devel)
+Requires:   libcynara-agent = %{version}-%{release}
+Requires:   libcynara-client-commons-devel = %{version}-%{release}
+
+%description -n libcynara-agent-devel
+agent client library (devel) for communication with cynara service and plugins
+
+#######################################################
 %package -n libcynara-storage
 Summary:    Cynara - storage
 
@@ -252,6 +268,7 @@ cp -a %{SOURCE1010} .
 cp -a %{SOURCE1011} .
 cp -a %{SOURCE1012} .
 cp -a %{SOURCE1013} .
+cp -a %{SOURCE1014} .
 cp -a test/db/db* .
 
 %build
@@ -352,6 +369,10 @@ fi
 
 %postun -n libcynara-admin -p /sbin/ldconfig
 
+%post -n libcynara-agent -p /sbin/ldconfig
+
+%postun -n libcynara-agent -p /sbin/ldconfig
+
 %post -n libcynara-storage -p /sbin/ldconfig
 
 %postun -n libcynara-storage -p /sbin/ldconfig
@@ -380,6 +401,10 @@ fi
 
 %postun -n libcynara-admin-devel -p /sbin/ldconfig
 
+%post -n libcynara-agent-devel -p /sbin/ldconfig
+
+%postun -n libcynara-agent-devel -p /sbin/ldconfig
+
 %post -n libcynara-commons-devel -p /sbin/ldconfig
 
 %postun -n libcynara-commons-devel -p /sbin/ldconfig
@@ -470,6 +495,16 @@ fi
 %{_libdir}/libcynara-admin.so
 %{_libdir}/pkgconfig/cynara-admin.pc
 
+%files -n libcynara-agent
+%manifest libcynara-agent.manifest
+%license LICENSE
+%{_libdir}/libcynara-agent.so.*
+
+%files -n libcynara-agent-devel
+%{_includedir}/cynara/cynara-agent.h
+%{_libdir}/libcynara-agent.so
+%{_libdir}/pkgconfig/cynara-agent.pc
+
 %files -n libcynara-storage
 %manifest libcynara-storage.manifest
 %license LICENSE
diff --git a/packaging/libcynara-agent.manifest b/packaging/libcynara-agent.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
index a93ae55..e37f19a 100644 (file)
@@ -20,6 +20,7 @@
 ADD_SUBDIRECTORY(cynara-client)
 ADD_SUBDIRECTORY(cynara-client-async)
 ADD_SUBDIRECTORY(cynara-admin)
+ADD_SUBDIRECTORY(cynara-agent)
 ADD_SUBDIRECTORY(cynara-creds-commons)
 ADD_SUBDIRECTORY(cynara-creds-dbus)
 ADD_SUBDIRECTORY(cynara-creds-socket)
diff --git a/pkgconfig/cynara-agent/CMakeLists.txt b/pkgconfig/cynara-agent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7782e29
--- /dev/null
@@ -0,0 +1,25 @@
+# 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        pkgconfig/cynara-agent/CMakeLists.txt
+# @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+#
+
+CONFIGURE_FILE(cynara-agent.pc.in cynara-agent.pc @ONLY)
+
+INSTALL(FILES
+    ${CMAKE_BINARY_DIR}/pkgconfig/cynara-agent/cynara-agent.pc
+    DESTINATION
+    ${LIB_INSTALL_DIR}/pkgconfig
+    )
diff --git a/pkgconfig/cynara-agent/cynara-agent.pc.in b/pkgconfig/cynara-agent/cynara-agent.pc.in
new file mode 100644 (file)
index 0000000..363a75c
--- /dev/null
@@ -0,0 +1,11 @@
+prefix=@CMAKE_INSTALL_PREFIX@
+exec_prefix=${prefix}
+libdir=@LIB_INSTALL_DIR@
+includedir=${prefix}/include
+
+Name: cynara-agent
+Description: cynara-agent package
+Version: @CYNARA_VERSION@
+Requires:
+Libs: -L${libdir} -lcynara-agent
+Cflags: -I${includedir}/cynara
index fe4d096..60a8a40 100644 (file)
@@ -49,6 +49,7 @@ ADD_SUBDIRECTORY(client)
 ADD_SUBDIRECTORY(client-async)
 ADD_SUBDIRECTORY(client-common)
 ADD_SUBDIRECTORY(admin)
+ADD_SUBDIRECTORY(agent)
 ADD_SUBDIRECTORY(storage)
 ADD_SUBDIRECTORY(service)
 ADD_SUBDIRECTORY(helpers/creds-commons)
diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt
new file mode 100644 (file)
index 0000000..1f31692
--- /dev/null
@@ -0,0 +1,47 @@
+# 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/agent/CMakeLists.txt
+# @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+#
+
+SET(LIB_CYNARA_AGENT_VERSION_MAJOR 0)
+SET(LIB_CYNARA_AGENT_VERSION ${LIB_CYNARA_AGENT_VERSION_MAJOR}.3.0)
+
+SET(CYNARA_LIB_CYNARA_AGENT_PATH ${CYNARA_PATH}/agent)
+
+SET(LIB_CYNARA_AGENT_SOURCES
+    ${CYNARA_LIB_CYNARA_AGENT_PATH}/api/agent-api.cpp
+    ${CYNARA_LIB_CYNARA_AGENT_PATH}/logic/Logic.cpp
+    )
+
+INCLUDE_DIRECTORIES(
+    ${CYNARA_PATH}/include
+    ${CYNARA_LIB_CYNARA_AGENT_PATH}
+    )
+
+ADD_LIBRARY(${TARGET_LIB_CYNARA_AGENT} SHARED ${LIB_CYNARA_AGENT_SOURCES})
+
+SET_TARGET_PROPERTIES(
+    ${TARGET_LIB_CYNARA_AGENT}
+    PROPERTIES
+        SOVERSION ${LIB_CYNARA_AGENT_VERSION_MAJOR}
+        VERSION ${LIB_CYNARA_AGENT_VERSION}
+    )
+
+TARGET_LINK_LIBRARIES(${TARGET_LIB_CYNARA_AGENT}
+    ${TARGET_CYNARA_COMMON}
+    )
+
+INSTALL(TARGETS ${TARGET_LIB_CYNARA_AGENT} DESTINATION ${LIB_INSTALL_DIR})
diff --git a/src/agent/api/ApiInterface.h b/src/agent/api/ApiInterface.h
new file mode 100644 (file)
index 0000000..93c5245
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *  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/agent/api/ApiInterface.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains libcynara-agent API interface definition.
+ */
+
+#ifndef SRC_AGENT_API_APIINTERFACE_H_
+#define SRC_AGENT_API_APIINTERFACE_H_
+
+#include <containers/RawBuffer.h>
+#include <response/pointers.h>
+#include <types/Agent.h>
+#include <types/ProtocolFields.h>
+
+namespace Cynara {
+
+class ApiInterface {
+public:
+    ApiInterface() = default;
+    virtual ~ApiInterface() {};
+
+    virtual int getRequest(AgentActionResponsePtr &actionResponsePtr) = 0;
+
+    virtual int putResponse(AgentRequestType requestType,
+                            ProtocolFrameSequenceNumber sequenceNumber,
+                            const RawBuffer &pluginData) = 0;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_AGENT_API_APIINTERFACE_H_ */
diff --git a/src/agent/api/agent-api.cpp b/src/agent/api/agent-api.cpp
new file mode 100644 (file)
index 0000000..4baec2d
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ *  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/agent/api/agent-api.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       Implementation of external libcynara-agent API
+ */
+
+#include <cstdlib>
+#include <cstring>
+
+#include <common.h>
+#include <containers/RawBuffer.h>
+#include <exceptions/TryCatch.h>
+#include <log/log.h>
+#include <response/AgentActionResponse.h>
+#include <response/pointers.h>
+#include <types/Agent.h>
+#include <types/ProtocolFields.h>
+
+#include <api/ApiInterface.h>
+#include <cynara-agent.h>
+#include <logic/Logic.h>
+
+struct cynara_agent {
+    Cynara::ApiInterface *impl;
+
+    cynara_agent(Cynara::ApiInterface *_impl) : impl(_impl) {}
+
+    ~cynara_agent() {
+        delete impl;
+    }
+};
+
+CYNARA_API
+int cynara_agent_initialize(cynara_agent **pp_cynara_agent, const char *p_agent_type) {
+    if (!pp_cynara_agent)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        *pp_cynara_agent = new cynara_agent(new Cynara::Logic(p_agent_type));
+
+        init_log();
+
+        LOGD("Cynara agent initialized");
+
+        return CYNARA_API_SUCCESS;
+    });
+}
+
+CYNARA_API
+int cynara_agent_finish(cynara_agent *pp_cynara_agent) {
+    delete pp_cynara_agent;
+
+    return CYNARA_API_SUCCESS;
+}
+
+CYNARA_API
+int cynara_agent_get_request(cynara_agent *p_cynara_agent, cynara_agent_msg_type *req_type,
+                             cynara_agent_req_id *req_id, void **data, size_t *data_size) {
+
+    if (!p_cynara_agent || !p_cynara_agent->impl)
+        return CYNARA_API_INVALID_PARAM;
+    if (!req_type || !req_id)
+        return CYNARA_API_INVALID_PARAM;
+    if (!data || !data_size)
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        Cynara::AgentActionResponsePtr actionResponsePtr;
+        int ret = p_cynara_agent->impl->getRequest(actionResponsePtr);
+        if (ret != CYNARA_API_SUCCESS)
+            return ret;
+
+        size_t dataSize = actionResponsePtr->data().size();
+        if (dataSize > 0) {
+            void *tmpData = malloc(dataSize);
+            if (tmpData == nullptr)
+                return CYNARA_API_OUT_OF_MEMORY;
+
+            *data = tmpData;
+            memcpy(*data, actionResponsePtr->data().data(), dataSize);
+        }
+
+        *data_size = dataSize;
+        *req_type = static_cast<cynara_agent_msg_type>(actionResponsePtr->type());
+        *req_id = actionResponsePtr->sequenceNumber();
+
+        return CYNARA_API_SUCCESS;
+    });
+}
+
+CYNARA_API
+int cynara_agent_put_response(cynara_agent *p_cynara_agent, const cynara_agent_msg_type resp_type,
+                              const cynara_agent_req_id req_id, const void *data,
+                              const size_t data_size) {
+
+    if (!p_cynara_agent || !p_cynara_agent->impl)
+        return CYNARA_API_INVALID_PARAM;
+    if ((resp_type != CYNARA_MSG_TYPE_ACTION) && (resp_type != CYNARA_MSG_TYPE_CANCEL))
+        return CYNARA_API_INVALID_PARAM;
+    if ((!data && data_size) || (data && !data_size))
+        return CYNARA_API_INVALID_PARAM;
+
+    return Cynara::tryCatch([&]() {
+        const char *first = static_cast<const char *>(data);
+        const char *last = first + data_size;
+        Cynara::RawBuffer pluginData(first, last);
+        return p_cynara_agent->impl->putResponse(resp_type, req_id, pluginData);
+    });
+}
diff --git a/src/agent/logic/Logic.cpp b/src/agent/logic/Logic.cpp
new file mode 100644 (file)
index 0000000..b8a66d4
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ *  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/agent/logic/Logic.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains implementation of Logic class - main libcynara-agent class
+ */
+
+#include <common.h>
+
+#include <cynara-error.h>
+
+#include "Logic.h"
+
+namespace Cynara {
+
+Logic::Logic(const AgentType &agentType) : m_agentType(agentType) {
+}
+
+int Logic::getRequest(AgentActionResponsePtr &resultPtr UNUSED) {
+    // TODO: implement
+    return CYNARA_API_SUCCESS;
+}
+
+int Logic::putResponse(const AgentResponseType responseType UNUSED,
+                       const ProtocolFrameSequenceNumber sequenceNumber UNUSED,
+                       const RawBuffer &pluginData UNUSED) {
+
+    // TODO: implement
+    return CYNARA_API_SUCCESS;
+}
+
+} // namespace Cynara
diff --git a/src/agent/logic/Logic.h b/src/agent/logic/Logic.h
new file mode 100644 (file)
index 0000000..facead7
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  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/agent/logic/Logic.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains definition of Logic class - main libcynara-agent class
+ */
+
+#ifndef SRC_AGENT_LOGIC_LOGIC_H_
+#define SRC_AGENT_LOGIC_LOGIC_H_
+
+#include <types/Agent.h>
+
+#include <api/ApiInterface.h>
+
+namespace Cynara {
+
+class Logic : public ApiInterface {
+public:
+    Logic(const AgentType &agentType);
+    virtual ~Logic() {};
+
+    virtual int getRequest(AgentActionResponsePtr &actionResponsePtr);
+
+    virtual int putResponse(const AgentResponseType responseType,
+                            const ProtocolFrameSequenceNumber sequenceNumber,
+                            const RawBuffer &pluginData);
+
+private:
+    AgentType m_agentType;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_AGENT_LOGIC_LOGIC_H_ */
index 72b7d7f..42f66eb 100644 (file)
@@ -46,6 +46,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/request/RequestTaker.cpp
     ${COMMON_PATH}/request/SetPoliciesRequest.cpp
     ${COMMON_PATH}/request/SignalRequest.cpp
+    ${COMMON_PATH}/response/AgentActionResponse.cpp
     ${COMMON_PATH}/response/CancelResponse.cpp
     ${COMMON_PATH}/response/CheckResponse.cpp
     ${COMMON_PATH}/response/CodeResponse.cpp
index 5c90004..e20a6ad 100644 (file)
@@ -30,6 +30,9 @@ namespace Cynara {
 class AdminCheckRequest;
 typedef std::shared_ptr<AdminCheckRequest> AdminCheckRequestPtr;
 
+class AgentActionRequest;
+typedef std::shared_ptr<AgentActionRequest> AgentActionRequestPtr;
+
 class CancelRequest;
 typedef std::shared_ptr<CancelRequest> CancelRequestPtr;
 
diff --git a/src/common/response/AgentActionResponse.cpp b/src/common/response/AgentActionResponse.cpp
new file mode 100644 (file)
index 0000000..4a8bcc8
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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/common/response/AgentActionResponse.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements common class for sending a request to agent
+ */
+
+#include <memory>
+
+#include <response/ResponseTaker.h>
+
+#include "AgentActionResponse.h"
+
+namespace Cynara {
+
+void AgentActionResponse::execute(ResponsePtr self, ResponseTakerPtr taker,
+                                  RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<AgentActionResponse>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/response/AgentActionResponse.h b/src/common/response/AgentActionResponse.h
new file mode 100644 (file)
index 0000000..f99c043
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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/common/response/AgentActionResponse.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines class for responding to agent action request
+ */
+
+#ifndef SRC_COMMON_RESPONSE_AGENTACTIONRESPONSE_H_
+#define SRC_COMMON_RESPONSE_AGENTACTIONRESPONSE_H_
+
+#include <containers/RawBuffer.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <response/Response.h>
+#include <types/Agent.h>
+
+namespace Cynara {
+
+class AgentActionResponse : public Response {
+public:
+    AgentActionResponse(const AgentResponseType type, const RawBuffer &data,
+                        ProtocolFrameSequenceNumber sequenceNumber) : Response(sequenceNumber),
+                        m_type(type), m_data(data) {}
+
+    ~AgentActionResponse() {}
+
+    virtual void execute(ResponsePtr self, ResponseTakerPtr taker, RequestContextPtr context) const;
+
+    const RawBuffer &data(void) const {
+        return m_data;
+    }
+
+    AgentResponseType type(void) const {
+        return m_type;
+    }
+
+private:
+    const AgentResponseType m_type;
+    const RawBuffer m_data;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_RESPONSE_AGENTACTIONRESPONSE_H_ */
index 3f558c4..34f84f5 100644 (file)
 
 namespace Cynara {
 
+void ResponseTaker::execute(RequestContextPtr context UNUSED, AgentActionResponsePtr response UNUSED) {
+    throw NotImplementedException();
+}
+
 void ResponseTaker::execute(RequestContextPtr context UNUSED, CancelResponsePtr response UNUSED) {
     throw NotImplementedException();
 }
index 0afdb65..1642072 100644 (file)
@@ -33,6 +33,7 @@ public:
     ResponseTaker() = default;
     virtual ~ResponseTaker() {};
 
+    virtual void execute(RequestContextPtr context, AgentActionResponsePtr response);
     virtual void execute(RequestContextPtr context, CancelResponsePtr response);
     virtual void execute(RequestContextPtr context, CheckResponsePtr response);
     virtual void execute(RequestContextPtr context, CodeResponsePtr response);
index 4e9b8fc..1774a4b 100644 (file)
@@ -27,6 +27,9 @@
 
 namespace Cynara {
 
+class AgentActionResponse;
+typedef std::shared_ptr<AgentActionResponse> AgentActionResponsePtr;
+
 class CancelResponse;
 typedef std::shared_ptr<CancelResponse> CancelResponsePtr;
 
diff --git a/src/common/types/Agent.h b/src/common/types/Agent.h
new file mode 100644 (file)
index 0000000..7f26af7
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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/common/types/Agent.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines agent related types
+ */
+
+#ifndef SRC_COMMON_TYPES_AGENT_H_
+#define SRC_COMMON_TYPES_AGENT_H_
+
+#include <cstdint>
+#include <string>
+
+namespace Cynara {
+
+typedef std::uint8_t AgentRequestType;
+typedef std::uint8_t AgentResponseType;
+typedef std::string AgentType;
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_TYPES_AGENT_H_ */
index b43bd1f..08f909c 100644 (file)
@@ -19,6 +19,7 @@
 INSTALL(FILES
     ${CYNARA_PATH}/include/cynara-admin.h
     ${CYNARA_PATH}/include/cynara-admin-types.h
+    ${CYNARA_PATH}/include/cynara-agent.h
     ${CYNARA_PATH}/include/cynara-client.h
     ${CYNARA_PATH}/include/cynara-client-async.h
     ${CYNARA_PATH}/include/cynara-client-plugin.h