source: vscpl/src/hu/varadiistvan/scpl/io/_win32/EventFailable.h@ 28:9b3c2d3ea9f3

Last change on this file since 28:9b3c2d3ea9f3 was 28:9b3c2d3ea9f3, checked in by István Váradi <ivaradi@…>, 17 months ago

Event object creation is moved into a factory.

File size: 4.7 KB
Line 
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_EVENTFAILABLE_H
30#define HU_VARADIISTVAN_SCPL_IO_WIN32_EVENTFAILABLE_H
31//------------------------------------------------------------------------------
32
33#include "../Failable.h"
34
35#include "EventFactory.h"
36
37#include <memory>
38
39//------------------------------------------------------------------------------
40
41namespace hu { namespace varadiistvan { namespace scpl { namespace io {
42
43//------------------------------------------------------------------------------
44
45class Event;
46
47//------------------------------------------------------------------------------
48
49/**
50 * A special subclass of Failable, the instances of which can be given
51 * as a Failable target object to events. If some operation on an
52 * event fails, the error code will be set on such an instance,
53 * associated with the event.
54 */
55class EventFailable : public Failable
56{
57protected:
58 /**
59 * The event factory for this object.
60 */
61 std::unique_ptr<EventFactory> eventFactory;
62
63protected:
64 /**
65 * Construct the object with the given event factory.
66 */
67 EventFailable(std::unique_ptr<EventFactory> eventFactory);
68
69 /**
70 * Create an event for this object using the event factory.
71 */
72 HANDLE createEvent();
73
74 /**
75 * Set the event represented by the given handle using the event factory.
76 */
77 bool setEvent(HANDLE handle);
78
79 /**
80 * Set the event represented by the given handle using the event factory.
81 */
82 bool resetEvent(HANDLE handle);
83
84 /**
85 * Destroy the event represented by the given handle using the event factory.
86 */
87 void destroyEvent(HANDLE handle);
88
89 friend class Event;
90};
91
92//------------------------------------------------------------------------------
93// Inline definitions
94//------------------------------------------------------------------------------
95
96inline EventFailable::EventFailable(std::unique_ptr<EventFactory> eventFactory) :
97 eventFactory(std::move(eventFactory))
98{
99}
100
101//------------------------------------------------------------------------------
102
103inline HANDLE EventFailable::createEvent()
104{
105 return eventFactory->createEvent();
106}
107
108//------------------------------------------------------------------------------
109
110inline bool EventFailable::setEvent(HANDLE handle)
111{
112 return eventFactory->setEvent(handle);
113}
114
115//------------------------------------------------------------------------------
116
117inline bool EventFailable::resetEvent(HANDLE handle)
118{
119 return eventFactory->resetEvent(handle);
120}
121
122//------------------------------------------------------------------------------
123
124inline void EventFailable::destroyEvent(HANDLE handle)
125{
126 eventFactory->destroyEvent(handle);
127}
128
129//------------------------------------------------------------------------------
130
131} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
132
133//------------------------------------------------------------------------------
134#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_EVENTFAILABLE_H
135
136// Local Variables:
137// mode: C++
138// c-basic-offset: 4
139// indent-tabs-mode: nil
140// End:
Note: See TracBrowser for help on using the repository browser.