sl@0
|
1 |
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// in its implementation.
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file The interface to an example camera device driver which uses Shared Chunks
|
sl@0
|
20 |
@publishedPartner
|
sl@0
|
21 |
@prototype 9.1
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
#ifndef __CAMERA1_H__
|
sl@0
|
25 |
#define __CAMERA1_H__
|
sl@0
|
26 |
|
sl@0
|
27 |
#include <e32cmn.h>
|
sl@0
|
28 |
#include <e32ver.h>
|
sl@0
|
29 |
#ifndef __KERNEL_MODE__
|
sl@0
|
30 |
#include <e32std.h>
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
|
sl@0
|
33 |
/**
|
sl@0
|
34 |
User interface for 'Camera1'
|
sl@0
|
35 |
*/
|
sl@0
|
36 |
class RCamera1 : public RBusLogicalChannel
|
sl@0
|
37 |
{
|
sl@0
|
38 |
public:
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
Structure for holding driver capabilities information
|
sl@0
|
41 |
(Just a version number in this example.)
|
sl@0
|
42 |
*/
|
sl@0
|
43 |
class TCaps
|
sl@0
|
44 |
{
|
sl@0
|
45 |
public:
|
sl@0
|
46 |
TVersion iVersion;
|
sl@0
|
47 |
};
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
Structure for holding driver configuration data
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
class TConfig
|
sl@0
|
53 |
{
|
sl@0
|
54 |
public:
|
sl@0
|
55 |
TSize iImageSize; /**< Size of image in pixels */
|
sl@0
|
56 |
TInt iImageBytesPerPixel; /**< Number of bytes used to represent a single pixel */
|
sl@0
|
57 |
TInt iFrameRate; /**< Speed to capture images at in frames per second*/
|
sl@0
|
58 |
TInt iNumImageBuffers; /**< Number of simultanious images the client wishes to process */
|
sl@0
|
59 |
};
|
sl@0
|
60 |
typedef TPckgBuf<TConfig> TConfigBuf;
|
sl@0
|
61 |
|
sl@0
|
62 |
#ifndef __KERNEL_MODE__
|
sl@0
|
63 |
public:
|
sl@0
|
64 |
TInt Open();
|
sl@0
|
65 |
void Close();
|
sl@0
|
66 |
TInt GetConfig(TConfigBuf& aConfig);
|
sl@0
|
67 |
TInt SetConfig(const TConfigBuf& aConfig);
|
sl@0
|
68 |
TInt StartCapture();
|
sl@0
|
69 |
TInt EndCapture();
|
sl@0
|
70 |
void CaptureImage(TRequestStatus& aStatus, TInt aReleaseImage=-1);
|
sl@0
|
71 |
void CaptureImageCancel();
|
sl@0
|
72 |
TInt ReleaseImage(TInt aReleaseImage);
|
sl@0
|
73 |
TInt Duplicate(const RThread& aSrc,TOwnerType aType=EOwnerProcess);
|
sl@0
|
74 |
inline RChunk ImageChunk() const;
|
sl@0
|
75 |
private:
|
sl@0
|
76 |
RChunk iChunk; /**< The chunk into which captured images will be placed */
|
sl@0
|
77 |
#endif
|
sl@0
|
78 |
|
sl@0
|
79 |
public:
|
sl@0
|
80 |
inline static const TDesC& Name();
|
sl@0
|
81 |
inline static TVersion VersionRequired();
|
sl@0
|
82 |
|
sl@0
|
83 |
private:
|
sl@0
|
84 |
/**
|
sl@0
|
85 |
Enumeration of Control messages.
|
sl@0
|
86 |
*/
|
sl@0
|
87 |
enum TControl
|
sl@0
|
88 |
{
|
sl@0
|
89 |
EGetConfig,
|
sl@0
|
90 |
ESetConfig,
|
sl@0
|
91 |
EStartCapture,
|
sl@0
|
92 |
EEndCapture,
|
sl@0
|
93 |
ECaptureImage,
|
sl@0
|
94 |
EReleaseImage
|
sl@0
|
95 |
};
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
Enumeration of Request messages.
|
sl@0
|
99 |
(None used in this example)
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
enum TRequest
|
sl@0
|
102 |
{
|
sl@0
|
103 |
ENumRequests,
|
sl@0
|
104 |
EAllRequests = (1<<ENumRequests)-1
|
sl@0
|
105 |
};
|
sl@0
|
106 |
|
sl@0
|
107 |
// Kernel side LDD channel is a friend
|
sl@0
|
108 |
friend class DCamera1Channel;
|
sl@0
|
109 |
};
|
sl@0
|
110 |
|
sl@0
|
111 |
/**
|
sl@0
|
112 |
The driver's name
|
sl@0
|
113 |
|
sl@0
|
114 |
@return The name of the driver
|
sl@0
|
115 |
|
sl@0
|
116 |
@internalComponent
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
inline const TDesC& RCamera1::Name()
|
sl@0
|
119 |
{
|
sl@0
|
120 |
_LIT(KCamera1Name,"CAMERA1");
|
sl@0
|
121 |
return KCamera1Name;
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
The driver's version
|
sl@0
|
126 |
|
sl@0
|
127 |
@return The version number of the driver
|
sl@0
|
128 |
|
sl@0
|
129 |
@internalComponent
|
sl@0
|
130 |
*/
|
sl@0
|
131 |
inline TVersion RCamera1::VersionRequired()
|
sl@0
|
132 |
{
|
sl@0
|
133 |
const TInt KMajorVersionNumber=1;
|
sl@0
|
134 |
const TInt KMinorVersionNumber=0;
|
sl@0
|
135 |
const TInt KBuildVersionNumber=KE32BuildVersionNumber;
|
sl@0
|
136 |
return TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
/*
|
sl@0
|
140 |
NOTE: The following methods would normally be exported from a seperate client DLL
|
sl@0
|
141 |
but are included inline in this header file for convenience.
|
sl@0
|
142 |
*/
|
sl@0
|
143 |
|
sl@0
|
144 |
#ifndef __KERNEL_MODE__
|
sl@0
|
145 |
|
sl@0
|
146 |
/**
|
sl@0
|
147 |
Open a logical channel to the driver
|
sl@0
|
148 |
|
sl@0
|
149 |
@return One of the system wide error codes.
|
sl@0
|
150 |
*/
|
sl@0
|
151 |
TInt RCamera1::Open()
|
sl@0
|
152 |
{
|
sl@0
|
153 |
return DoCreate(Name(),VersionRequired(),KNullUnit,NULL,NULL,EOwnerProcess);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
/**
|
sl@0
|
157 |
Close a logical channel to the driver
|
sl@0
|
158 |
*/
|
sl@0
|
159 |
void RCamera1::Close()
|
sl@0
|
160 |
{
|
sl@0
|
161 |
iChunk.Close();
|
sl@0
|
162 |
RBusLogicalChannel::Close();
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
Get the current configuration settings.
|
sl@0
|
167 |
|
sl@0
|
168 |
@param aConfig A structure which will be filled with the configuration settings.
|
sl@0
|
169 |
|
sl@0
|
170 |
@return KErrNone
|
sl@0
|
171 |
*/
|
sl@0
|
172 |
TInt RCamera1::GetConfig(TConfigBuf& aConfig)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
return DoControl(EGetConfig,(TAny*)&aConfig);
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
Set the current configuration settings.
|
sl@0
|
179 |
|
sl@0
|
180 |
@param aConfig The new configuration settings to be used.
|
sl@0
|
181 |
|
sl@0
|
182 |
@return KErrInUse if image capturing is already in progress
|
sl@0
|
183 |
KErrArgument if any configuration values are invalid.
|
sl@0
|
184 |
KErrNone otherwise
|
sl@0
|
185 |
|
sl@0
|
186 |
@post On success, iChunk will contain the handle of the chunk used to
|
sl@0
|
187 |
contain captured images.
|
sl@0
|
188 |
*/
|
sl@0
|
189 |
TInt RCamera1::SetConfig(const TConfigBuf& aConfig)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
iChunk.Close(); // The following call will give us a new handle
|
sl@0
|
192 |
return iChunk.SetReturnedHandle(DoControl(ESetConfig,(TAny*)&aConfig));
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Start the image capture process.
|
sl@0
|
197 |
|
sl@0
|
198 |
@return KErrNotReady if SetConfig() has not been previously called.
|
sl@0
|
199 |
KErrNone otherwise.
|
sl@0
|
200 |
|
sl@0
|
201 |
@pre The driver must have been previousely initialised by a call to SetConfig()
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
TInt RCamera1::StartCapture()
|
sl@0
|
204 |
{
|
sl@0
|
205 |
return DoControl(EStartCapture);
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
/**
|
sl@0
|
209 |
End the image capturing process.
|
sl@0
|
210 |
Also performs CaptureImageCancel()
|
sl@0
|
211 |
*/
|
sl@0
|
212 |
TInt RCamera1::EndCapture()
|
sl@0
|
213 |
{
|
sl@0
|
214 |
return DoControl(EEndCapture);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
/**
|
sl@0
|
218 |
Get the next available image and optionally release an already captured image.
|
sl@0
|
219 |
Only one request may be pending at any time.
|
sl@0
|
220 |
|
sl@0
|
221 |
@param aStatus The request status signaled when an image is available (or on error).
|
sl@0
|
222 |
The result value is the offset within iChunk where the capture image resides;
|
sl@0
|
223 |
or set to one of the system wide error codes when an error occurs:
|
sl@0
|
224 |
KErrNotReady if StartCapture() hasn't been previousely called,
|
sl@0
|
225 |
KErrInUse if there is already a pending CaptureImage() request,
|
sl@0
|
226 |
KErrOverflow if the client already has all the images buffers.
|
sl@0
|
227 |
|
sl@0
|
228 |
@param aReleaseImage The chunk offset of an image which the client has finished processing.
|
sl@0
|
229 |
Set to -1 to indicate 'no image'
|
sl@0
|
230 |
|
sl@0
|
231 |
@pre Image capturing must have been started with StartCapture()
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
void RCamera1::CaptureImage(TRequestStatus& aStatus,TInt aReleaseImage)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
aStatus=KRequestPending;
|
sl@0
|
236 |
DoControl(ECaptureImage,(TAny*)&aStatus,(TAny*)aReleaseImage);
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
/**
|
sl@0
|
240 |
Cancel a previous CaptureImage() request
|
sl@0
|
241 |
*/
|
sl@0
|
242 |
void RCamera1::CaptureImageCancel()
|
sl@0
|
243 |
{
|
sl@0
|
244 |
DoCancel(1<<ECaptureImage);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
Release an already captured image.
|
sl@0
|
249 |
|
sl@0
|
250 |
This makes the images buffer available again for the driver to capture images into.
|
sl@0
|
251 |
|
sl@0
|
252 |
@param aReleaseImage The chunk offset of the image to be released.
|
sl@0
|
253 |
This is a value returned by a CaptureImage() request.
|
sl@0
|
254 |
*/
|
sl@0
|
255 |
TInt RCamera1::ReleaseImage(TInt aReleaseImage)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
return DoControl(EReleaseImage,(TAny*)aReleaseImage);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
Override of RHandleBase::Duplicate.
|
sl@0
|
262 |
This takes care of also duplicating other resources owned by this object.
|
sl@0
|
263 |
@param aSrc A reference to the thread containing the handle which is to be
|
sl@0
|
264 |
duplicated for this thread.
|
sl@0
|
265 |
@param aType An enumeration whose enumerators define the ownership of this
|
sl@0
|
266 |
handle. If not explicitly specified, EOwnerProcess is taken
|
sl@0
|
267 |
as default.
|
sl@0
|
268 |
@return KErrNone, if successful; otherwise, one of the other system wide error
|
sl@0
|
269 |
codes.
|
sl@0
|
270 |
@see RHandleBase::Duplicate
|
sl@0
|
271 |
*/
|
sl@0
|
272 |
TInt RCamera1::Duplicate(const RThread& aSrc,TOwnerType aType)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
// Duplicate handle to channel
|
sl@0
|
275 |
TInt r=RHandleBase::Duplicate(aSrc,aType);
|
sl@0
|
276 |
if(r==KErrNone && iChunk.Handle()!=KNullHandle)
|
sl@0
|
277 |
{
|
sl@0
|
278 |
// Duplicate handle to chunk
|
sl@0
|
279 |
r = iChunk.Duplicate(aSrc,aType);
|
sl@0
|
280 |
if(r!=KErrNone)
|
sl@0
|
281 |
RHandleBase::Close(); // Undo channel open
|
sl@0
|
282 |
}
|
sl@0
|
283 |
if(r!=KErrNone)
|
sl@0
|
284 |
iChunk.SetHandle(KNullHandle); // On error, clear chunk handle
|
sl@0
|
285 |
return r;
|
sl@0
|
286 |
}
|
sl@0
|
287 |
|
sl@0
|
288 |
/**
|
sl@0
|
289 |
Obtain the chunk into which captured images will be placed.
|
sl@0
|
290 |
This chunk may change after calls to SetConfig().
|
sl@0
|
291 |
|
sl@0
|
292 |
@return The chunk
|
sl@0
|
293 |
|
sl@0
|
294 |
@pre The driver must have been configured using SetConfig()
|
sl@0
|
295 |
*/
|
sl@0
|
296 |
inline RChunk RCamera1::ImageChunk() const
|
sl@0
|
297 |
{
|
sl@0
|
298 |
return iChunk;
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
#endif // !__KERNEL_MODE__
|
sl@0
|
302 |
|
sl@0
|
303 |
#endif
|
sl@0
|
304 |
|