VirtualBox

source: vbox/trunk/include/VBox/com/EventQueue.h@ 17911

Last change on this file since 17911 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/** @file
2 * MS COM / XPCOM Abstraction Layer:
3 * Event and EventQueue class declaration
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___VBox_com_EventQueue_h
32#define ___VBox_com_EventQueue_h
33
34#if !defined (VBOX_WITH_XPCOM)
35#include <windows.h>
36#else
37#include <nsEventQueueUtils.h>
38#endif
39
40#include <VBox/com/defs.h>
41#include <VBox/com/assert.h>
42
43namespace com
44{
45
46class EventQueue;
47
48/**
49 * Base class for all events. Intended to be subclassed to introduce new events
50 * and handlers for them.
51 *
52 * Subclasses usually reimplement virtual #handler() (that does nothing by
53 * default) and add new data members describing the event.
54 */
55class Event
56{
57public:
58
59 Event() {}
60
61protected:
62
63 virtual ~Event() {};
64
65 /**
66 * Event handler. Called in the context of the event queue's thread.
67 * Always reimplemented by subclasses
68 *
69 * @return reserved, should be NULL.
70 */
71 virtual void *handler() { return NULL; }
72
73 friend class EventQueue;
74};
75
76/**
77 * Simple event queue.
78 *
79 * On Linux, if this queue is created on the main thread, it automatically
80 * processes XPCOM/IPC events while waiting for its own (Event) events.
81 */
82class EventQueue
83{
84public:
85
86 EventQueue();
87 ~EventQueue();
88
89 BOOL postEvent (Event *event);
90 BOOL waitForEvent (Event **event);
91 BOOL handleEvent (Event *event);
92
93private:
94
95#if !defined (VBOX_WITH_XPCOM)
96
97 DWORD mThreadId;
98
99#else
100
101 BOOL mEQCreated;
102
103 nsCOMPtr <nsIEventQueue> mEventQ;
104 nsCOMPtr <nsIEventQueueService> mEventQService;
105
106 Event *mLastEvent;
107 BOOL mGotEvent;
108
109 struct MyPLEvent : public PLEvent
110 {
111 MyPLEvent (Event *e) : event (e) {}
112 Event *event;
113 };
114
115 static void * PR_CALLBACK plEventHandler (PLEvent* self)
116 {
117 // nsIEventQueue doesn't expose PL_GetEventOwner(), so use an internal
118 // field of PLEvent directly (hackish, but doesn' require an extra lib)
119 EventQueue *owner = (EventQueue *) self->owner;
120 Assert (owner);
121 owner->mLastEvent = ((MyPLEvent *) self)->event;
122 owner->mGotEvent = TRUE;
123 return 0;
124 }
125
126 static void PR_CALLBACK plEventDestructor (PLEvent* self) { delete self; }
127
128#endif
129};
130
131} /* namespace com */
132
133#endif
134
Note: See TracBrowser for help on using the repository browser.

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