Fcitx
servicewatcher.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2016 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 #ifndef _FCITX_UTILS_DBUS_SERVICEWATCHER_H_
8 #define _FCITX_UTILS_DBUS_SERVICEWATCHER_H_
9 
10 #include <functional>
11 #include <memory>
12 #include <string>
13 #include <fcitx-utils/dbus/bus.h>
14 #include <fcitx-utils/fcitxutils_export.h>
15 #include <fcitx-utils/handlertable.h>
16 #include <fcitx-utils/macros.h>
17 
18 /// \addtogroup FcitxUtils
19 /// \{
20 /// \file
21 /// \brief API for service monitoring.
22 
23 namespace fcitx::dbus {
24 
25 using ServiceWatcherCallback = std::function<void(
26  const std::string &, const std::string &, const std::string &)>;
27 using ServiceWatcherEntry = HandlerTableEntry<ServiceWatcherCallback>;
28 
29 class ServiceWatcherPrivate;
30 
31 /**
32  * A class to be used to monitor the services registered on the Bus.
33  */
34 class FCITXUTILS_EXPORT ServiceWatcher {
35 public:
36  ServiceWatcher(Bus &bus);
37  ~ServiceWatcher();
38 
39  // unlike regular NameOwnerChanged signal, this will also initiate a
40  // GetNameOwner call to avoid race condition
41  // if GetNameOwner returns, it will intiate a call (name, "", owner) if
42  // service exists, otherwise (name, "", "")
43  FCITX_NODISCARD std::unique_ptr<ServiceWatcherEntry>
44  watchService(const std::string &name, ServiceWatcherCallback callback);
45 
46 private:
47  std::unique_ptr<ServiceWatcherPrivate> d_ptr;
48  FCITX_DECLARE_PRIVATE(ServiceWatcher);
49 };
50 } // namespace fcitx::dbus
51 
52 #endif // _FCITX_UTILS_DBUS_SERVICEWATCHER_H_
API for DBus bus.
A class that represents a connection to the Bus.
Definition: bus.h:51
A class to be used to monitor the services registered on the Bus.