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() |
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); |