forked from fcitx/fcitx5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestservicewatcher.cpp
46 lines (38 loc) · 1.2 KB
/
testservicewatcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* SPDX-FileCopyrightText: 2016-2016 CSSlayer <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
*/
#include "fcitx-utils/dbus/bus.h"
#include "fcitx-utils/dbus/servicewatcher.h"
#include "fcitx-utils/log.h"
using namespace fcitx::dbus;
using namespace fcitx;
#define TEST_SERVICE "org.fcitx.Fcitx.TestDBus"
int main() {
Bus bus(BusType::Session);
if (!bus.isOpen()) {
return 1;
}
EventLoop loop;
bus.attachEventLoop(&loop);
std::unique_ptr<HandlerTableEntry<ServiceWatcherCallback>>
handlerTableEntry;
ServiceWatcher watcher(bus);
if (!bus.requestName(TEST_SERVICE, {RequestNameFlag::AllowReplacement,
RequestNameFlag::ReplaceExisting})) {
return 1;
}
std::string name = bus.serviceOwner(TEST_SERVICE, 0);
FCITX_ASSERT(name == bus.uniqueName());
handlerTableEntry = watcher.watchService(
TEST_SERVICE, [&loop](const std::string &name, const std::string &,
const std::string &) {
FCITX_ASSERT(name == TEST_SERVICE);
loop.exit();
});
FCITX_ASSERT(bus.releaseName(TEST_SERVICE));
loop.exec();
return 0;
}