Basic module implementation. More...
#include <module.h>
Inherits NLNET::IModule, and NLMISC::ICommandsHandler.
Inherited by NLNET::CLocalGateway, and NLNET::CStandardGateway.
Public Member Functions | |
| template<class T > | |
| T * | getInterceptor (T *dummy, IModuleInterceptable *previous=NULL) |
| Search an interceptor in the interceptor list. | |
Static Public Member Functions | |
| static const std::string & | getInitStringHelp () |
| return the default init string (empty) | |
Protected Member Functions | |
| CModuleBase () | |
| ~CModuleBase () | |
| virtual void | registerInterceptor (IModuleInterceptable *interceptor) |
| virtual void | unregisterInterceptor (IModuleInterceptable *interceptor) |
| const std::string & | getCommandHandlerName () const |
| This methods implemented by CCommandHandler is used by the command registry to retrieve the name of the object instance. | |
| TModuleId | getModuleId () const |
| Return the module ID. | |
| const std::string & | getModuleName () const |
| Return the module name. | |
| const std::string & | getModuleClassName () const |
| Return the module class. | |
| const std::string & | getModuleFullyQualifiedName () const |
| Return the module fully qualified name. | |
| std::string | getModuleManifest () const |
| Return the manifest of the module. | |
| virtual void | onReceiveModuleMessage (IModuleProxy *senderModuleProxy, const CMessage &message) |
| Called by a socket to receive a message in the module context. | |
| void | _receiveModuleMessageTask () |
| The message dispatching task. | |
| void | queueModuleTask (CModuleTask *task) |
| CModuleTask * | getActiveModuleTask () |
| bool | initModule (const TParsedCommandLine &initInfo) |
| Module initialization. | |
| void | plugModule (IModuleSocket *moduleSocket) throw (EModuleAlreadyPluggedHere) |
| Plug this module in the specified socket. | |
| void | unplugModule (IModuleSocket *moduleSocket) throw (EModuleNotPluggedHere) |
| Unplug this module from the specified socket. | |
| void | getPluggedSocketList (std::vector< IModuleSocket * > &resultList) |
| Fill resultList vector with the list of socket into witch this module is currently plugged. | |
| void | invokeModuleOperation (IModuleProxy *destModule, const NLNET::CMessage &opMsg, NLNET::CMessage &resultMsg) throw (EInvokeFailed) |
| Do a module operation invocation. | |
| void | _onModuleUp (IModuleProxy *removedProxy) |
| Called just after a module as been effectively plugged into a socket. | |
| void | _onModuleDown (IModuleProxy *removedProxy) |
| bool | _onProcessModuleMessage (IModuleProxy *senderModuleProxy, const CMessage &message) |
| NLMISC_COMMAND_HANDLER_TABLE_END | NLMISC_CLASS_COMMAND_DECL (dump) |
| base module command table | |
| NLMISC_CLASS_COMMAND_DECL (plug) | |
| NLMISC_CLASS_COMMAND_DECL (unplug) | |
| NLMISC_CLASS_COMMAND_DECL (sendPing) | |
Protected Attributes | |
| IModuleFactory * | _ModuleFactory |
| Keep track of the module factory. | |
| TModuleId | _ModuleId |
| This is the local unique ID assigned to this module. | |
| std::string | _ModuleName |
| This is the module name. | |
| std::string | _FullyQualifedModuleName |
| This is the fully qualified module name. | |
Private Types | |
| typedef std::set< IModuleSocket * > | TModuleSockets |
| typedef std::list < IModuleInterceptable * > | TInterceptors |
Private Member Functions | |
| virtual void | setFactory (IModuleFactory *factory) |
| virtual IModuleFactory * | getFactory () |
Private Attributes | |
| TModuleSockets | _ModuleSockets |
| This is the sockets where the module is plugged in. | |
| TInterceptors | _ModuleInterceptors |
| This is the linked list of interceptor. | |
Friends | |
| class | CModuleManager |
| class | CModuleTask |
|
| |
| typedef std::list< std::pair < IModuleProxy *, CMessage > > | TMessageList |
| typedef std::list< CModuleTask * > | TModuleTasks |
| typedef std::vector < IModuleProxy * > | TInvokeStack |
| TMessageList | _SyncMessages |
| dynamically allocated list of synchronous message to process | |
| TModuleTasks | _ModuleTasks |
| list of coroutine to run for synchronous messaging (the first in the list is running) | |
| TInvokeStack | _InvokeStack |
| stack of server module with pending invocation response | |
| IModuleProxy * | _CurrentSender |
| The current message to process sender. | |
| const NLNET::CMessage * | _CurrentMessage |
| The current message to process. | |
| bool | _CurrentMessageFailed |
| True if the current message processing have generated an exception. | |
| CModuleTask * | _MessageDispatchTask |
| task for message dispatching | |
Basic module implementation.
Module implementor should derive from this class rather than rebuild a complete module from scratch (from IModule in fact). This class provide name and module registration, message dispatching to message handler, module socket interaction.
Definition at line 661 of file module.h.
typedef std::list<IModuleInterceptable*> NLNET::CModuleBase::TInterceptors [private] |
typedef std::vector<IModuleProxy*> NLNET::CModuleBase::TInvokeStack [private] |
typedef std::list<std::pair<IModuleProxy *, CMessage> > NLNET::CModuleBase::TMessageList [private] |
typedef std::set<IModuleSocket *> NLNET::CModuleBase::TModuleSockets [private] |
typedef std::list<CModuleTask*> NLNET::CModuleBase::TModuleTasks [private] |
| NLNET::CModuleBase::CModuleBase | ( | ) | [protected] |
Definition at line 179 of file module.cpp.
References registerInterceptor().
| NLNET::CModuleBase::~CModuleBase | ( | ) | [protected] |
Definition at line 191 of file module.cpp.
References _MessageDispatchTask, _ModuleInterceptors, _ModuleTasks, nlassert, and unregisterInterceptor().
| void NLNET::CModuleBase::_onModuleDown | ( | IModuleProxy * | removedProxy | ) | [protected, virtual] |
Implements NLNET::IModule.
Definition at line 550 of file module.cpp.
References _InvokeStack, _MessageDispatchTask, _ModuleInterceptors, _ModuleTasks, _SyncMessages, NLNET::CModuleTask::failInvoke(), H_AUTO, nlassert, and NLMISC::CCoTask::resume().
| void NLNET::CModuleBase::_onModuleUp | ( | IModuleProxy * | removedProxy | ) | [protected, virtual] |
Called just after a module as been effectively plugged into a socket.
Implements NLNET::IModule.
Definition at line 537 of file module.cpp.
References _ModuleInterceptors, H_AUTO, and NLNET::IModuleInterceptable::onModuleUp().
| bool NLNET::CModuleBase::_onProcessModuleMessage | ( | IModuleProxy * | senderModuleProxy, | |
| const CMessage & | message | |||
| ) | [protected] |
Definition at line 600 of file module.cpp.
References _ModuleInterceptors, NLNET::CMessage::Except, getModuleName(), NLNET::IModuleProxy::getModuleName(), NLNET::CMessage::getName(), NLNET::CMessage::getType(), H_AUTO, nlwarning, NLNET::CMessage::Request, NLNET::IModuleProxy::sendModuleMessage(), and NLNET::CMessage::setType().
Referenced by _receiveModuleMessageTask(), NLNET::CModuleTask::flushMessageQueue(), and onReceiveModuleMessage().
| void NLNET::CModuleBase::_receiveModuleMessageTask | ( | ) | [protected] |
The message dispatching task.
Definition at line 325 of file module.cpp.
References _CurrentMessage, _CurrentMessageFailed, _CurrentSender, _MessageDispatchTask, _onProcessModuleMessage(), H_AUTO, NLMISC::CCoTask::isTerminationRequested(), nlwarning, NLMISC::Exception::what(), and NLMISC::CCoTask::yield().
Referenced by initModule().
| CModuleTask * NLNET::CModuleBase::getActiveModuleTask | ( | ) | [protected] |
Definition at line 363 of file module.cpp.
References _ModuleTasks.
| const std::string & NLNET::CModuleBase::getCommandHandlerName | ( | ) | const [protected, virtual] |
This methods implemented by CCommandHandler is used by the command registry to retrieve the name of the object instance.
Implements NLMISC::ICommandsHandler.
Definition at line 397 of file module.cpp.
References getModuleName().
| IModuleFactory * NLNET::CModuleBase::getFactory | ( | ) | [private, virtual] |
Definition at line 649 of file module.cpp.
References _ModuleFactory.
Referenced by NLNET::CModuleManager::deleteModule().
| const std::string & NLNET::CModuleBase::getInitStringHelp | ( | ) | [static] |
return the default init string (empty)
Definition at line 372 of file module.cpp.
| T* NLNET::CModuleBase::getInterceptor | ( | T * | dummy, | |
| IModuleInterceptable * | previous = NULL | |||
| ) | [inline] |
Search an interceptor in the interceptor list.
By default, the method begin to search at the first interceptor. If 'previous' is set to a valid interceptor, then the search continue after it. the search is done by attempting a dynamic cast for each interceptor. If no interceptor match the required class, then NULL is returned.
Definition at line 756 of file module.h.
References _ModuleInterceptors.
| const std::string & NLNET::CModuleBase::getModuleClassName | ( | ) | const [protected, virtual] |
Return the module class.
Implements NLNET::IModule.
Definition at line 251 of file module.cpp.
References _ModuleFactory, and NLNET::IModuleFactory::getModuleClassName().
| const std::string & NLNET::CModuleBase::getModuleFullyQualifiedName | ( | ) | const [protected, virtual] |
Return the module fully qualified name.
the MFQN is the identifier that is used across process to identify each module. The MDQNis composed from the computer host name, the process ID and the module name. Format : <hostname>:<pid>:<moduleName> This name is guarantied to be unique (at least, if the host name is unique !)
Implements NLNET::IModule.
Definition at line 256 of file module.cpp.
References _FullyQualifedModuleName, _ModuleName, NLNET::IService::getHostName(), NLNET::IModuleManager::getInstance(), NLNET::IService::getInstance(), NLNET::IModuleManager::getUniqueNameRoot(), NLNET::IService::isServiceInitialized(), NLNET::CInetAddress::localHost(), and nlassertex.
Referenced by NLNET::CLocalGateway::getFullyQualifiedGatewayName(), and NLNET::CStandardGateway::getFullyQualifiedGatewayName().
| TModuleId NLNET::CModuleBase::getModuleId | ( | ) | const [protected, virtual] |
Return the module ID.
Each module has a local unique ID assigned by the manager during module creation. This ID is local because it is only valid inside a given process. When module are declared in another process, they receive a local ID that is different than the ID in their host process.
Implements NLNET::IModule.
Definition at line 241 of file module.cpp.
References _ModuleId.
| std::string NLNET::CModuleBase::getModuleManifest | ( | ) | const [protected, virtual] |
Return the manifest of the module.
The manifest is a simple string of undefined format. The manifest is used by a module to expose some intention or affinity (or whatever else you could imagine) of the module. The manifest if transmit along with the module proxy, allowing any module seeing the proxy to read the manifest. You should not use manifest to put big string because it is transmit with proxy information. Likewise, you should never use manifest to transmit critical data (such as password) because any module can read it.
Implements NLNET::IModule.
Definition at line 275 of file module.cpp.
References _ModuleInterceptors, and NLNET::IModuleInterceptable::buildModuleManifest().
| const std::string & NLNET::CModuleBase::getModuleName | ( | ) | const [protected, virtual] |
Return the module name.
Each module instance must have a unique name in the host process. If no mane is given during module creation, the module manager build a unique name from the module class and a number.
Implements NLNET::IModule.
Definition at line 246 of file module.cpp.
References _ModuleName.
Referenced by _onProcessModuleMessage(), getCommandHandlerName(), NLNET::CLocalGateway::getGatewayName(), NLNET::CStandardGateway::getGatewayName(), NLNET::CLocalGateway::getSocketName(), NLNET::CStandardGateway::getSocketName(), NLNET::CStandardGateway::NLMISC_CLASS_COMMAND_DECL(), NLNET::CStandardGateway::onModulePlugged(), NLNET::CStandardGateway::onModuleUnplugged(), and NLNET::CStandardGateway::sendModuleMessage().
| void NLNET::CModuleBase::getPluggedSocketList | ( | std::vector< IModuleSocket * > & | resultList | ) | [protected, virtual] |
Fill resultList vector with the list of socket into witch this module is currently plugged.
This method don't clear the result vector before filling it.
Implements NLNET::IModule.
Definition at line 435 of file module.cpp.
References _ModuleSockets.
| bool NLNET::CModuleBase::initModule | ( | const TParsedCommandLine & | initInfo | ) | [protected, virtual] |
Module initialization.
If the initialization return false, then the module manager deleted the module immediately.
Implements NLNET::IModule.
Reimplemented in NLNET::CStandardGateway, and NLNET::CLocalGateway.
Definition at line 379 of file module.cpp.
References _MessageDispatchTask, _receiveModuleMessageTask(), NLNET::TParsedCommandLine::getParam(), and NLMISC::ICommandsHandler::registerCommandsHandler().
| void NLNET::CModuleBase::invokeModuleOperation | ( | IModuleProxy * | destModule, | |
| const NLNET::CMessage & | opMsg, | |||
| NLNET::CMessage & | resultMsg | |||
| ) | throw (EInvokeFailed) [protected, virtual] |
Do a module operation invocation.
Caller MUST be in a module task to call this method. The call is blocking until receptions of the operation result message (or a module down)
Implements NLNET::IModule.
Definition at line 449 of file module.cpp.
References NLNET::CMessage::Except, NLNET::CMessage::getType(), H_AUTO, NLNET::msg, nlassert, NLNET::CMessage::Request, and NLNET::CMessage::Response.
| NLNET::CModuleBase::NLMISC_CLASS_COMMAND_DECL | ( | sendPing | ) | [protected] |
| NLNET::CModuleBase::NLMISC_CLASS_COMMAND_DECL | ( | unplug | ) | [protected] |
| NLNET::CModuleBase::NLMISC_CLASS_COMMAND_DECL | ( | plug | ) | [protected] |
| NLMISC_COMMAND_HANDLER_TABLE_END NLNET::CModuleBase::NLMISC_CLASS_COMMAND_DECL | ( | dump | ) | [protected] |
base module command table
Reimplemented in NLNET::CStandardGateway.
| void NLNET::CModuleBase::onReceiveModuleMessage | ( | IModuleProxy * | senderModuleProxy, | |
| const CMessage & | message | |||
| ) | [protected, virtual] |
Called by a socket to receive a message in the module context.
Basic implementation either forward directly to onProcessModuleMessage or queue the message in the coroutine message queue (when a synchronous messaging coroutine is started) for later dispatching.
Implements NLNET::IModule.
Definition at line 294 of file module.cpp.
References _CurrentMessage, _CurrentMessageFailed, _CurrentSender, _MessageDispatchTask, _ModuleTasks, _onProcessModuleMessage(), _SyncMessages, H_AUTO, and NLMISC::CCoTask::resume().
| void NLNET::CModuleBase::plugModule | ( | IModuleSocket * | moduleSocket | ) | throw (EModuleAlreadyPluggedHere) [protected, virtual] |
Plug this module in the specified socket.
Note that a module can be plugged in several socket at the same time, but not twice in the same socket.
Implements NLNET::IModule.
Definition at line 403 of file module.cpp.
References NLNET::CModuleSocket::_onModulePlugged(), and nlassert.
| void NLNET::CModuleBase::queueModuleTask | ( | CModuleTask * | task | ) | [protected] |
Definition at line 358 of file module.cpp.
References _ModuleTasks.
| void NLNET::CModuleBase::registerInterceptor | ( | IModuleInterceptable * | interceptor | ) | [protected, virtual] |
Implements NLNET::IInterceptorRegistrar.
Definition at line 222 of file module.cpp.
References _ModuleInterceptors, and nlassert.
Referenced by CModuleBase().
| void NLNET::CModuleBase::setFactory | ( | IModuleFactory * | factory | ) | [private, virtual] |
Implements NLNET::IModule.
Definition at line 642 of file module.cpp.
References _ModuleFactory, and nlassert.
| void NLNET::CModuleBase::unplugModule | ( | IModuleSocket * | moduleSocket | ) | throw (EModuleNotPluggedHere) [protected, virtual] |
Unplug this module from the specified socket.
Note that a module can be plugged in several socket at the same time, but not twice in the same socket. Throw an exception if the socket is not currently plug into the specified socket.
Implements NLNET::IModule.
Definition at line 421 of file module.cpp.
References NLNET::CModuleSocket::_onModuleUnplugged(), and nlassert.
| void NLNET::CModuleBase::unregisterInterceptor | ( | IModuleInterceptable * | interceptor | ) | [protected, virtual] |
Implements NLNET::IInterceptorRegistrar.
Definition at line 231 of file module.cpp.
References _ModuleInterceptors, NLNET::IModuleInterceptable::interceptorUnregistered(), and nlassert.
Referenced by ~CModuleBase().
friend class CModuleManager [friend] |
friend class CModuleTask [friend] |
const NLNET::CMessage* NLNET::CModuleBase::_CurrentMessage [private] |
The current message to process.
Definition at line 691 of file module.h.
Referenced by _receiveModuleMessageTask(), and onReceiveModuleMessage().
True if the current message processing have generated an exception.
Definition at line 693 of file module.h.
Referenced by _receiveModuleMessageTask(), and onReceiveModuleMessage().
IModuleProxy* NLNET::CModuleBase::_CurrentSender [private] |
The current message to process sender.
Definition at line 689 of file module.h.
Referenced by _receiveModuleMessageTask(), and onReceiveModuleMessage().
std::string NLNET::CModuleBase::_FullyQualifedModuleName [mutable, protected] |
This is the fully qualified module name.
Definition at line 709 of file module.h.
Referenced by getModuleFullyQualifiedName().
TInvokeStack NLNET::CModuleBase::_InvokeStack [private] |
stack of server module with pending invocation response
Definition at line 686 of file module.h.
Referenced by _onModuleDown().
task for message dispatching
Definition at line 696 of file module.h.
Referenced by _onModuleDown(), _receiveModuleMessageTask(), initModule(), onReceiveModuleMessage(), and ~CModuleBase().
IModuleFactory* NLNET::CModuleBase::_ModuleFactory [protected] |
Keep track of the module factory.
Definition at line 703 of file module.h.
Referenced by getFactory(), getModuleClassName(), and setFactory().
TModuleId NLNET::CModuleBase::_ModuleId [protected] |
This is the local unique ID assigned to this module.
Definition at line 705 of file module.h.
Referenced by NLNET::CModuleManager::createModule(), and getModuleId().
This is the linked list of interceptor.
Definition at line 673 of file module.h.
Referenced by _onModuleDown(), _onModuleUp(), _onProcessModuleMessage(), getInterceptor(), getModuleManifest(), registerInterceptor(), unregisterInterceptor(), and ~CModuleBase().
std::string NLNET::CModuleBase::_ModuleName [protected] |
This is the module name.
Definition at line 707 of file module.h.
Referenced by NLNET::CModuleManager::createModule(), getModuleFullyQualifiedName(), and getModuleName().
This is the sockets where the module is plugged in.
Definition at line 669 of file module.h.
Referenced by getPluggedSocketList().
TModuleTasks NLNET::CModuleBase::_ModuleTasks [private] |
list of coroutine to run for synchronous messaging (the first in the list is running)
Definition at line 682 of file module.h.
Referenced by _onModuleDown(), getActiveModuleTask(), onReceiveModuleMessage(), queueModuleTask(), NLNET::CModuleManager::updateModules(), and ~CModuleBase().
dynamically allocated list of synchronous message to process
Definition at line 679 of file module.h.
Referenced by _onModuleDown(), NLNET::CModuleTask::flushMessageQueue(), and onReceiveModuleMessage().
1.6.1