2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef ABSTRACTDBUSINTERFACE_H
20 #define ABSTRACTDBUSINTERFACE_H
24 #include <unordered_map>
27 #include <boost/any.hpp>
29 #include "abstractpropertytype.h"
30 #include <abstractroutingengine.h>
31 #include "varianttype.h"
33 const uint getPid(const char *owner);
35 typedef std::vector<VariantType*> PropertyDBusMap;
37 class AbstractDBusInterface
41 AbstractDBusInterface(std::string interfaceName, std::string objectName, GDBusConnection* connection);
43 virtual ~AbstractDBusInterface();
45 void setDBusConnection(GDBusConnection* connection)
47 mConnection = connection;
50 void registerObject();
51 void unregisterObject();
53 void addProperty(VariantType* property);
54 virtual void updateValue(VariantType* property);
56 static PropertyList implementedProperties() { return mimplementedProperties; }
58 static std::list<AbstractDBusInterface *> getObjectsForProperty(std::string property);
60 static list<AbstractDBusInterface*> interfaces();
62 static std::vector<string> supportedInterfaces();
64 std::string interfaceName() { return mInterfaceName; }
66 bool implementsProperty(std::string property);
69 * \brief hasPropertyDBus
70 * \param attributeName, name of DBus property
71 * \return true if attributeName is supported by this interface
73 bool hasPropertyDBus(std::string attributeName)
76 for(auto i : propertyDBusMap)
78 if(i->name() == attributeName)
87 std::string objectPath() { return mObjectPath; }
89 bool isSupported() { return supported; }
91 double time() { return mTime; }
93 VariantType* property(std::string propertyName)
95 if(properties.find(propertyName) != properties.end())
96 return properties[propertyName];
100 AbstractRoutingEngine* re;
102 void setObjectPath(std::string op)
104 if(objectMap.find(op) != objectMap.end())
108 objectMap[mObjectPath] = this;
111 std::string objectName() { return mPropertyName; }
113 Zone::Type zone() { return zoneFilter; }
115 std::string source() { return mSourceFilter; }
117 std::unordered_map<std::string, VariantType*> getProperties() { return properties; }
119 bool isRegistered() { return regId > 0; }
123 void startRegistration();
125 static GVariant *getProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
126 const gchar *interfaceName, const gchar * propertyName, GError** error,
128 static gboolean setProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
129 const gchar *interfaceName, const gchar * propertyName, GVariant *value,
130 GError** error, gpointer userData);
132 virtual void setProperty(std::string propertyName, GVariant * value);
133 virtual GVariant * getProperty(std::string propertyName);
135 void setTimeout(int timeout);
137 std::unordered_map<std::string, VariantType*> properties;
139 Zone::Type zoneFilter;
141 PropertyDBusMap propertyDBusMap;
145 std::string mSourceFilter;
148 std::string mInterfaceName;
149 std::string mObjectPath;
150 std::string mPropertyName;
151 std::string introspectionXml;
152 GDBusConnection * mConnection;
153 static std::unordered_map<std::string, AbstractDBusInterface*> objectMap;
154 static PropertyList mimplementedProperties;
160 #endif // ABSTRACTDBUSINTERFACE_H