--- /dev/null
+/*
+ * 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 SocketClient.cpp
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains implementation of cynara's socket client
+ */
+
+#include <memory>
+#include <string>
+
+#include <log/log.h>
+#include <protocol/Protocol.h>
+#include <protocol/ProtocolClient.h>
+#include <request/pointers.h>
+#include <request/Request.h>
+#include <request/RequestContext.h>
+#include <response/pointers.h>
+
+#include <sockets/Socket.h>
+
+#include "SocketClient.h"
+
+namespace Cynara {
+
+const std::string clientSocketPath("/run/cynara/cynara.socket");
+
+SocketClient::SocketClient() : m_socket(clientSocketPath),
+ m_protocol(std::make_shared<ProtocolClient>()) {
+}
+
+ResponsePtr SocketClient::askCynaraServer(RequestPtr request) {
+ //pass request to protocol
+ RequestContextPtr context = std::make_shared<RequestContext>(-1, ResponseTakerPtr(),
+ m_writeQueue);
+ request->execute(request, m_protocol, context);
+
+ //send request to cynara
+ if (!m_socket.sendToServer(m_writeQueue)) {
+ LOGW("Error sending request to Cynara. Service not available.");
+ return nullptr;
+ }
+
+ // receive response from cynara
+ while (true) {
+ if (!m_socket.receiveFromServer(m_readQueue)) {
+ LOGW("Error receiving response from Cynara. Service not available.");
+ return nullptr;
+ }
+ ResponsePtr response = m_protocol->extractResponseFromBuffer(m_readQueue);
+ if (response) {
+ return response;
+ }
+ }
+}
+
+} // namespace Cynara
--- /dev/null
+/*
+ * 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 SocketClient.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains definition of cynara's socket client
+ */
+
+#ifndef SRC_CLIENT_SOCKETS_SOCKETCLIENT_H_
+#define SRC_CLIENT_SOCKETS_SOCKETCLIENT_H_
+
+#include <memory>
+
+#include <common.h>
+#include <protocol/Protocol.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <response/ResponseTaker.h>
+
+#include <sockets/Socket.h>
+
+namespace Cynara {
+
+class SocketClient;
+typedef std::shared_ptr<SocketClient> SocketClientPtr;
+
+class SocketClient {
+private:
+ Socket m_socket;
+ ProtocolPtr m_protocol;
+ BinaryQueue m_readQueue;
+ BinaryQueue m_writeQueue;
+
+public:
+ SocketClient();
+ virtual ~SocketClient() = default;
+
+ //returns pointer to response
+ // or nullptr when connection to cynara service is lost
+ ResponsePtr askCynaraServer(RequestPtr request);
+};
+
+} // namespace Cynara
+
+#endif /* SRC_CLIENT_SOCKETS_SOCKETCLIENT_H_ */