OpenCPN Partial API docs
Loading...
Searching...
No Matches
dbus_server.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2023 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#ifndef DBUS_HANDLER_H__
26#define DBUS_HANDLER_H__
27
28#include <functional>
29#include <thread>
30
31#include <gio/gio.h>
32
33#include "model/instance_check.h"
34#include "model/local_api.h"
35#include "observable_evtvar.h"
36
38static const char* const kDbusName = "org.opencpn.OpenCPN";
39
41static const char* const kDbusObject = "/org/opencpn/OpenCPN";
42
44static const char* const kDbusInterface = "opencpn.desktop";
45
47static const gchar introspection_xml[] = R"""(
48<node>
49 <interface name='opencpn.desktop'>
50 <annotation name='org.gtk.GDBus.Annotation' value='OnInterface'/>
51 <annotation name='org.gtk.GDBus.Annotation' value='AlsoOnInterface'/>
52 <method name='Ping'>
53 <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
54 <arg type='u' name='level' direction='out'/>
55 <arg type='b' name='stat' direction='out'/>
56 </method>
57 <method name='Raise'>
58 <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
59 <!-- In the GUI case, raise application to top. -->
60 </method>
61 <method name='Open'>
62 <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
63 <arg type='s' name='level' direction='in'/>
64 <arg type='b' name='stat' direction='out'/>
65 </method>
66 <method name='GetRestEndpoint'>
67 <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
68 <arg type='s' name='endpoint' direction='out'/>
69 </method>
70 <method name='Quit'>
71 <annotation name='org.gtk.GDBus.Annotation' value='OnMethod'/>
72 </method>
73 </interface>
74</node>
75)""";
76
78static void HandleMethodCall(GDBusConnection* connection, const gchar* sender,
79 const gchar* object_path,
80 const gchar* interface_name,
81 const gchar* method_name, GVariant* parameters,
82 GDBusMethodInvocation* invocation,
83 gpointer user_data);
84
92class DbusServer : public LocalServerApi, public InstanceCheck {
93public:
94 static DbusServer& GetInstance();
95
97 static void Disconnect();
98
99 DbusServer(DbusServer&) = delete;
100 void operator=(const DbusServer&) = delete;
101
102 virtual ~DbusServer();
103
117 void WaitUntilValid() override;
118
120 GDBusNodeInfo* introspection_data;
121
126 bool IsMainInstance() { return m_is_main_instance; }
127
128 void SetMainInstance(bool value) { m_is_main_instance = value; }
129
130 DbusServer* UnitTestInstance() { return new DbusServer(); }
131
132protected:
133 DbusServer();
134
135private:
136 static DbusServer* s_instance;
137 bool m_is_main_instance;
138 unsigned m_owner_id;
139};
140
141#endif // DBUS_HANDLER_H__
Basic interface to low-level DBus library.
Definition dbus_server.h:92
GDBusNodeInfo * introspection_data
Callback context.
static void Disconnect()
Clear current singleton instance and disconnect from session bus.
void WaitUntilValid() override
Wait until ready.
bool IsMainInstance()
Check if this instance is the only one.
Common interface for all instance checkers.
Base interface for local server command handling.
Definition local_api.h:61
The local API has a server side handling commands and a client part issuing commands.