void AmSession::run() { try { try { onStart(); while (!sess_stopped.get() || (dlg.getStatus() == AmSipDialog::Disconnecting)// || // (dlg.getUACTransPending()) ){ waitForEvent(); processEvents(); DBG("%s dlg.getUACTransPending() = %i\n", dlg.callid.c_str(),dlg.getUACTransPending()); } if ( dlg.getStatus() != AmSipDialog::Disconnected ) { DBG("dlg '%s' not terminated: sending bye\n",dlg.callid.c_str()); if(dlg.bye() == 0){ while ( dlg.getStatus() != AmSipDialog::Disconnected ){ waitForEvent(); processEvents(); } } else { WARN("failed to terminate call properly\n"); } } } catch(const AmSession::Exception& e){ throw e; } catch(const string& str){ ERROR("%s\n",str.c_str()); throw AmSession::Exception(500,"unexpected exception."); } catch(...){ throw AmSession::Exception(500,"unexpected exception."); } } catch(const AmSession::Exception& e){ ERROR("%i %s\n",e.code,e.reason.c_str()); } destroy(); // wait at least until session is out of RtpScheduler DBG("session is stopped.\n"); //detached.wait_for(); }
bool EventValidator::waitForNotifyEvent(SIPX_NOTIFY_INFO* event, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_NOTIFY)) { UtlString* pString = allocNotifyEvent(event); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
int main(void) { // instantiate window GWindow window = newGWindow(320, 240); // instantiate button GButton button = newGButton("Button"); setActionCommand(button, "click"); // add button to southern region of window addToRegion(window, button, "SOUTH"); // listen for events while (true) { // wait for event GActionEvent event = waitForEvent(ACTION_EVENT); // if window was closed if (getEventType(event) == WINDOW_CLOSED) { break; } // if action command is "click" if (strcmp(getActionCommand(event), "click") == 0) { printf("button was clicked\n"); } } // that's all folks closeGWindow(window); return 0; }
bool EventValidator::waitForSubStatusEvent(SIPX_SUBSCRIPTION_STATE state, SIPX_SUBSCRIPTION_CAUSE cause, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_SUB_STATUS)) { UtlString* pString = allocSubStatusEvent(state, cause); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
bool EventValidator::waitForInfoEvent(SIPX_CALL hCall, SIPX_LINE hLine, const char* szContentType, const char* szContent, int nContentLength, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_INFO)) { UtlString* pString = allocInfoEvent(hCall, hLine, szContentType, szContent, nContentLength); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
bool EventValidator::waitForLineEvent(SIPX_LINE hLine, SIPX_LINESTATE_EVENT event, SIPX_LINESTATE_CAUSE cause, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_LINESTATE)) { UtlString* pString = allocLineStateEntry(hLine, event, cause); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
bool EventValidator::waitForMessage(SIPX_LINE hLine, const char* szMsg, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isMessageIgnored()) { UtlString* pString = allocMessageEvent(hLine, szMsg); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } } return bFound; }
int GuestFile::i_waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset) { AssertPtrReturn(pEvent, VERR_INVALID_POINTER); VBoxEventType_T evtType; ComPtr<IEvent> pIEvent; int vrc = waitForEvent(pEvent, uTimeoutMS, &evtType, pIEvent.asOutParam()); if (RT_SUCCESS(vrc)) { if (evtType == VBoxEventType_OnGuestFileOffsetChanged) { if (puOffset) { ComPtr<IGuestFileOffsetChangedEvent> pFileEvent = pIEvent; Assert(!pFileEvent.isNull()); HRESULT hr = pFileEvent->COMGETTER(Offset)((LONG64*)puOffset); ComAssertComRC(hr); } } else vrc = VWRN_GSTCTL_OBJECTSTATE_CHANGED; } return vrc; }
/* * Initialization before T-Kernel starts */ EXPORT ER init_device( void ) { UINT prid = get_prid(); IMPORT void CountWaitUsec( void ); /* cntwus.c */ if (prid == 0) { /* Initialization of kernel use spin lock */ InitCountSpinLock(&SpinLockObj); /* Compute loop count of micro second wait */ CountWaitUsec(); /* Save system shared information */ SaveSCInfo = SCInfo; /* Set boot device */ if ( SCInfo.bootdev[0] != '\0' ) { strncpy((char*)bootdevnm, (char*)SCInfo.bootdev, L_DEVNM+1); BootDeviceName = bootdevnm; } else { BootDeviceName = NULL; /* No boot device */ } } else{ // wait for first processor complete initialize waitForEvent(); } return E_OK; }
int main(void) { memset(&addr_msg, 0, sizeof(struct sockaddr_nl)); addr_msg.nl_family = AF_NETLINK; memset(&addr_poll, 0, sizeof(struct sockaddr_nl)); addr_poll.nl_family = AF_NETLINK; addr_poll.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR; addr_poll.nl_pid = 0; /* Create netlink sockets */ nl_socket_msg = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (nl_socket_msg <= 0) { perror("create netlink msg socket"); goto error; } if (bind(nl_socket_msg, (struct sockaddr *)(&addr_msg), sizeof(struct sockaddr_nl))) { perror("bind netlink msg socket"); goto error; } nl_socket_poll = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (nl_socket_poll <= 0) { perror("create netlink poll socket"); goto error; } if(bind(nl_socket_poll, (struct sockaddr *)(&addr_poll), sizeof(struct sockaddr_nl))) { perror("bind netlink poll socket"); goto error; } /* init data structure for trackable interface */ ifdata = (interface_info_t *) malloc(sizeof(interface_info_t)); if (ifdata == NULL) { printf("no memory to allocate ifdata\n"); goto error; } ifdata->name = strndup((char *) IFNAME, SYSFS_PATH_MAX); ifdata->i = -1; while (1) { waitForEvent(); } return 0; error: if (nl_socket_msg > 0) close(nl_socket_msg); if (nl_socket_poll > 0) close(nl_socket_poll); return -1; }
main(int argc, char **argv) { pthread_t ctlThr, evThr; char *hostname; int port; // if (argc != 3) { fprintf(stderr, "Usage: %s host-name port\n", argv[0]); fflush(stderr); exit(-1); } hostname = argv[1]; if ((port = atoi(argv[2])) <= 0) { fprintf(stderr, "Bad port number: %s\n", argv[2]); fflush(stderr); exit(-1); } // initHW(hostname, port); fprintf(stdout, "singe thread ...\n"); fprintf(stdout, "waiting for 5 seconds .. \n"); sleep(5); fprintf(stdout, "opening all doors\n"); handleDoor(0, DoorOpen); fprintf(stdout, "waiting for 3 seconds .. \n"); sleep(3); fprintf(stdout, "closing all doors\n"); handleDoor(0, DoorClose); fprintf(stdout, "asking \"where is cabin #1?\"\n"); whereIs(1); { EventDesc ed; fprintf(stdout, "output: type=%d\n", (int) waitForEvent(&ed)); } fprintf(stdout, "waiting for 3 seconds .. \n"); sleep(3); fprintf(stdout, "starting threads ...\n"); fflush(stdout); if (pthread_mutex_init(&mutex, NULL) < 0) { perror("pthread_mutex_init"); exit(1); } if (pthread_create(&ctlThr, NULL, ctlProc, (void *) 0) != 0) { perror("pthread_create"); exit(-1); } if (pthread_create(&evThr, NULL, evProc, (void *) 0) != 0) { perror("pthread_create"); exit(-1); } (void) pthread_join(ctlThr, NULL); (void) pthread_join(evThr, NULL); return 0; }
int main(void) { // instantiate window GWindow window = newGWindow(320, 240); GCheckBox checkBox = newGCheckBox("I agree"); setActionCommand(checkBox, "check"); addToRegion(window, checkBox, "SOUTH"); while (true) { GActionEvent event = waitForEvent(ACTION_EVENT); if (getEventType(event) == WINDOW_CLOSED) { break; } if (strcmp(getActionCommand(event), "check") == 0) { if (isSelected(checkBox)) { printf("Checkbox was checked\n"); } else { printf("Checkbox was unchecked\n"); } } } closeGWindow(window); return 0; }
void read(int fd, void* bufferPtr, const size_t size, int timeoutMS) { chr::high_resolution_clock::time_point deadline = chr::high_resolution_clock::now() + chr::milliseconds(timeoutMS); size_t nTotal = 0; for (;;) { int n = ::read(fd, reinterpret_cast<char*>(bufferPtr) + nTotal, size - nTotal); if (n >= 0) { nTotal += n; if (nTotal == size) { // All data is read, break loop break; } if (n == 0) { THROW_EXCEPTION(UtilsException, "Peer disconnected"); } } else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { // Neglected errors LOGD("Retrying read"); } else { THROW_EXCEPTION(UtilsException, "Error during read()", errno); } waitForEvent(fd, POLLIN, deadline); } }
void CoreEngine::timerEvent(QTimerEvent* te) { // Fetch away the debug events and notify if debuggee // stops. Note that IDebugEventCallback does not // cover all cases of a debuggee stopping execution // (such as step over,etc). if (te->timerId() != m_watchTimer) return; switch (waitForEvent(1)) { case S_OK: killWatchTimer(); emit watchTimerDebugEvent(); break; case S_FALSE: // Detect startup (all modules loaded) if the module // count no longer changes in a time-out. if (!m_modulesLoadedEmitted) { const int newModuleCount = moduleCount(); if (newModuleCount && newModuleCount == m_lastTimerModuleCount) { m_modulesLoadedEmitted = true; emit modulesLoaded(); } else { m_lastTimerModuleCount = newModuleCount; } } break; case E_PENDING: case E_FAIL: break; case E_UNEXPECTED: // Occurs on ExitProcess. killWatchTimer(); break; } }
/* * Main program. */ int main() { if (RANDOM_USE_SEED) { setRandomSeed(106); } intro(); // create GUI window and position the console to its right setConsoleLocation(WorldGrid::WINDOW_WIDTH + 6 * WorldAbstract::WINDOW_MARGIN, 20); // temporary // setConsoleSize(CONSOLE_WIDTH, CONSOLE_HEIGHT); setConsoleEventOnClose(true); TrailblazerGUI gui(WINDOW_TITLE); gui.snapConsoleLocation(); // main event loop to process events as they happen while (true) { GEvent e = waitForEvent(ACTION_EVENT | MOUSE_EVENT | WINDOW_EVENT); if (e.getEventType() == MOUSE_CLICKED || e.getEventType() == MOUSE_MOVED) { gui.processMouseEvent(GMouseEvent(e)); } else if (e.getEventClass() == ACTION_EVENT) { gui.processActionEvent(GActionEvent(e)); } else if (e.getEventClass() == WINDOW_EVENT) { gui.processWindowEvent(GWindowEvent(e)); } } return 0; }
int GuestFile::i_waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten) { AssertPtrReturn(pEvent, VERR_INVALID_POINTER); VBoxEventType_T evtType; ComPtr<IEvent> pIEvent; int vrc = waitForEvent(pEvent, uTimeoutMS, &evtType, pIEvent.asOutParam()); if (RT_SUCCESS(vrc)) { if (evtType == VBoxEventType_OnGuestFileWrite) { if (pcbWritten) { ComPtr<IGuestFileWriteEvent> pFileEvent = pIEvent; Assert(!pFileEvent.isNull()); HRESULT hr = pFileEvent->COMGETTER(Processed)((ULONG*)pcbWritten); ComAssertComRC(hr); } } else vrc = VWRN_GSTCTL_OBJECTSTATE_CHANGED; } return vrc; }
int main(void) { GWindow window = newGWindow(320, 240); GButton button = newGButton("button"); setActionCommand( button, "check" ); addToRegion(window, button, "SOUTH"); while( true ) { GActionEvent event = waitForEvent( ACTION_EVENT ); if( getEventType(event) == WINDOW_CLOSED ) { break; } else if( strcmp( getActionCommand(event) , "click") == 0 ) { printf("button was clicked\n"); } } closeGWindow(window); return 0; }
void resize(int w, int h) { if (w == width && h == height) { return; } glXWaitGL(); // We need to ensure that pending events are processed here, and XSync // with discard = True guarantees that, but it appears the limited // event processing we do so far is sufficient //XSync(display, True); Drawable::resize(w, h); // Tell the window manager to respect the requested size XSizeHints size_hints; size_hints.max_width = size_hints.min_width = w; size_hints.max_height = size_hints.min_height = h; size_hints.flags = PMinSize | PMaxSize; XSetWMNormalHints(display, window, &size_hints); XResizeWindow(display, window, w, h); waitForEvent(ConfigureNotify); glXWaitX(); }
// closes all connections inline int closeConnections() { for (int i=0; i<threadCounter; i++) { while (!cqPollerThreadEnded[i]) usleep(1000); } waitSendThread(); for (unsigned int i=0; i<connections.size(); i++) rdma_disconnect(connections[i]->id); for (unsigned int i=0; i<connections.size(); i++) waitForEvent(connections[i]->id, RDMA_CM_EVENT_DISCONNECTED, connections[i]->getContext()); for(unsigned i=0;i<connections.size();++i) { connections[i]->destroyConnection(); delete connections[i]; connections[i]=NULL; } for (int i=0; i<threadCounter; i++) free(contexts[i]); return 0; }
bool EventValidator::waitForKeepaliveEvent(SIPX_KEEPALIVE_EVENT event, SIPX_KEEPALIVE_CAUSE cause, SIPX_KEEPALIVE_TYPE type, const char* szRemoteAddress, int remotePort, int keepAliveSecs, bool bStrictOrderMatch /*= true*/, int iTimeoutInSecs /* = DEFAULT_TIMEOUT*/) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_KEEPALIVE)) { UtlString* pString = allocKeepaliveEvent(event, cause, type, szRemoteAddress, remotePort, keepAliveSecs); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { OsTask::delay(1000); report(); } return bFound; }
void SIPRegistrarClient::run() { DBG("SIPRegistrarClient starting...\n"); AmDynInvokeFactory* uac_auth_f = AmPlugIn::instance()->getFactory4Di("uac_auth"); if (uac_auth_f == NULL) { DBG("unable to get a uac_auth factory. registrations will not be authenticated.\n"); DBG("(do you want to load uac_auth module?)\n"); } else { uac_auth_i = uac_auth_f->getInstance(); } while (!stop_requested.get()) { if (registrations.size()) { unsigned int cnt = 250; while (cnt > 0) { usleep(2000); // every 2 ms processEvents(); cnt--; } checkTimeouts(); } else { waitForEvent(); processEvents(); } } }
bool EventValidator::waitForInfoStatusEvent(void* pCookie, int status, int responseCode, const char* szResponseText, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; if (!isIgnoredCateogry(EVENT_CATEGORY_INFO_STATUS)) { UtlString* pString = allocInfoStatusEvent(pCookie, status, responseCode, szResponseText); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
int main(void) { // instantiate window GWindow window = newGWindow(320, 240); // instantiate slider addToRegion(window, newGLabel("0"), "SOUTH"); GSlider slider = newGSlider(0, 100, 50); setActionCommand(slider, "slide"); addToRegion(window, slider, "SOUTH"); addToRegion(window, newGLabel("100"), "SOUTH"); // listen for events while (true) { // wait for event GActionEvent event = waitForEvent(ACTION_EVENT); // if window was closed if (getEventType(event) == WINDOW_CLOSED) { break; } // if action command is "slide" if (strcmp(getActionCommand(event), "slide") == 0) { printf("slider was slid to %i\n", getValue(slider)); } } // that's all folks closeGWindow(window); return 0; }
bool EventValidator::waitForMediaEvent(SIPX_MEDIA_EVENT event, SIPX_MEDIA_CAUSE cause, SIPX_MEDIA_TYPE type, bool bStrictOrderMatch, int iTimeoutInSecs) { bool bFound = true; #ifndef HAS_MEDIA_ACTIVE_EVENT if (event == MEDIA_REMOTE_ACTIVE) return true; #endif if (!isIgnoredCateogry(EVENT_CATEGORY_MEDIA)) { UtlString* pString = allocMediaEvent(event, cause, type); bFound = waitForEvent(pString->data(), bStrictOrderMatch, iTimeoutInSecs); delete pString; } if (!bFound) { // Wait a second for any additional events to pour in -- useful for // debugging. OsTask::delay(1000); report(); } return bFound; }
bool EventThread::threadLoop() { DisplayEventReceiver::Event event; Vector< sp<EventThread::Connection> > signalConnections; signalConnections = waitForEvent(&event); // dispatch events to listeners... const size_t count = signalConnections.size(); for (size_t i=0 ; i<count ; i++) { const sp<Connection>& conn(signalConnections[i]); // now see if we still need to report this event status_t err = conn->postEvent(event); if (err == -EAGAIN || err == -EWOULDBLOCK) { // The destination doesn't accept events anymore, it's probably // full. For now, we just drop the events on the floor. // FIXME: Note that some events cannot be dropped and would have // to be re-sent later. // Right-now we don't have the ability to do this. ALOGW("EventThread: dropping event (%08x) for connection %p", event.header.type, conn.get()); } else if (err < 0) { // handle any other error on the pipe as fatal. the only // reasonable thing to do is to clean-up this connection. // The most common error we'll get here is -EPIPE. removeDisplayEventConnection(signalConnections[i]); } } return true; }
void AmCallWatcher::run() { DBG("starting call watcher.\n"); garbage_collector->start(); while (true) { waitForEvent(); processEvents(); } }
void WaitForEventTest::testSetActive() { WaitForEvent waitForEvent(this, QEvent::ChildAdded); waitForEvent.d->mConditionMet = true; waitForEvent.setActive(true); QVERIFY(waitForEvent.isActive()); QVERIFY(!waitForEvent.conditionMet()); }
void show(void) { if (!visible) { XMapWindow(display, window); waitForEvent(window, Expose); Drawable::show(); } }
void showWindow(Window window) { // FIXME: This works for DRI drivers, but not NVIDIA proprietary drivers, // for which the only solution seems to be to use Pbuffers. if (true || !ws::headless) { XMapWindow(display, window); waitForEvent(window, MapNotify); } }
void WaitForEventTest::testHandleEventNotActive() { QObject parentObject; WaitForEventWithCustomHandling waitForEvent(&parentObject, QEvent::ChildAdded); QObject* childObject = new QObject(); childObject->setParent(&parentObject); QCOMPARE(waitForEvent.mHandledEventsCount, 0); }