Add RemoteMethod for remote method call 70/163770/4 accepted/tizen/4.0/unified/20180111.051159 submit/tizen/20180109.085832 submit/tizen/20180110.012731 submit/tizen_4.0/20180109.085933 tizen_4.0.IoT.p2_release
authorJaemin Ryu <jm77.ryu@samsung.com>
Wed, 13 Dec 2017 09:16:35 +0000 (18:16 +0900)
committersangwan kwon <sangwan.kwon@samsung.com>
Tue, 19 Dec 2017 04:37:45 +0000 (04:37 +0000)
Change-Id: I9899d839351204aa96ad4e63955778e6a93076b0
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
include/klay/rmi/connection.h
include/klay/rmi/method.h [new file with mode: 0644]
src/rmi/connection.cpp

index 27a87bc15fcc34728c3f9d38314df1c43984005c..4a8cd8030deb2b256d662a5770bc03affde62d80 100644 (file)
@@ -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 (file)
index 0000000..aae4ccc
--- /dev/null
@@ -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 <thread>
+#include <string>
+#include <memory>
+#include <iostream>
+
+#include <klay/klay.h>
+#include <klay/rmi/client.h>
+#include <klay/rmi/message.h>
+#include <klay/rmi/connection.h>
+#include <klay/rmi/callback-holder.h>
+
+namespace rmi {
+
+template <typename ExceptionModel = DefaultExceptionModel>
+class KLAY_EXPORT RemoteMethod {
+public:
+       RemoteMethod() = delete;
+       virtual ~RemoteMethod();
+
+       RemoteMethod(const RemoteMethod&) = delete;
+       RemoteMethod& operator=(const RemoteMethod&) = delete;
+
+       template<typename Type, typename... Args>
+       static Type invoke(Connection &connection, const std::string& method, Args&&... args)
+       {
+               Message request = connection.createMessage(Message::MethodCall, method);
+               request.packParameters(std::forward<Args>(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<Type>(response);
+
+               return response;
+       }
+};
+
+template <typename ExceptionModel>
+RemoteMethod<ExceptionModel>::~RemoteMethod()
+{
+}
+
+} // namespace rmi
+#endif //__RMI_REMOTEMETHOD_H__
index 1ecd54a8bb0c720068e64a3d160f97c33e8a8eb6..b46bbfafd28284ec72351b718302ce965b95a1bc 100644 (file)
@@ -25,6 +25,11 @@ Connection::Connection(Socket&& sock) :
 {
 }
 
+Connection::Connection(const std::string &address) :
+       socket(Socket::connect(address))
+{
+}
+
 Connection::~Connection() noexcept
 {
 }