2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "exampleplugin.h"
22 #include <boost/assert.hpp>
29 static gboolean timeoutCallback(gpointer data)
31 ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
33 src->randomizeProperties();
38 ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re)
39 :AbstractSource(re), velocity(0), engineSpeed(0)
41 re->setSupported(supported(), this);
43 debugOut("setting timeout");
44 g_timeout_add(1000, timeoutCallback, this );
50 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine)
52 return new ExampleSourcePlugin(routingengine);
56 string ExampleSourcePlugin::uuid()
58 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
61 boost::any ExampleSourcePlugin::getProperty(VehicleProperty::Property property)
63 if(property == VehicleProperty::VehicleSpeed)
67 else if(property == VehicleProperty::EngineSpeed)
73 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
75 if(reply->property == VehicleProperty::VehicleSpeed)
77 reply->value = velocity;
78 reply->completed(reply);
80 else if(reply->property == VehicleProperty::EngineSpeed)
82 reply->value = engineSpeed;
83 reply->completed(reply);
87 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , boost::any )
92 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
94 mRequests.push_back(property);
97 PropertyList ExampleSourcePlugin::supported()
100 props.push_back(VehicleProperty::EngineSpeed);
101 props.push_back(VehicleProperty::VehicleSpeed);
102 props.push_back(VehicleProperty::AccelerationX);
103 props.push_back(VehicleProperty::TransmissionShiftPosition);
104 props.push_back(VehicleProperty::SteeringWheelAngle);
109 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
111 mRequests.remove(property);
114 void ExampleSourcePlugin::randomizeProperties()
116 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
117 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
118 int accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
119 int transmissionShiftPostion = 1 + (6.00 * (rand() / (RAND_MAX + 1.0)));
120 int steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
122 DebugOut()<<"setting velocity to: "<<velocity<<endl;
123 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
125 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, velocity);
126 routingEngine->updateProperty(VehicleProperty::EngineSpeed, engineSpeed);
127 routingEngine->updateProperty(VehicleProperty::AccelerationX, accelerationX);
128 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, steeringWheelAngle);
129 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition, transmissionShiftPostion);