From: Sangwan Kwon Date: Mon, 6 Jan 2020 05:24:43 +0000 (+0900) Subject: Make Client to abstract class X-Git-Tag: submit/tizen/20200810.073515~110 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e3d3c34c5fc393352c7fb35ca4f45c1340e3daf;p=platform%2Fcore%2Fsecurity%2Fvist.git Make Client to abstract class Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/rmi/gateway.cpp b/src/vist/rmi/gateway.cpp index 1d8bc44..72768c7 100644 --- a/src/vist/rmi/gateway.cpp +++ b/src/vist/rmi/gateway.cpp @@ -21,6 +21,7 @@ #include #include +#include #include namespace vist { @@ -63,7 +64,7 @@ public: } private: - std::unique_ptr server; + std::unique_ptr server; }; Gateway::Gateway(const std::string& path) : pImpl(std::make_unique(*this, path)) diff --git a/src/vist/rmi/impl/client.hpp b/src/vist/rmi/impl/client.hpp index c9186e8..d673c64 100644 --- a/src/vist/rmi/impl/client.hpp +++ b/src/vist/rmi/impl/client.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2019-present 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. @@ -16,39 +16,28 @@ #pragma once -#include "protocol.hpp" - -#include -#include +#include namespace vist { namespace rmi { namespace impl { - -using boost::asio::local::stream_protocol; +namespace interface { class Client { public: - Client(const std::string& path) : socket(this->context) - { - try { - this->socket.connect(Protocol::Endpoint(path)); - } catch(const std::exception& e) { - ERROR(VIST) << "Failed to connect socket: " << e.what(); - std::rethrow_exception(std::current_exception()); - } - } - - inline Message request(Message& message) - { - return Protocol::Request(this->socket, message); - } - -private: - Protocol::Context context; - Protocol::Socket socket; + Client(const std::string&) {} + virtual ~Client() = default; + + Client(const Client&) = delete; + Client& operator=(const Client&) = delete; + + Client(Client&&) = default; + Client& operator=(Client&&) = default; + + virtual Message request(Message& message) = 0; }; +} // namespace interface } // namespace impl } // namespace rmi } // namespace vist diff --git a/src/vist/rmi/impl/general/client.hpp b/src/vist/rmi/impl/general/client.hpp index 920ca86..1ef64c2 100644 --- a/src/vist/rmi/impl/general/client.hpp +++ b/src/vist/rmi/impl/general/client.hpp @@ -16,7 +16,8 @@ #pragma once -#include "protocol.hpp" +#include +#include #include #include @@ -28,9 +29,9 @@ namespace general { using boost::asio::local::stream_protocol; -class Client { +class Client : public interface::Client { public: - Client(const std::string& path) : socket(this->context) + Client(const std::string& path) : interface::Client(path), socket(this->context) { try { this->socket.connect(Protocol::Endpoint(path)); @@ -40,7 +41,7 @@ public: } } - inline Message request(Message& message) + Message request(Message& message) override { return Protocol::Request(this->socket, message); } diff --git a/src/vist/rmi/impl/general/protocol.cpp b/src/vist/rmi/impl/general/protocol.cpp index c80394e..2a9d25e 100644 --- a/src/vist/rmi/impl/general/protocol.cpp +++ b/src/vist/rmi/impl/general/protocol.cpp @@ -65,7 +65,7 @@ Message Protocol::Request(Socket& socket, Message& message) return Protocol::Recv(socket); } -void Protocol::Async::dispatch(const Task& task) +void Protocol::Async::dispatch(const interface::Task& task) { auto self = shared_from_this(); const auto& header = boost::asio::buffer(&this->message.header, @@ -99,7 +99,7 @@ void Protocol::Async::dispatch(const Task& task) boost::asio::async_read(self->socket, header, handler); } -void Protocol::Async::process(const Task& task) +void Protocol::Async::process(const interface::Task& task) { bool raised = false; std::string errMsg; diff --git a/src/vist/rmi/impl/general/protocol.hpp b/src/vist/rmi/impl/general/protocol.hpp index 613af2c..6690bf4 100644 --- a/src/vist/rmi/impl/general/protocol.hpp +++ b/src/vist/rmi/impl/general/protocol.hpp @@ -42,8 +42,8 @@ struct Protocol { class Async : public std::enable_shared_from_this { public: explicit Async(Context& context) : socket(context) {} - void dispatch(const Task& task); - void process(const Task& task); + void dispatch(const interface::Task& task); + void process(const interface::Task& task); inline Socket& getSocket() { diff --git a/src/vist/rmi/impl/general/server.hpp b/src/vist/rmi/impl/general/server.hpp index 690f9dd..0a6f898 100644 --- a/src/vist/rmi/impl/general/server.hpp +++ b/src/vist/rmi/impl/general/server.hpp @@ -21,9 +21,7 @@ #include #include -#include #include -#include #include #include @@ -33,9 +31,9 @@ namespace rmi { namespace impl { namespace general { -class Server : public impl::Server { +class Server : public interface::Server { public: - Server(const std::string& path, const Task& task) : impl::Server(path, task) + Server(const std::string& path, const interface::Task& task) : interface::Server(path, task) { errno = 0; if (::unlink(path.c_str()) == -1 && errno != ENOENT) @@ -64,7 +62,7 @@ public: } private: - void accept(const Task& task) override + void accept(const interface::Task& task) override { auto asyncSession = std::make_shared(this->context); auto handler = [this, asyncSession, task](const auto& error) { diff --git a/src/vist/rmi/impl/ondemand/client.hpp b/src/vist/rmi/impl/ondemand/client.hpp index eb5073b..555d3ec 100644 --- a/src/vist/rmi/impl/ondemand/client.hpp +++ b/src/vist/rmi/impl/ondemand/client.hpp @@ -17,6 +17,7 @@ #pragma once #include +#include #include namespace vist { @@ -24,14 +25,15 @@ namespace rmi { namespace impl { namespace ondemand { -class Client { +class Client : public interface::Client { public: - Client(const std::string& path) : connection(path) + Client(const std::string& path) : interface::Client(path), connection(path) { - DEBUG(VIST) << "Success to connect to : " << path << " by fd[" << connection.getFd() << "]"; + DEBUG(VIST) << "Success to connect to : " << path + << " by fd[" << connection.getFd() << "]"; } - inline Message request(Message& message) + Message request(Message& message) override { return this->connection.request(message); } diff --git a/src/vist/rmi/impl/ondemand/server.hpp b/src/vist/rmi/impl/ondemand/server.hpp index 20b2fba..bb8b5d9 100644 --- a/src/vist/rmi/impl/ondemand/server.hpp +++ b/src/vist/rmi/impl/ondemand/server.hpp @@ -35,9 +35,11 @@ namespace rmi { namespace impl { namespace ondemand { -class Server : public impl::Server { +class Server : public interface::Server { public: - Server(const std::string& path, const Task& task) : impl::Server(path, task), socket(path) + Server(const std::string& path, const interface::Task& task) : + interface::Server(path, task), + socket(path) { this->accept(task); } @@ -62,7 +64,7 @@ public: } private: - void accept(const Task& task) override + void accept(const interface::Task& task) override { auto handler = [this, task]() { DEBUG(VIST) << "New session is accepted."; diff --git a/src/vist/rmi/impl/server.hpp b/src/vist/rmi/impl/server.hpp index 3e5d590..948d0c0 100644 --- a/src/vist/rmi/impl/server.hpp +++ b/src/vist/rmi/impl/server.hpp @@ -19,16 +19,18 @@ #include #include +#include namespace vist { namespace rmi { namespace impl { +namespace interface { using Task = std::function; class Server { public: - Server(const std::string&, const Task&) {} + explicit Server(const std::string&, const Task&) {} virtual ~Server() = default; Server(const Server&) = delete; @@ -44,6 +46,7 @@ private: virtual void accept(const Task& task) = 0; }; +} // namespace interface } // namespace impl } // namespace rmi } // namespace vist diff --git a/src/vist/rmi/remote.cpp b/src/vist/rmi/remote.cpp index 575a987..8d3b722 100644 --- a/src/vist/rmi/remote.cpp +++ b/src/vist/rmi/remote.cpp @@ -16,29 +16,31 @@ #include "remote.hpp" +#include #include -#include +#include #include +#include namespace vist { namespace rmi { -using namespace vist::rmi::impl::general; +using namespace vist::rmi::impl; class Remote::Impl { public: - explicit Impl(const std::string& path) : client(path) + explicit Impl(const std::string& path) : client(std::make_unique(path)) { } Message request(Message& message) { - return this->client.request(message); + return this->client->request(message); } private: - Client client; + std::unique_ptr client; }; Remote::Remote(const std::string& path) : pImpl(new Impl(path))