]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOEventSource.cpp
464c89d6251ab768ba0be932390acb1a01c0ab38
[apple/xnu.git] / iokit / Kernel / IOEventSource.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32
33 HISTORY
34 1998-7-13 Godfrey van der Linden(gvdl)
35 Created.
36 ]*/
37 #include <IOKit/IOLib.h>
38
39 #include <IOKit/IOEventSource.h>
40 #include <IOKit/IOWorkLoop.h>
41
42 #define super OSObject
43
44 OSDefineMetaClassAndAbstractStructors(IOEventSource, OSObject)
45 OSMetaClassDefineReservedUnused(IOEventSource, 0);
46 OSMetaClassDefineReservedUnused(IOEventSource, 1);
47 OSMetaClassDefineReservedUnused(IOEventSource, 2);
48 OSMetaClassDefineReservedUnused(IOEventSource, 3);
49 OSMetaClassDefineReservedUnused(IOEventSource, 4);
50 OSMetaClassDefineReservedUnused(IOEventSource, 5);
51 OSMetaClassDefineReservedUnused(IOEventSource, 6);
52 OSMetaClassDefineReservedUnused(IOEventSource, 7);
53
54 /* inline function implementations */
55 void IOEventSource::signalWorkAvailable() { workLoop->signalWorkAvailable(); }
56 void IOEventSource::openGate() { workLoop->openGate(); }
57 void IOEventSource::closeGate() { workLoop->closeGate(); }
58 bool IOEventSource::tryCloseGate() { return workLoop->tryCloseGate(); }
59 int IOEventSource::sleepGate(void *event, UInt32 type)
60 { return workLoop->sleepGate(event, type); }
61 void IOEventSource::wakeupGate(void *event, bool oneThread)
62 { workLoop->wakeupGate(event, oneThread); }
63
64 bool IOEventSource::init(OSObject *inOwner,
65 Action inAction)
66 {
67 if (!inOwner)
68 return false;
69
70 owner = inOwner;
71
72 if ( !super::init() )
73 return false;
74
75 (void) setAction(inAction);
76 enabled = true;
77
78 return true;
79 }
80
81 IOEventSource::Action IOEventSource::getAction () const { return action; };
82
83 void IOEventSource::setAction(Action inAction)
84 {
85 action = inAction;
86 }
87
88 IOEventSource *IOEventSource::getNext() const { return eventChainNext; };
89
90 void IOEventSource::setNext(IOEventSource *inNext)
91 {
92 eventChainNext = inNext;
93 }
94
95 void IOEventSource::enable()
96 {
97 enabled = true;
98 if (workLoop)
99 return signalWorkAvailable();
100 }
101
102 void IOEventSource::disable()
103 {
104 enabled = false;
105 }
106
107 bool IOEventSource::isEnabled() const
108 {
109 return enabled;
110 }
111
112 void IOEventSource::setWorkLoop(IOWorkLoop *inWorkLoop)
113 {
114 if ( !inWorkLoop )
115 disable();
116 workLoop = inWorkLoop;
117 }
118
119 IOWorkLoop *IOEventSource::getWorkLoop() const
120 {
121 return workLoop;
122 }
123
124 bool IOEventSource::onThread() const
125 {
126 return (workLoop != 0) && workLoop->onThread();
127 }