Addition of test plugin to test Map and List types, and Map and List fromVariant...
[profile/ivi/automotive-message-broker.git] / plugins / testplugin / testplugin.cpp
1 /*
2         Copyright (C) 2012  Intel Corporation
3
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.
8
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.
13
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
17 */
18
19
20 #include <iostream>
21 #include <boost/assert.hpp>
22 #include <boost/lexical_cast.hpp>
23 #include <glib.h>
24 #include <sstream>
25 //#include <json-glib/json-glib.h>
26 #include <listplusplus.h>
27 #include "debugout.h"
28 #include "timestamp.h"
29 #include "testplugin.h"
30 #define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
31 AbstractRoutingEngine *m_re;
32
33 //std::list<ObdPid*> Obd2Amb::supportedPidsList;
34
35 bool beginsWith(std::string a, std::string b)
36 {
37         return (a.compare(0, b.length(), b) == 0);
38 }
39 void TestPlugin::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value)
40 {
41
42 }
43
44 void TestPlugin::setSupported(PropertyList list)
45 {
46         m_re->updateSupported(list,PropertyList());
47 }
48 void TestPlugin::setConfiguration(map<string, string> config)
49 {
50 //      //Config has been passed, let's start stuff up.
51 }
52
53 TestPlugin::TestPlugin(AbstractRoutingEngine *re, map<string, string> config)
54         : AbstractSource(re, config)
55 {
56   DebugOut() << "Testing MapPropertyType" << endl;
57   MapPropertyType<BasicPropertyType<Door::Location>,BasicPropertyType<Door::Status>> propmap("something");
58   MapPropertyType<BasicPropertyType<Door::Location>,BasicPropertyType<Door::Status>> propmaptwo("something");
59   propmap.append(Door::LeftRear,Door::Ajar);
60   GVariant *var = propmap.toVariant();
61   gsize dictsize = g_variant_n_children(var);
62   //DebugOut() << var << endl;
63   propmaptwo.fromVariant(var);
64   DebugOut() << propmap.toString() << propmaptwo.toString() << endl;
65   if (propmap.toString() == propmap.toString())
66   {
67       DebugOut() << "Success!" << endl;
68   }
69   else
70   {
71       DebugOut() << "Failure" << endl;
72       exit(-1);
73   }
74   /*
75   DebugOut() << "Testing ListPropertyType" << endl;
76   ListPropertyType<BasicPropertyType<uint16_t> > listpropmap("something");
77   ListPropertyType<BasicPropertyType<uint16_t> > listpropmaptwo("something");
78   //listpropmap.append(new VehicleProperty::AccelerationXType());
79   //listpropmap.append(new VehicleProperty::MachineGunTurretStatusType());
80   listpropmap.append(new AbstractPropertyType<VehicleProperty::TripMeters>());
81   GVariant *newvar = listpropmap.toVariant();
82   DebugOut() << "Newvar created" << endl;
83   listpropmaptwo.fromVariant(newvar);
84   DebugOut() << listpropmap.toString() << listpropmaptwo.toString() << endl;
85   if (listpropmap.toString() == listpropmaptwo.toString())
86   {
87       DebugOut() << "Success!" << endl;
88   }
89   else
90   {
91       DebugOut() << "Failure" << endl;
92       exit(-1);
93   }*/
94     
95   DebugOut() << "Exiting..." << endl;
96   exit(-1);
97 }
98 TestPlugin::~TestPlugin()
99 {
100         DebugOut() << "TestPlugin Destructor called!!!"<<endl;
101 }
102
103 PropertyList TestPlugin::supported()
104 {
105         return PropertyList();
106 }
107
108 int TestPlugin::supportedOperations()
109 {
110         return Get | Set;
111 }
112
113 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
114 {
115         return new TestPlugin(routingengine, config);
116         
117 }
118 string TestPlugin::uuid()
119 {
120         return "f77af740-f1f8-11e1-aff1-0800200c9a66";
121 }
122 void TestPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
123 {
124 }
125
126
127 void TestPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
128 {
129 }
130
131
132 void TestPlugin::getPropertyAsync(AsyncPropertyReply *reply)
133 {
134         
135 }
136
137 AsyncPropertyReply *TestPlugin::setProperty(AsyncSetPropertyRequest request )
138 {
139         AsyncPropertyReply* reply = new AsyncPropertyReply (request);
140         return reply;
141 }