1/*
2 * Copyright (c) 2001-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef _ATATIMEREVENTSOURCE_H
24#define _ATATIMEREVENTSOURCE_H
25
26
27#include <IOKit/IOTypes.h>
28#include <IOKit/IOCommandGate.h>
29#include <IOKit/IOService.h>
30#include <IOKit/IOWorkLoop.h>
31#include <IOKit/IOTimerEventSource.h>
32#include <IOKit/ndrvsupport/IOMacOSTypes.h>
33
34
35/*!
36@class ATATimerEventSource
37
38@discussion
39Extend the timer event source to allow checking for timer expiration
40from behind the workloop.
41*/
42
43class ATATimerEventSource : public IOTimerEventSource
44{
45    OSDeclareDefaultStructors(ATATimerEventSource);
46
47	public:
48
49	/*!@function ataTimerEventSource
50	@abstract  allocate an instance of this type.
51	*/
52    static ATATimerEventSource *
53	ataTimerEventSource(OSObject *owner, Action action = 0);
54
55	/*!@function hasTimedOut
56	@abstract returns true if the timer has expired since the last enable/disable or setTimeout() or wakeAtTime() call.
57	*/
58	virtual bool hasTimedOut( void );
59
60	// override to initialize the time out flag.
61  	/*!@function
62	@abstract
63	*/
64	virtual bool init(OSObject *owner, Action action = 0);
65
66	/*!@function enable
67	@abstract overrides in order to set/clear the timed out flag
68	*/
69	virtual void enable();
70
71	/*!@function disable
72	@abstract overrides in order to set/clear the timed out flag
73	*/
74	virtual void disable();
75
76	/*!@function wakeAtTime
77	@abstract overrides in order to set/clear the timed out flag
78	*/
79	virtual IOReturn wakeAtTime(UnsignedWide abstime);
80
81	/*!@function cancelTimeout
82	@abstract overrides in order to set/clear the timed out flag
83	*/
84	virtual void cancelTimeout();
85
86protected:
87
88	enum{  kTimedOutTrue = 'true',
89			kTimedOutFalse = 'fals'
90		};
91
92	UInt32 hasExpired;
93
94
95	/*!@function myTimeout
96	@abstract my timeout function which sets the timedOut flag atomically.
97	*/
98	static void myTimeout(void *self);
99
100	/*!@function setTimeoutFunc
101	@abstract override to install my timeout function instead of the super's.
102	*/
103    virtual void setTimeoutFunc();
104
105	/*! @struct ExpansionData
106    @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future.
107    */
108    struct ExpansionData { };
109
110	/*! @var reserved
111    Reserved for future use.  (Internal use only)  */
112    ExpansionData *reserved;
113
114private:
115    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 0);
116    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 1);
117    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 2);
118    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 3);
119    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 4);
120    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 5);
121    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 6);
122    OSMetaClassDeclareReservedUnused(ATATimerEventSource, 7);
123
124};
125
126
127#endif /*_ATATIMEREVENTSOURCE_H*/
128