1 | // Copyright (c) 2013 by István Váradi
|
---|
2 |
|
---|
3 | // This file is part of VSCPL, a simple cross-platform utility library
|
---|
4 |
|
---|
5 | // Redistribution and use in source and binary forms, with or without
|
---|
6 | // modification, are permitted provided that the following conditions are met:
|
---|
7 |
|
---|
8 | // 1. Redistributions of source code must retain the above copyright notice, this
|
---|
9 | // list of conditions and the following disclaimer.
|
---|
10 | // 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | // this list of conditions and the following disclaimer in the documentation
|
---|
12 | // and/or other materials provided with the distribution.
|
---|
13 |
|
---|
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
15 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
---|
18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 |
|
---|
25 | // The views and conclusions contained in the software and documentation are those
|
---|
26 | // of the authors and should not be interpreted as representing official policies,
|
---|
27 | // either expressed or implied, of the FreeBSD Project.
|
---|
28 |
|
---|
29 | #ifndef HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
|
---|
30 | #define HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
|
---|
31 | //------------------------------------------------------------------------------
|
---|
32 |
|
---|
33 | #include "EventFailable.h"
|
---|
34 |
|
---|
35 | #include <windows.h>
|
---|
36 |
|
---|
37 | //------------------------------------------------------------------------------
|
---|
38 |
|
---|
39 | namespace hu { namespace varadiistvan { namespace scpl { namespace io {
|
---|
40 |
|
---|
41 | //------------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | class Waiter;
|
---|
44 |
|
---|
45 | //------------------------------------------------------------------------------
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Base class for classes that maintain a handle and may be subject to
|
---|
49 | * overlapped I/O operations whose completion is waited for in a
|
---|
50 | * Waiter.
|
---|
51 | */
|
---|
52 | class Overlappable : public EventFailable
|
---|
53 | {
|
---|
54 | protected:
|
---|
55 | /**
|
---|
56 | * The waiter to be used for waiting for events.
|
---|
57 | */
|
---|
58 | Waiter* waiter;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * The handle to use.
|
---|
62 | */
|
---|
63 | HANDLE handle;
|
---|
64 |
|
---|
65 | protected:
|
---|
66 | /**
|
---|
67 | * Construct the object.
|
---|
68 | */
|
---|
69 | Overlappable(Waiter* waiter = 0, HANDLE handle = 0);
|
---|
70 |
|
---|
71 | public:
|
---|
72 | /**
|
---|
73 | * Destroy the object.
|
---|
74 | */
|
---|
75 | virtual ~Overlappable();
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Get the waiter.
|
---|
79 | */
|
---|
80 | Waiter* getWaiter();
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Determine if the overlappable has a waiter.
|
---|
84 | */
|
---|
85 | bool hasWaiter() const;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Get the handle and clear it.
|
---|
89 | */
|
---|
90 | HANDLE releaseHandle();
|
---|
91 |
|
---|
92 | friend class Completer;
|
---|
93 | };
|
---|
94 |
|
---|
95 | //------------------------------------------------------------------------------
|
---|
96 | // Inline definitions
|
---|
97 | //------------------------------------------------------------------------------
|
---|
98 |
|
---|
99 | inline Overlappable::Overlappable(Waiter* waiter, HANDLE handle) :
|
---|
100 | waiter(waiter),
|
---|
101 | handle(handle)
|
---|
102 | {
|
---|
103 | }
|
---|
104 |
|
---|
105 | //------------------------------------------------------------------------------
|
---|
106 |
|
---|
107 | inline Overlappable::~Overlappable()
|
---|
108 | {
|
---|
109 | if (handle!=0) CloseHandle(handle);
|
---|
110 | }
|
---|
111 |
|
---|
112 | //------------------------------------------------------------------------------
|
---|
113 |
|
---|
114 | inline Waiter* Overlappable::getWaiter()
|
---|
115 | {
|
---|
116 | return waiter;
|
---|
117 | }
|
---|
118 |
|
---|
119 | //------------------------------------------------------------------------------
|
---|
120 |
|
---|
121 | inline bool Overlappable::hasWaiter() const
|
---|
122 | {
|
---|
123 | return waiter != 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //------------------------------------------------------------------------------
|
---|
127 |
|
---|
128 | inline HANDLE Overlappable::releaseHandle()
|
---|
129 | {
|
---|
130 | HANDLE h = handle;
|
---|
131 | handle = 0;
|
---|
132 | return h;
|
---|
133 | }
|
---|
134 |
|
---|
135 | //------------------------------------------------------------------------------
|
---|
136 |
|
---|
137 | } /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
|
---|
138 |
|
---|
139 | //------------------------------------------------------------------------------
|
---|
140 | #endif // HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
|
---|
141 |
|
---|
142 | // Local Variables:
|
---|
143 | // mode: C++
|
---|
144 | // c-basic-offset: 4
|
---|
145 | // indent-tabs-mode: nil
|
---|
146 | // End:
|
---|