Change Request* to RequestPtr implemented as shared_ptr<Request>
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 20 Jun 2014 17:18:19 +0000 (19:18 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:19:09 +0000 (14:19 +0200)
Handle case when no response is generated during request execution.

Change-Id: I2ffbcd520dcb910bae7ee342ab432fae457ef437

12 files changed:
src/common/exceptions/NoResponseGeneratedException.h [new file with mode: 0644]
src/service/protocol/Protocol.h
src/service/protocol/ProtocolAdmin.cpp
src/service/protocol/ProtocolAdmin.h
src/service/protocol/ProtocolClient.cpp
src/service/protocol/ProtocolClient.h
src/service/protocol/ProtocolSignal.cpp
src/service/protocol/ProtocolSignal.h
src/service/request/Request.h
src/service/sockets/Descriptor.cpp
src/service/sockets/Descriptor.h
src/service/sockets/SocketManager.cpp

diff --git a/src/common/exceptions/NoResponseGeneratedException.h b/src/common/exceptions/NoResponseGeneratedException.h
new file mode 100644 (file)
index 0000000..9709f68
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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        NoResponseGeneratedException.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       Implementation of NoResponseGeneratedException
+ */
+
+#ifndef SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_
+#define SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_
+
+#include "Exception.h"
+
+#include <exception>
+
+namespace Cynara {
+
+class NoResponseGeneratedException : public Exception {
+public:
+    NoResponseGeneratedException() = default;
+    virtual ~NoResponseGeneratedException() = default;
+};
+
+} /* namespace Cynara */
+
+#endif /* SRC_COMMON_EXCEPTIONS_NORESPONSEGENERATEDEXCEPTION_H_ */
index 9efae80c6c0a87771d1a43d72ed0eb2947618eed..282450ce2fc6ad2ba3e27881bbb07d87636be2f4 100644 (file)
@@ -37,7 +37,7 @@ public:
     Protocol();
     virtual ~Protocol();
 
-    virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
+    virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
 
     virtual void appendResponseToBuffer(CheckResponse &&response);
 };
index c130d8c4342f8c8d4c7674ba0a1aaa9e3c3499ad..bd298286bb69478ada9086ec166733b82dd8247c 100644 (file)
@@ -31,8 +31,8 @@ ProtocolAdmin::ProtocolAdmin() {
 ProtocolAdmin::~ProtocolAdmin() {
 }
 
-Request *ProtocolAdmin::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolAdmin::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     TODO_USE_ME(bufferQueue);
-    return nullptr;
+    return RequestPtr(nullptr);
 }
 } // namespace Cynara
index 3ca0769f4b73d86fc4fb87b589733b5d56b34ce0..3fe459def4694efdcd22a538cd75e6c769e75f74 100644 (file)
@@ -32,7 +32,7 @@ public:
     ProtocolAdmin();
     virtual ~ProtocolAdmin();
 
-    virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index 12dd34f27b800395adef61e67e01364a700e55e6..fb887dd63f9499f19e2670140d0462be5b831828 100644 (file)
@@ -31,9 +31,9 @@ ProtocolClient::ProtocolClient() {
 ProtocolClient::~ProtocolClient() {
 }
 
-Request *ProtocolClient::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolClient::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     TODO_USE_ME(bufferQueue);
-    return nullptr;
+    return RequestPtr(nullptr);
 }
 
 } // namespace Cynara
index f4deae376bb2f5fd97f1a5fc174bb39a1c2a18d1..19c5d140df10e6126f307030b4615672b01ed7d2 100644 (file)
@@ -32,7 +32,7 @@ public:
     ProtocolClient();
     virtual ~ProtocolClient();
 
-    virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index e20d13fccdc2d019b705195607d36e38f1244ca5..676d1d1b6742e5ad1b02c3ff39ccd367b21281f4 100644 (file)
@@ -31,9 +31,9 @@ ProtocolSignal::ProtocolSignal() {
 ProtocolSignal::~ProtocolSignal() {
 }
 
-Request *ProtocolSignal::extractRequestFromBuffer(BinaryQueue& bufferQueue) {
+RequestPtr ProtocolSignal::extractRequestFromBuffer(BinaryQueue &bufferQueue) {
     TODO_USE_ME(bufferQueue);
-    return nullptr;
+    return RequestPtr(nullptr);
 }
 
 } // namespace Cynara
index a54005236d2c9f3e990908b9d87e98695a0442c4..c74cf7d227051a25ee0488162df1dd4a3a2fed8e 100644 (file)
@@ -32,7 +32,7 @@ public:
     ProtocolSignal();
     virtual ~ProtocolSignal();
 
-    virtual Request *extractRequestFromBuffer(BinaryQueue &bufferQueue);
+    virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
 };
 
 } // namespace Cynara
index 14c7743bf54afaf6a01a277a96fbae3f3a19d16b..7ab5112919c738332fee333ad2dd7f3a65e0a3cc 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef SRC_SERVICE_REQUEST_REQUEST_H_
 #define SRC_SERVICE_REQUEST_REQUEST_H_
 
+#include <memory>
+
 #include <logic/Logic.h>
 
 namespace Cynara {
@@ -35,6 +37,8 @@ public:
     virtual void execute(Logic *logic, int sourceDesc) = 0;
 };
 
+typedef std::shared_ptr<Request> RequestPtr;
+
 } // namespace Cynara
 
 #endif /* SRC_SERVICE_REQUEST_REQUEST_H_ */
index 2e51ffe485df151d78419c59f350d3d8c112b0b5..661833d967f1106c8bafab7142268848c6d4cd35 100644 (file)
@@ -35,7 +35,7 @@ void Descriptor::pushReadBuffer(const RawBuffer &readbuffer) {
     m_readQueue.appendCopy(readbuffer.data(), readbuffer.size());
 }
 
-Request *Descriptor::extractRequest(void) {
+RequestPtr Descriptor::extractRequest(void) {
     return m_protocol->extractRequestFromBuffer(m_readQueue);
 }
 
index 3df54d655c90785f01be7c6c3b50970adb70b338..69225625e0541fde8bd6b36211bf7890fea73e04 100644 (file)
@@ -77,7 +77,7 @@ public:
     }
 
     void pushReadBuffer(const RawBuffer &readbuffer);
-    Request *extractRequest(void);
+    RequestPtr extractRequest(void);
 
     RawBuffer &prepareWriteBuffer(void);
 
index 1f955c890ab55db857c33044cb2c6f1728650e70..7ce4f088494aa3d67345bacbdc0b5acb5071b595 100644 (file)
@@ -36,6 +36,7 @@
 #include <common.h>
 #include <exceptions/DescriptorNotExistsException.h>
 #include <exceptions/InitException.h>
+#include <exceptions/NoResponseGeneratedException.h>
 #include <exceptions/UnexpectedErrorException.h>
 
 #include <logic/Logic.h>
@@ -215,17 +216,21 @@ bool SocketManager::handleRead(int fd, const RawBuffer &readbuffer) {
     desc.pushReadBuffer(readbuffer);
 
     try {
-        std::unique_ptr<Request> req(nullptr);
+        std::shared_ptr<Request> req(nullptr);
         for (;;) {
-            req.reset(desc.extractRequest());
-            if (req)
+            req = desc.extractRequest();
+            if (!req)
                 break;
 
             LOGD("request extracted");
-            req->execute(Cynara::getLogic(), fd);
+            try {
+                req->execute(Cynara::getLogic(), fd);
 
-            if (desc.hasDataToWrite())
+                if (desc.hasDataToWrite())
                     addWriteSocket(fd);
+            } catch (const NoResponseGeneratedException &ex) {
+                LOGD("no response generated");
+            }
         }
     } catch (const Exception &ex) {
         LOGE("Error handling request <%s>. Closing socket", ex.what());