Change Protocol* to ProtocolPtr implemented with shared_ptr
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 20 Jun 2014 16:57:19 +0000 (18:57 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:19:09 +0000 (14:19 +0200)
Change-Id: Ic1b6e7dd50ddf011e8700fa65fdb05560df3f32a

src/service/protocol/Protocol.h
src/service/request/RequestContext.cpp
src/service/request/RequestContext.h
src/service/sockets/Descriptor.cpp
src/service/sockets/Descriptor.h
src/service/sockets/SocketManager.cpp
src/service/sockets/SocketManager.h

index 7dac7fe..9efae80 100644 (file)
 #ifndef SRC_SERVICE_PROTOCOL_PROTOCOL_H_
 #define SRC_SERVICE_PROTOCOL_PROTOCOL_H_
 
+#include <memory>
+
 #include <common.h>
+
 #include <request/Request.h>
 #include <response/CheckResponse.h>
 
@@ -39,6 +42,8 @@ public:
     virtual void appendResponseToBuffer(CheckResponse &&response);
 };
 
+typedef std::shared_ptr<Protocol> ProtocolPtr;
+
 } // namespace Cynara
 
 #endif /* SRC_SERVICE_PROTOCOL_PROTOCOL_H_ */
index 8671f02..fdadea4 100644 (file)
@@ -31,7 +31,7 @@ BinaryQueue &RequestContext::resultQueue(int fd) {
     return Cynara::getSocketManager()->descriptor(fd).writeQueue();
 }
 
-Protocol *RequestContext::protocol(int fd) {
+ProtocolPtr RequestContext::protocol(int fd) {
     return Cynara::getSocketManager()->descriptor(fd).protocol();
 }
 
index 1d98a33..d026e48 100644 (file)
 
 namespace Cynara {
 
-class Protocol;
-
 class RequestContext {
 
 public:
     static BinaryQueue &resultQueue(int fd);
-    static Protocol *protocol(int fd);
+    static ProtocolPtr protocol(int fd);
 };
 
 } // namespace Cynara
index cc368bf..2e51ffe 100644 (file)
@@ -55,7 +55,7 @@ void Descriptor::clear(void) {
     m_readQueue.clear();
     m_writeQueue.clear();
     m_writeBuffer.clear();
-    m_protocol = nullptr;
+    m_protocol.reset();
 }
 
 } // namespace Cynara
index debb521..3df54d6 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef SRC_SERVICE_SOCKETS_DESCRIPTOR_H_
 #define SRC_SERVICE_SOCKETS_DESCRIPTOR_H_
 
+#include <memory>
+
 #include <common.h>
 
 #include <protocol/Protocol.h>
@@ -39,7 +41,7 @@ private:
     BinaryQueue m_writeQueue;
     RawBuffer m_writeBuffer;
 
-    Protocol *m_protocol;
+    ProtocolPtr m_protocol;
 
 public:
     Descriptor();
@@ -54,7 +56,7 @@ public:
 
     bool hasDataToWrite(void) const;
 
-    Protocol *protocol(void) {
+    ProtocolPtr protocol(void) {
         return m_protocol;
     }
 
@@ -62,7 +64,7 @@ public:
         return m_writeQueue;
     }
 
-    void setProtocol(Protocol *protocol) {
+    void setProtocol(ProtocolPtr protocol) {
         m_protocol = protocol;
     }
 
index 0a2a5be..1f955c8 100644 (file)
@@ -69,8 +69,8 @@ void SocketManager::init(void) {
     const mode_t clientSocketUMask(0);
     const mode_t adminSocketUMask(0077);
 
-    createDomainSocket(new ProtocolClient, clientSocketPath, clientSocketUMask);
-    createDomainSocket(new ProtocolAdmin, adminSocketPath, adminSocketUMask);
+    createDomainSocket(ProtocolPtr(new ProtocolClient), clientSocketPath, clientSocketUMask);
+    createDomainSocket(ProtocolPtr(new ProtocolAdmin), adminSocketPath, adminSocketUMask);
     // todo create signal descriptor
     LOGI("SocketManger init done");
 }
@@ -235,7 +235,7 @@ bool SocketManager::handleRead(int fd, const RawBuffer &readbuffer) {
     return true;
 }
 
-void SocketManager::createDomainSocket(Protocol *protocol, const std::string &path, mode_t mask) {
+void SocketManager::createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask) {
     int fd = getSocketFromSystemD(path);
     if (fd == -1)
         fd = createDomainSocketHelp(path, mask);
index 8478a44..3c784bc 100644 (file)
@@ -24,6 +24,7 @@
 #define SRC_SERVICE_SOCKETS_SOCKETMANAGER_H_
 
 #include <vector>
+#include <memory>
 #include <stdio.h>
 
 #include <common.h>
@@ -63,7 +64,7 @@ private:
     void closeSocket(int fd);
     bool handleRead(int fd, const RawBuffer &readbuffer);
 
-    void createDomainSocket(Protocol *protocol, const std::string &path, mode_t mask);
+    void createDomainSocket(ProtocolPtr protocol, const std::string &path, mode_t mask);
     int createDomainSocketHelp(const std::string &path, mode_t mask);
     int getSocketFromSystemD(const std::string &path);