2 * Copyright (C) 2012 TOYOTA MOTOR 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
29 #include <libwebsockets.h>
31 #include "ambconfig.h"
32 #include "controlwebsocket.h"
33 #include "messageformat.h"
35 class VICCommunicator;
38 * Vehicle information of MW
40 struct MWVehicleInfo {
43 char status[STATUSSIZE];
45 vector<int> delimeterposition;
47 bool operator==(const MWVehicleInfo& b) {
48 return (this->name == b.name);
53 * This class manages the vehicle information to be notified to MW.
58 * Conditions of vehicle information changes notification.
63 char mask[STATUSSIZE];
75 * This function registers the change notifiction contitions.
77 * @param name The name of vehicle information of MW
78 * @param interval Transmission interval change notification.
79 * @param sense Information to detect.
80 * @param mask For change detection mask.
81 * @return Success : true Failure : false
84 insert(std::string name, int interval, int sense, char *mask);
86 * This function removes the notification conditions.
88 * @param name The name of vehicle information of MW.
89 * @param mask For change detection mask.
90 * @return Success : true Failure : false
93 erase(std::string name, char *mask);
95 * This function removes the all notification conditions with a matching name.
97 * @param name The name of vehicle information of MW.
98 * @return Success : true Failure : false
101 eraseAllMask(std::string name);
103 * This function will check whether the vehicle information is applicable to the notification conditions.
104 * If applicable, update the internal table.
106 * @param name The name of vehicle information of MW.
107 * @param olddata Value before the change.
108 * @param newdata Value after the change.
109 * @param newtime Time after the change.
110 * @return Success : true Failure : false
113 checkNotify(std::string name, char *olddata, char *newdata,
117 NORMAL, ALLNAME, ALLCOMMID, ALLDATA
119 std::map<std::string, std::vector<NotifyOpt> > notifyMap;
120 char nochangemask[STATUSSIZE];
121 pthread_mutex_t mutex;
125 * Interface of MW and Plugin.
140 * @param comm Instance of VICCommunicator.
141 * @param conf Instance of Config.
142 * @return Success : true Failure : false
145 initialize(VICCommunicator *com, AMBConfig *conf);
147 * This function issues a request to send vehicle information to the MW.
149 * @param vehicleinfo Vehicle information of MW.
152 send(MWVehicleInfo *vehicleinfo);
154 * This function distributes the incoming mesage from the MW.
156 * @param commid socket id.
157 * @param keyeventtype The name of vehicle information of MW.
158 * @param recordtime Time of the message.
159 * @param data Binary data other than intersection.
160 * @param len Length of the message.
163 recvRawdata(int commid, char *keyeventtype, timeval recordtime, void *data,
166 * This function is a function of the received vehicle information message.
168 * @param type Type of the received message.
169 * @param commid socket id.
170 * @param keyeventtype The name of vehicle information of MW.
171 * @param recordtime Time of the message.
172 * @param data Binary data other than intersection.
173 * @param len Length of the message.
176 recvMessage(MessageType type, int commid, char *keyeventtype,
177 timeval recordtime, void *data, size_t len);
179 * Mapping the instance and destination socket ID.
181 * @param commid Socket ID.
185 registDestination(ControlWebsocket::ServerProtocol type, int commid);
187 * Unmapped instances and destination socket ID.
189 * @param commid Socket ID.
192 unregistDestination(ControlWebsocket::ServerProtocol type, int commid);
196 sendMessage(int commid, CommonStatus status, MWVehicleInfo *vehicleinfo);
198 createThread(PortInfo *portinfo);
200 find(std::string name);
202 procSetMessage(int commid, MWVehicleInfo *vi, char *keyeventtype, timeval recordtime,
203 DataOpt *data, size_t len);
205 procGetMessage(int commid, char *keyeventtype, timeval recordtime,
206 EventOpt *data, size_t len);
208 procCallbackMessage(int commid, char *keyeventtype, timeval recordtime,
209 EventOpt *data, size_t len);
211 static const int SERVERNUM = 4;
212 std::vector<MWVehicleInfo> vehicleinfoArray;
213 ControlWebsocket *websocketserver[SERVERNUM];
214 VICCommunicator *communicator;
215 std::map<int, ControlWebsocket::ServerProtocol> websocketservermap;
216 std::map<int, MWNotifyInfo> mwnotifyinfomap;
217 pthread_mutex_t mutex_socketmap;
219 #endif // MWINTERFACE_H