// Start the peer (unless someone has beaten us to it) HRESULT CInProcPlugHole::StartPeer(IIPDolphin** ppiPeer, REFCLSID rclsid, CLSCTX ctx) { *ppiPeer = NULL; // Lock the object while we check whether the VM should be started (another thread may // have beat us to it). However we don't hold the lock any longer than necessary, as // otherwise the VM can't call back with its peer interface without a deadlock occurring HRESULT hr = CO_E_ERRORINDLL; { ObjectLock lock(this); if (m_piMarshalledPeer == NULL && m_dwVMStarterId == 0) { if (rclsid != CLSID_NULL) UpdateImagePathForCLSID(rclsid); hr = StartVM(ctx); // Prevent any other threads from attempting to start the VM when // we release the lock but before the image calls back with the peer // interface pointer if (SUCCEEDED(hr)) m_dwVMStarterId = CoGetCurrentProcess(); } } if (m_dwVMStarterId != 0) { WaitForPeerToStart(); IIPDolphinPtr piPeer = GetPeerForCurrentThread(); if (piPeer) { // Reacquire the lock for once off initialization if this is the thread that // started the VM //ObjectLock lock(this); if (m_dwVMStarterId == CoGetCurrentProcess()) { // This is the thread that started the VM, so initialize the peer hr = piPeer->OnInitialize(); if (FAILED(hr)) Shutdown(); else *ppiPeer = piPeer.Detach(); } } else { // Deliberately terminate the VM here, but how? // Shutdown(); hr = CO_E_APPDIDNTREG; } } return hr; }
//Calls StartVM and initializes JNI structures to access ApplicationManager bool JavaInterface::StartJava() { if (jniError) return false; StartVM(); if (!isStarted()) return false; if (jniInitialized) return true; CheckAttachThread(); JNI::ReturnType ret; //share signatures const char *formatOneLong=JNI::BaseObject::getSignature(JNI::Int, 1, JNI::Object, "vdr/mhp/lang/NativeData"); const char *formatNoArguments=JNI::BaseObject::getSignature(JNI::Int, 0); if ( !( methods->initialize.SetMethod("vdr/mhp/ApplicationManager", "Initialize", JNI::Int, formatOneLong) && methods->newApplication.SetMethod("vdr/mhp/ApplicationManager", "NewApplication", JNI::Int, formatOneLong) && methods->applicationRemoved.SetMethod("vdr/mhp/ApplicationManager", "ApplicationRemoved", JNI::Int, formatOneLong) && methods->startApplication.SetMethod("vdr/mhp/ApplicationManager", "StartApplication", JNI::Int, formatOneLong) && methods->stopApplication.SetMethod("vdr/mhp/ApplicationManager", "StopApplication", JNI::Int, formatOneLong) && methods->pauseApplication.SetMethod("vdr/mhp/ApplicationManager", "PauseApplication", JNI::Int, formatOneLong) && methods->resumeApplication.SetMethod("vdr/mhp/ApplicationManager", "ResumeApplication", JNI::Int, formatOneLong) && methods->processKey.SetMethodWithArguments("vdr/mhp/ApplicationManager", "ProcessKey", JNI::Int, 1, JNI::Int) && methods->shutdown.SetMethod("vdr/mhp/ApplicationManager", "Shutdown", JNI::Int, formatNoArguments) && methods->stopApplications.SetMethod("vdr/mhp/ApplicationManager", "StopApplications", JNI::Int, formatNoArguments) && JNI::Exception::Initialize() && JNI::String::Initialize() && VdrMhpLangNativeDataImplementation::Initialize() ) ) { esyslog("Failed to initialize Java system: Cannot find method ID"); jniInitialized=false; jniError=true; return false; } delete[] formatOneLong; delete[] formatNoArguments; if (!methods->initialize.CallMethod(ret, (jobject)NativeDBData(&ApplicationInfo::Applications)) || ret.TypeInt != 0) { esyslog("Failed to initialize Java system: Cannot call method of ApplicationManager"); jniInitialized=false; jniError=true; return false; } jniInitialized = true; return true; }
int main( int argc, char **argv, char **envp ) { int dictsize = DEF_DICTSIZE; /* pass alternate dict size as an arg */ init_support(); /* FIX - change to loop around evaluate - this also means move below init_dictionary */ /* debug is a define for user area */ /* if ( (argc > 1) && strcmp( *(argv+1), "-d" ) == 0 ) debug = 1; */ init_dictionary( dictsize ); StartVM( "cold", argc, argv ); }
_Check_return_ HRESULT CLuaScriptProvider::Init() { return StartVM(); }