merge with 0.10's getHistory and fix for time and zone properties
authorKevron Rees <tripzero.kev@gmail.com>
Thu, 15 Aug 2013 21:47:29 +0000 (14:47 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Thu, 15 Aug 2013 22:28:13 +0000 (15:28 -0700)
ambd/core.cpp
docs/amb.idl
examples/databaseconfig
lib/abstractroutingengine.h
plugins/database/CMakeLists.txt
plugins/database/databasesink.cpp
plugins/dbus/abstractdbusinterface.cpp
plugins/dbus/abstractdbusinterface.h
plugins/dbus/dbusplugin.cpp

index 0222b8d..3c17ba0 100644 (file)
@@ -179,7 +179,7 @@ void Core::updateProperty(VehicleProperty::Property property, AbstractPropertyTy
 
                        if(value->sourceUuid != uuid)
                        {
-                               DebugOut(DebugOut::Warning)<<"Source not setting uuid for property "<<value->name<<endl;
+                               //DebugOut(DebugOut::Warning)<<"Source not setting uuid for property "<<value->name<<endl;
                                value->sourceUuid = uuid;
                        }
 
index 9c9fb0f..e3760da 100644 (file)
@@ -30,6 +30,24 @@ interface VehiclePropertyError   {
        readonly attribute DOMString message;
 };
 
+[NoInterfaceObject]
+interface Dictionary {
+       DOMString objectName;
+       any value;
+}
+
+[NoInterfaceObject]
+interface VehiclePropertyType {
+       readonly attribute double Time;
+       
+       /**
+       * \brief returns dictionary of objectName and values for data between
+       * 'beginTime' and 'endTime'
+       * \arg beginTime time stamp in Seconds since Unix Epoc
+       * \arg endTime time stamp in Seconds since Unix Epoc
+       **/
+       Dictionary getHistory(double beginTime, double endTime);
+}
 enum Zone {
        None = 0,
        Front = 1,
@@ -39,7 +57,6 @@ enum Zone {
        Rear = 1 << 4,
        Center = 1 << 5
 }
-
 [NoInterfaceObject]
 interface Manager  {
 
@@ -49,7 +66,7 @@ interface Manager  {
        sequence<DOMString> list();
        /**  
         *  \brief find the DBus object path which matches "objectName" and "zone".
-     *  \arg DOMString property is the requested property to be retrieved.
+        *  \arg DOMString property is the requested property to be retrieved.
         *  \arg Zone zone is the zone which the object
         *  \returns string representing the DBus Object path
        **/
index f2b663f..0405063 100644 (file)
                        "name" : "Database",
                        "path" : "/usr/lib/automotive-message-broker/databasesinkplugin.so",
                        "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }",
-                       "databaseFile" : "storage.db",
+                       "databaseFile" : "/tmp/storage",
                        "startOnLoad" : "true",
                        "bufferLength" : "1"
                },
                {
                        "name" : "Example Sink",
                        "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so"
+               },
+               {
+                       "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so"
                }
+               
        ]
 }
 
index e2a852e..f929608 100644 (file)
@@ -182,6 +182,8 @@ public:
                values.clear();
        }
 
+       AsyncPropertyReply::Error error;
+
        std::list<AbstractPropertyType*> values;
        bool success;
 };
index 7666fe9..882c26e 100644 (file)
@@ -7,7 +7,7 @@ pkg_check_modules(sqlite REQUIRED sqlite3)
 include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${sqlite_INCLUDE_DIRS})
 
 set(databasesinkplugin_headers databasesink.h utils.h basedb.hpp baseobject.h sqlitedatabase.h sqlitequery.h)
-set(databasesinkplugin_sources databasesink.cpp utils.cpp sqlitedatabase.cpp sqlitequery.cpp)
+set(databasesinkplugin_sources databasesink.cpp utils.cpp sqlitedatabase.cpp sqlitequery.cpp basedb.hpp)
 add_library(databasesinkplugin MODULE ${databasesinkplugin_sources})
 set_target_properties(databasesinkplugin PROPERTIES PREFIX "")
 target_link_libraries(databasesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${sqlite_LIBRARIES})
index 7ee522a..cac1408 100644 (file)
@@ -469,7 +469,7 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply)
 
        std::vector<std::vector<string>> data = db->select(query.str());
 
-       std::list<AbstractPropertyType*> cleanup;
+       DebugOut()<<"Dataset size "<<data.size()<<endl;
 
        for(auto i=0;i<data.size();i++)
        {
@@ -490,7 +490,6 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply)
                        property->sequence = dbobj.sequence;
 
                        reply->values.push_back(property);
-                       cleanup.push_back(property);
                }
        }
 
index 0d38b3f..c2a72e9 100644 (file)
@@ -17,15 +17,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #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;
 
 
@@ -53,16 +55,56 @@ static void handleMyMethodCall(GDBusConnection       *connection,
 
                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"))
@@ -128,7 +170,7 @@ AbstractDBusInterface::~AbstractDBusInterface()
                }
        }
 
-       interfaceMap.erase(mInterfaceName);
+       objectMap.erase(mObjectPath);
 
 }
 
@@ -270,7 +312,7 @@ void AbstractDBusInterface::updateValue(AbstractProperty *property)
 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)
@@ -283,7 +325,7 @@ list<AbstractDBusInterface *> AbstractDBusInterface::interfaces()
 {
        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);
        }
@@ -315,6 +357,7 @@ void AbstractDBusInterface::startRegistration()
                        "<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>";
 }
 
@@ -323,7 +366,12 @@ GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const
        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;
@@ -331,15 +379,21 @@ GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const
 
        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;
        }
 
@@ -350,9 +404,9 @@ GVariant* AbstractDBusInterface::getProperty(GDBusConnection* connection, const
 
 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;
        }
 
index 831f023..54906bd 100644 (file)
@@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 #include <boost/any.hpp>
 #include <nullptr.h>
 #include "abstractpropertytype.h"
+#include <abstractroutingengine.h>
 
 class AbstractProperty;
 
@@ -65,13 +66,15 @@ public:
 
        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; }
@@ -108,7 +111,7 @@ private:
        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;
 };
index 3b322f8..aa323b8 100644 (file)
@@ -32,7 +32,7 @@ DBusSink::DBusSink(string propertyName, AbstractRoutingEngine* engine, GDBusConn
        :AbstractDBusInterface("org.automotive."+propertyName, propertyName, connection),
          AbstractSink(engine, config)
 {
-
+       AbstractDBusInterface::re = engine;
 }
 
 void DBusSink::supportedChanged(PropertyList supportedProperties)