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 "demosinkplugin.h"
20 #include "abstractroutingengine.h"
24 #include <boost/assert.hpp>
31 string findReplace(string str, string tofind, string replacewith, string exclusions="")
35 size_t exclusionPos = exclusions.find(tofind,0);
37 while((i = str.find(tofind,i)) != string::npos)
39 if( exclusionPos != string::npos )
41 if(str.substr(i-exclusionPos,exclusions.length()) == exclusions)
43 i+=replacewith.size();
48 str.replace(i,tofind.size(),replacewith);
49 i+=replacewith.size();
56 DemoSink::DemoSink(AbstractRoutingEngine* re, map<string, string> config)
57 :AbstractSink(re, config)
59 routingEngine->subscribeToProperty(VehicleProperty::ButtonEvent, this);
60 routingEngine->subscribeToProperty(VehicleProperty::TurnSignal, this);
61 routingEngine->subscribeToProperty(VehicleProperty::MachineGunTurretStatus, this);
69 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
71 return new DemoSinkManager(routingengine, config);
74 const string DemoSink::uuid()
76 return "5b0e8a04-d6d7-43af-b827-1663627a25d9";
79 void DemoSink::propertyChanged(AbstractPropertyType *value)
81 VehicleProperty::Property property = value->name;
83 std::string app = configuration["script"];
84 std::string strValue = value->toString();
86 if(property == VehicleProperty::TurnSignal)
88 if(value->value<TurnSignals::TurnSignalType>() == TurnSignals::Right)
92 else if(value->value<TurnSignals::TurnSignalType>() == TurnSignals::Left)
96 else if(value->value<TurnSignals::TurnSignalType>() == TurnSignals::Off)
100 } else if (property == VehicleProperty::ButtonEvent) {
101 if (value->value<ButtonEvents::ButtonEventType>() == ButtonEvents::Preset1Button)
102 strValue = "Button1";
103 else if (value->value<ButtonEvents::ButtonEventType>() == ButtonEvents::Preset2Button)
104 strValue = "Button2";
105 else if (value->value<ButtonEvents::ButtonEventType>() == ButtonEvents::Preset3Button)
106 strValue = "Button3";
107 else if (value->value<ButtonEvents::ButtonEventType>() == ButtonEvents::Preset4Button)
108 strValue = "Button4";
111 string cmdline = findReplace(app,"%1",strValue);
112 GError* error = NULL;
114 if(!g_spawn_command_line_async(cmdline.c_str(), &error))
115 DebugOut()<<"Failed to launch command: "<<cmdline<<endl;
119 void DemoSink::supportedChanged(const PropertyList & list)
121 routingEngine->subscribeToProperty(VehicleProperty::ButtonEvent, this);
122 routingEngine->subscribeToProperty(VehicleProperty::TurnSignal, this);