#include <vist/rmi/impl/server.hpp>
#include <vist/rmi/impl/general/server.hpp>
+#include <memory>
#include <string>
namespace vist {
}
private:
- std::unique_ptr<impl::Server> server;
+ std::unique_ptr<interface::Server> server;
};
Gateway::Gateway(const std::string& path) : pImpl(std::make_unique<Impl>(*this, path))
/*
- * 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.
#pragma once
-#include "protocol.hpp"
-
-#include <vist/exception.hpp>
-#include <vist/logger.hpp>
+#include <string>
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
#pragma once
-#include "protocol.hpp"
+#include <vist/rmi/impl/client.hpp>
+#include <vist/rmi/impl/general/protocol.hpp>
#include <vist/exception.hpp>
#include <vist/logger.hpp>
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));
}
}
- inline Message request(Message& message)
+ Message request(Message& message) override
{
return Protocol::Request(this->socket, 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,
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;
class Async : public std::enable_shared_from_this<Async> {
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()
{
#include <vist/exception.hpp>
#include <vist/logger.hpp>
-#include <chrono>
#include <memory>
-#include <thread>
#include <errno.h>
#include <unistd.h>
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)
}
private:
- void accept(const Task& task) override
+ void accept(const interface::Task& task) override
{
auto asyncSession = std::make_shared<Protocol::Async>(this->context);
auto handler = [this, asyncSession, task](const auto& error) {
#pragma once
#include <vist/logger.hpp>
+#include <vist/rmi/impl/client.hpp>
#include <vist/rmi/impl/ondemand/connection.hpp>
namespace vist {
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);
}
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);
}
}
private:
- void accept(const Task& task) override
+ void accept(const interface::Task& task) override
{
auto handler = [this, task]() {
DEBUG(VIST) << "New session is accepted.";
#include <vist/rmi/message.hpp>
#include <functional>
+#include <string>
namespace vist {
namespace rmi {
namespace impl {
+namespace interface {
using Task = std::function<Message(Message&)>;
class Server {
public:
- Server(const std::string&, const Task&) {}
+ explicit Server(const std::string&, const Task&) {}
virtual ~Server() = default;
Server(const Server&) = delete;
virtual void accept(const Task& task) = 0;
};
+} // namespace interface
} // namespace impl
} // namespace rmi
} // namespace vist
#include "remote.hpp"
+#include <vist/rmi/impl/client.hpp>
#include <vist/rmi/impl/general/client.hpp>
-#include <string>
+#include <memory>
#include <mutex>
+#include <string>
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<general::Client>(path))
{
}
Message request(Message& message)
{
- return this->client.request(message);
+ return this->client->request(message);
}
private:
- Client client;
+ std::unique_ptr<interface::Client> client;
};
Remote::Remote(const std::string& path) : pImpl(new Impl(path))