Example #1
0
bool Cx_PluginLoader::UnloadPlugin(const wchar_t* name)
{
    CLockCount locker(&m_unloading);
    int moduleIndex = GetPluginIndex(name);
    HMODULE hdll = moduleIndex < 0 ? NULL : m_modules[moduleIndex]->hdll;

    if (NULL == hdll)
    {
        return false;
    }

    typedef bool (*FUNC_CANUNLOAD)();
    FUNC_CANUNLOAD pfnCan = (FUNC_CANUNLOAD)GetProcAddress(
        hdll, "x3CanUnloadPlugin");

    if (pfnCan && !pfnCan())
    {
        return false;
    }

    typedef void (*FUNC_UNLOAD)();
    FUNC_UNLOAD pfnUnload = (FUNC_UNLOAD)GetProcAddress(
        hdll, "x3UninitializePlugin");

    if (pfnUnload)
    {
        pfnUnload();
    }

    VERIFY(ClearModuleItems(hdll));
    ReleaseModule(hdll);

    return true;
}
Example #2
0
LWRESULT Cx_PluginLoader::UnloadPlugin(const MODID& modid, bool force_unload)
{
    int32_ moduleIndex = GetPluginIndex(modid);
	if(moduleIndex < 0)
		return LWDP_PLUGINMGR_NOT_FIND_MODULE;

	Ix_Module* pModule = m_modules[moduleIndex]->module;
	ASSERT_CHECK_RET(LWDP_MODULE_LOG, LWDP_POINTER_IS_NULL, pModule, "Cx_PluginLoader::UnloadPlugin Get Ix_Module Pointer Error");

	if(!force_unload)
	{
		if(!pModule->CanUnloadPlugin())
			return LWDP_PLUGINMGR_MODULE_USING;
	}
	else
	{
		lw_log_warning(LWDP_MODULE_LOG, "Force Unload Plugin(%s)", pModule->GetModuleName());
	}
	
	pModule->UninitializePlugin();

	MODID tmpModid = pModule->GetModuleMODID();
    ClearModuleItems(tmpModid);
    ReleaseModule(tmpModid);

	return LWDP_OK;
}
Example #3
0
bool ScriptFile::Load(Deserializer& source)
{
    PROFILE(LoadScript);
    
    ReleaseModule();
    
    // Create the module. Discard previous module if there was one
    asIScriptEngine* engine = script_->GetScriptEngine();
    scriptModule_ = engine->GetModule(GetName().CString(), asGM_ALWAYS_CREATE);
    if (!scriptModule_)
    {
        LOGERROR("Failed to create script module " + GetName());
        return false;
    }
    
    // Check if this file is precompiled bytecode
    if (source.ReadFileID() == "ASBC")
    {
        ByteCodeDeserializer deserializer = ByteCodeDeserializer(source);
        if (scriptModule_->LoadByteCode(&deserializer) >= 0)
        {
            LOGINFO("Loaded script module " + GetName() + " from bytecode");
            compiled_ = true;
            // Map script module to script resource with userdata
            scriptModule_->SetUserData(this);
            
            return true;
        }
        else
            return false;
    }
    else
        source.Seek(0);
    
    // Not bytecode: add the initial section and check for includes
    if (!AddScriptSection(engine, source))
        return false;
    
    // Compile. Set script engine logging to retained mode so that potential exceptions can show all error info
    ScriptLogMode oldLogMode = script_->GetLogMode();
    script_->SetLogMode(LOGMODE_RETAINED);
    script_->ClearLogMessages();
    int result = scriptModule_->Build();
    String errors = script_->GetLogMessages();
    script_->SetLogMode(oldLogMode);
    if (result < 0)
    {
        LOGERROR("Failed to compile script module " + GetName() + ":\n" + errors);
        return false;
    }
    if (!errors.Empty())
        LOGWARNING(errors);
    
    LOGINFO("Compiled script module " + GetName());
    compiled_ = true;
    // Map script module to script resource with userdata
    scriptModule_->SetUserData(this);
    
    return true;
}
Example #4
0
void CAcmUdp::ProcessMessage(CUdpMsg* &pMsg)
{
	uint32 nModule = pMsg->oHead.nModule;
	CAcmUdpModule* pModule = QueryModule(nModule);
	if(pModule)
	{
		pModule->ProcessAcmModuleMsg(this, pMsg);
		ReleaseModule(nModule);
	}
}
Example #5
0
long Cx_PluginLoader::UnloadPlugins()
{
    CLockCount locker(&m_unloading);
    SaveClsids();
    m_cache.Release();

    long i = 0;
    long count = 0;

    for (i = x3::GetSize(m_modules) - 1; i >= 0; i--)
    {
        typedef void (*FUNC_UNLOAD)();
        FUNC_UNLOAD pfnUnload = (FUNC_UNLOAD)GetProcAddress(
            m_modules[i]->hdll, "x3UninitializePlugin");
        if (pfnUnload)
        {
            pfnUnload();
        }
    }

    for (i = x3::GetSize(m_modules) - 1; i >= 0; i--)
    {
        ClearModuleItems(m_modules[i]->hdll);
    }

    for (i = x3::GetSize(m_modules) - 1; i >= 0; i--)
    {
        if (m_modules[i]->hdll)
        {
            ReleaseModule(m_modules[i]->hdll);
            count++;
        }
    }

    return count;
}
Example #6
0
ScriptFile::~ScriptFile()
{
    ReleaseModule();
}