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