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>
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;
49 * This class manages the vehicle information to be notified to MW.
54 * Conditions of vehicle information changes notification.
59 char mask[STATUSSIZE];
71 * This function registers the change notifiction contitions.
73 * @param name The name of vehicle information of MW
74 * @param interval Transmission interval change notification.
75 * @param sense Information to detect.
76 * @param mask For change detection mask.
77 * @return Success : true Failure : false
80 insert(std::string name, int interval, int sense, char *mask);
82 * This function removes the notification conditions.
84 * @param name The name of vehicle information of MW.
85 * @param mask For change detection mask.
86 * @return Success : true Failure : false
89 erase(std::string name, char *mask);
91 * This function removes the all notification conditions with a matching name.
93 * @param name The name of vehicle information of MW.
94 * @return Success : true Failure : false
97 eraseAllMask(std::string name);
99 * This function will check whether the vehicle information is applicable to the notification conditions.
100 * If applicable, update the internal table.
102 * @param name The name of vehicle information of MW.
103 * @param olddata Value before the change.
104 * @param newdata Value after the change.
105 * @param newtime Time after the change.
106 * @return Success : true Failure : false
109 checkNotify(std::string name, char *olddata, char *newdata,
113 NORMAL, ALLNAME, ALLCOMMID, ALLDATA
115 std::map<std::string, std::vector<NotifyOpt> > notifyMap;
116 char nochangemask[STATUSSIZE];
117 pthread_mutex_t mutex;
121 * Interface of MW and Plugin.
136 * @param comm Instance of VICCommunicator.
137 * @param conf Instance of Config.
138 * @return Success : true Failure : false
141 initialize(VICCommunicator *com, Config *conf);
143 * This function issues a request to send vehicle information to the MW.
145 * @param vehicleinfo Vehicle information of MW.
148 send(MWVehicleInfo *vehicleinfo);
150 * This function distributes the incoming mesage from the MW.
152 * @param commid socket id.
153 * @param keyeventtype The name of vehicle information of MW.
154 * @param recordtime Time of the message.
155 * @param data Binary data other than intersection.
156 * @param len Length of the message.
159 recvRawdata(int commid, char *keyeventtype, timeval recordtime, void *data,
162 * This function is a function of the received vehicle information message.
164 * @param type Type of the received message.
165 * @param commid socket id.
166 * @param keyeventtype The name of vehicle information of MW.
167 * @param recordtime Time of the message.
168 * @param data Binary data other than intersection.
169 * @param len Length of the message.
172 recvMessage(MessageType type, int commid, char *keyeventtype,
173 timeval recordtime, void *data, size_t len);
175 * Mapping the instance and destination socket ID.
177 * @param commid Socket ID.
181 registDestination(int commid);
183 * Unmapped instances and destination socket ID.
185 * @param commid Socket ID.
188 unregistDestination(int commid);
192 sendMessage(int commid, CommonStatus status, MWVehicleInfo *vehicleinfo);
194 createThread(PortInfo *portinfo);
196 find(std::string name);
198 procSetMessage(int commid, char *keyeventtype, timeval recordtime,
199 DataOpt *data, size_t len);
201 procGetMessage(int commid, char *keyeventtype, timeval recordtime,
202 EventOpt *data, size_t len);
204 procCallbackMessage(int commid, char *keyeventtype, timeval recordtime,
205 EventOpt *data, size_t len);
207 static const int SERVERNUM = 4;
208 std::vector<MWVehicleInfo> vehicleinfoArray;
209 ControlWebsocket *websocketserver[SERVERNUM];
210 VICCommunicator *communicator;
211 std::map<int, ControlWebsocket::ServerProtocol> websocketservermap;
212 std::map<int, MWNotifyInfo> mwnotifyinfomap;
214 #endif // MWINTERFACE_H