virtual void applicationStep() { // run VM AsebaVMRun(&vm, 65535); // reschedule a periodic event if we are not in step by step if (AsebaMaskIsClear(vm.flags, ASEBA_VM_STEP_BY_STEP_MASK) || AsebaMaskIsClear(vm.flags, ASEBA_VM_EVENT_ACTIVE_MASK)) AsebaVMSetupEvent(&vm, ASEBA_EVENT_LOCAL_EVENTS_START-0); }
void SimpleDashelConnection::incomingData(Dashel::Stream *stream) { // if we receive data from an old connection, disregard as we'll close the old stream soon if (stream != this->stream) { // read one byte to avoid deadlock char c; stream->read(&c, 1); return; } try { // receive data uint16_t temp; uint16_t len; stream->read(&temp, 2); len = bswap16(temp); stream->read(&temp, 2); lastMessageSource = bswap16(temp); lastMessageData.resize(len+2); stream->read(&lastMessageData[0], lastMessageData.size()); // execute event on all VM that are linked to this connection for (auto vmStateToEnvironmentKV: vmStateToEnvironment) { if (vmStateToEnvironmentKV.second.second == this) { AsebaProcessIncomingEvents(vmStateToEnvironmentKV.first); AsebaVMRun(vmStateToEnvironmentKV.first, 1000); } } } catch (Dashel::DashelException e) { SEND_NOTIFICATION(LOG_ERROR, "cannot read from socket", stream->getTargetName(), e.what()); } }