Debian Codegraph @

gobi-api/Gobi_2011-11-28-1533/Core/Event.h

raw
1 /*===========================================================================
2 FILE:
3 Event.h
4
5 DESCRIPTION:
6 Declaration of cEvent class
7
8 PUBLIC CLASSES AND METHODS:
9 WaitOnMultipleEvents
10 cEvent
11 Functionality to mimic Windows events using UNIX pipes (enhanced
12 somewhat to allow one to specify a DWORD value to pass through
13 when signalling the event)
14
15 WARNING:
16 This class is not designed to be thread safe
17
18 Copyright (c) 2011, Code Aurora Forum. All rights reserved.
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22 * Redistributions of source code must retain the above copyright
23 notice, this list of conditions and the following disclaimer.
24 * Redistributions in binary form must reproduce the above copyright
25 notice, this list of conditions and the following disclaimer in the
26 documentation and/or other materials provided with the distribution.
27 * Neither the name of Code Aurora Forum nor
28 the names of its contributors may be used to endorse or promote
29 products derived from this software without specific prior written
30 permission.
31
32
33 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 POSSIBILITY OF SUCH DAMAGE.
44 ===========================================================================*/
45
46 //---------------------------------------------------------------------------
47 // Pragmas
48 //---------------------------------------------------------------------------
49 #pragma once
50
51 //---------------------------------------------------------------------------
52 // Include Files
53 //---------------------------------------------------------------------------
54 #include "StdAfx.h"
55 #include <vector>
56
57 //---------------------------------------------------------------------------
58 // Prototype
59 //---------------------------------------------------------------------------
60
61 class cEvent;
62
63 /*=========================================================================*/
64 // Free methods
65 /*=========================================================================*/
66
67 // Wait for any of the events to be set and return the value
68 int WaitOnMultipleEvents(
69 std::vector <cEvent *> events,
70 DWORD timeoutMS,
71 DWORD & val,
72 DWORD & eventIndex );
73
74 /*=========================================================================*/
75 // Class cEvent
76 /*=========================================================================*/
77 class cEvent
78 {
79 public:
80 // Constructor
81 cEvent();
82
83 // Destructor
84 ~cEvent();
85
86 // Set/signal the event with the specified value
87 int Set( DWORD val );
88
89 // Wait for the event to be signalled and return the read in value
90 int Wait(
91 DWORD timeoutMS,
92 DWORD & val );
93
94 // Read and discard all values currently in the pipe
95 void Clear();
96
97 protected:
98 // Close pipe (used in errors or normal exit)
99 int Close();
100
101 // Read from the pipe
102 int Read( DWORD & val );
103
104 /* Internal error status */
105 int mError;
106
107 /* Internal pipes */
108 int mPipes[2];
109
110 // WaitOnMultipleEvents gets full access
111 friend int WaitOnMultipleEvents(
112 std::vector <cEvent *> events,
113 DWORD timeoutMS,
114 DWORD & val,
115 DWORD & eventIndex );
116 };
117