added automatic timeout for get() and set() commands
authorKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 20:48:04 +0000 (13:48 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 20:48:04 +0000 (13:48 -0700)
added error type for replies to get() and set() commands

RELEASE
examples/exampleconfig [new file with mode: 0644]
lib/abstractpropertytype.h
lib/abstractroutingengine.h

diff --git a/RELEASE b/RELEASE
index 95c66fc..31ff80c 100644 (file)
--- a/RELEASE
+++ b/RELEASE
@@ -5,6 +5,8 @@ New features:
 - Added org.automotive.Manager DBus interface.
 - Added org.automotive.Manager.findProperty method for finding a specific object path for a given property
 - OBD2 add support for AT/ST calls (ie, atrv for battery voltage) 
+- Added automatic and configurable timeout for get() calls
+- Added error type for get() calls
 
 Changes:
 - AbstractPropertyType class now contains information for zone and the property name
diff --git a/examples/exampleconfig b/examples/exampleconfig
new file mode 100644 (file)
index 0000000..60eeed3
--- /dev/null
@@ -0,0 +1,15 @@
+{
+       "sources" : [ 
+               {
+                       "name" : "ExampleSouce",
+                       "path" : "/usr/lib/automotive-message-broker/examplesourceplugin.so"
+               }
+       ],
+       "sinks": [
+               {
+                       "name" : "ExampleSink",
+                       "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so"
+               } 
+       ]
+}
+
index a2ef5ec..b22be1a 100644 (file)
@@ -70,6 +70,13 @@ public:
                return one == two;
        }
 
+       bool operator != (AbstractPropertyType &other)
+       {
+               std::string one = toString();
+               std::string two = other.toString();
+               return one != two;
+       }
+
        std::string name;
 
        double timestamp;
index 1c3ae98..9099181 100644 (file)
@@ -43,7 +43,7 @@ class AsyncPropertyRequest
 {
 public:
        AsyncPropertyRequest()
-               :property(VehicleProperty::NoValue)
+               :property(VehicleProperty::NoValue),timeout(10000)
        {
 
        }
@@ -53,6 +53,7 @@ public:
                this->property = request.property;
                this->completed = request.completed;
                this->sourceUuid = request.sourceUuid;
+               this->timeout = request.timeout;
        }
 
        AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
@@ -60,6 +61,7 @@ public:
                this->property = other.property;
                this->completed = other.completed;
                this->sourceUuid = other.sourceUuid;
+               this->timeout = other.timeout;
 
                return *this;
        }
@@ -67,20 +69,58 @@ public:
        VehicleProperty::Property property;
        std::string sourceUuid;
        GetPropertyCompletedSignal completed;
+       uint timeout;
 };
 
 class AsyncPropertyReply: public AsyncPropertyRequest
 {
 public:
        AsyncPropertyReply(const AsyncPropertyRequest &request)
-               :AsyncPropertyRequest(request), value(NULL), success(false)
+               :AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr)
        {
+               auto timeoutfunc = [](gpointer userData) {
+                       AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
+                       if(thisReply->success == false)
+                       {
+                               thisReply->error = Timeout;
+                               thisReply->completed(thisReply);
+                       }
+                       return 0;
+               };
+
+               if(timeout)
+               {
+                       timeoutSource = g_timeout_source_new(timeout);
+                       g_source_set_callback(timeoutSource,(GSourceFunc) timeoutfunc, this, nullptr);
+                       g_source_attach(timeoutSource, nullptr);
+               }
+       }
 
+       ~AsyncPropertyReply()
+       {
+               if(timeoutSource)
+               {
+                       g_source_destroy(timeoutSource);
+                       g_source_unref(timeoutSource);
+               }
        }
 
+       enum Error {
+               NoError,
+               Timeout,
+               InvalidOperation,
+               PermissionDenied
+       };
 
+       /**
+        * @brief value of the reply.  This may be null if success = false.  This is owned by the source.
+        */
        AbstractPropertyType* value;
        bool success;
+       Error error;
+
+private:
+       GSource* timeoutSource;
 };
 
 class AsyncSetPropertyRequest: public AsyncPropertyRequest