|
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 /** |
|
44 * This uses the TConstructor class to ensure safe construction of the CJavaEventSource |
|
45 * subclass, and then returns the Java handle to the object directly, hence the |
|
46 * somewhat different NewL method. |
|
47 */ |
|
48 |
|
49 TInt NativeHttpSession::NewL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ TInt aType, TInt aAPNId, TInt * aErr, TInt * apnerr) |
|
50 { |
|
51 NativeHttpSession* self = new(ELeave) NativeHttpSession(); |
|
52 |
|
53 *aErr = self->ConstructL(aJni, aPeer /* aServer*/, aType, aAPNId, apnerr); |
|
54 LOG1(ESOCKET,EInfo,"NativeHttpSession::NewL - aErr : %d",*aErr); |
|
55 |
|
56 self->attachToVm(aJni,aPeer); |
|
57 // Pop the cleanup of the object and create a handle: |
|
58 return reinterpret_cast<TInt>(self); //selfCleanup.GetHandle(); |
|
59 } |
|
60 |
|
61 void NativeHttpSession::vmAttached() |
|
62 { |
|
63 LOG(ESOCKET,EInfo,"+vmAttached"); |
|
64 jclass httpNativeClass = NULL; |
|
65 httpNativeClass = mJniEnv->FindClass("com/nokia/mj/impl/http/HttpConnectionNative"); |
|
66 |
|
67 iSubmitCallbackMethodID = NULL; |
|
68 iSubmitCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "transactionSubmitCallback", "(I)V"); |
|
69 |
|
70 iReadCallbackMethodID = NULL; |
|
71 iReadCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "dataReadyForReadCallBack", "(I)V"); |
|
72 |
|
73 LOG(ESOCKET,EInfo,"-vmAttached"); |
|
74 } |
|
75 |
|
76 TInt NativeHttpSession::ConstructL(JNIEnv& /*aJni*/, jobject /*aPeer*/,/* TJavaEventServer aServer, */ TInt aType, TInt aAPNId, TInt * apnerr) |
|
77 { |
|
78 TInt err; |
|
79 TInt handle = reinterpret_cast<TInt>(this); |
|
80 CallMethodL(err, this, &NativeHttpSession::ExecuteCreateHttpSessionL,handle, aType, aAPNId,apnerr, this); |
|
81 |
|
82 return err; |
|
83 } |
|
84 |
|
85 TInt NativeHttpSession::CreateTransactionL(JNIEnv* aJni, jobject aPeer, jstring aUri, jstring aRequestMethod) |
|
86 { |
|
87 std::wstring uri2 = JniUtils::jstringToWstring(aJni,aUri); |
|
88 std::wstring req2 = JniUtils::jstringToWstring(aJni,aRequestMethod); |
|
89 |
|
90 HBufC* t1 = S60CommonUtils::wstringToDes(uri2.c_str()); |
|
91 HBufC* t2 = S60CommonUtils::wstringToDes(req2.c_str()); |
|
92 |
|
93 TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer,/* NULL, */*iHttpSessionClient, (const TDesC*)t1, (const TDesC*)t2,this); |
|
94 return handle; |
|
95 } |
|
96 |
|
97 TInt NativeHttpSession::ExecuteCreateHttpSessionL(int aSelfhandle, TInt aType, TInt aAPNId, TInt* apnerr) |
|
98 { |
|
99 LOG(ESOCKET,EInfo,"+ExecuteCreateHttpSessionL"); |
|
100 TInt err = 0; |
|
101 NativeHttpSession *aSelf = reinterpret_cast<NativeHttpSession*>(aSelfhandle); |
|
102 |
|
103 LOG1(ESOCKET,EInfo,"NativeHttpSession uses APN: %d", aAPNId); |
|
104 if (aAPNId != -1) |
|
105 { |
|
106 LOG1(ESOCKET,EInfo,"NativeHttpSession creates client with APN: %d", aAPNId); |
|
107 TRAP(err,aSelf->iHttpSessionClient = HttpSessionClient::NewL(aType, aAPNId, apnerr)); |
|
108 } |
|
109 else |
|
110 { |
|
111 LOG(ESOCKET,EInfo,"NativeHttpSession creates client no APN"); |
|
112 TRAP(err,aSelf->iHttpSessionClient = HttpSessionClient::NewL(-1,-1, apnerr)); |
|
113 } |
|
114 |
|
115 LOG1(ESOCKET,EInfo,"ExecuteCreateHttpSessionL : err : %d",err); |
|
116 LOG(ESOCKET,EInfo,"-ExecuteCreateHttpSessionL "); |
|
117 return err; |
|
118 } |
|
119 |
|
120 void NativeHttpSession::doSubmitCallback(TInt aStatus,jobject &aPeer) |
|
121 { |
|
122 LOG(ESOCKET,EInfo,"+doSubmitCallback1"); |
|
123 jobject localPeerObject = mJniEnv->NewLocalRef(aPeer); |
|
124 if(localPeerObject) |
|
125 { |
|
126 // java side peer object may be GC'ed when this call is being made. |
|
127 mJniEnv->CallVoidMethod(aPeer,iSubmitCallbackMethodID,aStatus); |
|
128 } |
|
129 else |
|
130 { |
|
131 ELOG(ESOCKET,"NativeHttpSession::doSubmitCallback: Error!! java peer object not found "); |
|
132 } |
|
133 LOG(ESOCKET,EInfo,"-doSubmitCallback1"); |
|
134 } |
|
135 |
|
136 void NativeHttpSession::doReadCallback(TInt aStatus,jobject &aPeer) |
|
137 { |
|
138 LOG(ESOCKET,EInfo,"+doReadCallback1"); |
|
139 jobject localPeerObject = mJniEnv->NewLocalRef(aPeer); |
|
140 if(localPeerObject) |
|
141 { |
|
142 mJniEnv->CallVoidMethod(aPeer,iReadCallbackMethodID,aStatus); |
|
143 } |
|
144 else |
|
145 { |
|
146 ELOG(ESOCKET,"NativeHttpSession::doReadCallback: Error!! java peer object not found "); |
|
147 } |
|
148 LOG(ESOCKET,EInfo,"-doReadCallback1"); |
|
149 } |
|
150 |