|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class for reading data from Java SourceStream to native side |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CMMASOURCESTREAM_H |
|
20 #define CMMASOURCESTREAM_H |
|
21 |
|
22 //#include <jutils.h> |
|
23 #include "mmafunctionserver.h" |
|
24 |
|
25 class CMMASourceStreamEvent; |
|
26 class MMMASourceStreamListener; |
|
27 class MMMAEventPoster; |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KMMAReadAllData = -1; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 /** |
|
34 * Class for reading data from Java SourceStream to native side |
|
35 * |
|
36 * |
|
37 */ |
|
38 NONSHARABLE_CLASS(CMMASourceStream): public CBase |
|
39 { |
|
40 public: |
|
41 /** |
|
42 * Status of the source stream reader |
|
43 */ |
|
44 enum TStatus |
|
45 { |
|
46 EReadAll = 1, |
|
47 ERead = 2, |
|
48 EMoreData = 3, |
|
49 ECompleted = 4, |
|
50 EClosed = 5 |
|
51 }; |
|
52 |
|
53 public: // Constructors and destructors |
|
54 /** |
|
55 * Object creation. Static method. |
|
56 * |
|
57 * @param aJNIEnv handle to used jni environment |
|
58 * @param aEventPoster handle to event poster |
|
59 * @param aJavaSourceStream handle to java SourceStream object |
|
60 * @param aListener Handle to source stream listener |
|
61 * |
|
62 * @return CMMASourceStream object |
|
63 */ |
|
64 static CMMASourceStream* NewL(JNIEnv* aJNIEnv, |
|
65 MMMAEventPoster* aEventPoster, |
|
66 jobject aJavaSourceStream, |
|
67 MMMASourceStreamListener* aListener); |
|
68 |
|
69 /** |
|
70 * The same as NewL with cleanup stack |
|
71 * @see NewL |
|
72 */ |
|
73 static CMMASourceStream* NewLC(JNIEnv* aJNIEnv, |
|
74 MMMAEventPoster* aEventPoster, |
|
75 jobject aJavaSourceStream, |
|
76 MMMASourceStreamListener* aListener); |
|
77 |
|
78 /** |
|
79 * Deletes owned objects |
|
80 */ |
|
81 ~CMMASourceStream(); // Destructor |
|
82 |
|
83 protected: // Constructors and destructors |
|
84 |
|
85 /** |
|
86 * Set variables |
|
87 * @param aEventPoster handle to event poster |
|
88 * @param aListener handle to source stream listener |
|
89 */ |
|
90 CMMASourceStream(MMMAEventPoster* aEventPoster, |
|
91 MMMASourceStreamListener* aListener); |
|
92 |
|
93 /** |
|
94 * 2nd phase constructor |
|
95 * |
|
96 * @param aJNIEnv used jni environment |
|
97 * @param aJavaSourceStream handle to java source stream object |
|
98 */ |
|
99 void ConstructL(JNIEnv* aJNIEnv, jobject aJavaSourceStream); |
|
100 |
|
101 public: // New methods |
|
102 /** |
|
103 * Writes data to from java buffer to native side |
|
104 * |
|
105 * @param aData data passed by Java side |
|
106 * @param aLength size of passed data |
|
107 * @param state of this class |
|
108 */ |
|
109 virtual void WriteL(const TUint8* aData, |
|
110 TInt aLength, TInt aState); |
|
111 /** |
|
112 * Read aLength bytes from Java source stream |
|
113 * |
|
114 * @param aLength size of read |
|
115 */ |
|
116 void ReadL(TInt aLength); |
|
117 |
|
118 /** |
|
119 * Read all data from Java source stream, clears buffer |
|
120 */ |
|
121 void ReadAllL(); |
|
122 |
|
123 /** |
|
124 * Reset all data |
|
125 */ |
|
126 virtual void ResetData(); |
|
127 |
|
128 /** |
|
129 * Creates data buffer |
|
130 * |
|
131 * @param aBufferSize data buffer size |
|
132 */ |
|
133 void CreateDataBufferL(TInt aBufferSize); |
|
134 |
|
135 |
|
136 protected: // New methods |
|
137 |
|
138 /** |
|
139 * Prepare whatever is necessary for reading |
|
140 */ |
|
141 virtual void PrepareReadL(); |
|
142 |
|
143 protected: |
|
144 CMMASourceStreamEvent* iReadEvent; |
|
145 MMMAEventPoster* iEventPoster; |
|
146 MMMASourceStreamListener* iListener; |
|
147 |
|
148 protected: |
|
149 /** |
|
150 * Buffer where data from java side will be read, Owned |
|
151 */ |
|
152 HBufC8* iData; |
|
153 |
|
154 /** |
|
155 * number of bytes coming from java stream, KMMAReadAllData is whole stream |
|
156 */ |
|
157 TInt iReadLength; |
|
158 |
|
159 /** |
|
160 * current position |
|
161 */ |
|
162 TInt iBufferPosition; |
|
163 }; |
|
164 |
|
165 #endif // CMMASOURCESTREAM_H |