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; }
65 void setInterfaceName(const std::string & ifaceName)
67 mInterfaceName = ifaceName;
70 bool implementsProperty(std::string property);
73 * \brief hasPropertyDBus
74 * \param attributeName, name of DBus property
75 * \return true if attributeName is supported by this interface
77 bool hasPropertyDBus(std::string attributeName)
80 for(auto i : propertyDBusMap)
82 if(i->name() == attributeName)
91 std::string objectPath() { return mObjectPath; }
93 bool isSupported() { return supported; }
95 double time() { return mTime; }
97 VariantType* property(std::string propertyName)
99 if(properties.find(propertyName) != properties.end())
100 return properties[propertyName];
104 AbstractRoutingEngine* re;
106 void setObjectPath(std::string op)
108 if(objectMap.find(op) != objectMap.end())
112 objectMap[mObjectPath] = this;
115 std::string objectName() { return mPropertyName; }
117 Zone::Type zone() { return zoneFilter; }
119 std::string source() { return mSourceFilter; }
121 std::unordered_map<std::string, VariantType*> getProperties() { return properties; }
123 bool isRegistered() { return regId > 0; }
127 void startRegistration();
129 static GVariant *getProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
130 const gchar *interfaceName, const gchar * propertyName, GError** error,
132 static gboolean setProperty(GDBusConnection * connection, const gchar * sender, const gchar *objectPath,
133 const gchar *interfaceName, const gchar * propertyName, GVariant *value,
134 GError** error, gpointer userData, std::function<void (bool, AsyncPropertyReply::Error)> callback);
136 static void handleMyMethodCall(GDBusConnection *connection, const gchar *sender, const gchar *object_path,
137 const gchar *interface_name, const gchar *method_name, GVariant *parameters,
138 GDBusMethodInvocation *invocation, gpointer user_data);
140 virtual void setProperty(std::string propertyName, GVariant * value, std::function<void (bool, AsyncPropertyReply::Error)> callback);
141 virtual GVariant * getProperty(std::string propertyName);
143 void setTimeout(int timeout);
145 std::unordered_map<std::string, VariantType*> properties;
147 Zone::Type zoneFilter;
149 PropertyDBusMap propertyDBusMap;
153 std::string mSourceFilter;
156 std::string mInterfaceName;
157 std::string mObjectPath;
158 std::string mPropertyName;
159 std::string introspectionXml;
160 GDBusConnection * mConnection;
161 static std::unordered_map<std::string, AbstractDBusInterface*> objectMap;
162 static PropertyList mimplementedProperties;
168 #endif // ABSTRACTDBUSINTERFACE_H