Chameleon

Chameleon Svn Source Tree

Root/branches/mozodojo/i386/include/IOKit/IOSharedDataQueue.h

1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _IOKIT_IOSHAREDDATAQUEUE_H
30#define _IOKIT_IOSHAREDDATAQUEUE_H
31
32#ifdef dequeue
33#undef dequeue
34#endif
35
36#include <IOKit/IODataQueue.h>
37
38typedef struct _IODataQueueEntry IODataQueueEntry;
39
40/*!
41 * @class IOSharedDataQueue : public IODataQueue
42 * @abstract A generic queue designed to pass data both from the kernel to a user process and from a user process to the kernel.
43 * @discussion The IOSharedDataQueue class is designed to also allow a user process to queue data to kernel code. IOSharedDataQueue objects are designed to be used in a single producer / single consumer situation. As such, there are no locks on the data itself. Because the kernel enqueue and user-space dequeue methods follow a strict set of guidelines, no locks are necessary to maintain the integrity of the data struct.
44 *
45 * <br>Each data entry can be variable sized, but the entire size of the queue data region (including overhead for each entry) must be specified up front.
46 *
47 * <br>In order for the IODataQueue instance to notify the user process that data is available, a notification mach port must be set. When the queue is empty and a new entry is added, a message is sent to the specified port.
48 *
49 * <br>In order to make the data queue memory available to a user process, the method getMemoryDescriptor() must be used to get an IOMemoryDescriptor instance that can be mapped into a user process. Typically, the clientMemoryForType() method on an IOUserClient instance will be used to request the IOMemoryDescriptor and then return it to be mapped into the user process.
50 */
51class IOSharedDataQueue : public IODataQueue
52{
53 OSDeclareDefaultStructors(IOSharedDataQueue)
54
55 struct ExpansionData {
56 };
57 /*! @var reserved
58 Reserved for future use. (Internal use only) */
59 ExpansionData * _reserved;
60
61protected:
62 virtual void free();
63
64public:
65 /*!
66 * @function withCapacity
67 * @abstract Static method that creates a new IOSharedDataQueue instance with the capacity specified in the size parameter.
68 * @discussion The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>. The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>.<br> This method allocates a new IODataQueue instance and then calls initWithCapacity() with the given size parameter. If the initWithCapacity() fails, the new instance is released and zero is returned.
69 * @param size The size of the data queue memory region.
70 * @result Returns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.
71 */
72 static IOSharedDataQueue *withCapacity(UInt32 size);
73
74 /*!
75 * @function withEntries
76 * @abstract Static method that creates a new IOSharedDataQueue instance with the specified number of entries of the given size.
77 * @discussion This method will create a new IOSharedDataQueue instance with enough capacity for numEntries of entrySize. It does account for the IODataQueueEntry overhead for each entry. Note that the numEntries and entrySize are simply used to determine the data region size. They do not actually restrict the size of number of entries that can be added to the queue.<br> This method allocates a new IODataQueue instance and then calls initWithEntries() with the given numEntries and entrySize parameters. If the initWithEntries() fails, the new instance is released and zero is returned.
78 * @param numEntries Number of entries to allocate space for.
79 * @param entrySize Size of each entry.
80 * @result Reeturns the newly allocated IOSharedDataQueue instance. Zero is returned on failure.
81 */
82 static IOSharedDataQueue *withEntries(UInt32 numEntries, UInt32 entrySize);
83
84 /*!
85 * @function initWithCapacity
86 * @abstract Initializes an IOSharedDataQueue instance with the capacity specified in the size parameter.
87 * @discussion The actual size of the entire data queue memory region (to be shared into a user process) is equal to the capacity plus the IODataQueueMemory overhead. This overhead value can be determined from the DATA_QUEUE_MEMORY_HEADER_SIZE and DATA_QUEUE_MEMORY_APPENDIX_SIZE macro in <IOKit/IODataQueueShared.h>. The size of the data queue memory region must include space for the overhead of each IODataQueueEntry. This entry overhead can be determined from the DATA_QUEUE_ENTRY_HEADER_SIZE macro in <IOKit/IODataQueueShared.h>.
88 * @param size The size of the data queue memory region.
89 * @result Returns true on success and false on failure.
90 */
91 virtual Boolean initWithCapacity(UInt32 size);
92
93 /*!
94 * @function getMemoryDescriptor
95 * @abstract Returns a memory descriptor covering the IODataQueueMemory region.
96 * @discussion The IOMemoryDescriptor instance returned by this method is intended to be mapped into a user process. This is the memory region that the IODataQueueClient code operates on.
97 * @result Returns a newly allocated IOMemoryDescriptor for the IODataQueueMemory region. Returns zero on failure.
98 */
99 virtual IOMemoryDescriptor *getMemoryDescriptor();
100
101 /*!
102 * @function peek
103 * @abstract Used to peek at the next entry on the queue.
104 * @discussion This function can be used to look at the next entry which allows the entry to be received without having to copy it with dequeue. In order to do this, call peek to get the entry. Then call dequeue with a NULL data pointer. That will cause the head to be moved to the next entry, but no memory to be copied.
105 * @result Returns a pointer to the next IODataQueueEntry if one is available. 0 (NULL) is returned if the queue is empty.
106 */
107 virtual IODataQueueEntry * peek();
108
109 /*!
110 * @function dequeue
111 * @abstract Dequeues the next available entry on the queue and copies it into the given data pointer.
112 * @discussion This function will dequeue the next available entry on the queue. If a data pointer is provided, it will copy the data into the memory region if there is enough space available as specified in the dataSize parameter. If no data pointer is provided, it will simply move the head value past the current entry.
113 * @param data A pointer to the data memory region in which to copy the next entry data on the queue. If this parameter is 0 (NULL), it will simply move to the next entry.
114 * @param dataSize A pointer to the size of the data parameter. On return, this contains the size of the actual entry data - even if the original size was not large enough.
115 * @result Returns true on success and false on failure. Typically failure means that the queue is empty.
116 */
117 virtual Boolean dequeue(void *data, UInt32 *dataSize);
118
119 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 0);
120 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 1);
121 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 2);
122 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 3);
123 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 4);
124 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 5);
125 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 6);
126 OSMetaClassDeclareReservedUnused(IOSharedDataQueue, 7);
127};
128
129#endif /* _IOKIT_IOSHAREDDATAQUEUE_H */
130

Archive Download this file

Revision: 1232