Add wheel plugin subdir for wheel source plugin
authorJames Ausmus <james.ausmus@intel.com>
Fri, 17 Aug 2012 23:25:21 +0000 (16:25 -0700)
committerJames Ausmus <james.ausmus@intel.com>
Fri, 17 Aug 2012 23:25:21 +0000 (16:25 -0700)
Modify plugins/CMakeLists.txt to include wheel subdir

Signed-off-by: James Ausmus <james.ausmus@intel.com>
plugins/CMakeLists.txt
plugins/wheel/CMakeLists.txt [new file with mode: 0644]
plugins/wheel/wheelplugin.cpp [new file with mode: 0644]
plugins/wheel/wheelplugin.h [new file with mode: 0644]

index f9a3476..5f21b68 100644 (file)
@@ -14,4 +14,6 @@ set(examplesinkplugin_sources examplesink.cpp)
 
 add_library(examplesinkplugin MODULE ${examplesinkplugin_sources})
 set_target_properties(examplesinkplugin PROPERTIES PREFIX "")
-target_link_libraries(examplesinkplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
\ No newline at end of file
+target_link_libraries(examplesinkplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
+
+add_subdirectory(wheel)
diff --git a/plugins/wheel/CMakeLists.txt b/plugins/wheel/CMakeLists.txt
new file mode 100644 (file)
index 0000000..77bd497
--- /dev/null
@@ -0,0 +1,9 @@
+
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs})
+
+set(wheelsourceplugin_headers wheelplugin.h)
+set(wheelsourceplugin_sources wheelplugin.cpp)
+
+add_library(wheelsourceplugin MODULE ${wheelsourceplugin_sources})
+set_target_properties(wheelsourceplugin PROPERTIES PREFIX "")
+target_link_libraries(wheelsourceplugin -lamb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
diff --git a/plugins/wheel/wheelplugin.cpp b/plugins/wheel/wheelplugin.cpp
new file mode 100644 (file)
index 0000000..fcec888
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+Copyright (C) 2012 Intel Corporation
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "wheelplugin.h"
+
+#include <iostream>
+#include <boost/assert.hpp>
+#include <glib.h>
+
+using namespace std;
+
+#include "debugout.h"
+
+static gboolean timeoutCallback(gpointer data)
+{
+       WheelSourcePlugin* src = (WheelSourcePlugin*)data;
+       
+       src->randomizeProperties();
+       
+       return true;
+}
+
+WheelSourcePlugin::WheelSourcePlugin(AbstractRoutingEngine* re)
+:AbstractSource(re), velocity(0), engineSpeed(0)
+{
+       re->setSupported(supported(), this);
+       
+       debugOut("setting timeout");
+       g_timeout_add(1000, timeoutCallback, this );
+       
+}
+
+
+
+extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine)
+{
+       return new WheelSourcePlugin(routingengine);
+       
+}
+
+string WheelSourcePlugin::uuid()
+{
+       return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
+}
+
+boost::any WheelSourcePlugin::getProperty(VehicleProperty::Property property)
+{
+       if(property == VehicleProperty::VehicleSpeed)
+       {
+               return velocity;
+       }
+       else if(property == VehicleProperty::EngineSpeed)
+       {
+               return engineSpeed;
+       }
+}
+
+void WheelSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
+{
+       if(reply->property == VehicleProperty::VehicleSpeed)
+       {
+               reply->value = velocity;
+               reply->completed(reply);
+       }
+       else if(reply->property == VehicleProperty::EngineSpeed)
+       {
+               reply->value = engineSpeed;
+               reply->completed(reply);
+       }
+}
+
+void WheelSourcePlugin::setProperty(VehicleProperty::Property , boost::any )
+{
+
+}
+
+void WheelSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
+{
+       mRequests.push_back(property);
+}
+
+PropertyList WheelSourcePlugin::supported()
+{
+       PropertyList props;
+       props.push_back(VehicleProperty::EngineSpeed);
+       props.push_back(VehicleProperty::VehicleSpeed);
+       
+       return props;
+}
+
+void WheelSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
+{
+       mRequests.remove(property);
+}
+
+void WheelSourcePlugin::randomizeProperties()
+{
+       velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
+       engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
+       
+       DebugOut()<<"setting velocity to: "<<velocity<<endl;
+       DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
+       
+       routingEngine->updateProperty(VehicleProperty::VehicleSpeed, velocity);
+       routingEngine->updateProperty(VehicleProperty::EngineSpeed, engineSpeed);
+}
diff --git a/plugins/wheel/wheelplugin.h b/plugins/wheel/wheelplugin.h
new file mode 100644 (file)
index 0000000..dddbb1b
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+Copyright (C) 2012 Intel Corporation
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef WHEELPLUGIN_H
+#define WHEELPLUGIN_H
+
+#include <abstractsource.h>
+#include <string>
+
+using namespace std;
+
+class WheelSourcePlugin: public AbstractSource
+{
+
+public:
+       WheelSourcePlugin(AbstractRoutingEngine* re);
+       
+       string uuid();
+       boost::any getProperty(VehicleProperty::Property property);
+       void getPropertyAsync(AsyncPropertyReply *reply);
+       void setProperty(VehicleProperty::Property, boost::any);
+       void subscribeToPropertyChanges(VehicleProperty::Property property);
+       void unsubscribeToPropertyChanges(VehicleProperty::Property property);
+       PropertyList supported();
+       
+       void propertyChanged(VehicleProperty::Property property, boost::any value, string uuid) {}
+       void supportedChanged(PropertyList) {}
+       
+       void randomizeProperties();
+       
+private:
+       PropertyList mRequests;
+       uint16_t velocity;
+       uint16_t engineSpeed;
+};
+
+#endif // WHEELPLUGIN_H