VirtualBox

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

Last change on this file since 2734 was 1, checked in by vboxsync, 55 years ago

import

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