Add infos into target window
[ryzomcore.git] / ryzom / server / src / general_utilities_service / gus_net.h
blob6ae9e936b1d7e560810becc7d24e155315f88185
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #ifndef GUS_NET_H
18 #define GUS_NET_H
20 //-----------------------------------------------------------------------------
21 // includes
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 //-----------------------------------------------------------------------------
33 // GUSNET namespace
34 //-----------------------------------------------------------------------------
36 namespace GUSNET
38 //-----------------------------------------------------------------------------
39 // class CModuleMessage
40 //-----------------------------------------------------------------------------
42 class CModuleMessage: public NLMISC::CRefCount
44 public:
45 // ctor
46 CModuleMessage();
48 // read accessors
49 const NLMISC::CSString& getMessageName() const;
50 uint32 getSenderId() const;
51 TRawMsgBodyPtr getMsgBody() const;
52 const TModuleIdVector& getDestinationModuleIds() const;
54 // write accessors
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);
61 // serialise
62 void serial(NLMISC::IStream& stream);
64 private:
65 // private data
66 NLMISC::CSString _MsgName;
67 uint32 _SenderId;
68 TRawMsgBodyPtr _Body;
69 TModuleIdVector _DestinationModuleIds;
71 typedef NLMISC::CSmartPtr<CModuleMessage> TModuleMessagePtr;
74 //-----------------------------------------------------------------------------
75 // class CGusNet
76 //-----------------------------------------------------------------------------
78 class CGusNet
80 public:
81 // get hold of the singleton instance
82 static CGusNet* getInstance();
84 public:
85 // CGusNet interface
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 //-----------------------------------------------------------------------------
125 // GUSNET namespace
126 //-----------------------------------------------------------------------------
128 namespace GUSNET
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 //-----------------------------------------------------------------------------
153 #endif