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"
32 #include "dbussignaller.h"
34 const uint getPid(const char *owner);
36 typedef std::vector<VariantType*> PropertyDBusMap;
38 class AbstractDBusInterface
42 AbstractDBusInterface(std::string interfaceName, std::string objectName, GDBusConnection* connection);
44 virtual ~AbstractDBusInterface();
46 void setDBusConnection(GDBusConnection* connection)
48 mConnection = connection;
51 void registerObject();
52 void unregisterObject();
54 void addProperty(AbstractProperty* property);
55 virtual void updateValue(AbstractProperty* property);
57 static PropertyList implementedProperties() { return mimplementedProperties; }
59 static std::list<AbstractDBusInterface *> getObjectsForProperty(std::string property);
61 static list<AbstractDBusInterface*> interfaces();
63 static std::vector<string> supportedInterfaces();
65 std::string interfaceName() { return mInterfaceName; }
67 bool implementsProperty(std::string property);
70 * \brief hasPropertyDBus
71 * \param attributeName, name of DBus property
72 * \return true if attributeName is supported by this interface
74 bool hasPropertyDBus(std::string attributeName)
77 for(auto i : propertyDBusMap)
79 if(i->dbusName() == attributeName)
88 std::string objectPath() { return mObjectPath; }
90 bool isSupported() { return supported; }
92 double time() { return mTime; }
94 AbstractProperty* property(std::string propertyName)
96 if(properties.find(propertyName) != properties.end())
97 return properties[propertyName];
101 AbstractRoutingEngine* re;
103 void setObjectPath(std::string op)
105 if(objectMap.find(op) != objectMap.end())
109 objectMap[mObjectPath] = this;
112 std::string objectName() { return mPropertyName; }
114 Zone::Type zone() { return zoneFilter; }
116 std::string source() { return mSourceFilter; }
118 std::unordered_map<std::string, AbstractProperty*> getProperties() { return properties; }
120 bool isRegistered() { return regId > 0; }
124 void startRegistration();
126 static GVariant *getProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
127 const gchar *interfaceName, const gchar * propertyName, GError** error,
129 static gboolean setProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
130 const gchar *interfaceName, const gchar * propertyName, GVariant *value,
131 GError** error, gpointer userData);
133 virtual void setProperty(std::string propertyName, GVariant * value);
134 virtual GVariant * getProperty(std::string propertyName);
136 void setTimeout(int timeout);
138 std::unordered_map<std::string, AbstractProperty*> properties;
140 Zone::Type zoneFilter;
142 PropertyDBusMap propertyDBusMap;
146 std::string mSourceFilter;
149 std::string mInterfaceName;
150 std::string mObjectPath;
151 std::string mPropertyName;
152 std::string introspectionXml;
153 GDBusConnection * mConnection;
154 static std::unordered_map<std::string, AbstractDBusInterface*> objectMap;
155 static PropertyList mimplementedProperties;
161 #endif // ABSTRACTDBUSINTERFACE_H