*/
#include "abstractdbusinterface.h"
-#include "debugout.h"
+
+#include <abstractroutingengine.h>
+#include <debugout.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <gio/gio.h>
+#include <listplusplus.h>
-#include "listplusplus.h"
#include "abstractproperty.h"
-unordered_map<string, AbstractDBusInterface*> AbstractDBusInterface::interfaceMap;
+unordered_map<string, AbstractDBusInterface*> AbstractDBusInterface::objectMap;
list<string> AbstractDBusInterface::mimplementedProperties;
auto propertyMap = iface->getProperties();
-// auto cb = [&invocation](std::list<>){};
+ std::list<std::string> propertyList;
for(auto itr = propertyMap.begin(); itr != propertyMap.end(); itr++)
{
- std::string propertyName = (*itr).first;
-
+ AbstractProperty* prop = (*itr).second;
+ propertyList.push_back(prop->ambPropertyName());
}
- //AsyncRangePropertyRequest
+ std::string ifaceName = iface->interfaceName();
+
+ AsyncRangePropertyRequest request;
+
+ request.properties = propertyList;
+ request.timeBegin = beginTime;
+ request.timeEnd = endTime;
+
+ request.completed = [&invocation,&ifaceName](AsyncRangePropertyReply* reply)
+ {
+ if(!reply->success)
+ {
+ stringstream str;
+ str<<"Error during request: "<<reply->error;
+ ifaceName += ".Error";
+ g_dbus_method_invocation_return_dbus_error(invocation, ifaceName.c_str(), str.str().c_str());
+ return;
+ }
+
+ if(!reply->values.size())
+ {
+ ifaceName += ".Error";
+ g_dbus_method_invocation_return_dbus_error(invocation, ifaceName.c_str(), "No results");
+ return;
+ }
+
+ GVariantBuilder builder;
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_DICTIONARY);
+
+
+ for(auto itr = reply->values.begin(); itr != reply->values.end(); itr++)
+ {
+ AbstractPropertyType* value = *itr;
+
+ g_variant_builder_add(&builder, "{sv}", value->name.c_str(), g_variant_ref(value->toVariant()));
+ }
+
+ g_dbus_method_invocation_return_value(invocation,g_variant_new("(a{sv})",&builder));
+ };
+
+ iface->re->getRangePropertyAsync(request);
}
else if(boost::algorithm::starts_with(method,"get"))
}
}
- interfaceMap.erase(mInterfaceName);
+ objectMap.erase(mObjectPath);
}
std::list<AbstractDBusInterface *> AbstractDBusInterface::getObjectsForProperty(string object)
{
std::list<AbstractDBusInterface *> l;
- for(auto itr = interfaceMap.begin(); itr != interfaceMap.end(); itr++)
+ for(auto itr = objectMap.begin(); itr != objectMap.end(); itr++)
{
AbstractDBusInterface * interface = (*itr).second;
if(interface->objectName() == object)
{
std::list<AbstractDBusInterface*> ifaces;
- for(auto itr = interfaceMap.begin(); itr != interfaceMap.end(); itr++)
+ for(auto itr = objectMap.begin(); itr != objectMap.end(); itr++)
{
ifaces.push_back((*itr).second);
}
"<method name='getHistory'>"
" <arg type='d' direction='in' name='beginTimestamp' />"
" <arg type='d' direction='in' name='endTimestamp' />"
+ " <arg type='a{sv}' direction='out' name='result' />"
"</method>";
}
std::string pn = propertyName;
if(pn == "Time")
{
- double time = interfaceMap[interfaceName]->time();
+ if(objectMap.find(objectPath) == objectMap.end())
+ {
+ DebugOut(DebugOut::Error)<<objectPath<<" is not a valid object path."<<endl;
+ return nullptr;
+ }
+ double time = objectMap[objectPath]->time();
GVariant* value = g_variant_new("(d)", time);
return value;
if(pn == "Zone")
{
- Zone::Type zone = interfaceMap[objectPath]->zone();
+ if(objectMap.find(objectPath) == objectMap.end())
+ {
+ DebugOut(DebugOut::Error)<<objectPath<<" is not a valid object path."<<endl;
+ return nullptr;
+ }
+
+ Zone::Type zone = objectMap[objectPath]->zone();
GVariant* value = g_variant_new("(i)",(int)zone);
return value;
}
- if(interfaceMap.count(objectPath))
+ if(objectMap.count(objectPath))
{
- GVariant* value = interfaceMap[objectPath]->getProperty(propertyName);
+ GVariant* value = objectMap[objectPath]->getProperty(propertyName);
return value;
}
gboolean AbstractDBusInterface::setProperty(GDBusConnection* connection, const gchar* sender, const gchar* objectPath, const gchar* interfaceName, const gchar* propertyName, GVariant* value, GError** error, gpointer userData)
{
- if(interfaceMap.count(objectPath))
+ if(objectMap.count(objectPath))
{
- interfaceMap[objectPath]->setProperty(propertyName, value);
+ objectMap[objectPath]->setProperty(propertyName, value);
return true;
}
#include <boost/any.hpp>
#include <nullptr.h>
#include "abstractpropertytype.h"
+#include <abstractroutingengine.h>
class AbstractProperty;
double time() { return mTime; }
+ AbstractRoutingEngine* re;
+
void setObjectPath(std::string op)
{
- if(interfaceMap.find(op) != interfaceMap.end())
- interfaceMap.erase(op);
+ if(objectMap.find(op) != objectMap.end())
+ objectMap.erase(op);
mObjectPath = op;
- interfaceMap[mObjectPath] = this;
+ objectMap[mObjectPath] = this;
}
std::string objectName() { return mPropertyName; }
std::string mPropertyName;
std::string introspectionXml;
GDBusConnection * mConnection;
- static std::unordered_map<std::string, AbstractDBusInterface*> interfaceMap;
+ static std::unordered_map<std::string, AbstractDBusInterface*> objectMap;
static std::list<std::string> mimplementedProperties;
guint regId;
};