remove hard coded path into CMake files
[profile/ivi/ico-vic-amb-plugin.git] / src / viccommunicator.cc
1 /**
2  * Copyright (C) 2012  TOYOTA MOTOR 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 #include <string.h>
20
21 #include "debugout.h"
22
23 #include "ambinterface.h"
24 #include "convert.h"
25 #include "messageformat.h"
26 #include "mwinterface.h"
27 #include "viccommunicator.h"
28
29 VICCommunicator::VICCommunicator()
30 {
31 }
32
33 VICCommunicator::~VICCommunicator()
34 {
35 }
36
37 bool
38 VICCommunicator::initialize(AMBIF *amb, MWIF *mw, Converter *conv)
39 {
40     converter = conv;
41     ambif = amb;
42     mwif = mw;
43     return true;
44 }
45
46 void
47 VICCommunicator::setAMBVehicleInfo(MWVehicleInfo *vehicleinfo)
48 {
49     AMBVehicleInfo ambvehicleinfo[maxambdatasize];
50     DebugOut(8) << "VICCOMM" << " in setAMBVehicleInfo(" << vehicleinfo->name
51                 << ")" << " status[0] = " << vehicleinfo->status[0] << "\n";
52     resetAmbBuf(&ambvehicleinfo[0], maxambdatasize);
53     int ret = converter->convertMWtoAMB(vehicleinfo, &ambvehicleinfo[0],
54                                         maxambdatasize);
55     for (int i = 0; i < ret; i++) {
56         ambif->requestUpdate(&ambvehicleinfo[i]);
57         DebugOut(8) << "VICCOMM" << " out setAMBVehicleInfo(AMBname = "
58                     << ambvehicleinfo[i].name << ","
59                     << ambvehicleinfo[i].value->toString() << ")\n";
60     }
61     for (int i = 0; i < maxambdatasize; i++) {
62         if (ambvehicleinfo[i].value != NULL) {
63             delete ambvehicleinfo[i].value;
64         }
65     }
66     DebugOut(10) << "VICCOMM" << " out setAMBVehicleInfo(MWname = "
67             << vehicleinfo->name << ")\n";
68 }
69
70 void
71 VICCommunicator::getAMBVehicleInfo(MWVehicleInfo *vehicleinfo)
72 {
73     AMBVehicleInfo *ambvehicleinfo[maxambdatasize];
74     AMBVehicleInfo tempambvehicleinfo[maxambdatasize];
75
76     DebugOut(8) << "VICCOMM" << " in getAMBVehicleInfo(" << vehicleinfo->name
77                 << "," << vehicleinfo->status[0] << ")\n";
78     resetAmbBuf(&tempambvehicleinfo[0], maxambdatasize);
79     int ret = converter->convertMWtoAMB(vehicleinfo, &tempambvehicleinfo[0],
80                                         maxambdatasize);
81     for (int i = 0; i < ret; i++) {
82         delete tempambvehicleinfo[i].value;
83         ambvehicleinfo[i] = ambif->getPropertyRequest(
84                 tempambvehicleinfo[i].name);
85         DebugOut(8) << "VICCOMM" << " getAMBVehicleInfo(AMBname = "
86                     << ambvehicleinfo[i]->name << ","
87                     << ambvehicleinfo[i]->value->toString() << ")\n";
88         converter->convertAMBtoMW(ambvehicleinfo[i], vehicleinfo);
89     }
90     DebugOut(8) << "VICCOMM" << " out getAMBVehicleInfo(MWname = "
91                 << vehicleinfo->name << "," << vehicleinfo->status[0] << ")\n";
92 }
93
94 void
95 VICCommunicator::setMWVehicleInfo(AMBVehicleInfo *vehicleinfo)
96 {
97     MWVehicleInfo mwvehicleinfo;
98     DebugOut(8) << "VICCOMM" << " in setMWVehicleInfo(AMBname = "
99                 << vehicleinfo->name << "," << vehicleinfo->value->toString()
100                 << ")\n";
101     resetMwBuf(&mwvehicleinfo);
102     converter->convertAMBtoMW(vehicleinfo, &mwvehicleinfo);
103     mwif->send(&mwvehicleinfo);
104     DebugOut(8) << "VICCOMM" << " out setMWVehicleInfo(MWname = "
105                 << mwvehicleinfo.name << "," << mwvehicleinfo.status[0] << ")\n";
106 }
107
108 void
109 VICCommunicator::getMWVehicleInfo(AMBVehicleInfo *vehicleinfo)
110 {
111     /* don't use */
112 }
113
114 void
115 VICCommunicator::resetAmbBuf(AMBVehicleInfo *vehicleinfo, size_t len)
116 {
117     for (int i = 0; i < static_cast<int>(len); i++) {
118         vehicleinfo[i].name = "";
119         vehicleinfo[i].value = NULL;
120         vehicleinfo[i].isCustom = false;
121     }
122 }
123
124 void
125 VICCommunicator::resetMwBuf(MWVehicleInfo *vehicleinfo)
126 {
127     vehicleinfo->name = "";
128     vehicleinfo->recordtime.tv_sec = 0;
129     vehicleinfo->recordtime.tv_usec = 0;
130     memset(vehicleinfo->status, 0, STATUSSIZE);
131 }