void Handler::dispatchMessage(const sp<Message>& message) { if (message->mCallback != NULL) { handleCallback(message); } else { handleMessage(message); } }
void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData) { PluginObject* obj = static_cast<PluginObject*>(instance->pdata); if (obj->onURLNotify) executeScript(obj, obj->onURLNotify); handleCallback(obj, url, reason, notifyData); }
// Called every frame void UMidiInterfaceComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); while (!messageQueue.IsEmpty()) { CallbackMessage message; messageQueue.Dequeue(message); handleCallback(message.deltaTime, &message.message); } }
void Handler::dispatchMessage(const sp<Message>& msg) { if (msg->callback != nullptr) { handleCallback(msg); } else { if (mCallback != nullptr) { if (mCallback->handleMessage(msg)) { return; } } handleMessage(msg); } }
/*------------------------------------------------------------------------ * resched_lab1 - Reschedule processor to highest priority eligible process *------------------------------------------------------------------------ */ void resched_lab1(void) /* Assumes interrupts are disabled */ { struct procent *ptold; /* Ptr to table entry for old process */ struct procent *ptnew; /* Ptr to table entry for new process */ /* If rescheduling is deferred, record attempt and return */ if (Defer.ndefers > 0) { Defer.attempt = TRUE; return; } /* Point to process table entry for the current (old) process */ ptold = &proctab[currpid]; if (ptold->prstate == PR_CURR) { /* Process remains eligible */ if (ptold->prprio > firstkey(readylist)) { return; } /* Old process will no longer remain current */ ptold->prstate = PR_READY; insert(currpid, readylist, ptold->prprio); } /* Force context switch to highest priority ready process */ currpid = dequeue(readylist); ptnew = &proctab[currpid]; ptnew->prstate = PR_CURR; preempt = QUANTUM; /* Reset time slice for process */ ctxsw(&ptold->prstkptr, &ptnew->prstkptr); // LAB 4Q3: Invoke the handleCallback handleCallback(); /* Old process returns here when resumed */ return; }
size_t SimGSM::recv() { unsigned long timeout = millis() + _first_time; _buf_size = 0; while (millis() < timeout) { if (_serial->available()) { _buf[_buf_size++] = _serial->read(); if (_intra_time > 0) timeout = millis() + _intra_time; if (_buf_size >= GSM_BUFFER_SIZE) break; } } _buf[_buf_size] = 0; #ifdef ECHO_ENABLED if (_buf_size > 0) console.write((byte *) _buf, _buf_size); #endif handleCallback(); return _buf_size; }
bool DialogManager::handleCallback(int playerid, int /* dialogid */, int response, int listitem, const std::string &inputtext) { auto iter = mPlayerDialogStacks.find(playerid); if(iter == mPlayerDialogStacks.end()) { LOG(ERROR) << "A dialog callback is called while there is no " "such a dialog or the player trigger it is disconnected."; return false; } size_t size = iter->second.size(); if(size == 0) { LOG(ERROR) << "A dialog callback is called while the player's " "dialog stack is empty"; return false; } auto top = iter->second.top().get(); bool canpop = top->handleCallback(response != 0, listitem, inputtext); /** * If oldSize != newSize after invoking handleCallback, * there must be a new dialog pushed into the stack, * therefore we should not pop the new top. */ if(canpop && size == iter->second.size()) { iter->second.pop(); } // find first dialog which wants to display while(iter->second.size() > 0) { top = iter->second.top().get(); if(top->display()) break; else iter->second.pop(); } return true; }
/* ------------------------------------------------------------------------ * resched_lab3 - Multi-feedback queue will now be the default scheduler going forward * This is the scheduler from lab3 that achieves constant time dequeue * since the size of the levels in the dispatch table is a fixed number *------------------------------------------------------------------------- */ void resched_lab3(void) { uint32 currTime = clktimemsec; struct procent *ptold; /* Ptr to table entry for old process */ struct procent *ptnew; /* Ptr to table entry for new process */ /* If rescheduling is deferred, record attempt and return */ if (Defer.ndefers > 0) { Defer.attempt = TRUE; return; } /* Point to process table entry for the current (old) process */ uint32 addToTotalTime =0; /* Point to process table entry for the current (old) process */ ptold = &proctab[currpid]; //Update the total processing time for context switched out process // Handle the case where the counter overflows then get the absolute value of difference addToTotalTime = (currTime)-(ptold->prctxswintime); ptold->prcpumsec = ptold->prcpumsec + addToTotalTime; ptold = &proctab[currpid]; pri16 oldprio = ptold->prprio; if (ptold->prstate == PR_CURR) { // update the priority based on TS dispatch table values for active process's time quantum expiration scenario pri16 oldprio = ptold->prprio; int timegiven = tsdtab[oldprio].ts_quantum; if(currpid != 0) { ptold->prprio = tsdtab[oldprio].ts_tqexp; } // cpu- intensive process if(currproc_eligible()) // check eligibility of current process to get another quantum { ptold->prctxswintime = currTime; return; } else { // current process will be switched out // enqueu at correct location for when next time it may be selected // by scheduler it will be at correct level on multi-level feedback queue. ptold->prstate = PR_READY; enqueue(currpid, queueArr[ptold->prprio]); } } else if (ptold->prstate == PR_SLEEP) { // io- intensive process // update the priority based on TS dispatch table values for sleep return if(currpid != 0) ptold->prprio = tsdtab[ptold->prprio].ts_slpret; } /* Force context switch to highest priority ready process */ currpid = multifeedbackDQ(); ptnew = &proctab[currpid]; ptnew->prstate = PR_CURR; ptnew->prctxswintime = currTime; preempt = tsdtab[ptnew->prprio].ts_quantum; /* Reset time slice for process */ ctxsw(&ptold->prstkptr, &ptnew->prstkptr); // LAB 4Q3: Invoke the handleCallback handleCallback(); /* Old process returns here when resumed */ return; }
/*------------------------------------------------------------------------ * resched_lab2 - fair scheduler from lab2, need to set lab2flag according to specs * given in lab2 documentation on 503 course website. *------------------------------------------------------------------------ */ void resched_lab2(void) { uint32 currTime = clktimemsec; struct procent *ptold; /* Ptr to table entry for old process */ struct procent *ptnew; /* Ptr to table entry for new process */ /* If rescheduling is deferred, record attempt and return */ if (Defer.ndefers > 0) { Defer.attempt = TRUE; return; } uint32 addToTotalTime =0; /* Point to process table entry for the current (old) process */ ptold = &proctab[currpid]; //Update the total processing time for context switched out process // Handle the case where the counter overflows then get the absolute value of difference addToTotalTime = (currTime)-(ptold->prctxswintime); // if the old process id is not of null user then update its total CPU time // else ignore this step because prcpumsec of null user is already set to max to // force it to only execute if no other process is ready if(currpid != 0) ptold->prcpumsec = ptold->prcpumsec + addToTotalTime; // totest switches the key for the readylist queue to be tested based on the lab we are running. // For the lab3, its the priority of the process // and for lab 4 and 5 it's the prcpumsec, the cpu time given to the process int32 totest = ptold->prprio; // Here the totest will be set to the negation of prcpumsec // because we wan't to maintain using the insert function that // inserts elements in decreasing order. By this negation of prcpumsec would // cause the element with the least prcpumsec to be the first to be dequeud at the head. // Hence, we are followin the rules of the dynamic priority scheduling algorithm if(lab2flag == 4 || lab2flag == 5) totest =-(int32)ptold->prcpumsec; if (ptold->prstate == PR_CURR) { /* Process remains eligible */ if (totest > firstkey(readylist)) { ptold->prctxswintime = currTime; if(lab2flag ==5) reward_ready_waiting(); return; } /* Old process will no longer remain current */ if(lab2flag == 5) reward_ready_waiting(); ptold->prstate = PR_READY; // The only other place an insert happens is at the ready method // even there we have chosen to implement a similar strategy of choosing the value // of key based on the lab that we are dealing with. That is, either to insert // based on priority or the negation of the prcpumsec spent. insert(currpid, readylist, totest); currpid = dequeue(readylist); } else { //even if the process is in sleep state and calling a reschedule // we must reward the other processes // of course, as soon as the process that is dequeued is removed its key value // would also if(lab2flag ==5) reward_ready_waiting(); currpid = dequeue(readylist); } /* Force context switch to highest priority ready process */ ptnew = &proctab[currpid]; ptnew->prstate = PR_CURR; preempt = QUANTUM; /* Reset time slice for process */ //Update the context switch-in time for new process ptnew->prctxswintime = currTime; ctxsw(&ptold->prstkptr, &ptnew->prstkptr); // LAB 4Q3: Invoke the handleCallback handleCallback(); /* Old process returns here when resumed */ return; }
void Player::OnQueueNextItem() { TRACE; handleCallback(new CallbackFunction<Player>(this,&Player::onQueueNextItem)); }
void Player::OnPlayBackResumed() { TRACE; handleCallback(new CallbackFunction<Player>(this,&Player::onPlayBackResumed)); }