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>
21 * @brief System service control class using dbus interface to communicate with systemd
24 #ifndef COMMON_SERVICE_MANAGER_H
25 #define COMMON_SERVICE_MANAGER_H
27 #include <dbus/dbus.h>
32 class ServiceManager {
34 ServiceManager() = delete;
35 ServiceManager(const char *service_name);
39 void restartService();
40 pid_t getServicePid();
44 virtual ~ServiceManager();
47 void addBusMatch(const char *member);
48 void subscribeSignals();
49 void reloadDbusManager();
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();
58 std::string handleObjectPathMsgReply();
59 uint32_t handleVariantUIntMsgReply();
60 void finalizeMsgReply();
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();
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();
76 DBusConnection *m_conn;
79 DBusPendingCall *m_pending;
81 const std::string m_dbus_client_name;
82 const std::string m_service_name;
83 std::string m_unitPath;
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;
91 std::set<std::string> m_runningJobs;
92 const std::string m_reloadingToken;
95 #endif // COMMON_SERVICE_MANAGER_H