aboutsummaryrefslogtreecommitdiff
path: root/src/DBusObject.h
blob: 123964e24ed17f652d925af453f6dcb243a2f7b7 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2017 Paul Nettle. 
// 
// This file is part of Gobbledegook. 
// 
// Gobbledegook is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
// 
// Gobbledegook is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more details. 
// 
// You should have received a copy of the GNU General Public License 
// along with Gobbledegook.  If not, see <http://www.gnu.org/licenses/>. 
 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
// 
// >> 
// >>>  INSIDE THIS FILE 
// >> 
// 
// This is an abstraction of a D-Bus object. 
// 
// >> 
// >>>  DISCUSSION 
// >> 
// 
// See the discussino at the top of DBusObject.cpp 
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 
#pragma once
 
#include <gio/gio.h>
#include <string>
#include <list>
#include <memory>
 
#include "DBusInterface.h"
#include "DBusObjectPath.h"
 
struct GattProperty;
struct GattService;
struct GattUuid;
 
struct DBusObject
{
// A convenience typedef for describing our list of interface 
typedef std::list<std::shared_ptr<DBusInterface> > InterfaceList;
 
// Construct a root object with no parent 
// 
// We'll include a publish flag since only root objects can be published 
DBusObject(const DBusObjectPath &path, bool publish = true);
 
// Construct a node object 
// 
// Nodes inherit their parent's publish path 
DBusObject(DBusObject *pParent, const DBusObjectPath &pathElement);
 
// 
// Accessors 
// 
 
// Returns the `publish` flag 
bool isPublished() const;
 
// Returns the path node for this object within the hierarchy 
// 
// This method only returns the node. To get the full path, use `getPath()` 
const DBusObjectPath &getPathNode() const;
 
// Returns the full path for this object within the hierarchy 
// 
// This method returns the full path. To get the current node, use `getPathNode()` 
DBusObjectPath getPath() const;
 
// Returns the parent object in the hierarchy 
DBusObject &getParent();
 
// Returns the list of children objects 
const std::list<DBusObject> &getChildren() const;
 
// Add a child to this object 
DBusObject &addChild(const DBusObjectPath &pathElement);
 
// Returns a list of interfaces for this object 
const InterfaceList &getInterfaces() const;
 
// Templated method for adding typed interfaces to the object 
template<typename T>
std::shared_ptr<T> addInterface(std::shared_ptr<T> interface)
{
interfaces.push_back(interface);
return std::static_pointer_cast<T>(interfaces.back());
}
 
// Internal method used to generate introspection XML used to describe our services on D-Bus 
std::string generateIntrospectionXML(int depth = 0) const;
 
// Convenience functions to add a GATT service to the hierarchy 
// 
// We simply add a new child at the given path and add an interface configured as a GATT service to it using the given UUID. 
// 
// To end a service, call `gattServiceEnd()` 
GattService &gattServiceBegin(const std::string &pathElement, const GattUuid &uuid);
 
// 
// Helpful routines for searching objects 
// 
 
// Finds an interface by name within this D-Bus object 
std::shared_ptr<const DBusInterface> findInterface(const DBusObjectPath &path, const std::string &interfaceName, const DBusObjectPath &basePath = DBusObjectPath()const;
 
// Finds a BlueZ method by name within the specified D-Bus interface 
bool callMethod(const DBusObjectPath &path, const std::string &interfaceName, const std::string &methodName, GDBusConnection *pConnection, GVariant *pParameters, GDBusMethodInvocation *pInvocation, gpointer pUserData, const DBusObjectPath &basePath = DBusObjectPath()const;
 
// Periodic timer tick propagation 
void tickEvents(GDBusConnection *pConnection, void *pUserData = nullptr) const;
 
// ----------------------------------------------------------------------------------------------------------------------------- 
// D-Bus signals 
// ----------------------------------------------------------------------------------------------------------------------------- 
 
// Emits a signal on the bus from the given path, interface name and signal name, containing a GVariant set of parameters 
void emitSignal(GDBusConnection *pBusConnection, const std::string &interfaceName, const std::string &signalName, GVariant *pParameters);
 
private:
bool publish;
DBusObjectPath path;
InterfaceList interfaces;
std::list<DBusObject> children;
DBusObject *pParent;
};