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(std::unique_ptr<EventFactory> eventFactory,
|
---|
70 | Waiter* waiter = 0, HANDLE handle = 0);
|
---|
71 |
|
---|
72 | public:
|
---|
73 | /**
|
---|
74 | * Destroy the object.
|
---|
75 | */
|
---|
76 | virtual ~Overlappable();
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Get the waiter.
|
---|
80 | */
|
---|
81 | Waiter* getWaiter();
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Determine if the overlappable has a waiter.
|
---|
85 | */
|
---|
86 | bool hasWaiter() const;
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Get the handle and clear it.
|
---|
90 | */
|
---|
91 | HANDLE releaseHandle();
|
---|
92 |
|
---|
93 | friend class Completer;
|
---|
94 | };
|
---|
95 |
|
---|
96 | //------------------------------------------------------------------------------
|
---|
97 | // Inline definitions
|
---|
98 | //------------------------------------------------------------------------------
|
---|
99 |
|
---|
100 | inline Overlappable::Overlappable(std::unique_ptr<EventFactory> eventFactory,
|
---|
101 | Waiter* waiter, HANDLE handle) :
|
---|
102 | EventFailable(std::move(eventFactory)),
|
---|
103 | waiter(waiter),
|
---|
104 | handle(handle)
|
---|
105 | {
|
---|
106 | }
|
---|
107 |
|
---|
108 | //------------------------------------------------------------------------------
|
---|
109 |
|
---|
110 | inline Overlappable::~Overlappable()
|
---|
111 | {
|
---|
112 | if (handle!=0) CloseHandle(handle);
|
---|
113 | }
|
---|
114 |
|
---|
115 | //------------------------------------------------------------------------------
|
---|
116 |
|
---|
117 | inline Waiter* Overlappable::getWaiter()
|
---|
118 | {
|
---|
119 | return waiter;
|
---|
120 | }
|
---|
121 |
|
---|
122 | //------------------------------------------------------------------------------
|
---|
123 |
|
---|
124 | inline bool Overlappable::hasWaiter() const
|
---|
125 | {
|
---|
126 | return waiter != 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 | //------------------------------------------------------------------------------
|
---|
130 |
|
---|
131 | inline HANDLE Overlappable::releaseHandle()
|
---|
132 | {
|
---|
133 | HANDLE h = handle;
|
---|
134 | handle = 0;
|
---|
135 | return h;
|
---|
136 | }
|
---|
137 |
|
---|
138 | //------------------------------------------------------------------------------
|
---|
139 |
|
---|
140 | } /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
|
---|
141 |
|
---|
142 | //------------------------------------------------------------------------------
|
---|
143 | #endif // HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
|
---|
144 |
|
---|
145 | // Local Variables:
|
---|
146 | // mode: C++
|
---|
147 | // c-basic-offset: 4
|
---|
148 | // indent-tabs-mode: nil
|
---|
149 | // End:
|
---|