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
17 #ifndef __POLICY_CLIENT_H__
18 #define __POLICY_CLIENT_H__
25 #include <klay/rmi/method.h>
26 #include <klay/gmainloop.h>
28 typedef std::function<void(const char*, const char*, void*)> SignalHandler;
30 class DevicePolicyClient {
32 DevicePolicyClient() noexcept;
33 ~DevicePolicyClient() noexcept;
35 int subscribeSignal(const std::string& name,
36 const SignalHandler& handler,
38 int unsubscribeSignal(int subscriberId) noexcept;
39 int getMaintenanceMode();
41 template<typename Type, typename... Args>
42 Type methodCall(const std::string& method, Args&&... args)
44 if (!getMaintenanceMode()) {
45 errno = EPROTONOSUPPORT;
49 rmi::Connection conn(clientAddress);
50 Type ret = rmi::RemoteMethod<>::invoke<Type, Args...>(conn, method, std::forward<Args>(args)...);
55 std::string clientAddress;
56 std::unique_ptr<ScopedGMainLoop> mainloop;
59 DevicePolicyClient& GetDevicePolicyClient(void* handle);
61 #endif //__POLICY_CLIENT_H__