1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "nel/net/module_socket.h"
20 #include "nel/net/module.h"
21 #include "nel/net/module_manager.h"
22 #include "nel/net/module_gateway.h"
23 #include "nel/net/module_common.h"
26 using namespace NLMISC
;
31 CModuleSocket::CModuleSocket()
32 : _SocketRegistered(false)
36 CModuleSocket::~CModuleSocket()
42 void CModuleSocket::registerSocket()
44 if (!_SocketRegistered
)
46 _SocketRegistered
= true;
47 IModuleManager::getInstance().registerModuleSocket(this);
51 void CModuleSocket::unregisterSocket()
53 if (_SocketRegistered
)
55 IModuleManager::getInstance().unregisterModuleSocket(this);
56 _SocketRegistered
= false;
60 void CModuleSocket::_onModulePlugged(const TModulePtr
&pluggedModule
)
62 TPluggedModules::TBToAMap::const_iterator
it(_PluggedModules
.getBToAMap().find(pluggedModule
));
63 if (it
!= _PluggedModules
.getBToAMap().end())
65 throw IModule::EModuleAlreadyPluggedHere();
68 _PluggedModules
.add(pluggedModule
->getModuleId(), pluggedModule
);
70 // callback socket implementation
71 onModulePlugged(pluggedModule
);
74 void CModuleSocket::_onModuleUnplugged(const TModulePtr
&pluggedModule
)
76 TPluggedModules::TBToAMap::const_iterator
it(_PluggedModules
.getBToAMap().find(pluggedModule
));
77 if (it
== _PluggedModules
.getBToAMap().end())
79 throw EModuleNotPluggedHere();
82 // callback socket implementation
83 onModuleUnplugged(pluggedModule
);
85 _PluggedModules
.removeWithB(pluggedModule
);
88 void CModuleSocket::sendModuleMessage(IModule
*senderModule
, TModuleId destModuleProxyId
, const NLNET::CMessage
&message
)
90 TPluggedModules::TBToAMap::const_iterator
it(_PluggedModules
.getBToAMap().find(senderModule
));
91 if (it
== _PluggedModules
.getBToAMap().end())
93 throw EModuleNotPluggedHere();
96 // forward to socket implementation
97 _sendModuleMessage(senderModule
, destModuleProxyId
, message
);
101 void CModuleSocket::broadcastModuleMessage(IModule
*senderModule
, const NLNET::CMessage
&message
)
103 TPluggedModules::TBToAMap::const_iterator
it(_PluggedModules
.getBToAMap().find(senderModule
));
104 if (it
== _PluggedModules
.getBToAMap().end())
106 throw EModuleNotPluggedHere();
109 // forward to socket implementation
110 _broadcastModuleMessage(senderModule
, message
);