Remove Bumjin Im as contact of dbus access class
[platform/core/test/security-tests.git] / tests / common / service_manager.h
1 /*
2  * Copyright (c) 2013-2014 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  * @file        service_manager.h
18  * @author      Zbigniew Jasinski <z.jasinski@samsung.com>
19  * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
20  * @version     1.1
21  * @brief       System service control class using dbus interface to communicate with systemd
22  */
23
24 #ifndef COMMON_SERVICE_MANAGER_H
25 #define COMMON_SERVICE_MANAGER_H
26
27 #include <dbus/dbus.h>
28
29 #include <set>
30 #include <string>
31
32 class ServiceManager {
33 public:
34     ServiceManager() = delete;
35     ServiceManager(const char *service_name);
36
37     void startService();
38     void stopService();
39     void restartService();
40     pid_t getServicePid();
41     void maskService();
42     void unmaskService();
43
44     virtual ~ServiceManager();
45 private:
46     void connect();
47     void addBusMatch(const char *member);
48     void subscribeSignals();
49     void reloadDbusManager();
50     void requestName();
51     void getUnitPath();
52     void newMethodCall(const char *method);
53     void appendToMsg(const char *argument);
54     void appendToMsg(const char *const *argument);
55     void appendToMsg(bool argument);
56     void sendMsgWithReply();
57     void getMsgReply();
58     std::string handleObjectPathMsgReply();
59     uint32_t handleVariantUIntMsgReply();
60     void finalizeMsgReply();
61
62     void connectToDBus();
63     void sendToService(const char *method);
64     void sendMaskToService();
65     void sendUnmaskToService();
66     uint32_t getUIntProperty(const char *interface, const char *property);
67     void sendResetFailedToService();
68
69     static DBusHandlerResult messageHandler(DBusConnection *conn, DBusMessage *msg, void *t);
70     bool isSignal(DBusMessage *msg, const char *signal);
71     void signalJobRemovedHandler(DBusMessage *msg);
72     void signalJobNewHandler(DBusMessage *msg);
73     void signalReloadingHandler(DBusMessage *msg);
74     void waitForRunningJobsFinish();
75
76     DBusConnection *m_conn;
77     DBusMessage *m_msg;
78     DBusError m_err;
79     DBusPendingCall *m_pending;
80
81     const std::string m_dbus_client_name;
82     const std::string m_service_name;
83     std::string m_unitPath;
84
85     const std::string m_dbus_systemd_destination;
86     const std::string m_dbus_systemd_path;
87     const std::string m_dbus_systemd_manager_interface;
88     const std::string m_dbus_systemd_properties_interface;
89     const std::string m_dbus_systemd_service_interface;
90
91     std::set<std::string> m_runningJobs;
92     const std::string m_reloadingToken;
93 };
94
95 #endif // COMMON_SERVICE_MANAGER_H