Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / common / src / game_share / callback_adaptor.h
blobbae22e3fa3e82a17adc5e2a38fb2c210d0e16024
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/>.
18 #ifndef CALLBACK_ADAPTER_H
19 #define CALLBACK_ADAPTER_H
21 #include "nel/net/callback_client.h"
22 #include "nel/net/callback_server.h"
24 class ICallbackServerAdaptor
26 void *_ContainerClass;
27 public:
28 ICallbackServerAdaptor(void *containerClass)
29 : _ContainerClass(containerClass)
33 virtual ~ICallbackServerAdaptor()
37 void *getContainerClass()
39 return _ContainerClass;
42 virtual void addCallbackArray(const NLNET::TCallbackItem *callbackarray, sint arraysize) =0;
43 virtual void setConnectionCallback(NLNET::TNetCallback cb, void *arg) =0;
44 virtual void setDisconnectionCallback(NLNET::TNetCallback cb, void *arg) =0;
45 virtual void init(uint16 port) =0;
46 virtual void disconnect( NLNET::TSockId hostid) =0;
47 virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid, bool log = true) =0;
48 virtual void update() =0;
51 class ICallbackClientAdaptor
53 void *_ContainerClass;
54 public:
55 ICallbackClientAdaptor(void *containerClass)
56 : _ContainerClass(containerClass)
60 virtual ~ICallbackClientAdaptor()
64 void *getContainerClass()
66 return _ContainerClass;
68 virtual void addCallbackArray(const NLNET::TCallbackItem *callbackarray, sint arraysize) =0;
69 virtual void setDisconnectionCallback(NLNET::TNetCallback cb, void *arg) =0;
70 virtual void connect( const NLNET::CInetAddress& addr ) =0;
71 virtual bool connected( ) =0;
72 virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid = NLNET::InvalidSockId, bool log = true) =0;
73 virtual void update() =0;
76 /** this is the default adaptor that make use of the NeL callback server
78 class CNelCallbackServerAdaptor : public ICallbackServerAdaptor
80 protected:
81 NLNET::CCallbackServer _CallbackServer;
83 public:
84 CNelCallbackServerAdaptor(void *containerClass)
85 : ICallbackServerAdaptor(containerClass)
87 _CallbackServer.setUserData(this);
90 protected:
91 virtual void addCallbackArray(const NLNET::TCallbackItem *callbackarray, sint arraysize)
93 _CallbackServer.addCallbackArray(callbackarray, arraysize);
95 virtual void setConnectionCallback(NLNET::TNetCallback cb, void *arg)
97 _CallbackServer.setConnectionCallback(cb, arg);
99 virtual void setDisconnectionCallback(NLNET::TNetCallback cb, void *arg)
101 _CallbackServer.setDisconnectionCallback(cb, arg);
103 virtual void init(uint16 port)
105 _CallbackServer.init(port);
107 virtual void disconnect( NLNET::TSockId hostid)
109 _CallbackServer.disconnect(hostid);
112 virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid, bool log = true)
114 _CallbackServer.send(buffer, hostid, log);
116 virtual void update()
118 _CallbackServer.update();
122 /** this is the default adaptor that make use of the NeL callback client
124 class CNelCallbackClientAdaptor : public ICallbackClientAdaptor
126 protected:
127 NLNET::CCallbackClient _CallbackClient;
129 public:
130 CNelCallbackClientAdaptor(void *containerClass)
131 : ICallbackClientAdaptor(containerClass)
133 _CallbackClient.setUserData(this);
136 protected:
137 virtual void addCallbackArray(const NLNET::TCallbackItem *callbackarray, sint arraysize)
139 _CallbackClient.addCallbackArray(callbackarray, arraysize);
141 virtual void setDisconnectionCallback(NLNET::TNetCallback cb, void *arg)
143 _CallbackClient.setDisconnectionCallback(cb, arg);
145 virtual void connect( const NLNET::CInetAddress& addr )
147 _CallbackClient.connect(addr);
149 virtual bool connected()
151 return _CallbackClient.connected();
154 virtual void send(const NLNET::CMessage &buffer, NLNET::TSockId hostid = NLNET::InvalidSockId, bool log = true)
156 _CallbackClient.send(buffer, hostid, log);
158 virtual void update()
160 _CallbackClient.update();
165 #endif // CALLBACK_ADAPTER_H