VirtualBox

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

Last change on this file since 46649 was 46649, checked in by vboxsync, 11 years ago

Forward ported r85941 and required build fixes (Main: Implemented new event queue to separate system's native event queue and our own. Also, XPCOM is not needed for handling our own events. On Windows this also fixes the system's queue quota limitation).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: EventQueue.h 46649 2013-06-19 11:47:32Z vboxsync $ */
2/** @file
3 * Event queue class declaration.
4 */
5
6/*
7 * Copyright (C) 2013 Oracle Corporation
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
27#ifndef ___VBox_com_EventQueue_h
28#define ___VBox_com_EventQueue_h
29
30#include <list>
31
32#include <iprt/asm.h>
33#include <iprt/critsect.h>
34
35#include <VBox/com/defs.h>
36#include <VBox/com/assert.h>
37
38namespace com
39{
40
41class EventQueue;
42
43/**
44 * Base class for all events. Intended to be subclassed to introduce new
45 * events and handlers for them.
46 *
47 * Subclasses usually reimplement virtual #handler() (that does nothing by
48 * default) and add new data members describing the event.
49 */
50class Event
51{
52public:
53
54 Event(void) :
55 mRefCount(0) { }
56 virtual ~Event(void) { AssertMsg(!mRefCount,
57 ("Reference count of event=%p not 0 on destruction (is %RU32)\n",
58 this, mRefCount)); }
59public:
60
61 uint32_t AddRef(void) { return ASMAtomicIncU32(&mRefCount); }
62 void Release(void)
63 {
64 Assert(mRefCount);
65 uint32_t cRefs = ASMAtomicDecU32(&mRefCount);
66 if (!cRefs)
67 delete this;
68 }
69
70protected:
71
72 /**
73 * Event handler. Called in the context of the event queue's thread.
74 * Always reimplemented by subclasses
75 *
76 * @return reserved, should be NULL.
77 */
78 virtual void *handler(void) { return NULL; }
79
80 friend class EventQueue;
81
82protected:
83
84 /** The event's reference count. */
85 uint32_t mRefCount;
86};
87
88typedef std::list< Event* > EventQueueList;
89typedef std::list< Event* >::iterator EventQueueListIterator;
90typedef std::list< Event* >::const_iterator EventQueueListIteratorConst;
91
92/**
93 * Simple event queue.
94 */
95class EventQueue
96{
97public:
98
99 EventQueue(void);
100 virtual ~EventQueue(void);
101
102public:
103
104 BOOL postEvent(Event *event);
105 int processEventQueue(RTMSINTERVAL cMsTimeout);
106 int interruptEventQueueProcessing();
107
108private:
109
110 /** Critical section for serializing access to this
111 * event queue. */
112 RTCRITSECT mCritSect;
113 /** Event semaphore for getting notified on new
114 * events being handled. */
115 RTSEMEVENT mSemEvent;
116 /** The actual event queue, implemented as a list. */
117 EventQueueList mEvents;
118 /** Shutdown indicator. */
119 bool mShutdown;
120};
121
122} /* namespace com */
123
124#endif
125
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