blob: 9823af5c9f3777b02d35062848bf910e33326034 (
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
|
/* Copyright (C) 2013 BMW Group
* Author: Manfred Bathelt (manfred.bathelt@bmw.de)
* Author: Juergen Gehring (juergen.gehring@bmw.de)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DBusFreedesktopPropertiesStub.h"
#include "DBusStubAdapter.h"
#include "DBusServicePublisher.h"
#include "DBusOutputStream.h"
#include "DBusInputStream.h"
#include <cassert>
#include <vector>
namespace CommonAPI {
namespace DBus {
DBusFreedesktopPropertiesStub::DBusFreedesktopPropertiesStub(const std::string& dbusObjectPath,
const std::string& dbusInterfaceName,
const std::shared_ptr<DBusProxyConnection>& dbusConnection,
const std::shared_ptr<DBusStubAdapter>& dbusStubAdapter) :
dbusObjectPath_(dbusObjectPath),
dbusConnection_(dbusConnection),
dbusStubAdapter_(dbusStubAdapter) {
assert(!dbusObjectPath.empty());
assert(dbusObjectPath[0] == '/');
assert(dbusConnection);
dbusInterfacesLock_.lock();
if(managedInterfaces_.find(dbusInterfaceName) == managedInterfaces_.end()) {
managedInterfaces_.insert({dbusInterfaceName, dbusStubAdapter});
}
dbusInterfacesLock_.unlock();
}
DBusFreedesktopPropertiesStub::~DBusFreedesktopPropertiesStub() {
// TODO: maybee some deregistration etc.
}
const char* DBusFreedesktopPropertiesStub::getMethodsDBusIntrospectionXmlData() const {
return "<interface name=\"org.freedesktop.DBus.Properties\">\n"
"<method name=\"Get\">\n"
"<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n"
"<arg type=\"s\" name=\"property_name\" direction=\"in\"/>\n"
"<arg type=\"v\" name=\"value\" direction=\"out\"/>\n"
"</method>\n"
"<method name=\"GetAll\">\n"
"<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n"
"<arg type=\"a{sv}\" name=\"properties\" direction=\"out\"/>\n"
"</method>\n"
"<method name=\"Set\">\n"
"<arg type=\"s\" name=\"interface_name\" direction=\"in\"/>\n"
"<arg type=\"s\" name=\"property_name\" direction=\"in\"/>\n"
"<arg type=\"v\" name=\"value\" direction=\"in\"/>\n"
"</method>\n"
"<signal name=\"PropertiesChanged\">\n"
"<arg type=\"s\" name=\"interface_name\"/>\n"
"<arg type=\"a{sv}\" name=\"changed_properties\"/>\n"
"<arg type=\"as\" name=\"invalidated_properties\"/>\n"
"</signal>\n"
"</interface>\n";
}
bool DBusFreedesktopPropertiesStub::onInterfaceDBusMessage(const DBusMessage& dbusMessage) {
auto dbusConnection = dbusConnection_.lock();
if (!dbusConnection || !dbusConnection->isConnected()) {
return false;
}
if (!dbusMessage.isMethodCallType() || !(dbusMessage.hasMemberName("Get") || dbusMessage.hasMemberName("GetAll") || dbusMessage.hasMemberName("Set"))) {
return false;
}
DBusInputStream dbusInputStream(dbusMessage);
std::string interfaceName;
dbusInputStream >> interfaceName;
if(dbusInputStream.hasError()) {
return false;
}
std::lock_guard<std::mutex> dbusInterfacesLock(dbusInterfacesLock_);
auto managedInterfacesIterator = managedInterfaces_.find(interfaceName);
if(managedInterfacesIterator == managedInterfaces_.end()) {
return false;
}
return managedInterfacesIterator->second->onInterfaceDBusFreedesktopPropertiesMessage(dbusMessage);
}
const bool DBusFreedesktopPropertiesStub::hasFreedesktopProperties() {
return false;
}
const std::string& DBusFreedesktopPropertiesStub::getDBusObjectPath() const {
return dbusObjectPath_;
}
const char* DBusFreedesktopPropertiesStub::getInterfaceName() {
return "org.freedesktop.DBus.Properties";
}
} // namespace DBus
} // namespace CommonAPI
|