TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / dbus / bus.h
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #ifndef ANBOX_DBUS_BUS_H_
19 #define ANBOX_DBUS_BUS_H_
20
21 #include "anbox/do_not_copy_or_move.h"
22
23 #include <atomic>
24 #include <memory>
25 #include <mutex>
26 #include <thread>
27
28 #include <systemd/sd-bus.h>
29
30 namespace anbox {
31 namespace dbus {
32 class Bus : public DoNotCopyOrMove {
33  public:
34   enum class Type {
35     System,
36     Session
37   };
38
39   Bus(Type type);
40   ~Bus();
41
42   sd_bus* raw();
43
44   bool has_service_with_name(const std::string& name);
45   void run_async();
46   void stop();
47
48  private:
49   void worker_main();
50
51   sd_bus *bus_ = nullptr;
52   std::thread worker_thread_;
53   std::atomic_bool running_{false};
54 };
55 using BusPtr = std::shared_ptr<Bus>;
56 }  // namespace dbus
57 }  // namespace anbox
58
59 #endif