TEST_F(LedgerUnitTest, testAppendSystemDecreeIncrementsTheSize) { std::stringstream ss; auto queue = std::make_shared<paxos::RolloverQueue<paxos::Decree>>(ss); paxos::Ledger ledger(queue); ASSERT_EQ(GetQueueSize(queue), 0); ledger.Append(paxos::Decree(paxos::Replica("an_author"), 1, "decree_contents", paxos::DecreeType::AddReplicaDecree)); ASSERT_EQ(GetQueueSize(queue), 1); }
void ProcessData(){ while(GetQueueSize() >= 3){ if(DeQueue() == startByte){ // byte1 = DeQueue(); // byte2 = DeQueue(); byte1 = 0; byte2 = 0; if(byte1 != currentDir){ currentDir = byte1; TB0CCR1 = 0; TB0CCR2 = 0; TB1CCR1 = 0; TB1CCR2 = 0; } if(byte1 == 1){ TB0CCR1 = (byte2/100.0)*(TB0CCR0); TB1CCR1 = TB0CCR1; }else if(byte1 == 2){ TB0CCR2 = (byte2/100.0)*(TB0CCR0); TB1CCR2 = TB0CCR2; } } } }
/** @brief Identify Cluster Identify Query Response * * * * @param timeout Ver.: always */ boolean emberAfIdentifyClusterIdentifyQueryResponseCallback(int16u timeout) { // TODO: !!! IMPORTANT !!! add handling for several responses // now the state machine might be broken as we use only one global variable // for storing incoming connection information like Short ID and endpoint // // ignore broadcasts from yourself and from devices that are not // in the identifying state const EmberAfClusterCommand *const current_cmd = emberAfCurrentCommand(); if (emberAfGetNodeId() != current_cmd->source && timeout != 0) { emberAfDebugPrintln("DEBUG: Got ID Query response"); emberAfDebugPrintln("DEBUG: Sender 0x%2X", emberAfCurrentCommand()->source); // Queue is empty, so we can start commissioning process // otherwise we push it in the queue and will process later if (GetQueueSize() == 0) { // ID Query received -> go to the discover state for getting clusters info emberAfDebugPrintln("DEBUG: QUEUE IS EMPTY"); SetNextState(SC_EZ_DISCOVER); SetNextEvent(SC_EZEV_CHECK_CLUSTERS); emberEventControlSetActive(StateMachineEvent); } // Store information about endpoint and short ID of the incoming response // for further processing in the Matching (SC_EZ_MATCH) state SetInConnBaseInfo(current_cmd->source, current_cmd->apsFrame->sourceEndpoint); emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS); } return TRUE; }
bool CWinEventsAndroid::MessagePump() { bool ret = false; // Do not always loop, only pump the initial queued count events. else if ui keep pushing // events the loop won't finish then it will block xbmc main message loop. for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) { // Pop up only one event per time since in App::OnEvent it may init modal dialog which init // deeper message loop and call the deeper MessagePump from there. XBMC_Event pumpEvent; { CSingleLock lock(m_eventsCond); if (m_events.empty()) return ret; pumpEvent = m_events.front(); m_events.pop_front(); } ret |= g_application.OnEvent(pumpEvent); if (pumpEvent.type == XBMC_MOUSEBUTTONUP) g_windowManager.SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0); } return ret; }
bool CWinEventsAndroid::MessagePump() { bool ret = false; // Do not always loop, only pump the initial queued count events. else if ui keep pushing // events the loop won't finish then it will block xbmc main message loop. for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) { // Pop up only one event per time since in App::OnEvent it may init modal dialog which init // deeper message loop and call the deeper MessagePump from there. XBMC_Event pumpEvent; { CSingleLock lock(g_inputCond); if (events.size() == 0) return ret; pumpEvent = events.front(); events.pop_front(); } ret |= g_application.OnEvent(pumpEvent); } return ret; }
bool CWinEventsMir::MessagePump() { auto ret = GetQueueSize(); while (GetQueueSize()) { XBMC_Event e; { std::lock_guard<decltype(m_mutex)> event_lock(m_mutex); e = m_events.front(); m_events.pop(); } g_application.OnEvent(e); } return ret; }
TEST_F(LedgerUnitTest, testAppendIgnoresDuplicateDecrees) { std::stringstream ss; auto queue = std::make_shared<paxos::RolloverQueue<paxos::Decree>>(ss); paxos::Ledger ledger(queue); ledger.Append(paxos::Decree(paxos::Replica("a_author"), 1, "a_content", paxos::DecreeType::UserDecree)); ledger.Append(paxos::Decree(paxos::Replica("a_author"), 1, "a_content", paxos::DecreeType::UserDecree)); ASSERT_EQ(GetQueueSize(queue), 1); }
TEST_F(LedgerUnitTest, testAppendWritesOutOfOrderDecreeWithOrderedRoot) { std::stringstream ss; auto queue = std::make_shared<paxos::RolloverQueue<paxos::Decree>>(ss); paxos::Ledger ledger(queue); paxos::Decree current_decree(paxos::Replica("a_author"), 2, "a_content", paxos::DecreeType::UserDecree); current_decree.root_number = 1; ledger.Append(current_decree); paxos::Decree next_decree(paxos::Replica("a_author"), 1, "a_content", paxos::DecreeType::UserDecree); next_decree.root_number = 2; ledger.Append(next_decree); ASSERT_EQ(GetQueueSize(queue), 2); }
static CommissioningState_t CheckQuery(void) { emberAfDebugPrintln("DEBUG: Check query"); CommissioningState_t next_st = SC_EZ_UNKNOWN; if (GetQueueSize() != 0) { SetNextEvent(SC_EZEV_CHECK_CLUSTERS); next_st = SC_EZ_DISCOVER; } else { SetNextEvent(SC_EZEV_QUEUE_EMPTY); next_st = SC_EZ_BIND; } emberEventControlSetActive(StateMachineEvent); return next_st; }
int _tmain(int argc, _TCHAR* argv[]) { HANDLE h = open_device(CAN_BAUD_500K,0); SFFMessage *msg = NULL; int num_network = 0; while(1) { num_network = GetQueueSize(h, CAN_GET_SFF_SIZE); printf("%d\n", num_network); msg = read_message(h); } // SFFMessage sff[4]; // SFFMessage *cur = sff; // // memset(sff, 0, 4 * sizeof(SFFMessage)); // // DbgLineToSFF("IDH: 01, IDL: 67, Len: 08, Data: 00 60 00 00 00 00 00 69", cur++); // DbgLineToSFF("IDH: 01, IDL: 68, Len: 08, Data: 00 60 00 00 00 00 00 00", cur++); // DbgLineToSFF("IDH: 01, IDL: 69, Len: 08, Data: 41 41 41 41 41 41 41 41", cur++); // // cur = sff; //// write_messages(h, &cur); //// PrintSFF(&sff[2], NULL); // cur = read_message(h); //// cur = read_message_by_wid(h, 0x80); // PrintSFF(cur, NULL); // //// write_message(h, cur); //// write_messages_from_file(h, "..\\test.dat"); // // close_device(h); return 0; }
// WCWeightFairQueuer: function called by the classifier to enqueue // the packets.. // TODO: Debug this function... void *weightedFairScheduler(void *pc) { pktcore_t *pcore = (pktcore_t *)pc; List *keylst; int nextqid, qcount, rstatus, pktsize; char *nextqkey; gpacket_t *in_pkt; simplequeue_t *nextq; long queueSizes[100]; //Array to store bytes sent for each queue id int PacketsSent[10]; int i, j;//To iterate through the queue length array long crtStarvedQid; double crtStarvedQidWeight; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); while (1) { verbose(1, "[weightedFairScheduler]:: Weighted Fair Queue schedule processing... "); keylst = map_keys(pcore->queues); qcount = list_length(keylst); pthread_mutex_lock(&(pcore->qlock)); if (pcore->packetcnt == 0) pthread_cond_wait(&(pcore->schwaiting), &(pcore->qlock)); pthread_mutex_unlock(&(pcore->qlock)); pthread_testcancel(); for(i = 0; i <qcount; i++) { nextqkey = list_item(keylst, i); // get the queue.. nextq = map_get(pcore->queues, nextqkey); if(GetQueueSize(nextq) > 0) { crtStarvedQidWeight = (queueSizes[i] / (nextq->weight) ); //TODO crtStarvedQid = i; break; } } if(i == qcount) { list_release(keylst); usleep(rconfig.schedcycle); continue; } for(j = i; j < qcount; j++) { nextqkey = list_item(keylst, j); // get the queue.. nextq = map_get(pcore->queues, nextqkey); if(( (queueSizes[j] / (nextq->weight)) < crtStarvedQidWeight) && (GetQueueSize(nextq) > 0)) //TODO { crtStarvedQid = j; crtStarvedQidWeight = queueSizes[j] / (nextq->weight) ; //TODO } } nextqid = crtStarvedQid; nextqkey = list_item(keylst, nextqid); // get the queue.. nextq = map_get(pcore->queues, nextqkey); // read the queue.. rstatus = readQueue(nextq, (void **)&in_pkt, &pktsize);//Here we get the packet size. if (rstatus == EXIT_SUCCESS) { writeQueue(pcore->workQ, in_pkt, pktsize); verbose(1, "[weightedFairScheduler---Just sent]:: Queue[%d] has now sent %lu bytes", nextqid, queueSizes[nextqid]); queueSizes[nextqid] = queueSizes[nextqid] + findPacketSize(&(in_pkt->data));//Storing updated data sent in array PacketsSent[nextqid]++; } for(i = 0; i <qcount; i++) { nextqkey = list_item(keylst, i); // get the queue.. nextq = map_get(pcore->queues, nextqkey); verbose(1, "Packets Queued[%d] = %d, Bytes sent = %d, Packets Sent = %d", i, GetQueueSize(nextq), queueSizes[i], PacketsSent[i]); } list_release(keylst); pthread_mutex_lock(&(pcore->qlock)); if (rstatus == EXIT_SUCCESS) { (pcore->packetcnt)--; } pthread_mutex_unlock(&(pcore->qlock)); usleep(rconfig.schedcycle); } }
bool CWinEventsAndroid::MessagePump() { bool ret = false; // Do not always loop, only pump the initial queued count events. else if ui keep pushing // events the loop won't finish then it will block xbmc main message loop. for (size_t pumpEventCount = GetQueueSize(); pumpEventCount > 0; --pumpEventCount) { // Pop up only one event per time since in App::OnEvent it may init modal dialog which init // deeper message loop and call the deeper MessagePump from there. XBMC_Event pumpEvent; { CSingleLock lock(m_eventsCond); if (m_events.empty()) return ret; pumpEvent = m_events.front(); m_events.pop_front(); #if DEBUG_MESSAGEPUMP CLog::Log(LOGDEBUG, " pop event, size(%d), fvalue(%f)", m_events.size(), pumpEvent.jaxis.fvalue); #endif } if ((pumpEvent.type == XBMC_JOYBUTTONUP) || (pumpEvent.type == XBMC_JOYBUTTONDOWN) || (pumpEvent.type == XBMC_JOYAXISMOTION) || (pumpEvent.type == XBMC_JOYHATMOTION)) { int item; int type; uint32_t holdTime; APP_InputDevice input_device; float amount = 1.0f; short input_type; type = pumpEvent.type; switch (type) { case XBMC_JOYAXISMOTION: // The typical joystick keymap xml has the following where 'id' is the axis // and 'limit' is which action to choose (ie. Up or Down). // <axis id="5" limit="-1">Up</axis> // <axis id="5" limit="+1">Down</axis> // One would think that limits is in reference to fvalue but // it is really in reference to id :) The sign of item passed // into ProcessJoystickEvent indicates the action mapping. item = pumpEvent.jaxis.axis; if (fabs(pumpEvent.jaxis.fvalue) < ALMOST_ZERO) amount = 0.0f; else if (pumpEvent.jaxis.fvalue < 0.0f) item = -item; holdTime = 0; input_device.id = pumpEvent.jaxis.which; input_type = JACTIVE_AXIS; break; case XBMC_JOYHATMOTION: item = pumpEvent.jhat.hat | 0xFFF00000 | (pumpEvent.jhat.value<<16); holdTime = 0; input_device.id = pumpEvent.jhat.which; input_type = JACTIVE_HAT; break; case XBMC_JOYBUTTONUP: case XBMC_JOYBUTTONDOWN: item = pumpEvent.jbutton.button; holdTime = pumpEvent.jbutton.holdTime; input_device.id = pumpEvent.jbutton.which; input_type = JACTIVE_BUTTON; break; } // look for device name in our inputdevice cache // so we can lookup and match the right joystick.xxx.xml for (size_t i = 0; i < m_input_devices.size(); i++) { if (m_input_devices[i].id == input_device.id) input_device.name = m_input_devices[i].name; } if (input_device.name.empty()) { // not in inputdevice cache, fetch and cache it. CJNIViewInputDevice view_input_device = CJNIViewInputDevice::getDevice(input_device.id); input_device.name = view_input_device.getName(); CLog::Log(LOGDEBUG, "CWinEventsAndroid::MessagePump:caching id(%d), device(%s)", input_device.id, input_device.name.c_str()); m_input_devices.push_back(input_device); } if (type == XBMC_JOYAXISMOTION || type == XBMC_JOYHATMOTION) { // Joystick autorepeat -> only handle axis CSingleLock lock(m_lasteventCond); m_lastevent.push(pumpEvent); } if (fabs(amount) >= ALMOST_ZERO) { ret |= CInputManager::GetInstance().ProcessJoystickEvent(g_windowManager.GetActiveWindowID(), input_device.name, item, input_type, amount, holdTime); } } else { ret |= g_application.OnEvent(pumpEvent); } if (pumpEvent.type == XBMC_MOUSEBUTTONUP) g_windowManager.SendMessage(GUI_MSG_UNFOCUS_ALL, 0, 0, 0, 0); } return ret; }
void FindPath(PathFinder* pf) { //printf("(%d, %d) -> (%d, %d)\t", pf->startx, pf->starty, pf->endx, pf->endy); for (int i = 0; i < pf->map->width; i++) { for (int e = 0; e < pf->map->height; e++) { pf->nodeMap[i][e].f = 0; pf->nodeMap[i][e].g = 0; pf->nodeMap[i][e].h = 0; pf->nodeMap[i][e].open = NoList; pf->nodeMap[i][e].parent = NULL; } } DeleteQueue(pf->openList); pf->openList = CreateQueue(nodeMinCompare, pf->map->width * pf->map->height); int x = pf->startx; int y = pf->starty; // Step 1: Add starting node to the open list. AddOpen(pf, x, y, NULL); // Step 2: Repeat // If there's nothing in the open list anymore or we arrive at the destination, stop while (GetQueueSize(pf->openList) > 0) { //printf("%d ", GetQueueSize(pf->openList)); // a) Look for the lowest F cost square on the open list. Node* current = (Node*)QueueRemove(pf->openList); x = current->x; y = current->y; // b) Switch it to the closed list. current->open = OnClosedList; // c) For each of the 8 squares adjacent to this current square, attempt to add it // to the open list. // AddOpen checks for adjacent-validity and whether the node is a wall or not. AddOpen(pf, x - 0, y - 1, current); AddOpen(pf, x - 0, y + 1, current); AddOpen(pf, x - 1, y - 0, current); AddOpen(pf, x + 1, y - 0, current); // Diagonal Check if (pf->allowDiagonal) { AddOpen(pf, x - 1, y - 1, current); AddOpen(pf, x + 1, y - 1, current); AddOpen(pf, x - 1, y + 1, current); AddOpen(pf, x + 1, y + 1, current); } // Are we done? if (x == pf->endx && y == pf->endy && pf->nodeMap[pf->endx][pf->endy].open == OnClosedList) { // Step 3: Save Path DeletePath(pf); SavePath(pf, current); /* PathNode* p = pf->path; if (p == NULL) printf(" No Path?"); while (p) { printf("(%p) %d, %d", p, p->x, p->y); p = p->parent; } */ break; } } printf("Pathfinding done\n"); }