VirtualBox

Changeset 20598 in vbox for trunk/src/VBox/Main/xpcom


Ignore:
Timestamp:
Jun 15, 2009 6:08:09 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48645
Message:

Main: implmented waitForEvents(aTimeout) API for XPCOM targets, added command to VBox shell using this API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xpcom/server.cpp

    r20081 r20598  
    244244static PRBool volatile gKeepRunning = PR_TRUE;
    245245
     246nsresult XPCOM_waitForEvents(PRInt32 aTimeout)
     247{
     248  nsIEventQueue* q = gEventQ;
     249  PRBool hasEvents = false;
     250  nsresult rc;
     251
     252  if (!gKeepRunning || !q)
     253    return NS_OK;
     254
     255  rc = q->PendingEvents(&hasEvents);
     256  if (NS_FAILED (rc))
     257    return NS_ERROR_FAILURE;
     258
     259  if (hasEvents)
     260  {
     261    q->ProcessPendingEvents();
     262    return NS_OK;
     263  }
     264 
     265  if (aTimeout == 0)
     266     return NS_OK;
     267
     268  PRInt32 fd;
     269  fd = q->GetEventQueueSelectFD();
     270
     271  if (fd < 0 && aTimeout == -1)
     272  {
     273    /* fallback */
     274    PLEvent *pEvent = NULL;
     275    rc = q->WaitForEvent(&pEvent);
     276    if (NS_SUCCEEDED(rc))
     277      q->HandleEvent(pEvent);
     278
     279    q->ProcessPendingEvents();
     280    return NS_OK;
     281  }
     282
     283  /* Cannot perform timed wait otherwise */
     284  AssertReturn(fd >= 0, NS_ERROR_FAILURE);
     285 
     286  fd_set fdsetR, fdsetE;
     287  struct timeval tv;
     288
     289  FD_ZERO(&fdsetR);
     290  FD_SET(fd, &fdsetR);
     291
     292  fdsetE = fdsetR;
     293  if (aTimeout > 0)
     294  {
     295    /* LogRel(("sleep %d\n", aTimeout)); */
     296    tv.tv_sec = (PRInt64)aTimeout / 1000;
     297    tv.tv_usec = ((PRInt64)aTimeout % 1000) * 1000;
     298  }
     299
     300  /** @todo: What to do for XPCOM platforms w/o select() ? */
     301  int n = select(fd + 1, &fdsetR, NULL, &fdsetE, aTimeout < 0 ? NULL : &tv);
     302  rc = (n >= 0) ? NS_OK :  NS_ERROR_FAILURE;
     303
     304  /* process pending events, no matter what */
     305  q->ProcessPendingEvents();
     306
     307  return rc;
     308}
     309
    246310/////////////////////////////////////////////////////////////////////////////
    247311
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette