From d8e48681a31b2647d1211edc4adbe09427fc7ced Mon Sep 17 00:00:00 2001 From: Jaemin Ryu Date: Wed, 13 Dec 2017 18:16:35 +0900 Subject: [PATCH] Add RemoteMethod for remote method call Change-Id: I9899d839351204aa96ad4e63955778e6a93076b0 Signed-off-by: Jaemin Ryu --- include/klay/rmi/connection.h | 1 + include/klay/rmi/method.h | 70 +++++++++++++++++++++++++++++++++++ src/rmi/connection.cpp | 5 +++ 3 files changed, 76 insertions(+) create mode 100644 include/klay/rmi/method.h diff --git a/include/klay/rmi/connection.h b/include/klay/rmi/connection.h index 27a87bc..4a8cd80 100644 --- a/include/klay/rmi/connection.h +++ b/include/klay/rmi/connection.h @@ -29,6 +29,7 @@ namespace rmi { class KLAY_EXPORT Connection { public: Connection(Socket&& sock); + Connection(const std::string &address); Connection(const Connection&) = delete; ~Connection() noexcept; diff --git a/include/klay/rmi/method.h b/include/klay/rmi/method.h new file mode 100644 index 0000000..aae4ccc --- /dev/null +++ b/include/klay/rmi/method.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 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 + */ + +#ifndef __RMI_REMOTEMETHOD_H__ +#define __RMI_REMOTEMETHOD_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace rmi { + +template +class KLAY_EXPORT RemoteMethod { +public: + RemoteMethod() = delete; + virtual ~RemoteMethod(); + + RemoteMethod(const RemoteMethod&) = delete; + RemoteMethod& operator=(const RemoteMethod&) = delete; + + template + static Type invoke(Connection &connection, const std::string& method, Args&&... args) + { + Message request = connection.createMessage(Message::MethodCall, method); + request.packParameters(std::forward(args)...); + connection.send(request); + + Type response; + Message reply = connection.dispatch(); + if (reply.isError()) { + std::string klass; + reply.disclose(klass); + ExceptionModel exception; + exception.raise(reply.target(), klass); + } + + reply.disclose(response); + + return response; + } +}; + +template +RemoteMethod::~RemoteMethod() +{ +} + +} // namespace rmi +#endif //__RMI_REMOTEMETHOD_H__ diff --git a/src/rmi/connection.cpp b/src/rmi/connection.cpp index 1ecd54a..b46bbfa 100644 --- a/src/rmi/connection.cpp +++ b/src/rmi/connection.cpp @@ -25,6 +25,11 @@ Connection::Connection(Socket&& sock) : { } +Connection::Connection(const std::string &address) : + socket(Socket::connect(address)) +{ +} + Connection::~Connection() noexcept { } -- 2.34.1