2 * Copyright (c) 2015 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
21 const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber";
22 const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber";
24 const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock";
29 KrateContext::KrateContext() noexcept
33 KrateContext::~KrateContext() noexcept
38 int KrateContext::connect(const std::string& address) noexcept
41 client.reset(new rmi::Client(address));
43 } catch (runtime::Exception& e) {
50 int KrateContext::connect() noexcept
52 return connect(KRATE_MANAGER_ADDRESS);
55 void KrateContext::disconnect() noexcept
60 int KrateContext::subscribeSignal(const std::string& name,
61 const SignalListener& listener,
64 auto listenerDispatcher = [listener, data](std::string &name, std::string &from, std::string &object) {
65 listener(from.c_str(), object.c_str(), data);
69 return client->subscribe<std::string, std::string, std::string>(SUBSCRIBER_REGISTER,
70 name, listenerDispatcher);
71 } catch (runtime::Exception& e) {
72 std::cout << e.what() << std::endl;
77 int KrateContext::unsubscribeSignal(int subscriberId)
79 return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId);