javacommons/gcfprotocols/http/src.s60/nativehttpsession.cpp
changeset 23 98ccebc37403
parent 21 2a9601315dfc
child 48 e0d6e9bd3ca7
--- a/javacommons/gcfprotocols/http/src.s60/nativehttpsession.cpp	Mon May 03 12:27:20 2010 +0300
+++ b/javacommons/gcfprotocols/http/src.s60/nativehttpsession.cpp	Fri May 14 15:47:24 2010 +0300
@@ -40,37 +40,6 @@
 }
 
 
-NativeHttpSession::~NativeHttpSession()
-{
-    JELOG2(ESOCKET);
-
-    //delete iHttpSessionClient;
-    TInt handle = reinterpret_cast<TInt>(this);
-
-    CallMethod(this, &NativeHttpSession::ExecuteCloseHttpSessionL,handle, this);
-
-    if (iMonitor != NULL)
-        iMonitor->wait();
-
-    iHttpSessionClient = NULL;
-    stopServer();
-
-    delete iMonitor;
-    iMonitor = NULL;
-
-}
-
-void NativeHttpSession::ExecuteCloseHttpSessionL(int /*aSelfhandle*/)
-{
-    if (iHttpSessionClient !=NULL)
-    {
-        delete iHttpSessionClient;
-        iHttpSessionClient = NULL;
-    }
-
-    iMonitor->notify();
-
-}
 /**
  * This uses the TConstructor class to ensure safe construction of the CJavaEventSource
  * subclass, and then returns the Java handle to the object directly, hence the
@@ -80,20 +49,10 @@
 TInt NativeHttpSession::NewL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ TInt aType, TInt aAPNId, TInt * aErr, TInt * apnerr)
 {
     NativeHttpSession* self =   new(ELeave) NativeHttpSession();
-    // Cleanup the event source object if a leave occurs during construction:
-    //TConstructor selfCleanup(self, aJni);
-//  FeatureManager::InitializeLibL();
-    // TBool isSupported = false; //FeatureManager::FeatureSupported( KFeatureIdJavaApiEnhancementsIap );//KFeatureIdJavaAPIEnhancementsIAP
-//   FeatureManager::UnInitializeLib();
-    //  if( isSupported )
-    //      {
+    
     *aErr = self->ConstructL(aJni, aPeer  /* aServer*/, aType, aAPNId, apnerr);
     LOG1(ESOCKET,EInfo,"NativeHttpSession::NewL - aErr : %d",*aErr);
-    //    }
-    //else
-    //    {
-    //  self->ConstructL(aJni, aPeer, /*aServer,*/ aType, -1 );
-    // }
+   
     self->attachToVm(aJni,aPeer);
     // Pop the cleanup of the object and create a handle:
     return reinterpret_cast<TInt>(self); //selfCleanup.GetHandle();
@@ -111,28 +70,11 @@
     iReadCallbackMethodID = NULL;
     iReadCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "dataReadyForReadCallBack", "(I)V");
 
-    // mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,1);
-
-    /*  httpNativeClass = mJniEnv->FindClass("com/nokia/mj/impl/gcf/protocol/http/Protocol");
-       if ( httpNativeClass == NULL )
-        {
-           LOG(ESOCKET,EInfo,"+httpNativeClass is null");
-        }
-    iSubmitCallbackMethodID = NULL;
-      iSubmitCallbackMethodID = mJniEnv->GetMethodID( httpNativeClass, "temp", "(I)V" );
-      if ( iSubmitCallbackMethodID == NULL )
-        {
-           LOG(ESOCKET,EInfo,"+iMethodID is NULL");
-        }
-         mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,1);*/
     LOG(ESOCKET,EInfo,"-vmAttached");
 }
 
 TInt NativeHttpSession::ConstructL(JNIEnv& /*aJni*/, jobject /*aPeer*/,/* TJavaEventServer aServer, */ TInt aType, TInt aAPNId, TInt * apnerr)
 {
-//  CJavaEventSourceBase::ConstructL(aJni, aPeer, aServer);
-    //iSuiteId = aSuiteId;
-
     TInt err;
     TInt handle = reinterpret_cast<TInt>(this);
     CallMethodL(err, this, &NativeHttpSession::ExecuteCreateHttpSessionL,handle, aType, aAPNId,apnerr, this);
@@ -148,9 +90,6 @@
     HBufC* t1 = S60CommonUtils::wstringToDes(uri2.c_str());
     HBufC* t2 = S60CommonUtils::wstringToDes(req2.c_str());
 
-    //  RJString uri( *aJni, aUri );
-    // RJString reqMethod( *aJni, aRequestMethod );
-    //TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer, Server(), *iHttpSessionClient, (const TDesC*)&uri, (const TDesC*)&reqMethod);
     TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer,/* NULL, */*iHttpSessionClient, (const TDesC*)t1, (const TDesC*)t2,this);
     return handle;
 }
@@ -178,27 +117,34 @@
     return err;
 }
 
-//RHTTPSession&  NativeHttpSession::Session()
-//  {
-//  return iHttpSessionClient->Session();
-//  }
-
-
-
-
 void NativeHttpSession::doSubmitCallback(TInt aStatus,jobject &aPeer)
 {
-    LOG(ESOCKET,EInfo,"+doSubmitCallback1");
-    //mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,aStatus);
-    mJniEnv->CallVoidMethod(aPeer,iSubmitCallbackMethodID,aStatus);
+    LOG(ESOCKET,EInfo,"+doSubmitCallback1");    
+    jobject localPeerObject = mJniEnv->NewLocalRef(aPeer);
+    if(localPeerObject)
+    {
+    		// java side peer object may be GC'ed when this call is being made. 
+    		mJniEnv->CallVoidMethod(aPeer,iSubmitCallbackMethodID,aStatus);
+    }
+    else
+    {
+    		ELOG(ESOCKET,"NativeHttpSession::doSubmitCallback: Error!! java peer object not found ");
+  	}	
     LOG(ESOCKET,EInfo,"-doSubmitCallback1");
 }
 
 void NativeHttpSession::doReadCallback(TInt aStatus,jobject &aPeer)
 {
     LOG(ESOCKET,EInfo,"+doReadCallback1");
-//  mJniEnv->CallVoidMethod(mJavaPeerObject,iReadCallbackMethodID,aStatus);
-    mJniEnv->CallVoidMethod(aPeer,iReadCallbackMethodID,aStatus);
+    jobject localPeerObject = mJniEnv->NewLocalRef(aPeer);
+    if(localPeerObject)
+    {
+    		mJniEnv->CallVoidMethod(aPeer,iReadCallbackMethodID,aStatus);
+    }
+    else
+    {
+    		ELOG(ESOCKET,"NativeHttpSession::doReadCallback: Error!! java peer object not found ");
+  	}    
     LOG(ESOCKET,EInfo,"-doReadCallback1");
 }