From 524d4bb8aad042f011ce8f781a1a4e333bbee8dd Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Thu, 17 Jul 2014 20:07:16 +0200 Subject: [PATCH] Add CodeResponse class - a simple response with just a status This class shall be used as an answer for administrative requests: * InsertOrUpdateBucketRequest; * RemoveBucketRequest; * SetPoliciesRequest. Change-Id: I764ff5947a728504227114a1c5297df184a0c4bc --- src/common/CMakeLists.txt | 1 + src/common/response/CodeResponse.cpp | 34 ++++++++++++++++++++++ src/common/response/CodeResponse.h | 54 +++++++++++++++++++++++++++++++++++ src/common/response/ResponseTaker.cpp | 4 +++ src/common/response/ResponseTaker.h | 1 + src/common/response/pointers.h | 3 ++ 6 files changed, 97 insertions(+) create mode 100644 src/common/response/CodeResponse.cpp create mode 100644 src/common/response/CodeResponse.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 39b9e47..d2d5e03 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -38,6 +38,7 @@ SET(COMMON_SOURCES ${COMMON_PATH}/request/SetPoliciesRequest.cpp ${COMMON_PATH}/request/SignalRequest.cpp ${COMMON_PATH}/response/CheckResponse.cpp + ${COMMON_PATH}/response/CodeResponse.cpp ${COMMON_PATH}/response/ResponseTaker.cpp ${COMMON_PATH}/sockets/Socket.cpp ${COMMON_PATH}/sockets/SocketClient.cpp diff --git a/src/common/response/CodeResponse.cpp b/src/common/response/CodeResponse.cpp new file mode 100644 index 0000000..5b6f749 --- /dev/null +++ b/src/common/response/CodeResponse.cpp @@ -0,0 +1,34 @@ +/* + * 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 CodeResponse.cpp + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file implements class for responding to a request with a code + */ + +#include + +#include "CodeResponse.h" + +namespace Cynara { + +void CodeResponse::execute(ResponsePtr self, ResponseTakerPtr taker, + RequestContextPtr context) const { + taker->execute(context, std::dynamic_pointer_cast(self)); +} + +} // namespace Cynara diff --git a/src/common/response/CodeResponse.h b/src/common/response/CodeResponse.h new file mode 100644 index 0000000..ec04e03 --- /dev/null +++ b/src/common/response/CodeResponse.h @@ -0,0 +1,54 @@ +/* + * 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 CodeResponse.h + * @author Lukasz Wojciechowski + * @version 1.0 + * @brief This file defines class for responding to a request with a code + */ + +#ifndef SRC_COMMON_RESPONSE_CODERESPONSE_H_ +#define SRC_COMMON_RESPONSE_CODERESPONSE_H_ + +#include +#include +#include + +namespace Cynara { + +class CodeResponse : public Response { +public: + enum Code { + OK, + NO_BUCKET, + NOT_ALLOWED + }; + + const Code m_code; + + CodeResponse(Code code, ProtocolFrameSequenceNumber sequenceNumber) : + Response(sequenceNumber), m_code(code) { + } + + virtual ~CodeResponse() = default; + + virtual void execute(ResponsePtr self, ResponseTakerPtr taker, + RequestContextPtr context) const; +}; + +} // namespace Cynara + +#endif /* SRC_COMMON_RESPONSE_CODERESPONSE_H_ */ diff --git a/src/common/response/ResponseTaker.cpp b/src/common/response/ResponseTaker.cpp index 4ad200f..759c023 100644 --- a/src/common/response/ResponseTaker.cpp +++ b/src/common/response/ResponseTaker.cpp @@ -32,4 +32,8 @@ void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponsePtr r throw NotImplementedException(); } +void ResponseTaker::execute(RequestContextPtr context UNUSED, CodeResponsePtr response UNUSED) { + throw NotImplementedException(); +} + } // namespace Cynara diff --git a/src/common/response/ResponseTaker.h b/src/common/response/ResponseTaker.h index a54974c..545f60f 100644 --- a/src/common/response/ResponseTaker.h +++ b/src/common/response/ResponseTaker.h @@ -34,6 +34,7 @@ public: virtual ~ResponseTaker() = default; virtual void execute(RequestContextPtr context, CheckResponsePtr response); + virtual void execute(RequestContextPtr context, CodeResponsePtr response); }; } // namespace Cynara diff --git a/src/common/response/pointers.h b/src/common/response/pointers.h index 3d39d2c..16d0a95 100644 --- a/src/common/response/pointers.h +++ b/src/common/response/pointers.h @@ -30,6 +30,9 @@ namespace Cynara { class CheckResponse; typedef std::shared_ptr CheckResponsePtr; +class CodeResponse; +typedef std::shared_ptr CodeResponsePtr; + class Response; typedef std::shared_ptr ResponsePtr; -- 2.7.4