From fee91a55de39cc66ac4f0b4e9c3936874f1aa3d9 Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Thu, 2 Oct 2014 14:06:45 +0200 Subject: [PATCH] Implement agent<->cynara communication layer Only agent side communication layer was implemented. Also protocol is not implemented. Change-Id: Ic11bd0ea92284c98366a7f833f0d339f2784dad0 --- src/agent/CMakeLists.txt | 1 + src/agent/logic/Logic.cpp | 118 ++++++++++++++++++++++++-- src/agent/logic/Logic.h | 8 ++ src/agent/socket/AgentSocketClient.cpp | 102 ++++++++++++++++++++++ src/agent/socket/AgentSocketClient.h | 69 +++++++++++++++ src/common/CMakeLists.txt | 3 + src/common/protocol/ProtocolAgent.cpp | 11 +++ src/common/protocol/ProtocolAgent.h | 3 + src/common/request/AgentActionRequest.cpp | 36 ++++++++ src/common/request/AgentActionRequest.h | 60 +++++++++++++ src/common/request/AgentRegisterRequest.cpp | 36 ++++++++ src/common/request/AgentRegisterRequest.h | 53 ++++++++++++ src/common/request/RequestTaker.cpp | 8 ++ src/common/request/RequestTaker.h | 2 + src/common/request/pointers.h | 3 + src/common/response/AgentRegisterResponse.cpp | 36 ++++++++ src/common/response/AgentRegisterResponse.h | 53 ++++++++++++ src/common/response/ResponseTaker.cpp | 4 + src/common/response/ResponseTaker.h | 1 + src/common/response/pointers.h | 3 + 20 files changed, 602 insertions(+), 8 deletions(-) create mode 100644 src/agent/socket/AgentSocketClient.cpp create mode 100644 src/agent/socket/AgentSocketClient.h create mode 100644 src/common/request/AgentActionRequest.cpp create mode 100644 src/common/request/AgentActionRequest.h create mode 100644 src/common/request/AgentRegisterRequest.cpp create mode 100644 src/common/request/AgentRegisterRequest.h create mode 100644 src/common/response/AgentRegisterResponse.cpp create mode 100644 src/common/response/AgentRegisterResponse.h diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt index 1f31692..83d90f6 100644 --- a/src/agent/CMakeLists.txt +++ b/src/agent/CMakeLists.txt @@ -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( diff --git a/src/agent/logic/Logic.cpp b/src/agent/logic/Logic.cpp index b8a66d4..d6576fe 100644 --- a/src/agent/logic/Logic.cpp +++ b/src/agent/logic/Logic.cpp @@ -20,28 +20,130 @@ * @brief This file contains implementation of Logic class - main libcynara-agent class */ +#include + #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #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(PathConfig::SocketPath::agent, + std::make_shared()); + m_responseTakerPtr = std::make_shared(); + m_responseBuffer = std::make_shared(); } -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(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(response); + if (!registerResponsePtr) { + LOGC("Casting response to AgentRegisterResponse failed."); + return CYNARA_API_UNKNOWN_ERROR; + } + LOGD("registerResponse: answer code [%d]", static_cast(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(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(responseType, pluginData, + sequenceNumber); + m_responseBuffer->clear(); + RequestContextPtr contextPtr = std::make_shared(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 diff --git a/src/agent/logic/Logic.h b/src/agent/logic/Logic.h index facead7..e8ff3e7 100644 --- a/src/agent/logic/Logic.h +++ b/src/agent/logic/Logic.h @@ -26,6 +26,7 @@ #include #include +#include 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 index 0000000..780c996 --- /dev/null +++ b/src/agent/socket/AgentSocketClient.cpp @@ -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 + * @version 1.0 + * @brief This file contains implementation of agent socket client + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "AgentSocketClient.h" + +namespace Cynara { + +AgentSocketClient::AgentSocketClient(const std::string &socketPath, ProtocolPtr protocol) + : m_socket(socketPath), m_protocol(protocol) { + m_writeQueue = std::make_shared(); + m_readQueue = std::make_shared(); +} + +ResponsePtr AgentSocketClient::askCynaraServer(RequestPtr request) { + //pass request to protocol + RequestContextPtr context = std::make_shared(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 index 0000000..ee58c49 --- /dev/null +++ b/src/agent/socket/AgentSocketClient.h @@ -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 + * @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 +#include + +#include +#include +#include +#include +#include + +namespace Cynara { + +class AgentSocketClient; +typedef std::shared_ptr 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_ */ diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 42f66eb..7f3da76 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 diff --git a/src/common/protocol/ProtocolAgent.cpp b/src/common/protocol/ProtocolAgent.cpp index f4d26a1..7d85d31 100644 --- a/src/common/protocol/ProtocolAgent.cpp +++ b/src/common/protocol/ProtocolAgent.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/src/common/protocol/ProtocolAgent.h b/src/common/protocol/ProtocolAgent.h index 68baf46..92fb788 100644 --- a/src/common/protocol/ProtocolAgent.h +++ b/src/common/protocol/ProtocolAgent.h @@ -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 index 0000000..1e51313 --- /dev/null +++ b/src/common/request/AgentActionRequest.cpp @@ -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 + * @version 1.0 + * @brief This file implements agent action request class + */ + +#include + +#include + +#include "AgentActionRequest.h" + +namespace Cynara { + +void AgentActionRequest::execute(RequestPtr self, RequestTakerPtr taker, + RequestContextPtr context) const { + taker->execute(context, std::dynamic_pointer_cast(self)); +} + +} // namespace Cynara diff --git a/src/common/request/AgentActionRequest.h b/src/common/request/AgentActionRequest.h new file mode 100644 index 0000000..f187435 --- /dev/null +++ b/src/common/request/AgentActionRequest.h @@ -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 + * @version 1.0 + * @brief This file defines agent register request class + */ + +#ifndef SRC_COMMON_REQUEST_AGENTACTIONTREQUEST_H_ +#define SRC_COMMON_REQUEST_AGENTACTIONTREQUEST_H_ + +#include + +#include +#include +#include + +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 index 0000000..6488193 --- /dev/null +++ b/src/common/request/AgentRegisterRequest.cpp @@ -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 + * @version 1.0 + * @brief This file implements agent register request class + */ + +#include + +#include + +#include "AgentRegisterRequest.h" + +namespace Cynara { + +void AgentRegisterRequest::execute(RequestPtr self, RequestTakerPtr taker, + RequestContextPtr context) const { + taker->execute(context, std::dynamic_pointer_cast(self)); +} + +} // namespace Cynara diff --git a/src/common/request/AgentRegisterRequest.h b/src/common/request/AgentRegisterRequest.h new file mode 100644 index 0000000..aa6f61b --- /dev/null +++ b/src/common/request/AgentRegisterRequest.h @@ -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 + * @version 1.0 + * @brief This file defines agent register request class + */ + +#ifndef SRC_COMMON_REQUEST_AGENTREGISTERREQUEST_H_ +#define SRC_COMMON_REQUEST_AGENTREGISTERREQUEST_H_ + +#include + +#include +#include + +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_ */ diff --git a/src/common/request/RequestTaker.cpp b/src/common/request/RequestTaker.cpp index a4d7c2d..f46d428 100644 --- a/src/common/request/RequestTaker.cpp +++ b/src/common/request/RequestTaker.cpp @@ -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(); } diff --git a/src/common/request/RequestTaker.h b/src/common/request/RequestTaker.h index 522d8bb..f190e69 100644 --- a/src/common/request/RequestTaker.h +++ b/src/common/request/RequestTaker.h @@ -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); diff --git a/src/common/request/pointers.h b/src/common/request/pointers.h index e20a6ad..19429a9 100644 --- a/src/common/request/pointers.h +++ b/src/common/request/pointers.h @@ -33,6 +33,9 @@ typedef std::shared_ptr AdminCheckRequestPtr; class AgentActionRequest; typedef std::shared_ptr AgentActionRequestPtr; +class AgentRegisterRequest; +typedef std::shared_ptr AgentRegisterRequestPtr; + class CancelRequest; typedef std::shared_ptr CancelRequestPtr; diff --git a/src/common/response/AgentRegisterResponse.cpp b/src/common/response/AgentRegisterResponse.cpp new file mode 100644 index 0000000..fe15bd3 --- /dev/null +++ b/src/common/response/AgentRegisterResponse.cpp @@ -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 + * @version 1.0 + * @brief This file implements class for responding to agent register request + */ + +#include + +#include + +#include "AgentRegisterResponse.h" + +namespace Cynara { + +void AgentRegisterResponse::execute(ResponsePtr self, ResponseTakerPtr taker, + RequestContextPtr context) const { + taker->execute(context, std::dynamic_pointer_cast(self)); +} + +} // namespace Cynara diff --git a/src/common/response/AgentRegisterResponse.h b/src/common/response/AgentRegisterResponse.h new file mode 100644 index 0000000..0b8f678 --- /dev/null +++ b/src/common/response/AgentRegisterResponse.h @@ -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 + * @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 +#include +#include + +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_ */ diff --git a/src/common/response/ResponseTaker.cpp b/src/common/response/ResponseTaker.cpp index 34f84f5..cf5ae40 100644 --- a/src/common/response/ResponseTaker.cpp +++ b/src/common/response/ResponseTaker.cpp @@ -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(); } diff --git a/src/common/response/ResponseTaker.h b/src/common/response/ResponseTaker.h index 1642072..6256e73 100644 --- a/src/common/response/ResponseTaker.h +++ b/src/common/response/ResponseTaker.h @@ -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); diff --git a/src/common/response/pointers.h b/src/common/response/pointers.h index 1774a4b..378fed4 100644 --- a/src/common/response/pointers.h +++ b/src/common/response/pointers.h @@ -30,6 +30,9 @@ namespace Cynara { class AgentActionResponse; typedef std::shared_ptr AgentActionResponsePtr; +class AgentRegisterResponse; +typedef std::shared_ptr AgentRegisterResponsePtr; + class CancelResponse; typedef std::shared_ptr CancelResponsePtr; -- 2.7.4