2 * Copyright (c) 2013-2014 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 * @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>
22 * @brief Declaration of service control class using dbus interface to communicate with systemd
25 #ifndef COMMON_SERVICE_MANAGER_H
26 #define COMMON_SERVICE_MANAGER_H
28 #include <dbus/dbus.h>
30 #include <dbus_connection.h>
31 #include <dbus_message_in.h>
32 #include <dbus_message_out.h>
38 class ServiceManager {
40 ServiceManager() = delete;
41 ServiceManager(const std::string &serviceName);
42 ~ServiceManager() = default;
46 void restartService();
47 pid_t getServicePid();
48 timeval getServiceStartTimestamp();
53 void addBusMatch(const std::string &member);
54 void subscribeSignals();
55 void reloadDbusManager();
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);
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();
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();
76 DBus::Connection m_connection;
78 const std::string m_serviceName;
79 std::string m_unitPath;
81 std::set<std::string> m_runningJobs;
84 #endif // COMMON_SERVICE_MANAGER_H