javacommons/gcfprotocols/http/src.s60/nativehttpsession.cpp
changeset 23 98ccebc37403
parent 21 2a9601315dfc
child 48 e0d6e9bd3ca7
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
    38     createServerToNewThread();
    38     createServerToNewThread();
    39     iMonitor = java::util::Monitor::createMonitor();
    39     iMonitor = java::util::Monitor::createMonitor();
    40 }
    40 }
    41 
    41 
    42 
    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 /**
    43 /**
    75  * This uses the TConstructor class to ensure safe construction of the CJavaEventSource
    44  * 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
    45  * subclass, and then returns the Java handle to the object directly, hence the
    77  * somewhat different NewL method.
    46  * somewhat different NewL method.
    78  */
    47  */
    79 
    48 
    80 TInt NativeHttpSession::NewL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ TInt aType, TInt aAPNId, TInt * aErr, TInt * apnerr)
    49 TInt NativeHttpSession::NewL(JNIEnv& aJni, jobject aPeer,/* TJavaEventServer aServer,*/ TInt aType, TInt aAPNId, TInt * aErr, TInt * apnerr)
    81 {
    50 {
    82     NativeHttpSession* self =   new(ELeave) NativeHttpSession();
    51     NativeHttpSession* self =   new(ELeave) NativeHttpSession();
    83     // Cleanup the event source object if a leave occurs during construction:
    52     
    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);
    53     *aErr = self->ConstructL(aJni, aPeer  /* aServer*/, aType, aAPNId, apnerr);
    91     LOG1(ESOCKET,EInfo,"NativeHttpSession::NewL - aErr : %d",*aErr);
    54     LOG1(ESOCKET,EInfo,"NativeHttpSession::NewL - aErr : %d",*aErr);
    92     //    }
    55    
    93     //else
       
    94     //    {
       
    95     //  self->ConstructL(aJni, aPeer, /*aServer,*/ aType, -1 );
       
    96     // }
       
    97     self->attachToVm(aJni,aPeer);
    56     self->attachToVm(aJni,aPeer);
    98     // Pop the cleanup of the object and create a handle:
    57     // Pop the cleanup of the object and create a handle:
    99     return reinterpret_cast<TInt>(self); //selfCleanup.GetHandle();
    58     return reinterpret_cast<TInt>(self); //selfCleanup.GetHandle();
   100 }
    59 }
   101 
    60 
   109     iSubmitCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "transactionSubmitCallback", "(I)V");
    68     iSubmitCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "transactionSubmitCallback", "(I)V");
   110 
    69 
   111     iReadCallbackMethodID = NULL;
    70     iReadCallbackMethodID = NULL;
   112     iReadCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "dataReadyForReadCallBack", "(I)V");
    71     iReadCallbackMethodID = mJniEnv->GetMethodID(httpNativeClass, "dataReadyForReadCallBack", "(I)V");
   113 
    72 
   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");
    73     LOG(ESOCKET,EInfo,"-vmAttached");
   129 }
    74 }
   130 
    75 
   131 TInt NativeHttpSession::ConstructL(JNIEnv& /*aJni*/, jobject /*aPeer*/,/* TJavaEventServer aServer, */ TInt aType, TInt aAPNId, TInt * apnerr)
    76 TInt NativeHttpSession::ConstructL(JNIEnv& /*aJni*/, jobject /*aPeer*/,/* TJavaEventServer aServer, */ TInt aType, TInt aAPNId, TInt * apnerr)
   132 {
    77 {
   133 //  CJavaEventSourceBase::ConstructL(aJni, aPeer, aServer);
       
   134     //iSuiteId = aSuiteId;
       
   135 
       
   136     TInt err;
    78     TInt err;
   137     TInt handle = reinterpret_cast<TInt>(this);
    79     TInt handle = reinterpret_cast<TInt>(this);
   138     CallMethodL(err, this, &NativeHttpSession::ExecuteCreateHttpSessionL,handle, aType, aAPNId,apnerr, this);
    80     CallMethodL(err, this, &NativeHttpSession::ExecuteCreateHttpSessionL,handle, aType, aAPNId,apnerr, this);
   139 
    81 
   140     return err;
    82     return err;
   146     std::wstring  req2 = JniUtils::jstringToWstring(aJni,aRequestMethod);
    88     std::wstring  req2 = JniUtils::jstringToWstring(aJni,aRequestMethod);
   147 
    89 
   148     HBufC* t1 = S60CommonUtils::wstringToDes(uri2.c_str());
    90     HBufC* t1 = S60CommonUtils::wstringToDes(uri2.c_str());
   149     HBufC* t2 = S60CommonUtils::wstringToDes(req2.c_str());
    91     HBufC* t2 = S60CommonUtils::wstringToDes(req2.c_str());
   150 
    92 
   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);
    93     TInt handle= NativeHttpTransaction::NewL(*aJni,aPeer,/* NULL, */*iHttpSessionClient, (const TDesC*)t1, (const TDesC*)t2,this);
   155     return handle;
    94     return handle;
   156 }
    95 }
   157 
    96 
   158 TInt NativeHttpSession::ExecuteCreateHttpSessionL(int aSelfhandle, TInt aType, TInt aAPNId, TInt*  apnerr)
    97 TInt NativeHttpSession::ExecuteCreateHttpSessionL(int aSelfhandle, TInt aType, TInt aAPNId, TInt*  apnerr)
   176     LOG1(ESOCKET,EInfo,"ExecuteCreateHttpSessionL : err :  %d",err);
   115     LOG1(ESOCKET,EInfo,"ExecuteCreateHttpSessionL : err :  %d",err);
   177     LOG(ESOCKET,EInfo,"-ExecuteCreateHttpSessionL ");
   116     LOG(ESOCKET,EInfo,"-ExecuteCreateHttpSessionL ");
   178     return err;
   117     return err;
   179 }
   118 }
   180 
   119 
   181 //RHTTPSession&  NativeHttpSession::Session()
       
   182 //  {
       
   183 //  return iHttpSessionClient->Session();
       
   184 //  }
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 void NativeHttpSession::doSubmitCallback(TInt aStatus,jobject &aPeer)
   120 void NativeHttpSession::doSubmitCallback(TInt aStatus,jobject &aPeer)
   190 {
   121 {
   191     LOG(ESOCKET,EInfo,"+doSubmitCallback1");
   122     LOG(ESOCKET,EInfo,"+doSubmitCallback1");    
   192     //mJniEnv->CallVoidMethod(mJavaPeerObject,iSubmitCallbackMethodID,aStatus);
   123     jobject localPeerObject = mJniEnv->NewLocalRef(aPeer);
   193     mJniEnv->CallVoidMethod(aPeer,iSubmitCallbackMethodID,aStatus);
   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   	}	
   194     LOG(ESOCKET,EInfo,"-doSubmitCallback1");
   133     LOG(ESOCKET,EInfo,"-doSubmitCallback1");
   195 }
   134 }
   196 
   135 
   197 void NativeHttpSession::doReadCallback(TInt aStatus,jobject &aPeer)
   136 void NativeHttpSession::doReadCallback(TInt aStatus,jobject &aPeer)
   198 {
   137 {
   199     LOG(ESOCKET,EInfo,"+doReadCallback1");
   138     LOG(ESOCKET,EInfo,"+doReadCallback1");
   200 //  mJniEnv->CallVoidMethod(mJavaPeerObject,iReadCallbackMethodID,aStatus);
   139     jobject localPeerObject = mJniEnv->NewLocalRef(aPeer);
   201     mJniEnv->CallVoidMethod(aPeer,iReadCallbackMethodID,aStatus);
   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   	}    
   202     LOG(ESOCKET,EInfo,"-doReadCallback1");
   148     LOG(ESOCKET,EInfo,"-doReadCallback1");
   203 }
   149 }
   204 
   150