VirtualBox

Changeset 31579 in vbox for trunk/include/VBox/com


Ignore:
Timestamp:
Aug 11, 2010 5:21:27 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64686
Message:

EventQueue: Fix losing messages, use the right queue type on XPCOM (the fact that event handling in VBoxSVC worked was mainly luck), big code cleanup. VBoxHeadless and VirtualBoxImpl now use the only remaining event processing style. Eliminated redundant custom StateChange event in VBoxHeadless.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/EventQueue.h

    r31372 r31579  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2828#define ___VBox_com_EventQueue_h
    2929
    30 #if !defined (VBOX_WITH_XPCOM)
     30#ifndef VBOX_WITH_XPCOM
    3131# include <Windows.h>
    32 #else
     32#else // VBOX_WITH_XPCOM
    3333# include <nsEventQueueUtils.h>
    34 #endif
     34#endif // VBOX_WITH_XPCOM
    3535
    3636#include <VBox/com/defs.h>
     
    4343
    4444/**
    45  *  Base class for all events. Intended to be subclassed to introduce new events
    46  *  and handlers for them.
     45 *  Base class for all events. Intended to be subclassed to introduce new
     46 *  events and handlers for them.
    4747 *
    4848 *  Subclasses usually reimplement virtual #handler() (that does nothing by
     
    7474 *  When using XPCOM, this will map onto the default XPCOM queue for the thread.
    7575 *  So, if a queue is created on the main thread, it automatically processes
    76  *  XPCOM/IPC events while waiting for its own (Event) events.
     76 *  XPCOM/IPC events while waiting.
    7777 *
    7878 *  When using Windows, Darwin and OS/2, this will map onto the native thread
    7979 *  queue/runloop.  So, windows messages and what not will be processed while
    8080 *  waiting for events.
     81 *
     82 *  @note It is intentional that there is no way to retrieve arbitrary
     83 *  events and controlling their processing. There is no use case which
     84 *  warrants introducing the complexity of platform independent events.
    8185 */
    8286class EventQueue
     
    8791    ~EventQueue();
    8892
    89     BOOL postEvent (Event *event);
    90     BOOL waitForEvent (Event **event);
    91     BOOL handleEvent (Event *event);
     93    BOOL postEvent(Event *event);
    9294    int processEventQueue(uint32_t cMsTimeout);
    9395    int interruptEventQueueProcessing();
     
    107109    static EventQueue *mMainQueue;
    108110
    109 #if !defined (VBOX_WITH_XPCOM)
     111#ifndef VBOX_WITH_XPCOM
    110112
    111113    /** The thread which the queue belongs to. */
     
    114116    HANDLE mhThread;
    115117
    116 #else
     118#else // VBOX_WITH_XPCOM
    117119
    118120    /** Whether it was created (and thus needs destroying) or if a queue already
     
    120122    BOOL mEQCreated;
    121123
     124    /** Whether event processing should be interrupted. */
     125    BOOL mInterrupted;
     126
    122127    nsCOMPtr <nsIEventQueue> mEventQ;
    123128    nsCOMPtr <nsIEventQueueService> mEventQService;
    124129
    125     Event *mLastEvent;
    126     BOOL mGotEvent;
     130    static void *PR_CALLBACK plEventHandler(PLEvent *self);
     131    static void PR_CALLBACK plEventDestructor(PLEvent *self);
    127132
    128     struct MyPLEvent : public PLEvent
    129     {
    130         MyPLEvent (Event *e) : event (e) {}
    131         Event *event;
    132     };
    133 
    134     static void * PR_CALLBACK plEventHandler (PLEvent* self)
    135     {
    136         // nsIEventQueue doesn't expose PL_GetEventOwner(), so use an internal
    137         // field of PLEvent directly (hackish, but doesn' require an extra lib)
    138         EventQueue *owner = (EventQueue *) self->owner;
    139         Assert (owner);
    140         owner->mLastEvent = ((MyPLEvent *) self)->event;
    141         owner->mGotEvent = TRUE;
    142         return 0;
    143     }
    144 
    145     static void PR_CALLBACK plEventDestructor (PLEvent* self) { delete self; }
    146 
    147 #endif
     133#endif // VBOX_WITH_XPCOM
    148134};
    149135
Note: See TracChangeset for help on using the changeset viewer.

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