~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/libs/xpcom18a4/python/src/module/_xpcom.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
493
493
 
494
494
#ifdef VBOX
495
495
 
496
 
static nsIEventQueue* g_mainEventQ = nsnull;
 
496
#  include <VBox/com/EventQueue.h>
 
497
#  include <iprt/err.h>
497
498
 
498
 
static PyObject* 
 
499
static PyObject*
499
500
PyXPCOMMethod_WaitForEvents(PyObject *self, PyObject *args)
500
501
{
501
502
  PRInt32 aTimeout;
502
503
 
503
504
  if (!PyArg_ParseTuple(args, "i", &aTimeout))
504
 
    return NULL;
505
 
 
506
 
  nsIEventQueue* q = g_mainEventQ;
507
 
  PRBool hasEvents = PR_FALSE;
508
 
  nsresult rc;
509
 
  PRInt32 fd, result = 0;
510
 
 
511
 
  if (q == nsnull) 
512
 
    return NULL;
513
 
 
514
 
  if (aTimeout == 0)
515
 
    goto ok;
516
 
 
517
 
  rc = q->PendingEvents(&hasEvents);
518
 
  if (NS_FAILED (rc))
519
 
    return NULL;
520
 
 
521
 
  if (hasEvents)
522
 
    goto ok;
523
 
  
524
 
  fd = q->GetEventQueueSelectFD();
525
 
  if (fd < 0 && aTimeout < 0)
526
 
  {
527
 
    /* fallback */
528
 
    PLEvent *pEvent = NULL;
529
 
    Py_BEGIN_ALLOW_THREADS
530
 
    rc = q->WaitForEvent(&pEvent);
531
 
    Py_END_ALLOW_THREADS
532
 
    if (NS_SUCCEEDED(rc))
533
 
      q->HandleEvent(pEvent);
534
 
    goto ok;
535
 
  }
536
 
 
537
 
  /* Cannot perform timed wait otherwise */
538
 
  if (fd < 0)
539
 
#ifdef RT_OS_DARWIN
540
 
      /** 
541
 
       * @todo: maybe need some way to implement timed wait on Darwin,
542
 
       *        just return immediately instead
543
 
       */
544
 
      goto ok;
545
 
#else
 
505
    return NULL; /** @todo throw exception */
 
506
 
 
507
  int rc;
 
508
  com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
 
509
  NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
 
510
  if (!aEventQ)
546
511
      return NULL;
547
 
#endif
548
 
  
549
 
  {
550
 
    fd_set fdsetR, fdsetE;
551
 
    struct timeval tv;
552
 
    
553
 
    FD_ZERO(&fdsetR);
554
 
    FD_SET(fd, &fdsetR);
555
 
 
556
 
    fdsetE = fdsetR;
557
 
    if (aTimeout > 0)
558
 
      {
559
 
        tv.tv_sec = (PRInt64)aTimeout / 1000;
560
 
        tv.tv_usec = ((PRInt64)aTimeout % 1000) * 1000;
561
 
      }
562
 
    
563
 
    /** @todo: What to do for XPCOM platforms w/o select() ? */
564
 
    Py_BEGIN_ALLOW_THREADS;
565
 
    int n = select(fd + 1, &fdsetR, NULL, &fdsetE, aTimeout < 0 ? NULL : &tv);
566
 
    result = (n == 0) ?  1 :  0;
567
 
    Py_END_ALLOW_THREADS;
568
 
  }
569
 
 ok:
570
 
  q->ProcessPendingEvents();
571
 
 
572
 
  return PyInt_FromLong(result);
573
 
}
574
 
 
575
 
PR_STATIC_CALLBACK(void *) PyHandleEvent(PLEvent *ev)
576
 
{
577
 
  return nsnull;
578
 
}
579
 
 
580
 
PR_STATIC_CALLBACK(void) PyDestroyEvent(PLEvent *ev)
581
 
{
582
 
  delete ev;
583
 
}
584
 
 
585
 
static PyObject* 
 
512
 
 
513
  Py_BEGIN_ALLOW_THREADS
 
514
  rc = aEventQ->processEventQueue(aTimeout < 0 ? RT_INDEFINITE_WAIT : (uint32_t)aTimeout);
 
515
  Py_END_ALLOW_THREADS
 
516
  if (RT_SUCCESS(rc))
 
517
      return PyInt_FromLong(0);
 
518
 
 
519
  if (   rc == VERR_TIMEOUT
 
520
      || rc == VERR_INTERRUPTED)
 
521
      return PyInt_FromLong(1);
 
522
 
 
523
  return NULL; /** @todo throw correct exception */
 
524
}
 
525
 
 
526
static PyObject*
586
527
PyXPCOMMethod_InterruptWait(PyObject *self, PyObject *args)
587
528
{
588
 
  nsIEventQueue* q = g_mainEventQ;
589
 
  PRInt32 result = 0;
590
 
  nsresult rc;
591
 
 
592
 
  PLEvent *ev = new PLEvent();
593
 
  if (!ev)
594
 
  {
595
 
    result = 1;
596
 
    goto done;
597
 
  }
598
 
  q->InitEvent (ev, NULL, PyHandleEvent, PyDestroyEvent);
599
 
  rc = q->PostEvent (ev);
600
 
  if (NS_FAILED(rc))
601
 
  {
602
 
    result = 2;
603
 
    goto done;
604
 
  }
605
 
 
606
 
 done:
607
 
  return PyInt_FromLong(result);
 
529
  com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
 
530
  NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
 
531
  if (!aEventQ)
 
532
      return NULL;
 
533
 
 
534
  aEventQ->interruptEventQueueProcessing();
 
535
 
 
536
  return PyInt_FromLong(0);
608
537
}
609
538
 
610
539
static void deinitVBoxPython();
611
540
 
612
 
static PyObject* 
 
541
static PyObject*
613
542
PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args)
614
543
{
615
544
    Py_BEGIN_ALLOW_THREADS;
620
549
 
621
550
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
622
551
 
623
 
static PyObject* 
 
552
static PyObject*
624
553
PyXPCOMMethod_AttachThread(PyObject *self, PyObject *args)
625
554
{
626
555
    nsresult rv;
652
581
    return PyInt_FromLong(result);
653
582
}
654
583
 
655
 
static PyObject* 
 
584
static PyObject*
656
585
PyXPCOMMethod_DetachThread(PyObject *self, PyObject *args)
657
586
{
658
587
    nsresult rv;
683
612
    /** @todo: better throw an exception on error */
684
613
    return PyInt_FromLong(result);
685
614
}
686
 
#endif
 
615
 
 
616
#endif /* VBOX */
687
617
 
688
618
extern PYXPCOM_EXPORT PyObject *PyXPCOMMethod_IID(PyObject *self, PyObject *args);
689
619
 
853
783
 
854
784
    rc = com::Initialize();
855
785
 
856
 
    if (NS_SUCCEEDED(rc))
857
 
    {
858
 
      NS_GetMainEventQ (&g_mainEventQ);
859
 
    }
860
 
 
861
786
    init_xpcom();
862
787
  }
863
788
}
864
789
 
865
 
static 
 
790
static
866
791
void deinitVBoxPython()
867
792
{
868
 
 
869
 
  if (g_mainEventQ)
870
 
    NS_RELEASE(g_mainEventQ); 
871
 
  
872
793
  com::Shutdown();
873
794
}
874
 
#endif
 
795
 
 
796
#endif /* VBOX_PYXPCOM */