MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / mainLoop

Method mainLoop

src/server/lcdapi/api/LCDClient.cpp:225–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225void LCDClient::mainLoop()
226{
227 ::pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
228 string reply;
229 while(true)
230 {
231 _serverConnection >> reply;
232
233 if ( (0 == reply.find("huh?")) || (0 == reply.compare("success")) )
234 {
235 //const LCDLock l(&_sendMutex);
236 _answer = reply;
237 ::pthread_cond_signal(&_gotAnswer);
238 }
239 else
240 {
241 if (0 == reply.find("key"))
242 {
243 const KeyEvent key(reply.substr(4, string::npos));
244 if (_callbacks.end() != _callbacks.find(key))
245 {
246 KeyEventInfo *kevI = new KeyEventInfo;
247 kevI->kev = key;
248 kevI->callback = _callbacks[key];
249
250 ::pthread_t tid;
251 ::pthread_create(&tid, 0, &handleKeyEvent, kevI);
252 }
253
254 }
255 else if (0 == reply.find("listen"))
256 {
257 _currentScreen = reply.substr(7);
258 }
259 else if (0 == reply.find("ignore"))
260 {
261 if (_currentScreen == reply.substr(7))
262 {
263 _currentScreen.clear();
264 }
265 }
266 else if (0 == reply.find("menuevent"))
267 {
268 istringstream response(reply.substr(10));
269 string menu_event;
270 string menu_id;
271 string value; // N.B. Not for all event types
272 response >> menu_event >> menu_id >> value;
273
274 // Invoke handler, if we have one.
275 const MenuEventHandlerMap::const_iterator iter =
276 _handlers.find(menu_id);
277 if (_handlers.end() != iter) {
278 const map<string, LCDMenuEventHandler*>& menu_handlers =
279 iter->second;
280 if (menu_handlers.end() != menu_handlers.find(menu_event)) {
281 LCDMenuEventHandler* handler = _handlers[menu_id][menu_event];
282 if (NULL != handler) {

Callers 1

mainRepliesLoopFunction · 0.80

Calls 3

findMethod · 0.45
endMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected