Check VCONF value for Maintenance Mode
[platform/core/security/device-policy-client.git] / libs / policy-client.h
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
15  */
16
17 #ifndef __POLICY_CLIENT_H__
18 #define __POLICY_CLIENT_H__
19
20 #include <string>
21 #include <memory>
22 #include <functional>
23 #include <cerrno>
24
25 #include <klay/rmi/method.h>
26 #include <klay/gmainloop.h>
27
28 typedef std::function<void(const char*, const char*, void*)> SignalHandler;
29
30 class DevicePolicyClient {
31 public:
32         DevicePolicyClient() noexcept;
33         ~DevicePolicyClient() noexcept;
34
35         int subscribeSignal(const std::string& name,
36                                                 const SignalHandler& handler,
37                                                 void* data) noexcept;
38         int unsubscribeSignal(int subscriberId) noexcept;
39         int getMaintenanceMode();
40
41         template<typename Type, typename... Args>
42         Type methodCall(const std::string& method, Args&&... args)
43         {
44                 if (!getMaintenanceMode()) {
45                         errno = EPROTONOSUPPORT;
46                         return Type();
47                 }
48
49                 rmi::Connection conn(clientAddress);
50                 Type ret = rmi::RemoteMethod<>::invoke<Type, Args...>(conn, method, std::forward<Args>(args)...);
51                 return ret;
52         }
53
54 private:
55         std::string clientAddress;
56         std::unique_ptr<ScopedGMainLoop> mainloop;
57 };
58
59 DevicePolicyClient& GetDevicePolicyClient(void* handle);
60
61 #endif //__POLICY_CLIENT_H__