From 8bb970360124dfb1603f885bd0df70fba646a2a8 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Sat, 8 Jun 2013 13:48:04 -0700 Subject: [PATCH] added automatic timeout for get() and set() commands added error type for replies to get() and set() commands --- RELEASE | 2 ++ examples/exampleconfig | 15 +++++++++++++++ lib/abstractpropertytype.h | 7 +++++++ lib/abstractroutingengine.h | 44 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 examples/exampleconfig diff --git a/RELEASE b/RELEASE index 95c66fc..31ff80c 100644 --- 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 index 0000000..60eeed3 --- /dev/null +++ b/examples/exampleconfig @@ -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" + } + ] +} + diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h index a2ef5ec..b22be1a 100644 --- a/lib/abstractpropertytype.h +++ b/lib/abstractpropertytype.h @@ -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; diff --git a/lib/abstractroutingengine.h b/lib/abstractroutingengine.h index 1c3ae98..9099181 100644 --- a/lib/abstractroutingengine.h +++ b/lib/abstractroutingengine.h @@ -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(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 -- 2.7.4