|
1 /* |
|
2 * Copyright (c) 2008 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: NativeHttpSession |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "nativehttpsession.h" |
|
20 #include "nativehttptransaction.h" |
|
21 #include <http/thttpfilteriterator.h> |
|
22 #include "httpsessionclient.h" |
|
23 #include <e32svr.h> |
|
24 #include "logger.h" |
|
25 #include <flogger.h> |
|
26 |
|
27 #include "javajniutils.h" |
|
28 |
|
29 using namespace java::util; |
|
30 |
|
31 #include "s60commonutils.h" |
|
32 #include "fs_methodcall.h" |
|
33 |
|
34 |
|
35 NativeHttpSession::NativeHttpSession(): java::util::FunctionServer("Myhttp1Server") |
|
36 { |
|
37 JELOG2(ESOCKET); |
|
38 createServerToNewThread(); |
|
39 iMonitor = java::util::Monitor::createMonitor(); |
|
40 } |
|
41 |
|
42 |
|
43 NativeHttpSession::~NativeHttpSession() |
|
44 { |
|
45 JELOG2(ESOCKET); |
|
46 |
|
47 //delete iHttpSessionClient; |
|
48 TInt handle = reinterpret_cast<TInt>(this); |
|
49 |
|
50 CallMethod(this, &NativeHttpSession::ExecuteCloseHttpSessionL,handle, this); |
|
51 |
|
52 if (iMonitor != NULL) |
|
53 iMonitor->wait(); |
|
54 |
|
55 iHttpSessionClient = NULL; |
|
56 stopServer(); |
|
57 |
|
58 delete iMonitor; |
|
59 iMonitor = NULL; |
|
60 |
|
61 } |
|
62 |
|
63 void NativeHttpSession::ExecuteCloseHttpSessionL(int /*aSelfhandle*/) |
|
64 { |
|
65 if (iHttpSessionClient !=NULL) |
|
66 { |
|
67 delete iHttpSessionClient; |
|
68 iHttpSessionClient = NULL; |
|
69 } |
|
70 |
|
71 iMonitor->notify(); |
|
72 |
|
73 } |
|
74 /** |
|
75 * This uses the TConstructor class to ensure safe construction of the CJavaEventSource |
|
76 * subclass, and then returns the Java handle to the object directly, hence the |
|
77 * somewhat different NewL method. |
|
78 */ |
|
79 |
|
80 TInt NativeHttpSession::NewL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ TInt aType, TInt aAPNId, TInt * aErr, TInt * apnerr) |
|
81 { |
|
82 NativeHttpSession* self = new(ELeave) NativeHttpSession(); |
|
83 // Cleanup the event source object if a leave occurs during construction: |
|
84 //TConstructor selfCleanup(self, aJni); |
|
85 // FeatureManager::InitializeLibL(); |
|
86 // TBool isSupported = false; //FeatureManager::FeatureSupported( KFeatureIdJavaApiEnhancementsIap );//KFeatureIdJavaAPIEnhancementsIAP |
|
87 // FeatureManager::UnInitializeLib(); |
|
88 // if( isSupported ) |
|
89 // { |
|
90 *aErr = self->ConstructL(aJni, aPeer /* aServer*/, aType, aAPNId, apnerr); |
|
91 LOG1(ESOCKET,EInfo,"NativeHttpSession::NewL - aErr : %d",*aErr); |
|
92 // } |
|
93 //else |
|
94 // { |
|
95 // self->ConstructL(aJni, aPeer, /*aServer,*/ aType, -1 ); |
|
96 // } |
|
97 self->attachToVm(aJni,aPeer); |
|
98 // Pop the cleanup of the object and create a handle: |
|
99 return reinterpret_cast<TInt>(self); //selfCleanup.GetHandle(); |
|
100 } |
|
101 |
|
102 void NativeHttpSession::vmAttached() |
|
103 { |
|
104 LOG(ESOCKET,EInfo,"+vmAttached"); |
|
105 jclass httpNativeClass = NULL; |
|
106 httpNativeClass = mJniEnv->FindClass("com/nokia/mj/impl/http/HttpConnectionNative"); |
|
107 |
|
108 iSubmitCallbackMethodID = NULL; |
|
109 iSubmitCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "transactionSubmitCallback", "(I)V"); |
|
110 |
|
111 iReadCallbackMethodID = NULL; |
|
112 iReadCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "dataReadyForReadCallBack", "(I)V"); |
|
113 |
|
114 // mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,1); |
|
115 |
|
116 /* httpNativeClass = mJniEnv->FindClass("com/nokia/mj/impl/gcf/protocol/http/Protocol"); |
|
117 if ( httpNativeClass == NULL ) |
|
118 { |
|
119 LOG(ESOCKET,EInfo,"+httpNativeClass is null"); |
|
120 } |
|
121 iSubmitCallbackMethodID = NULL; |
|
122 iSubmitCallbackMethodID = mJniEnv->GetMethodID( httpNativeClass, "temp", "(I)V" ); |
|
123 if ( iSubmitCallbackMethodID == NULL ) |
|
124 { |
|
125 LOG(ESOCKET,EInfo,"+iMethodID is NULL"); |
|
126 } |
|
127 mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,1);*/ |
|
128 LOG(ESOCKET,EInfo,"-vmAttached"); |
|
129 } |
|
130 |
|
131 TInt NativeHttpSession::ConstructL(JNIEnv& /*aJni*/, jobject /*aPeer*/,/* TJavaEventServer aServer, */ TInt aType, TInt aAPNId, TInt * apnerr) |
|
132 { |
|
133 // CJavaEventSourceBase::ConstructL(aJni, aPeer, aServer); |
|
134 //iSuiteId = aSuiteId; |
|
135 |
|
136 TInt err; |
|
137 TInt handle = reinterpret_cast<TInt>(this); |
|
138 CallMethodL(err, this, &NativeHttpSession::ExecuteCreateHttpSessionL,handle, aType, aAPNId,apnerr, this); |
|
139 |
|
140 return err; |
|
141 } |
|
142 |
|
143 TInt NativeHttpSession::CreateTransactionL(JNIEnv* aJni, jobject aPeer, jstring aUri, jstring aRequestMethod) |
|
144 { |
|
145 std::wstring uri2 = JniUtils::jstringToWstring(aJni,aUri); |
|
146 std::wstring req2 = JniUtils::jstringToWstring(aJni,aRequestMethod); |
|
147 |
|
148 HBufC* t1 = S60CommonUtils::wstringToDes(uri2.c_str()); |
|
149 HBufC* t2 = S60CommonUtils::wstringToDes(req2.c_str()); |
|
150 |
|
151 // RJString uri( *aJni, aUri ); |
|
152 // RJString reqMethod( *aJni, aRequestMethod ); |
|
153 //TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer, Server(), *iHttpSessionClient, (const TDesC*)&uri, (const TDesC*)&reqMethod); |
|
154 TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer,/* NULL, */*iHttpSessionClient, (const TDesC*)t1, (const TDesC*)t2,this); |
|
155 return handle; |
|
156 } |
|
157 |
|
158 TInt NativeHttpSession::ExecuteCreateHttpSessionL(int aSelfhandle, TInt aType, TInt aAPNId, TInt* apnerr) |
|
159 { |
|
160 LOG(ESOCKET,EInfo,"+ExecuteCreateHttpSessionL"); |
|
161 TInt err = 0; |
|
162 NativeHttpSession *aSelf = reinterpret_cast<NativeHttpSession*>(aSelfhandle); |
|
163 |
|
164 LOG1(ESOCKET,EInfo,"NativeHttpSession uses APN: %d", aAPNId); |
|
165 if (aAPNId != -1) |
|
166 { |
|
167 LOG1(ESOCKET,EInfo,"NativeHttpSession creates client with APN: %d", aAPNId); |
|
168 TRAP(err,aSelf->iHttpSessionClient = HttpSessionClient::NewL(aType, aAPNId, apnerr)); |
|
169 } |
|
170 else |
|
171 { |
|
172 LOG(ESOCKET,EInfo,"NativeHttpSession creates client no APN"); |
|
173 TRAP(err,aSelf->iHttpSessionClient = HttpSessionClient::NewL(-1,-1, apnerr)); |
|
174 } |
|
175 |
|
176 LOG1(ESOCKET,EInfo,"ExecuteCreateHttpSessionL : err : %d",err); |
|
177 LOG(ESOCKET,EInfo,"-ExecuteCreateHttpSessionL "); |
|
178 return err; |
|
179 } |
|
180 |
|
181 //RHTTPSession& NativeHttpSession::Session() |
|
182 // { |
|
183 // return iHttpSessionClient->Session(); |
|
184 // } |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 void NativeHttpSession::doSubmitCallback(TInt aStatus,jobject &aPeer) |
|
190 { |
|
191 LOG(ESOCKET,EInfo,"+doSubmitCallback1"); |
|
192 //mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,aStatus); |
|
193 mJniEnv->CallVoidMethod(aPeer,iSubmitCallbackMethodID,aStatus); |
|
194 LOG(ESOCKET,EInfo,"-doSubmitCallback1"); |
|
195 } |
|
196 |
|
197 void NativeHttpSession::doReadCallback(TInt aStatus,jobject &aPeer) |
|
198 { |
|
199 LOG(ESOCKET,EInfo,"+doReadCallback1"); |
|
200 // mJniEnv->CallVoidMethod(mJavaPeerObject,iReadCallbackMethodID,aStatus); |
|
201 mJniEnv->CallVoidMethod(aPeer,iReadCallbackMethodID,aStatus); |
|
202 LOG(ESOCKET,EInfo,"-doReadCallback1"); |
|
203 } |
|
204 |