javaruntimes/midp/runtimestarter/src/midpruntimestarter.cpp
branchRCL_3
changeset 17 0fd27995241b
parent 14 04becd199f91
child 18 9ac0a0a7da70
equal deleted inserted replaced
15:f9bb0fca356a 17:0fd27995241b
    21 #include <algorithm>
    21 #include <algorithm>
    22 #include <iostream>
    22 #include <iostream>
    23 #include <fstream>
    23 #include <fstream>
    24 #include <unistd.h>
    24 #include <unistd.h>
    25 
    25 
       
    26 #ifndef __SYMBIAN32__
       
    27 #include <signal.h>
       
    28 #endif // __SYMBIAN32__
       
    29 
    26 #include "midpruntimestarter.h"
    30 #include "midpruntimestarter.h"
    27 #include "applicationinfosetter.h"
    31 #include "applicationinfosetter.h"
    28 #include "runtimeexception.h"
    32 #include "runtimeexception.h"
    29 #include "runtimestarterutils.h"
    33 #include "runtimestarterutils.h"
    30 #include "midpruntimearguments.h"
    34 #include "midpruntimearguments.h"
    57 const wchar_t* const RUNTIME_MAIN_CLASS = L"com.nokia.mj.impl.rt.midp.Main";
    61 const wchar_t* const RUNTIME_MAIN_CLASS = L"com.nokia.mj.impl.rt.midp.Main";
    58 const wchar_t* const TRUE_WSTR          = L"true";
    62 const wchar_t* const TRUE_WSTR          = L"true";
    59 
    63 
    60 
    64 
    61 MidpRuntimeStarter::MidpRuntimeStarter(): mMidletInfo(new MidletInfo()), // codescanner::nonleavenew
    65 MidpRuntimeStarter::MidpRuntimeStarter(): mMidletInfo(new MidletInfo()), // codescanner::nonleavenew
    62         mRuntimeState(Constructed)
    66         mRuntimeState(Constructed), mShudownOk(false)
    63 {
    67 {
    64     JELOG2(EJavaRuntime);
    68     JELOG2(EJavaRuntime);
    65 }
    69 }
    66 
    70 
    67 MidpRuntimeStarter::~MidpRuntimeStarter()
    71 MidpRuntimeStarter::~MidpRuntimeStarter()
   233     if (mComms.get())
   237     if (mComms.get())
   234     {
   238     {
   235         mComms->disconnect();
   239         mComms->disconnect();
   236     }
   240     }
   237     CoreUi::releaseUi(coreUiLoader);
   241     CoreUi::releaseUi(coreUiLoader);
       
   242 
       
   243     // Close the thread that ensures the exit.
       
   244     if (mExitMonitor.get())
       
   245     {
       
   246         mShudownOk = true;
       
   247         LOG(EJavaRuntime, EInfo, "Notifying exit thread.");
       
   248         mExitMonitor->notify();
       
   249     }
   238 
   250 
   239     return status;
   251     return status;
   240 }
   252 }
   241 
   253 
   242 
   254 
   487         errorStr.append(JavaCommonUtils::intToString(request));
   499         errorStr.append(JavaCommonUtils::intToString(request));
   488         throw RuntimeException(errorStr, __FILE__, __FUNCTION__, __LINE__);
   500         throw RuntimeException(errorStr, __FILE__, __FUNCTION__, __LINE__);
   489     }
   501     }
   490 
   502 
   491 }
   503 }
       
   504 
       
   505 void* MidpRuntimeStarter::ensureExit(void* ptr)
       
   506 {
       
   507     JELOG2(EUtils);
       
   508 #ifdef __SYMBIAN32__
       
   509     RThread().SetPriority(EPriorityMore);
       
   510 #endif // __SYMBIAN32__
       
   511     MidpRuntimeStarter* starter = reinterpret_cast<MidpRuntimeStarter*>(ptr);
       
   512     LOG(EJavaRuntime, EInfo, "Starting to wait for the shutdown.");
       
   513     const int waitTime = 1000; // 1 second.
       
   514     starter->mExitMonitor->wait(waitTime);
       
   515     LOG(EJavaRuntime, EInfo, "woke up from monitor.");
       
   516     if (!starter->mShudownOk)
       
   517     {
       
   518         LOG(EJavaRuntime, EInfo, "Killing process.");
       
   519 #ifdef __SYMBIAN32__
       
   520         RProcess().Kill(0);
       
   521 #else
       
   522         kill(getpid(), SIGTERM);
       
   523 #endif // __SYMBIAN32__
       
   524     }
       
   525     LOG(EJavaRuntime, EInfo, "Clean exit.");
       
   526     return 0;
       
   527 }
       
   528 
   492 void MidpRuntimeStarter::closeRuntimeInd()
   529 void MidpRuntimeStarter::closeRuntimeInd()
   493 {
   530 {
   494     JELOG2(EJavaRuntime);
   531     JELOG2(EJavaRuntime);
   495     LOG(EJavaRuntime, EInfo, "Starter got close indication from JVM");
   532     LOG(EJavaRuntime, EInfo, "Starter got close indication from JVM");
       
   533 
       
   534     // Create a thread for ensure the exit of the process, if something goes
       
   535     // wrong.
       
   536     pthread_t tid;
       
   537     mExitMonitor.reset(Monitor::createMonitor());
       
   538     pthread_create(&tid, 0, ensureExit, this);
       
   539 
   496     if (mMidletInfo->mPushStart)
   540     if (mMidletInfo->mPushStart)
   497     {
   541     {
   498         closePush();
   542         closePush();
   499     }
   543     }
       
   544 
   500 }
   545 }
   501 
   546 
   502 void MidpRuntimeStarter::setUids(const Uid& midletUid, const Uid& midletSuiteUid)
   547 void MidpRuntimeStarter::setUids(const Uid& midletUid, const Uid& midletSuiteUid)
   503 {
   548 {
   504     JELOG2(EJavaRuntime);
   549     JELOG2(EJavaRuntime);