1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
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/>.
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 #include "nel/misc/mem_stream.h"
25 #include "nel/misc/smart_ptr.h"
26 #include "nel/misc/sstring.h"
28 #include "gus_module.h"
29 #include "gus_net_types.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 // class CModuleMessage
40 //-----------------------------------------------------------------------------
42 class CModuleMessage
: public NLMISC::CRefCount
49 const NLMISC::CSString
& getMessageName() const;
50 uint32
getSenderId() const;
51 TRawMsgBodyPtr
getMsgBody() const;
52 const TModuleIdVector
& getDestinationModuleIds() const;
55 void setMessageName(const NLMISC::CSString
& name
);
56 void setSenderId(uint32 id
);
57 void setMsgBody(TRawMsgBodyPtr body
);
58 void setDestinationModuleIds(const TModuleIdVector
& remoteIds
);
59 void setDestinationModuleId(uint32 remoteId
);
62 void serial(NLMISC::IStream
& stream
);
66 NLMISC::CSString _MsgName
;
69 TModuleIdVector _DestinationModuleIds
;
71 typedef NLMISC::CSmartPtr
<CModuleMessage
> TModuleMessagePtr
;
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
81 // get hold of the singleton instance
82 static CGusNet
* getInstance();
87 // register / unregister a local module when it is instantiated (in CModuleManager)
88 virtual void registerModule(GUS::TModulePtr module
)=0;
89 virtual void unregisterModule(GUS::TModulePtr module
)=0;
91 // lookup a remote module record from
92 virtual TRemoteModulePtr
lookupRemoteModule(uint32 uniqueId
)=0;
94 // send the message to a single remote modules
95 virtual void sendMessage(const NLMISC::CSString
& msgName
, const TRawMsgBodyPtr
& msgBody
,uint32 destinationModuleId
, uint32 senderModuleId
)=0;
97 // send the message to several remote modules
98 virtual void sendMessage(const NLMISC::CSString
& msgName
, const TRawMsgBodyPtr
& msgBody
,const TModuleIdVector
& destinationModuleIds
, uint32 senderModuleId
)=0;
100 // broadcast the message to all remote modules
101 virtual void broadcastMessage(const NLMISC::CSString
& msgName
, const TRawMsgBodyPtr
& msgBody
, uint32 senderModuleId
)=0;
103 // display info on the net singleton
104 virtual void display() const=0;
108 //-----------------------------------------------------------------------------
109 // wrappers for CGusNet():: sendModuleMessage()
110 //-----------------------------------------------------------------------------
112 // send a message with a single template object attached
113 template<class T
> void sendModuleMessage(const NLMISC::CSString
& msgName
, const T
& object
, uint32 destinationModuleId
, const GUS::IModule
* senderModule
);
114 template<class T
> void sendModuleMessage(const NLMISC::CSString
& msgName
, const T
& object
, const TModuleIdVector
& destinationModuleIds
, const GUS::IModule
* senderModule
);
117 //-----------------------------------------------------------------------------
118 // includes for inclines
119 //-----------------------------------------------------------------------------
121 #include "gus_module_manager.h"
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
131 // wrappers for CGusNet():: sendModuleMessage()
132 //-----------------------------------------------------------------------------
134 // send a message with a single template object attached to a specific module
135 template<class T
> void sendModuleMessage(const T
& object
, uint32 destinationModuleId
, const GUS::IModule
* senderModule
)
137 TRawMsgBodyPtr msgBody
= new CRawMsgBody
;
138 msgBody
->serial(const_cast<T
&>(object
));
139 CGusNet::getInstance()->sendMessage(object
.getName(),msgBody
,destinationModuleId
,GUS::CModuleManager::getInstance()->getModuleId(senderModule
));
142 // send a message with a single template object attached to several specific modules
143 template<class T
> void sendModuleMessage(const T
& object
, const TModuleIdVector
& destinationModuleIds
, const GUS::IModule
* senderModule
)
145 TRawMsgBodyPtr msgBody
= new CRawMsgBody
;
146 msgBody
->serial(const_cast<T
&>(object
));
147 CGusNet::getInstance()->sendMessage(object
.getName(),msgBody
,destinationModuleIds
,GUS::CModuleManager::getInstance()->getModuleId(senderModule
));
152 //-----------------------------------------------------------------------------