~ubuntu-branches/ubuntu/natty/virtualbox-ose/natty-updates

« back to all changes in this revision

Viewing changes to include/VBox/com/EventQueue.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2010-10-15 02:12:28 UTC
  • mfrom: (0.3.10 upstream) (0.4.19 sid)
  • Revision ID: james.westby@ubuntu.com-20101015021228-5e6vbxgtes8mg189
Tags: 3.2.10-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - VirtualBox should go in Accessories, not in System tools.
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Add ubuntu-01-fix-build-gcc45.patch to fix FTBFS due to uninitalized
  variables. Thanks to Lubomir Rintel <lkundrak@v3.sk> for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 */
5
5
 
6
6
/*
7
 
 * Copyright (C) 2006-2007 Oracle Corporation
 
7
 * Copyright (C) 2006-2010 Oracle Corporation
8
8
 *
9
9
 * This file is part of VirtualBox Open Source Edition (OSE), as
10
10
 * available from http://www.virtualbox.org. This file is free software;
27
27
#ifndef ___VBox_com_EventQueue_h
28
28
#define ___VBox_com_EventQueue_h
29
29
 
30
 
#if !defined (VBOX_WITH_XPCOM)
 
30
#ifndef VBOX_WITH_XPCOM
31
31
# include <Windows.h>
32
 
#else
 
32
#else // VBOX_WITH_XPCOM
33
33
# include <nsEventQueueUtils.h>
34
 
#endif
 
34
#endif // VBOX_WITH_XPCOM
35
35
 
36
36
#include <VBox/com/defs.h>
37
37
#include <VBox/com/assert.h>
42
42
class EventQueue;
43
43
 
44
44
/**
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.
47
47
 *
48
48
 *  Subclasses usually reimplement virtual #handler() (that does nothing by
49
49
 *  default) and add new data members describing the event.
74
74
 *
75
75
 *  When using XPCOM, this will map onto the default XPCOM queue for the thread.
76
76
 *  So, if a queue is created on the main thread, it automatically processes
77
 
 *  XPCOM/IPC events while waiting for its own (Event) events.
 
77
 *  XPCOM/IPC events while waiting.
78
78
 *
79
79
 *  When using Windows, Darwin and OS/2, this will map onto the native thread
80
80
 *  queue/runloop.  So, windows messages and what not will be processed while
81
81
 *  waiting for events.
 
82
 *
 
83
 *  @note It is intentional that there is no way to retrieve arbitrary
 
84
 *  events and controlling their processing. There is no use case which
 
85
 *  warrants introducing the complexity of platform independent events.
82
86
 */
83
87
class EventQueue
84
88
{
87
91
    EventQueue();
88
92
    ~EventQueue();
89
93
 
90
 
    BOOL postEvent (Event *event);
91
 
    BOOL waitForEvent (Event **event);
92
 
    BOOL handleEvent (Event *event);
93
 
    int processEventQueue(uint32_t cMsTimeout);
 
94
    BOOL postEvent(Event *event);
 
95
    int processEventQueue(RTMSINTERVAL cMsTimeout);
94
96
    int interruptEventQueueProcessing();
95
97
    int getSelectFD();
96
98
    static int init();
102
104
    {
103
105
        return mEventQ.get();
104
106
    }
 
107
#else
 
108
    static int dispatchMessageOnWindows(MSG const *pMsg, int rc);
105
109
#endif
106
110
 
107
111
private:
108
 
    static EventQueue *mMainQueue;
 
112
    static EventQueue *sMainQueue;
109
113
 
110
 
#if !defined (VBOX_WITH_XPCOM)
 
114
#ifndef VBOX_WITH_XPCOM
111
115
 
112
116
    /** The thread which the queue belongs to. */
113
117
    DWORD mThreadId;
114
118
    /** Duplicated thread handle for MsgWaitForMultipleObjects. */
115
119
    HANDLE mhThread;
116
120
 
117
 
#else
 
121
#else // VBOX_WITH_XPCOM
118
122
 
119
123
    /** Whether it was created (and thus needs destroying) or if a queue already
120
124
     *  associated with the thread was used. */
121
 
    BOOL mEQCreated;
 
125
    bool mEQCreated;
 
126
 
 
127
    /** Whether event processing should be interrupted. */
 
128
    bool mInterrupted;
122
129
 
123
130
    nsCOMPtr <nsIEventQueue> mEventQ;
124
131
    nsCOMPtr <nsIEventQueueService> mEventQService;
125
132
 
126
 
    Event *mLastEvent;
127
 
    BOOL mGotEvent;
128
 
 
129
 
    struct MyPLEvent : public PLEvent
130
 
    {
131
 
        MyPLEvent (Event *e) : event (e) {}
132
 
        Event *event;
133
 
    };
134
 
 
135
 
    static void * PR_CALLBACK plEventHandler (PLEvent* self)
136
 
    {
137
 
        // nsIEventQueue doesn't expose PL_GetEventOwner(), so use an internal
138
 
        // field of PLEvent directly (hackish, but doesn' require an extra lib)
139
 
        EventQueue *owner = (EventQueue *) self->owner;
140
 
        Assert (owner);
141
 
        owner->mLastEvent = ((MyPLEvent *) self)->event;
142
 
        owner->mGotEvent = TRUE;
143
 
        return 0;
144
 
    }
145
 
 
146
 
    static void PR_CALLBACK plEventDestructor (PLEvent* self) { delete self; }
147
 
 
148
 
#endif
 
133
    static void *PR_CALLBACK plEventHandler(PLEvent *self);
 
134
    static void PR_CALLBACK plEventDestructor(PLEvent *self);
 
135
 
 
136
#endif // VBOX_WITH_XPCOM
149
137
};
150
138
 
151
139
} /* namespace com */