|
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 // Shared Chunks in its implementation. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file Kernel side interfaces to example data converter device driver which uses |
|
20 @publishedPartner |
|
21 @prototype 9.1 |
|
22 */ |
|
23 |
|
24 #ifndef __CONVERT1_DEV_H__ |
|
25 #define __CONVERT1_DEV_H__ |
|
26 |
|
27 /** |
|
28 Logical Device (factory class) for 'Convert1' |
|
29 */ |
|
30 class DConvert1Factory : public DLogicalDevice |
|
31 { |
|
32 public: |
|
33 DConvert1Factory(); |
|
34 ~DConvert1Factory(); |
|
35 // Inherited from DLogicalDevice |
|
36 virtual TInt Install(); |
|
37 virtual void GetCaps(TDes8& aDes) const; |
|
38 virtual TInt Create(DLogicalChannelBase*& aChannel); |
|
39 // Resource handling methods |
|
40 TInt ClaimResource(TInt& aResourceId); |
|
41 void ReleaseResource(TInt aResourceId); |
|
42 private: |
|
43 NFastMutex iResourceMutex; /**< Mutex to protect access to iResourceFlags */ |
|
44 TUint iResourceFlags; /**< Bitfield of flags representing device resources available for use. |
|
45 I.e. iResourceFlags&(1<<resourceId) is true if resource 'resourceId' is free. */ |
|
46 }; |
|
47 |
|
48 /** |
|
49 Class representing a buffer of data |
|
50 */ |
|
51 class DChunkBuffer |
|
52 { |
|
53 public: |
|
54 DChunkBuffer(); |
|
55 ~DChunkBuffer(); |
|
56 TInt Create(TInt aSize); |
|
57 void Destroy(); |
|
58 TInt SetMaxSize(TInt aMaxSize); |
|
59 TInt Open(TAny* aAddress, TInt aSize, TBool aWrite=EFalse); |
|
60 TInt Open(TInt aChunkHandle, TInt aOffset, TInt aSize, TBool aWrite=EFalse); |
|
61 void Close(); |
|
62 TInt Copy(TAny* aAddress, TInt aSize); |
|
63 private: |
|
64 TInt SetPhysicalAddresses(TInt aSize); |
|
65 public: |
|
66 DChunk* iChunk; /**< The chunk which contains the buffer */ |
|
67 TInt iChunkOffset; /**< Offset, in bytes, of buffer start within the chunk */ |
|
68 TInt iMaxSize; /**< Maximum size of buffer n bytes */ |
|
69 TLinAddr iChunkBase; /**< Linear address in kernel process for the start of the chunk */ |
|
70 TUint32 iChunkMapAttr; /**< MMU mapping attributes for chunk */ |
|
71 TPhysAddr iPhysicalAddress; /**< Physical address of buffer. KPhysAddrInvalid if buffer not physically contiguous */ |
|
72 TPhysAddr* iPhysicalPages; /**< List of physical addresses for buffer pages. 0 if buffer is physically contiguous */ |
|
73 }; |
|
74 |
|
75 /** |
|
76 Logical Channel class for 'Convert1' |
|
77 */ |
|
78 class DConvert1Channel : public DLogicalChannelBase |
|
79 { |
|
80 public: |
|
81 DConvert1Channel(DConvert1Factory* aFactory); |
|
82 virtual ~DConvert1Channel(); |
|
83 // Inherited from DObject |
|
84 virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); |
|
85 // Inherited from DLogicalChannelBase |
|
86 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
87 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
88 private: |
|
89 // Panic reasons |
|
90 enum TPanic |
|
91 { |
|
92 ERequestFromWrongThread=1, |
|
93 ERequestAlreadyPending |
|
94 }; |
|
95 // Implementation for the differnt kinds of messages sent through RBusLogicalChannel |
|
96 TInt DoControl(TInt aFunction, TAny* a1, TAny* a2); |
|
97 TInt DoRequest(TInt aNotReqNo, TAny* a1, TAny* a2); |
|
98 TInt DoCancel(TUint aMask); |
|
99 // Methods for configuration |
|
100 TInt GetConfig(TDes8* aConfigBuf); |
|
101 TInt SetConfig(const TDesC8* aConfigBuf,RConvert1::TBufferInfo* aBufferInfo); |
|
102 // Methods for capturing images |
|
103 void ConvertDes(const TDesC8* aSrc,TRequestStatus* aRequestStatus); |
|
104 void ConvertChunk(const RConvert1::TConvertArgs* aSrcArgs,TRequestStatus* aRequestStatus); |
|
105 void ConvertInChunk(TInt aSize,TRequestStatus* aRequestStatus); |
|
106 void ConvertCancel(); |
|
107 void ConvertComplete(TInt aResult); |
|
108 static void ConvertDfcTrampoline(TAny* aSelf); |
|
109 void ConvertDfc(); |
|
110 // Methods which program the convert hardware |
|
111 void DoConvertStart(TInt aOffset,TInt aSize); |
|
112 void DoConvertCancel(); |
|
113 private: |
|
114 DConvert1Factory* iFactory; /**< Pointer to device driver factory object */ |
|
115 TInt iResourceId; /**< The id of the device hardware resource owned by this channel */ |
|
116 |
|
117 NFastMutex iConvertMutex; /**< Mutex to protect access to driver state */ |
|
118 |
|
119 DChunkBuffer* iSource; /**< Buffer containing the converter's input data */ |
|
120 DChunkBuffer iInBuffer; /**< Buffer into which client supplied data can be copied */ |
|
121 DChunkBuffer iOutBuffer; /**< Buffer containing the converter's output data */ |
|
122 DChunkBuffer iClientBuffer; /**< Buffer representing client supplied chunk data */ |
|
123 |
|
124 DThread* iClient; /**< The single client thread for this channel */ |
|
125 TRequestStatus* iConvertRequestStatus; /**< The request status for client ConvertImage request */ |
|
126 |
|
127 RConvert1::TConfig iConfig; /**< The driver configuration information */ |
|
128 |
|
129 NTimer iConvertTimer; /**< Timer used to emulate image capture hardware */ |
|
130 }; |
|
131 |
|
132 #endif |
|
133 |