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 #include <logger.h> |
|
19 #include "mmafunctionserver.h" |
|
20 #include "cmmadatasourcestream.h" |
|
21 #include "mmmasourcestreamlistener.h" |
|
22 #include "cmmastreamrequest.h" |
|
23 #include "cmmasourcestreamevent.h" |
|
24 |
|
25 |
|
26 // CONSTRUCTION |
|
27 CMMADataSourceStream* CMMADataSourceStream::NewLC(JNIEnv* aJNIEnv, |
|
28 MMMAEventPoster* aEventPoster, |
|
29 jobject aJavaSourceStream, |
|
30 MMMASourceStreamListener* aListener, |
|
31 MMAFunctionServer* aEventSource |
|
32 ) |
|
33 { |
|
34 CMMADataSourceStream* self = new(ELeave) CMMADataSourceStream(aEventPoster, |
|
35 aListener); |
|
36 CleanupStack::PushL(self); |
|
37 self->ConstructL(aJNIEnv, aEventSource, aJavaSourceStream); |
|
38 return self; |
|
39 } |
|
40 |
|
41 |
|
42 CMMADataSourceStream::~CMMADataSourceStream() |
|
43 { |
|
44 LOG( EJavaMMAPI, EInfo, "MMA::CMMADataSourceStream::~"); |
|
45 } |
|
46 |
|
47 |
|
48 // Default constructor |
|
49 CMMADataSourceStream::CMMADataSourceStream(MMMAEventPoster* aEventPoster, |
|
50 MMMASourceStreamListener* aListener): |
|
51 CMMASourceStream(aEventPoster, aListener) |
|
52 { |
|
53 } |
|
54 |
|
55 |
|
56 inline void CMMADataSourceStream::ConstructL(JNIEnv* aJNIEnv,MMAFunctionServer* /*aEventSource*/, |
|
57 jobject aJavaSourceStream) |
|
58 { |
|
59 CMMASourceStream::ConstructL(aJNIEnv, aJavaSourceStream); |
|
60 CreateDataBufferL(KMMAStreamRequestBufferSize); |
|
61 } |
|
62 |
|
63 void CMMADataSourceStream::WriteL(const TUint8* aData, |
|
64 TInt aLength, |
|
65 TInt aState) |
|
66 { |
|
67 LOG1( EJavaMMAPI, EInfo, "MMA::CMMADataSourceStream::WriteL data length %d", aLength); |
|
68 LOG1( EJavaMMAPI, EInfo, "MMA::CMMADataSourceStream::WriteL state %d", aState); |
|
69 |
|
70 if (!iRequest) |
|
71 { |
|
72 // there is no request to write |
|
73 return; |
|
74 } |
|
75 |
|
76 if (aState >= KErrNone) |
|
77 { |
|
78 if ((aState == CMMASourceStream::ECompleted) && |
|
79 aLength == -1) |
|
80 { |
|
81 // Stream ended |
|
82 iRequest->RequestBuffer() = 1; |
|
83 } |
|
84 else if ((iData->Length() == 0) && |
|
85 (iRequest->DataPtr().Length() == 0)) |
|
86 { |
|
87 iRequest->DataPtr().Append(aData, aLength); |
|
88 // read next |
|
89 iEventPoster->PostEvent(iReadEvent, |
|
90 CMMAEvent::ENotifyPriority); |
|
91 return; |
|
92 } |
|
93 else if (iData->Length() == 0) |
|
94 { |
|
95 iData->Des().Append(aData, aLength); |
|
96 } |
|
97 } |
|
98 |
|
99 // complete read operation |
|
100 CMMAStreamRequest* r = iRequest; |
|
101 iRequest = NULL; |
|
102 r->CompleteRead(aState); |
|
103 LOG( EJavaMMAPI, EInfo, "MMA::CMMADataSourceStream::WriteL completed"); |
|
104 } |
|
105 |
|
106 void CMMADataSourceStream::ResetData() |
|
107 { |
|
108 LOG( EJavaMMAPI, EInfo, "MMA::CMMADataSourceStream::ResetData"); |
|
109 } |
|
110 |
|
111 CMMAStreamRequest* CMMADataSourceStream::Request() |
|
112 { |
|
113 return iRequest; |
|
114 } |
|
115 |
|
116 void CMMADataSourceStream::Read(CMMAStreamRequest* aRequest) |
|
117 { |
|
118 // Setting NULL, means that all read completes are ignored |
|
119 if (!aRequest) |
|
120 { |
|
121 iRequest = NULL; |
|
122 return; |
|
123 } |
|
124 |
|
125 if (!iRequest) |
|
126 { |
|
127 iRequest = aRequest; |
|
128 iRequest->RequestBuffer() = 0; |
|
129 iReadEvent->SetLength(aRequest->DataPtr().MaxLength()); |
|
130 |
|
131 if (iData->Length() > 0) |
|
132 { |
|
133 // Previous read buffered data |
|
134 iRequest->DataPtr().Append(*iData); |
|
135 |
|
136 // re-use buffer |
|
137 iData->Des().SetLength(0); |
|
138 } |
|
139 |
|
140 // data has been requested, note will be sent |
|
141 iEventPoster->PostEvent(iReadEvent, CMMAEvent::ENotifyPriority); |
|
142 } |
|
143 // else java is already reading |
|
144 } |
|
145 |
|
146 // END OF FILE |
|