Complete response handling path
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 26 Jun 2014 19:12:31 +0000 (21:12 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:19:10 +0000 (14:19 +0200)
Add Response class - base for all response classes.
Add extractResponseFromBuffer() method to all protocol classes.
Change all response objects references to shared pointers.

Change-Id: I9ac88c8e70ca8084bc2653a0b6aa545320d8de35

18 files changed:
src/common/CMakeLists.txt
src/common/protocol/Protocol.h
src/common/protocol/ProtocolAdmin.cpp
src/common/protocol/ProtocolAdmin.h
src/common/protocol/ProtocolClient.cpp
src/common/protocol/ProtocolClient.h
src/common/protocol/ProtocolSignal.cpp
src/common/protocol/ProtocolSignal.h
src/common/request/Request.h
src/common/request/RequestContext.h
src/common/request/pointers.h
src/common/response/CheckResponse.cpp [new file with mode: 0644]
src/common/response/CheckResponse.h
src/common/response/Response.h [new file with mode: 0644]
src/common/response/ResponseTaker.cpp
src/common/response/ResponseTaker.h
src/common/response/pointers.h
src/service/logic/Logic.cpp

index feac88e..dbc5c3a 100644 (file)
@@ -30,6 +30,7 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/protocol/ProtocolSignal.cpp
     ${COMMON_PATH}/request/CheckRequest.cpp
     ${COMMON_PATH}/request/RequestTaker.cpp
+    ${COMMON_PATH}/response/CheckResponse.cpp
     ${COMMON_PATH}/response/ResponseTaker.cpp
     ${COMMON_PATH}/types/PolicyBucket.cpp
     ${COMMON_PATH}/types/PolicyKey.cpp
index a4e0839..b0f5c53 100644 (file)
@@ -28,6 +28,7 @@
 #include <containers/BinaryQueue.h>
 #include <request/pointers.h>
 #include <request/RequestTaker.h>
+#include <response/pointers.h>
 #include <response/ResponseTaker.h>
 
 namespace Cynara {
@@ -38,6 +39,7 @@ public:
     virtual ~Protocol() = default;
 
     virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
+    virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue) = 0;
 };
 
 typedef std::shared_ptr<Protocol> ProtocolPtr;
index bd29828..0a949f4 100644 (file)
@@ -35,4 +35,10 @@ RequestPtr ProtocolAdmin::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     TODO_USE_ME(bufferQueue);
     return RequestPtr(nullptr);
 }
+
+ResponsePtr ProtocolAdmin::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+    TODO_USE_ME(bufferQueue);
+    return ResponsePtr(nullptr);
+}
+
 } // namespace Cynara
index ce7388a..eb5d644 100644 (file)
@@ -33,6 +33,7 @@ public:
     virtual ~ProtocolAdmin();
 
     virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index fb887dd..4528679 100644 (file)
@@ -36,4 +36,9 @@ RequestPtr ProtocolClient::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     return RequestPtr(nullptr);
 }
 
+ResponsePtr ProtocolClient::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+    TODO_USE_ME(bufferQueue);
+    return ResponsePtr(nullptr);
+}
+
 } // namespace Cynara
index 8eb8052..3f25d22 100644 (file)
@@ -33,6 +33,7 @@ public:
     virtual ~ProtocolClient();
 
     virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index 676d1d1..9a69648 100644 (file)
@@ -36,4 +36,9 @@ RequestPtr ProtocolSignal::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     return RequestPtr(nullptr);
 }
 
+ResponsePtr ProtocolSignal::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+    TODO_USE_ME(bufferQueue);
+    return ResponsePtr(nullptr);
+}
+
 } // namespace Cynara
index bb93af9..a5efdc4 100644 (file)
@@ -33,6 +33,7 @@ public:
     virtual ~ProtocolSignal();
 
     virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index 6e7d6fa..5dc0ac9 100644 (file)
@@ -33,7 +33,8 @@ public:
     Request() = default;
     virtual ~Request() = default;
 
-    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const = 0;
+    virtual void execute(RequestPtr self, RequestTakerPtr taker,
+                         RequestContextPtr context) const = 0;
 };
 
 } // namespace Cynara
index 880583e..dd003c8 100644 (file)
@@ -43,11 +43,10 @@ public:
         : m_desc(desc), m_responseTaker(responseTaker), m_responseQueue(responseQueue) {
     }
 
-    template <class T>
-    void returnResponse(RequestContextPtr self, T &&response) const {
+    void returnResponse(RequestContextPtr self, ResponsePtr response) const {
         ResponseTakerPtr taker = m_responseTaker.lock();
         if (taker)
-            taker->execute(self, std::move(response));
+            response->execute(response, taker, self);
     }
 
     BinaryQueue &responseQueue(void) const {
index 1def987..c492336 100644 (file)
@@ -17,7 +17,7 @@
  * @file        pointers.h
  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
  * @version     1.0
- * @brief       This file defines request base class
+ * @brief       This file defines request classes pointers
  */
 
 #ifndef SRC_COMMON_REQUEST_POINTERS_H_
diff --git a/src/common/response/CheckResponse.cpp b/src/common/response/CheckResponse.cpp
new file mode 100644 (file)
index 0000000..2e72372
--- /dev/null
@@ -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        CheckRequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements check response class
+ */
+
+#include <memory>
+
+#include "CheckResponse.h"
+
+namespace Cynara {
+
+void CheckResponse::execute(ResponsePtr self, ResponseTakerPtr taker,
+                            RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<CheckResponse>(self));
+}
+
+} // namespace Cynara
index 0c0fec2..0cb1182 100644 (file)
 
 #include <types/PolicyResult.h>
 
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <response/Response.h>
+
 namespace Cynara {
 
-struct CheckResponse {
+class CheckResponse : public Response {
+public:
     const PolicyResult &m_resultRef;
 
     CheckResponse(const PolicyResult &result) : m_resultRef(result) {
     }
+
+    virtual ~CheckResponse() = default;
+
+    virtual void execute(ResponsePtr self, ResponseTakerPtr taker,
+                         RequestContextPtr context) const;
 };
 
 } // namespace Cynara
diff --git a/src/common/response/Response.h b/src/common/response/Response.h
new file mode 100644 (file)
index 0000000..31d66bc
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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        Response.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines response base class
+ */
+
+#ifndef SRC_COMMON_RESPONSE_RESPONSE_H_
+#define SRC_COMMON_RESPONSE_RESPONSE_H_
+
+#include <response/pointers.h>
+#include <response/ResponseTaker.h>
+
+namespace Cynara {
+
+class Response {
+public:
+    Response() = default;
+    virtual ~Response() = default;
+
+    virtual void execute(ResponsePtr self, ResponseTakerPtr taker,
+                         RequestContextPtr context) const = 0;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_RESPONSE_RESPONSE_H_ */
index 6e52094..4ad200f 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace Cynara {
 
-void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponse &&response UNUSED) {
+void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponsePtr response UNUSED) {
     throw NotImplementedException();
 }
 
index 8093fab..6100356 100644 (file)
@@ -33,7 +33,7 @@ public:
     ResponseTaker() = default;
     virtual ~ResponseTaker() = default;
 
-    virtual void execute(RequestContextPtr context, CheckResponse &&response);
+    virtual void execute(RequestContextPtr context, CheckResponsePtr response);
 };
 
 } // namespace Cynara
index 3f238d6..3d39d2c 100644 (file)
 
 namespace Cynara {
 
+class CheckResponse;
+typedef std::shared_ptr<CheckResponse> CheckResponsePtr;
+
+class Response;
+typedef std::shared_ptr<Response> ResponsePtr;
+
 class ResponseTaker;
 typedef std::shared_ptr<ResponseTaker> ResponseTakerPtr;
 typedef std::weak_ptr<ResponseTaker> ResponseTakerWeakPtr;
index 9432231..98d7d05 100644 (file)
@@ -42,7 +42,7 @@ Logic::~Logic() {
 void Logic::execute(RequestContextPtr context, CheckRequestPtr request) {
     PolicyResult result(PredefinedPolicyType::DENY);
     if (check(context, request->key(), result)) {
-        context->returnResponse(context, CheckResponse(result));
+        context->returnResponse(context, std::make_shared<CheckResponse>(result));
     }
 }