MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / triggerEvent

Function triggerEvent

modules/drivers/w3csensor/sensor.c:390–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388}
389
390void triggerEvent(xsSensor sensor, uint8_t eventKind, const char *errorMsg)
391{
392 xsMachine *the = sensor->the;
393 EventHandler handler, prev;
394
395 xsmcVars(2);
396
397 sensor->servicing = true;
398 for (handler = sensor->handlers; NULL != handler; handler = handler->next)
399 handler->service = true;
400
401again:
402 for (handler = sensor->handlers; NULL != handler; handler = handler->next) {
403 if ((eventKind != (handler->eventKind & kEventKindMask)) || !handler->service)
404 continue;
405
406 handler->service = false;
407
408 xsTry {
409 xsmcSetNewObject(xsVar(0));
410 if (kEventKindReading == eventKind)
411 xsmcSetString(xsVar(1), "reading");
412 else if (kEventKindActivate == eventKind)
413 xsmcSetString(xsVar(1), "activate");
414 if (kEventKindError == eventKind)
415 xsmcSetString(xsVar(1), "error");
416 xsmcDefine(xsVar(0), xsID_type, xsVar(1), xsDontDelete | xsDontSet);
417
418 xsmcSetNumber(xsVar(1), sensor->timestamp);
419 xsmcDefine(xsVar(0), xsID_timeStamp, xsVar(1), xsDontDelete | xsDontSet);
420
421 if (errorMsg) {
422 xsmcSetString(xsVar(1), (char *)errorMsg);
423 xsVar(1) = xsNew1(xsGlobal, xsID_Error, xsVar(1));
424 xsmcSet(xsVar(0), xsID_error, xsVar(1));
425 }
426
427 xsResult = xsReference(handler->reference);
428 if (kHandlerKindFunction == handler->handlerKind)
429 xsCallFunction1(xsResult, sensor->obj, xsVar(0));
430 else
431 xsCall1(xsResult, xsID_handleEvent, xsVar(0));
432 }
433 xsCatch {
434 }
435 goto again;
436 }
437
438again2:
439 for (handler = sensor->handlers, prev = NULL; NULL != handler; prev = handler, handler = handler->next) {
440 handler->service = false;
441 if (handler->removed) {
442 if (prev)
443 prev->next = handler->next;
444 else
445 sensor->handlers = handler->next;
446
447 c_free(handler);

Callers 2

readSensorFunction · 0.85
triggerErrorEventFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected