2 * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 #ifndef __ODE_CLIENT_H__
18 #define __ODE_CLIENT_H__
24 #include <klay/rmi/client.h>
25 #include <rmi/common.h>
27 typedef std::function<void(void*)> SignalListener;
29 typedef std::unique_ptr<rmi::Client> RmiClientPtr;
31 class ClientContext final {
32 const char* SUBSCRIBER_REGISTER = "ServerContext::registerNotificationSubscriber";
33 const char* SUBSCRIBER_UNREGISTER = "ServerContext::unregisterNotificationSubscriber";
36 ClientContext() noexcept;
37 ~ClientContext() noexcept;
39 int connect() noexcept;
40 int connect(const std::string& address) noexcept;
41 void disconnect() noexcept;
44 * TODO use more generic subscription method below in internal/external
45 * encryption and remove this one.
47 int subscribeSignal(const std::string& name, const SignalListener& listener, void* data);
48 void unsubscribeSignal(int subscriberId);
50 template<typename ...Args>
51 int subscribeSignal(const std::string& name, const std::function<void(Args...)>& listener)
54 int ret = client->subscribe<Args...>(SUBSCRIBER_REGISTER, name, listener);
56 return ode::error::Unknown;
58 } catch (runtime::Exception& e) {
59 std::cout << e.what() << std::endl;
60 return ode::error::Unknown;
64 template<typename Interface, typename... Args>
65 Interface createInterface(Args&&... args) noexcept
67 return Interface(client, std::forward<Args>(args)...);
74 #endif //__ODE_CLIENT_H__