summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <kevron.m.rees@intel.com>2014-12-30 13:23:19 -0800
committerKevron Rees <kevron.m.rees@intel.com>2014-12-30 13:23:19 -0800
commit37de1221f9f67c0064237f41f4e2617ae69e6a60 (patch)
tree01bebb4ee8c0f0c9e45f5bbfa9abe1334304eb53
parent0365817383327577cfa942c6790d12c8c255f726 (diff)
downloadautomotive-message-broker-37de1221f9f67c0064237f41f4e2617ae69e6a60.tar.gz
fixed bool handling in ambctl and database logging on startup
-rw-r--r--lib/asyncqueue.hpp9
-rw-r--r--plugins/database/databasesink.cpp38
-rw-r--r--plugins/database/databasesink.h2
-rw-r--r--plugins/dbus/abstractdbusinterface.cpp2
-rw-r--r--tools/ambctl.py2
5 files changed, 37 insertions, 16 deletions
diff --git a/lib/asyncqueue.hpp b/lib/asyncqueue.hpp
index 3602bb97..ed0c69b4 100644
--- a/lib/asyncqueue.hpp
+++ b/lib/asyncqueue.hpp
@@ -62,6 +62,9 @@ public:
}
}
+ if(!mQueue.size())
+ throw std::runtime_error("nothing in queue");
+
auto itr = mQueue.begin();
T item = *itr;
@@ -73,9 +76,11 @@ public:
virtual void append(T item)
{
- std::lock_guard<std::mutex> lock(mutex);
+ {
+ std::lock_guard<std::mutex> lock(mutex);
- mQueue.insert(item);
+ mQueue.insert(item);
+ }
if(mBlocking)
{
diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp
index 9bfe5b25..b2a3ba9b 100644
--- a/plugins/database/databasesink.cpp
+++ b/plugins/database/databasesink.cpp
@@ -22,7 +22,7 @@ static void * cbFunc(Shared* shared)
{
if(!shared)
{
- throw std::runtime_error("Could not cast shared object.");
+ throw std::runtime_error("Could not get shared object.");
}
///new tripID:
@@ -61,7 +61,7 @@ static void * cbFunc(Shared* shared)
insertList.push_back(dict);
- if(insertList.size() > bufferLength)
+ if(insertList.size() >= bufferLength)
{
shared->db->exec("BEGIN IMMEDIATE TRANSACTION");
for(int i=0; i< insertList.size(); i++)
@@ -175,6 +175,7 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
if(config.find("startOnLoad")!= config.end())
{
+ DebugOut() << "start on load? " << config["startOnLoad"] << endl;
databaseLogging->setValue(config["startOnLoad"] == "true");
}
@@ -247,6 +248,8 @@ void DatabaseSink::parseConfig()
void DatabaseSink::stopDb()
{
+ databaseLogging->setValue(false);
+
if(!shared)
return;
@@ -259,19 +262,21 @@ void DatabaseSink::stopDb()
delete shared;
shared = NULL;
+
+ routingEngine->updateProperty(databaseLogging.get(), source.uuid());
}
void DatabaseSink::startDb()
{
if(playback->value<bool>())
{
- DebugOut(0)<<"ERROR: tried to start logging during playback. Only logging or playback can be used at one time"<<endl;
+ DebugOut(DebugOut::Error)<<"ERROR: tried to start logging during playback. Only logging or playback can be used at one time"<<endl;
return;
}
if(shared)
{
- DebugOut(0)<<"WARNING: logging already started. doing nothing."<<endl;
+ DebugOut(DebugOut::Warning)<<"WARNING: logging already started. doing nothing."<<endl;
return;
}
@@ -281,6 +286,9 @@ void DatabaseSink::startDb()
thread->detach();
thread = amb::make_unique(new std::thread(cbFunc, shared));
+
+ databaseLogging->setValue(true);
+ routingEngine->updateProperty(databaseLogging.get(), source.uuid());
}
void DatabaseSink::startPlayback()
@@ -296,9 +304,7 @@ void DatabaseSink::startPlayback()
vector<vector<string> > results = shared->db->select("SELECT * FROM "+tablename);
- /// we are done with shared. clean up:
- delete shared;
- shared = NULL;
+ stopDb();
if(playbackShared)
{
@@ -339,6 +345,9 @@ void DatabaseSink::initDb()
void DatabaseSink::setDatabaseFileName(string filename)
{
+ bool isLogging = databaseLogging->value<bool>();
+
+ stopDb();
initDb();
vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key, zone, source FROM " + tablename);
@@ -360,8 +369,11 @@ void DatabaseSink::setDatabaseFileName(string filename)
}
}
- delete shared;
- shared = NULL;
+ if(isLogging)
+ {
+ stopDb();
+ startDb();
+ }
routingEngine->updateSupported(supported(), PropertyList(), &source);
}
@@ -404,6 +416,8 @@ void DatabaseSink::init()
setDatabaseFileName(configuration["databaseFile"]);
}
+ DebugOut() << "databaseLogging: " << databaseLogging->value<bool>() << endl;
+
routingEngine->updateSupported(supported(), PropertyList(), &source);
}
@@ -487,13 +501,13 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply)
delete db;
}
-AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request)
+AsyncPropertyReply *DatabaseSink::setProperty(const AsyncSetPropertyRequest &request)
{
AsyncPropertyReply* reply = AmbPluginImpl::setProperty(request);
if(request.property == DatabaseLogging)
{
- if(request.value->value<bool>())
+ if(databaseLogging->value<bool>())
{
startDb();
}
@@ -508,7 +522,7 @@ AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request)
}
else if( request.property == DatabasePlayback)
{
- if(request.value->value<bool>())
+ if(playback->value<bool>())
{
startPlayback();
}
diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h
index 2e9709d9..8976f416 100644
--- a/plugins/database/databasesink.h
+++ b/plugins/database/databasesink.h
@@ -151,7 +151,7 @@ public:
///source role:
virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply);
- virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
+ virtual AsyncPropertyReply * setProperty(const AsyncSetPropertyRequest & request);
virtual void subscribeToPropertyChanges(VehicleProperty::Property property);
virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property);
int supportedOperations() const { return AbstractSource::GetRanged | AbstractSource::Get | AbstractSource::Set;}
diff --git a/plugins/dbus/abstractdbusinterface.cpp b/plugins/dbus/abstractdbusinterface.cpp
index 9933be38..f4c575c1 100644
--- a/plugins/dbus/abstractdbusinterface.cpp
+++ b/plugins/dbus/abstractdbusinterface.cpp
@@ -55,7 +55,7 @@ const uint getPid(const char *owner)
if(error)
{
- throw std::runtime_error(error->message);
+ DebugOut(DebugOut::Error)<< error->message << endl;
}
uint thePid=0;
diff --git a/tools/ambctl.py b/tools/ambctl.py
index ad95324f..836503bf 100644
--- a/tools/ambctl.py
+++ b/tools/ambctl.py
@@ -104,6 +104,8 @@ def processCommand(command, commandArgs, noMain=True):
object = managerInterface.FindObjectForZone(objectName, zone)
propertiesInterface = dbus.Interface(bus.get_object("org.automotive.message.broker", object),"org.freedesktop.DBus.Properties")
property = propertiesInterface.Get("org.automotive."+objectName, propertyName)
+ if property.__class__ == dbus.Boolean:
+ value = value.lower() == "true"
realValue = property.__class__(value)
propertiesInterface.Set("org.automotive."+objectName, propertyName, realValue)
property = propertiesInterface.Get("org.automotive."+objectName, propertyName)