Make SocketClient independent of specific protocol and path
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Wed, 2 Jul 2014 07:28:35 +0000 (09:28 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Thu, 3 Jul 2014 12:19:11 +0000 (14:19 +0200)
Add protocol and socket path to SocketClient constructor.
Pass path to client socket and ProtocolClient object to
SocketClient in libcynara-client Logic class.

Change-Id: I45e991b8309616876248289558265e5df915012d

src/client/logic/Logic.cpp
src/client/sockets/SocketClient.cpp
src/client/sockets/SocketClient.h

index 4a46c33..6b04973 100644 (file)
@@ -26,6 +26,8 @@
 #include <exceptions/ServerConnectionErrorException.h>
 #include <exceptions/UnexpectedErrorException.h>
 #include <log/log.h>
+#include <protocol/Protocol.h>
+#include <protocol/ProtocolClient.h>
 #include <request/CheckRequest.h>
 #include <request/pointers.h>
 #include <response/CheckResponse.h>
 
 namespace Cynara {
 
+const std::string clientSocketPath("/run/cynara/cynara.socket");
+
 Logic::Logic() {
-    m_socketClient = std::make_shared<SocketClient>();
+    m_socketClient = std::make_shared<SocketClient>(clientSocketPath,
+                                                    std::make_shared<ProtocolClient>());
 }
 
 cynara_api_result Logic::check(const std::string &client, const std::string &session UNUSED,
index 9bab9b1..90f89de 100644 (file)
@@ -25,7 +25,6 @@
 
 #include <log/log.h>
 #include <protocol/Protocol.h>
-#include <protocol/ProtocolClient.h>
 #include <request/pointers.h>
 #include <request/Request.h>
 #include <request/RequestContext.h>
 
 namespace Cynara {
 
-const std::string clientSocketPath("/run/cynara/cynara.socket");
-
-SocketClient::SocketClient() : m_socket(clientSocketPath),
-    m_protocol(std::make_shared<ProtocolClient>()) {
+SocketClient::SocketClient(const std::string &socketPath, ProtocolPtr protocol)
+        : m_socket(socketPath), m_protocol(protocol) {
 }
 
 ResponsePtr SocketClient::askCynaraServer(RequestPtr request) {
index f0af703..d3e16a1 100644 (file)
@@ -46,7 +46,7 @@ private:
     BinaryQueue m_writeQueue;
 
 public:
-    SocketClient();
+    SocketClient(const std::string &socketPath, ProtocolPtr protocol);
     virtual ~SocketClient() = default;
 
     //returns pointer to response