Implement agent<->cynara communication layer 42/28542/14
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 22:12:20 +0000 (23:12 +0100)
Only agent side communication layer was implemented. Also protocol is
not implemented.

Change-Id: Ic11bd0ea92284c98366a7f833f0d339f2784dad0

20 files changed:
src/agent/CMakeLists.txt
src/agent/logic/Logic.cpp
src/agent/logic/Logic.h
src/agent/socket/AgentSocketClient.cpp [new file with mode: 0644]
src/agent/socket/AgentSocketClient.h [new file with mode: 0644]
src/common/CMakeLists.txt
src/common/protocol/ProtocolAgent.cpp
src/common/protocol/ProtocolAgent.h
src/common/request/AgentActionRequest.cpp [new file with mode: 0644]
src/common/request/AgentActionRequest.h [new file with mode: 0644]
src/common/request/AgentRegisterRequest.cpp [new file with mode: 0644]
src/common/request/AgentRegisterRequest.h [new file with mode: 0644]
src/common/request/RequestTaker.cpp
src/common/request/RequestTaker.h
src/common/request/pointers.h
src/common/response/AgentRegisterResponse.cpp [new file with mode: 0644]
src/common/response/AgentRegisterResponse.h [new file with mode: 0644]
src/common/response/ResponseTaker.cpp
src/common/response/ResponseTaker.h
src/common/response/pointers.h

index 1f31692..83d90f6 100644 (file)
@@ -24,6 +24,7 @@ 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
+    ${CYNARA_LIB_CYNARA_AGENT_PATH}/socket/AgentSocketClient.cpp
     )
 
 INCLUDE_DIRECTORIES(
index b8a66d4..d6576fe 100644 (file)
  * @brief       This file contains implementation of Logic class - main libcynara-agent class
  */
 
+#include <memory>
+
 #include <common.h>
+#include <config/PathConfig.h>
+#include <log/log.h>
+#include <protocol/Protocol.h>
+#include <protocol/ProtocolAgent.h>
+#include <request/AgentActionRequest.h>
+#include <request/AgentRegisterRequest.h>
+#include <request/pointers.h>
+#include <request/RequestContext.h>
+#include <response/AgentActionResponse.h>
+#include <response/AgentRegisterResponse.h>
+#include <response/pointers.h>
+#include <types/ProtocolFields.h>
 
 #include <cynara-error.h>
 
 #include "Logic.h"
 
+namespace {
+
+Cynara::ProtocolFrameSequenceNumber generateSequenceNumber(void) {
+    static Cynara::ProtocolFrameSequenceNumber sequenceNumber = 0;
+    return ++sequenceNumber;
+}
+
+} // namespace anonymous
+
 namespace Cynara {
 
-Logic::Logic(const AgentType &agentType) : m_agentType(agentType) {
+Logic::Logic(const AgentType &agentType) : m_agentType(agentType), m_registered(false) {
+    m_agentSocket = std::make_shared<AgentSocketClient>(PathConfig::SocketPath::agent,
+                                                        std::make_shared<ProtocolAgent>());
+    m_responseTakerPtr = std::make_shared<ProtocolAgent>();
+    m_responseBuffer = std::make_shared<BinaryQueue>();
 }
 
-int Logic::getRequest(AgentActionResponsePtr &resultPtr UNUSED) {
-    // TODO: implement
-    return CYNARA_API_SUCCESS;
+int Logic::registerInCynara(void) {
+    ProtocolFrameSequenceNumber sequenceNumber = generateSequenceNumber();
+
+    //Ask cynara service
+    AgentRegisterResponsePtr registerResponsePtr;
+    RequestPtr request = std::make_shared<AgentRegisterRequest>(m_agentType, sequenceNumber);
+    ResponsePtr response = m_agentSocket->askCynaraServer(request);
+    if (!response) {
+        LOGW("Disconnected by cynara server.");
+        return CYNARA_API_SERVICE_NOT_AVAILABLE;
+    }
+
+    registerResponsePtr = std::dynamic_pointer_cast<AgentRegisterResponse>(response);
+    if (!registerResponsePtr) {
+        LOGC("Casting response to AgentRegisterResponse failed.");
+        return CYNARA_API_UNKNOWN_ERROR;
+    }
+    LOGD("registerResponse: answer code [%d]", static_cast<int>(registerResponsePtr->m_code));
+
+    switch (registerResponsePtr->m_code) {
+        case AgentRegisterResponse::DONE:
+            return CYNARA_API_SUCCESS;
+        case AgentRegisterResponse::REJECTED:
+            LOGE("Registering agent of type <%s> has been rejected", m_agentType.c_str());
+            return CYNARA_API_ACCESS_DENIED;
+        default:
+            LOGE("Registering agent of type <%s> has finished with unknown error",
+                 m_agentType.c_str());
+            return CYNARA_API_UNKNOWN_ERROR;
+    }
 }
 
-int Logic::putResponse(const AgentResponseType responseType UNUSED,
-                       const ProtocolFrameSequenceNumber sequenceNumber UNUSED,
-                       const RawBuffer &pluginData UNUSED) {
+int Logic::ensureConnection(void) {
+    switch (m_agentSocket->connect()) {
+        case SS_CONNECTED:
+            return CYNARA_API_SUCCESS;
+        case SS_RECONNECTED:
+            return registerInCynara();
+        case SS_DISCONNECTED:
+            LOGE("Agent socket disconnected.");
+            return CYNARA_API_SERVICE_NOT_AVAILABLE;
+    }
 
-    // TODO: implement
+    return CYNARA_API_UNKNOWN_ERROR;
+}
+
+int Logic::getRequest(AgentActionResponsePtr &resultPtr) {
+    int ret = ensureConnection();
+    if (ret != CYNARA_API_SUCCESS)
+        return ret;
+
+    ResponsePtr responsePtr = m_agentSocket->receiveResponseFromServer();
+    if (!responsePtr) {
+        LOGW("Disconnected by cynara server.");
+        return CYNARA_API_SERVICE_NOT_AVAILABLE;
+    }
+
+    AgentActionResponsePtr actionResponsePtr =
+        std::dynamic_pointer_cast<AgentActionResponse>(responsePtr);
+    if (!actionResponsePtr) {
+        LOGC("Casting request to AgentActionResponse failed.");
+        return CYNARA_API_UNKNOWN_ERROR;
+    }
+    LOGD("agentActionResponse: type: [%" PRIu8 "], data length: [%zu]",
+         actionResponsePtr->type(), actionResponsePtr->data().size());
+
+    resultPtr = actionResponsePtr;
     return CYNARA_API_SUCCESS;
 }
 
+int Logic::putResponse(const AgentResponseType responseType,
+                       const ProtocolFrameSequenceNumber sequenceNumber,
+                       const RawBuffer &pluginData) {
+    if (!m_agentSocket->isConnected()) {
+        LOGE("Agent not connected to cynara service.");
+        return CYNARA_API_SERVICE_NOT_AVAILABLE;
+    }
+
+    RequestPtr requestPtr = std::make_shared<AgentActionRequest>(responseType, pluginData,
+                                                                 sequenceNumber);
+    m_responseBuffer->clear();
+    RequestContextPtr contextPtr = std::make_shared<RequestContext>(ResponseTakerPtr(),
+                                                                    m_responseBuffer);
+    requestPtr->execute(requestPtr, m_responseTakerPtr, contextPtr);
+    return m_agentSocket->sendDataToServer(*m_responseBuffer) ? CYNARA_API_SUCCESS :
+                                                     CYNARA_API_SERVICE_NOT_AVAILABLE;
+}
+
 } // namespace Cynara
index facead7..e8ff3e7 100644 (file)
@@ -26,6 +26,7 @@
 #include <types/Agent.h>
 
 #include <api/ApiInterface.h>
+#include <socket/AgentSocketClient.h>
 
 namespace Cynara {
 
@@ -42,6 +43,13 @@ public:
 
 private:
     AgentType m_agentType;
+    AgentSocketPtr m_agentSocket;
+    bool m_registered;
+    RequestTakerPtr m_responseTakerPtr;
+    BinaryQueuePtr m_responseBuffer;
+
+    int registerInCynara(void);
+    int ensureConnection(void);
 };
 
 } // namespace Cynara
diff --git a/src/agent/socket/AgentSocketClient.cpp b/src/agent/socket/AgentSocketClient.cpp
new file mode 100644 (file)
index 0000000..780c996
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  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/socket/AgentSocket.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains implementation of agent socket client
+ */
+
+#include <memory>
+#include <string>
+
+#include <log/log.h>
+#include <protocol/Protocol.h>
+#include <request/pointers.h>
+#include <request/Request.h>
+#include <request/RequestContext.h>
+#include <response/pointers.h>
+#include <sockets/Socket.h>
+
+#include "AgentSocketClient.h"
+
+namespace Cynara {
+
+AgentSocketClient::AgentSocketClient(const std::string &socketPath, ProtocolPtr protocol)
+        : m_socket(socketPath), m_protocol(protocol) {
+    m_writeQueue = std::make_shared<BinaryQueue>();
+    m_readQueue = std::make_shared<BinaryQueue>();
+}
+
+ResponsePtr AgentSocketClient::askCynaraServer(RequestPtr request) {
+    //pass request to protocol
+    RequestContextPtr context = std::make_shared<RequestContext>(ResponseTakerPtr(), m_writeQueue);
+    request->execute(request, m_protocol, context);
+
+    //send request to cynara
+    if (!sendDataToServer(*m_writeQueue)) {
+        return nullptr;
+    }
+
+    // receive response from cynara
+    return receiveResponseFromServer();
+}
+
+ResponsePtr AgentSocketClient::receiveResponseFromServer(void) {
+    while (true) {
+        if (!m_socket.receiveFromServer(*m_readQueue)) {
+            LOGW("Error receiving data from Cynara. Service not available.");
+            return nullptr;
+        }
+
+        ResponsePtr response = m_protocol->extractResponseFromBuffer(m_readQueue);
+        if (response) {
+            return response;
+        }
+    }
+}
+
+bool AgentSocketClient::sendDataToServer(BinaryQueue &data) {
+    if (m_socket.sendToServer(data) == Socket::SendStatus::CONNECTION_LOST) {
+        LOGW("Error sending data to Cynara. Service not available.");
+        return false;
+    }
+
+    return true;
+}
+
+bool AgentSocketClient::isConnected(void) {
+    return m_socket.isConnected();
+}
+
+AgentSocketState AgentSocketClient::connect(void) {
+    if (isConnected())
+        return SS_CONNECTED;
+
+    if (m_socket.connect() == Socket::ConnectionStatus::CONNECTION_SUCCEEDED) {
+        resetState();
+        return SS_RECONNECTED;
+    }
+
+    return SS_DISCONNECTED;
+}
+
+void AgentSocketClient::resetState(void) {
+    m_readQueue->clear();
+    m_writeQueue->clear();
+}
+
+} // namespace Cynara
diff --git a/src/agent/socket/AgentSocketClient.h b/src/agent/socket/AgentSocketClient.h
new file mode 100644 (file)
index 0000000..ee58c49
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  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/socket/AgentSocketClient.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file contains definition of agent socket client
+ */
+
+#ifndef SRC_AGENT_SOCKET_AGENTSOCKETCLIENT_H_
+#define SRC_AGENT_SOCKET_AGENTSOCKETCLIENT_H_
+
+#include <memory>
+#include <string>
+
+#include <containers/BinaryQueue.h>
+#include <protocol/Protocol.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <sockets/Socket.h>
+
+namespace Cynara {
+
+class AgentSocketClient;
+typedef std::shared_ptr<AgentSocketClient> AgentSocketPtr;
+
+typedef enum {
+    SS_DISCONNECTED,
+    SS_CONNECTED,
+    SS_RECONNECTED,
+} AgentSocketState;
+
+class AgentSocketClient {
+public:
+    AgentSocketClient(const std::string &socketPath, ProtocolPtr protocol);
+    virtual ~AgentSocketClient() {};
+
+    bool isConnected(void);
+    AgentSocketState connect(void);
+
+    ResponsePtr receiveResponseFromServer(void);
+    bool sendDataToServer(BinaryQueue &data);
+    ResponsePtr askCynaraServer(RequestPtr request);
+
+private:
+    Socket m_socket;
+    ProtocolPtr m_protocol;
+    BinaryQueuePtr m_readQueue;
+    BinaryQueuePtr m_writeQueue;
+
+    void resetState(void);
+};
+
+} // namespace Cynara
+
+#endif /* SRC_AGENT_SOCKET_AGENTSOCKETCLIENT_H_ */
index 42f66eb..7f3da76 100644 (file)
@@ -39,6 +39,8 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/protocol/ProtocolSerialization.cpp
     ${COMMON_PATH}/protocol/ProtocolSignal.cpp
     ${COMMON_PATH}/request/AdminCheckRequest.cpp
+    ${COMMON_PATH}/request/AgentActionRequest.cpp
+    ${COMMON_PATH}/request/AgentRegisterRequest.cpp
     ${COMMON_PATH}/request/CancelRequest.cpp
     ${COMMON_PATH}/request/CheckRequest.cpp
     ${COMMON_PATH}/request/InsertOrUpdateBucketRequest.cpp
@@ -47,6 +49,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/request/SetPoliciesRequest.cpp
     ${COMMON_PATH}/request/SignalRequest.cpp
     ${COMMON_PATH}/response/AgentActionResponse.cpp
+    ${COMMON_PATH}/response/AgentRegisterResponse.cpp
     ${COMMON_PATH}/response/CancelResponse.cpp
     ${COMMON_PATH}/response/CheckResponse.cpp
     ${COMMON_PATH}/response/CodeResponse.cpp
index f4d26a1..7d85d31 100644 (file)
@@ -23,6 +23,7 @@
 #include <inttypes.h>
 #include <memory>
 
+#include <attributes/attributes.h>
 #include <exceptions/InvalidProtocolException.h>
 #include <log/log.h>
 #include <protocol/ProtocolFrameSerializer.h>
@@ -81,4 +82,14 @@ ResponsePtr ProtocolAgent::extractResponseFromBuffer(BinaryQueuePtr bufferQueue)
     return nullptr;
 }
 
+void ProtocolAgent::execute(RequestContextPtr context UNUSED,
+                            AgentActionRequestPtr request UNUSED) {
+    //TODO: implement
+}
+
+void ProtocolAgent::execute(RequestContextPtr context UNUSED,
+                            AgentActionResponsePtr request UNUSED) {
+    //TODO: implement
+}
+
 } // namespace Cynara
index 68baf46..92fb788 100644 (file)
@@ -40,6 +40,9 @@ public:
 
     virtual RequestPtr extractRequestFromBuffer(BinaryQueuePtr bufferQueue);
     virtual ResponsePtr extractResponseFromBuffer(BinaryQueuePtr bufferQueue);
+
+    virtual void execute(RequestContextPtr context, AgentActionRequestPtr request);
+    virtual void execute(RequestContextPtr context, AgentActionResponsePtr response);
 };
 
 } // namespace Cynara
diff --git a/src/common/request/AgentActionRequest.cpp b/src/common/request/AgentActionRequest.cpp
new file mode 100644 (file)
index 0000000..1e51313
--- /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/request/AgentActionRequest.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements agent action request class
+ */
+
+#include <memory>
+
+#include <request/RequestTaker.h>
+
+#include "AgentActionRequest.h"
+
+namespace Cynara {
+
+void AgentActionRequest::execute(RequestPtr self, RequestTakerPtr taker,
+                                 RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<AgentActionRequest>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/request/AgentActionRequest.h b/src/common/request/AgentActionRequest.h
new file mode 100644 (file)
index 0000000..f187435
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 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/request/AgentActionRequest.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines agent register request class
+ */
+
+#ifndef SRC_COMMON_REQUEST_AGENTACTIONTREQUEST_H_
+#define SRC_COMMON_REQUEST_AGENTACTIONTREQUEST_H_
+
+#include <types/Agent.h>
+
+#include <containers/RawBuffer.h>
+#include <request/pointers.h>
+#include <request/Request.h>
+
+namespace Cynara {
+
+class AgentActionRequest : public Request {
+public:
+    AgentActionRequest(const AgentRequestType type, const RawBuffer &data,
+                       ProtocolFrameSequenceNumber sequenceNumber) : Request(sequenceNumber),
+                       m_type(type), m_data(data) {
+    }
+
+    virtual ~AgentActionRequest() {};
+
+    const RawBuffer &data(void) const {
+        return m_data;
+    }
+
+    AgentRequestType type(void) const {
+        return m_type;
+    }
+
+    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const;
+
+private:
+    const AgentRequestType m_type;
+    const RawBuffer m_data;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_REQUEST_AGENTACTIONTREQUEST_H_ */
diff --git a/src/common/request/AgentRegisterRequest.cpp b/src/common/request/AgentRegisterRequest.cpp
new file mode 100644 (file)
index 0000000..6488193
--- /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/request/AgentRegisterRequest.cpp
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements agent register request class
+ */
+
+#include <memory>
+
+#include <request/RequestTaker.h>
+
+#include "AgentRegisterRequest.h"
+
+namespace Cynara {
+
+void AgentRegisterRequest::execute(RequestPtr self, RequestTakerPtr taker,
+                                   RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<AgentRegisterRequest>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/request/AgentRegisterRequest.h b/src/common/request/AgentRegisterRequest.h
new file mode 100644 (file)
index 0000000..aa6f61b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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/request/AgentRegisterRequest.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines agent register request class
+ */
+
+#ifndef SRC_COMMON_REQUEST_AGENTREGISTERREQUEST_H_
+#define SRC_COMMON_REQUEST_AGENTREGISTERREQUEST_H_
+
+#include <types/Agent.h>
+
+#include <request/pointers.h>
+#include <request/Request.h>
+
+namespace Cynara {
+
+class AgentRegisterRequest : public Request {
+public:
+    AgentRegisterRequest(const AgentType &agentType, ProtocolFrameSequenceNumber sequenceNumber) :
+        Request(sequenceNumber), m_agentType(agentType) {
+    }
+
+    virtual ~AgentRegisterRequest() {};
+
+    const AgentType &agentType(void) const {
+        return m_agentType;
+    }
+
+    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const;
+
+private:
+    AgentType m_agentType;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_REQUEST_AGENTREGISTERREQUEST_H_ */
index a4d7c2d..f46d428 100644 (file)
@@ -33,6 +33,14 @@ void RequestTaker::execute(RequestContextPtr context UNUSED, AdminCheckRequestPt
     throw NotImplementedException();
 }
 
+void RequestTaker::execute(RequestContextPtr context UNUSED, AgentActionRequestPtr request UNUSED) {
+    throw NotImplementedException();
+}
+
+void RequestTaker::execute(RequestContextPtr context UNUSED, AgentRegisterRequestPtr request UNUSED) {
+    throw NotImplementedException();
+}
+
 void RequestTaker::execute(RequestContextPtr context UNUSED, CancelRequestPtr request UNUSED) {
     throw NotImplementedException();
 }
index 522d8bb..f190e69 100644 (file)
@@ -33,6 +33,8 @@ public:
     virtual ~RequestTaker() {};
 
     virtual void execute(RequestContextPtr context, AdminCheckRequestPtr request);
+    virtual void execute(RequestContextPtr context, AgentActionRequestPtr request);
+    virtual void execute(RequestContextPtr context, AgentRegisterRequestPtr request);
     virtual void execute(RequestContextPtr context, CancelRequestPtr request);
     virtual void execute(RequestContextPtr context, CheckRequestPtr request);
     virtual void execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr request);
index e20a6ad..19429a9 100644 (file)
@@ -33,6 +33,9 @@ typedef std::shared_ptr<AdminCheckRequest> AdminCheckRequestPtr;
 class AgentActionRequest;
 typedef std::shared_ptr<AgentActionRequest> AgentActionRequestPtr;
 
+class AgentRegisterRequest;
+typedef std::shared_ptr<AgentRegisterRequest> AgentRegisterRequestPtr;
+
 class CancelRequest;
 typedef std::shared_ptr<CancelRequest> CancelRequestPtr;
 
diff --git a/src/common/response/AgentRegisterResponse.cpp b/src/common/response/AgentRegisterResponse.cpp
new file mode 100644 (file)
index 0000000..fe15bd3
--- /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/AgentRegisterResponse.cpp
+ * @author      Adam  Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements class for responding to agent register request
+ */
+
+#include <memory>
+
+#include <request/RequestTaker.h>
+
+#include "AgentRegisterResponse.h"
+
+namespace Cynara {
+
+void AgentRegisterResponse::execute(ResponsePtr self, ResponseTakerPtr taker,
+                                    RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<AgentRegisterResponse>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/response/AgentRegisterResponse.h b/src/common/response/AgentRegisterResponse.h
new file mode 100644 (file)
index 0000000..0b8f678
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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/AgentRegisterResponse.h
+ * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines class for responding to agent register request
+ */
+
+#ifndef SRC_COMMON_RESPONSE_AGENTREGISTERRESPONSE_H_
+#define SRC_COMMON_RESPONSE_AGENTREGISTERRESPONSE_H_
+
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <response/Response.h>
+
+namespace Cynara {
+
+class AgentRegisterResponse : public Response {
+public:
+    enum Code {
+        DONE,
+        REJECTED,
+        ERROR
+    };
+
+    const Code m_code;
+
+    AgentRegisterResponse(Code code, ProtocolFrameSequenceNumber sequenceNumber) :
+        Response(sequenceNumber), m_code(code) {
+    }
+
+    virtual ~AgentRegisterResponse() {};
+
+    virtual void execute(ResponsePtr self, ResponseTakerPtr taker, RequestContextPtr context) const;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_RESPONSE_AGENTREGISTERRESPONSE_H_ */
index 34f84f5..cf5ae40 100644 (file)
@@ -32,6 +32,10 @@ void ResponseTaker::execute(RequestContextPtr context UNUSED, AgentActionRespons
     throw NotImplementedException();
 }
 
+void ResponseTaker::execute(RequestContextPtr context UNUSED, AgentRegisterResponsePtr response UNUSED) {
+    throw NotImplementedException();
+}
+
 void ResponseTaker::execute(RequestContextPtr context UNUSED, CancelResponsePtr response UNUSED) {
     throw NotImplementedException();
 }
index 1642072..6256e73 100644 (file)
@@ -34,6 +34,7 @@ public:
     virtual ~ResponseTaker() {};
 
     virtual void execute(RequestContextPtr context, AgentActionResponsePtr response);
+    virtual void execute(RequestContextPtr context, AgentRegisterResponsePtr response);
     virtual void execute(RequestContextPtr context, CancelResponsePtr response);
     virtual void execute(RequestContextPtr context, CheckResponsePtr response);
     virtual void execute(RequestContextPtr context, CodeResponsePtr response);
index 1774a4b..378fed4 100644 (file)
@@ -30,6 +30,9 @@ namespace Cynara {
 class AgentActionResponse;
 typedef std::shared_ptr<AgentActionResponse> AgentActionResponsePtr;
 
+class AgentRegisterResponse;
+typedef std::shared_ptr<AgentRegisterResponse> AgentRegisterResponsePtr;
+
 class CancelResponse;
 typedef std::shared_ptr<CancelResponse> CancelResponsePtr;