⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 warpluginengine.cpp

📁 ftpserver very good sample
💻 CPP
字号:
#include "StdAfx.h"#include "WarPluginEngine.h"   // class implemented#ifndef WAR_AUTO_LOCK_H#   include "WarAutoLock.h"#endif#ifndef WAR_PLUGIN_SUPPORT_H#   include "WarPluginSupport.h"#endif#ifndef WAR_LOG_H#   include "WarLog.h"#endif#define AUTO_LOCK WarAutoLock my_lock(mLock)using namespace std;/////////////////////////////// PUBLIC ///////////////////////////////////////WarPluginEngine *WarPluginEngine::spThis;//============================= LIFECYCLE ====================================WarPluginEngine::WarPluginEngine(){    if (NULL != spThis)        WarThrow(WarError(WAR_ERR_ALREADY_INITIALIZED), NULL);    spThis = this;}// WarPluginEngineWarPluginEngine::~WarPluginEngine(){    if (this == spThis)        spThis = NULL;}// ~WarPluginEngine//============================= OPERATORS ====================================//============================= OPERATIONS ===================================void WarPluginEngine::NotifyOnClassInstance(    WarPluginModule *modulePtr,    const war_ccstr_t className)    throw(WarException){    AUTO_LOCK;    // Check that the module is registered    // Throws is not    Lookup(modulePtr);    mNotifyList.insert(module_want_class_map_t::value_type(        string(className), modulePtr));}void WarPluginEngine::RegisterPluginSupportClassInstance(    WarPluginBaseSupport *pClassInstance)    throw (WarException){    NotifyModules(pClassInstance, WarPluginModule::NOTIFY_CREATED);}void WarPluginEngine::UnregisterPluginSupportClassInstance(    WarPluginBaseSupport *pClassInstance)    throw (WarException){    NotifyModules(pClassInstance, WarPluginModule::NOTIFY_DELETED);}void WarPluginEngine::RegisterPluginModule(WarPluginModule *pModule)throw (WarException){    AUTO_LOCK;        mModules.push_back(pModule);}void WarPluginEngine::UnregisterPluginModule(WarPluginModule *pModule)throw (WarException){        AUTO_LOCK;    // Delete references in the "want class" lookup mapagain:     module_want_class_map_t::iterator P;    for(P = mNotifyList.begin()        ; P != mNotifyList.end()        ; ++P)    {        if (P->second == pModule)        {            mNotifyList.erase(P);            goto again;        }       }        // Delete the module reference    mModules.erase(Lookup(pModule));}//============================= ACCESS     ===================================//============================= INQUIRY    ===================================/////////////////////////////// PROTECTED  ////////////////////////////////////////////////////////////////// PRIVATE    ///////////////////////////////////void WarPluginEngine::NotifyModules(    WarPluginBaseSupport *pClassInstance,    const WarPluginModule::NotificationE notificationType)    throw (WarException){    // Notify any plugins that monitors this class    AUTO_LOCK;    typedef module_want_class_map_t::const_iterator I;    pair<I, I> range = mNotifyList.equal_range(        pClassInstance->GetClassName());    for (I P = range.first; P != range.second; ++P)    {        try        {            P->second->OnClassInstance(pClassInstance,                notificationType);        }        catch(WarException& ex)        {            WarLog err_log(WARLOG_ERROR, "WarPluginEngine::RegisterPluginSupportClassInstance()");            err_log << "Caught unexpected exception when initializing "                "plugin instances for the class \""                << pClassInstance->GetClassName()                << "\". "                << ex                << war_endl;        }    }}WarPluginEngine::module_list_t::iterator WarPluginEngine::Lookup(    const WarPluginModule *pModule)    throw(WarException){    module_list_t::iterator P;    for(P = mModules.begin()        ; P != mModules.end()        ; ++P)    {        if (*P == pModule)            return P;    }    WarThrow(WarError(WAR_ERR_OBJECT_NOT_FOUND), NULL);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -