f1f492f01d00bb67f74474df886d08a0768d46f4
[platform/core/test/security-tests.git] / src / 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  * @author      Marcin Niesluchowski <m.niesluchow@samsungcom>
21  * @version     1.1
22  * @brief       Declaration of service control class using dbus interface to communicate with systemd
23  */
24
25 #ifndef COMMON_SERVICE_MANAGER_H
26 #define COMMON_SERVICE_MANAGER_H
27
28 #include <dbus/dbus.h>
29
30 #include <dbus_connection.h>
31 #include <dbus_message_in.h>
32 #include <dbus_message_out.h>
33
34 #include <cstdint>
35 #include <set>
36 #include <string>
37
38 class ServiceManager {
39 public:
40     ServiceManager() = delete;
41     ServiceManager(const std::string &serviceName);
42     ~ServiceManager() = default;
43
44     void startService();
45     void stopService();
46     void restartService();
47     pid_t getServicePid();
48     timeval getServiceStartTimestamp();
49     void maskService();
50     void unmaskService();
51
52 private:
53     void addBusMatch(const std::string &member);
54     void subscribeSignals();
55     void reloadDbusManager();
56     void getUnitPath();
57     DBus::MessageOut newMethodCall(const std::string &method);
58     std::string handleObjectPathMsgReply(DBus::MessageIn &messageIn);
59     uint32_t handleVariantUIntMsgReply(DBus::MessageIn &messageIn);
60     uint64_t handleVariantUInt64MsgReply(DBus::MessageIn &messageIn);
61
62     void sendToService(const std::string &method);
63     void sendMaskToService();
64     void sendUnmaskToService();
65     DBus::MessageIn sendPropertyGetMsg(const std::string &interface, const std::string &property);
66     uint32_t getUIntProperty(const std::string &interface, const std::string &property);
67     uint64_t getUInt64Property(const std::string &interface, const std::string &property);
68     void sendResetFailedToService();
69
70     static DBusHandlerResult messageHandler(DBusConnection *conn, DBusMessage *msg, void *t);
71     void signalJobRemovedHandler(DBus::MessageIn &messageIn);
72     void signalJobNewHandler(DBus::MessageIn &messageIn);
73     void signalReloadingHandler(DBus::MessageIn &messageIn);
74     void waitForRunningJobsFinish();
75
76     DBus::Connection m_connection;
77
78     const std::string m_serviceName;
79     std::string m_unitPath;
80
81     std::set<std::string> m_runningJobs;
82 };
83
84 #endif // COMMON_SERVICE_MANAGER_H