Easy Simple Network Library  0.3.7
All Classes Functions Modules
Session.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of "esnetwork" library.
4 It is licensed under the terms of the BSD license.
5 For the latest info, see http://esnetwork.sourceforge.net
6 
7 Copyright (c) 2012-2013 Lin Jia Jun (Joe Lam)
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 
13 1. Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 -----------------------------------------------------------------------------
30 */
31 
32 #ifndef _ESN_SESSION_H_
33 #define _ESN_SESSION_H_
34 
35 #include <vector>
36 
37 #include <boost/shared_ptr.hpp>
38 #include <boost/weak_ptr.hpp>
39 
40 #include "CommonData.h"
41 
42 namespace esnlib
43 {
44 
45 class Buffer;
46 class IoBuffer;
47 class IoFilter;
48 class IoHandler;
49 
51 class Session
52 {
53 
54 public:
55 
56  Session();
57  virtual ~Session();
58 
60  virtual void Open() = 0;
61 
65  virtual void Close(bool rightnow = true) = 0;
66 
70  virtual bool Connected() = 0;
71 
75  virtual void Write(boost::shared_ptr<IoBuffer> data) = 0;
76 
81  virtual void Write(const char* buf, int bufsize) = 0;
82 
86  virtual void Write(void* data) = 0;
87 
91  virtual void WriteData(void* data) = 0;
92 
96  virtual void WriteBuffer(boost::shared_ptr<IoBuffer> data) = 0;
97 
101  virtual void Broadcast(boost::shared_ptr<IoBuffer> data) = 0;
102 
106  virtual void Broadcast(void* data) = 0;
107 
111  virtual int GetSessionCount() = 0;
112 
117  virtual int GetSessions(std::vector< boost::shared_ptr<Session> > & sessions) = 0;
118 
123  virtual boost::shared_ptr<Session> GetSessionById(int id) = 0;
124 
130  virtual bool TestIdle(int idletype, int idletime) = 0;
131 
135  virtual int GetId() = 0;
136 
140  virtual void SetId(int id) = 0;
141 
146  virtual bool GetOrderlyHandling(int optype) = 0;
147 
152  virtual void SetOrderlyHandling(int optype, bool value) = 0;
153 
158  virtual int GetMaxMessageQueueSize(int optype) = 0;
159 
164  virtual void SetMaxMessageQueueSize(int optype, int value) = 0;
165 
169  virtual int GetState() = 0;
170 
174  virtual boost::shared_ptr<IoFilter> GetIoFilter() = 0;
175 
179  virtual boost::shared_ptr<IoHandler> GetIoHandler() = 0;
180 
184  virtual boost::shared_ptr<IoBuffer> GetReadCache() = 0;
185 
190  virtual boost::shared_ptr<IoBuffer> GetFreeBuffer(int bufsize) = 0;
191 
195  virtual void TakeBack(boost::shared_ptr<IoBuffer> buf) = 0;
196 
200  virtual void TakeBack(boost::shared_ptr<Buffer> buf) = 0;
201 
206  virtual boost::shared_ptr<IoBuffer> EncodeBuffer(void* data) = 0;
207 
212  virtual void* DecodeBuffer(boost::shared_ptr<IoBuffer> data) = 0;
213 
217  virtual bool HasSsl() = 0;
218 
222  virtual bool HasData() = 0;
223 
227  virtual CommonDataPtr GetData() = 0;
228 
232  virtual bool HasGlobalData() = 0;
233 
237  virtual CommonDataPtr GetGlobalData() = 0;
238 
242  virtual std::string GetRemoteIp() = 0;
243 
247  virtual int GetRemotePort() = 0;
248 
252  virtual std::string GetLocalIp() = 0;
253 
257  virtual int GetLocalPort() = 0;
258 
262  virtual void ProcessIncomingData(bool asynccall) = 0;
263 
267  virtual void ProcessOutgoingData(bool asynccall) = 0;
268 
269 protected:
270 
271 private:
272 
273 };
274 
275 typedef boost::shared_ptr<Session> SessionPtr;
276 typedef boost::weak_ptr<Session> SessionRef;
277 
278 }
279 
280 
281 #endif // _ESN_SESSION_H_
282 
virtual int GetId()=0
virtual CommonDataPtr GetData()=0
virtual CommonDataPtr GetGlobalData()=0
virtual void SetOrderlyHandling(int optype, bool value)=0
virtual void ProcessIncomingData(bool asynccall)=0
virtual boost::shared_ptr< Session > GetSessionById(int id)=0
virtual void Open()=0
Open the session.
virtual void SetId(int id)=0
virtual int GetLocalPort()=0
virtual std::string GetLocalIp()=0
virtual boost::shared_ptr< IoHandler > GetIoHandler()=0
virtual bool TestIdle(int idletype, int idletime)=0
virtual bool HasGlobalData()=0
virtual void Close(bool rightnow=true)=0
virtual bool HasData()=0
virtual bool Connected()=0
virtual void WriteData(void *data)=0
virtual bool HasSsl()=0
virtual void WriteBuffer(boost::shared_ptr< IoBuffer > data)=0
virtual void ProcessOutgoingData(bool asynccall)=0
virtual int GetState()=0
virtual int GetMaxMessageQueueSize(int optype)=0
virtual boost::shared_ptr< IoFilter > GetIoFilter()=0
virtual std::string GetRemoteIp()=0
virtual void Write(boost::shared_ptr< IoBuffer > data)=0
virtual bool GetOrderlyHandling(int optype)=0
virtual int GetRemotePort()=0
virtual void SetMaxMessageQueueSize(int optype, int value)=0
virtual boost::shared_ptr< IoBuffer > EncodeBuffer(void *data)=0
virtual int GetSessions(std::vector< boost::shared_ptr< Session > > &sessions)=0
Session class (interface)
Definition: Session.h:51
Definition: Buffer.h:37
virtual void * DecodeBuffer(boost::shared_ptr< IoBuffer > data)=0
virtual void TakeBack(boost::shared_ptr< IoBuffer > buf)=0
virtual boost::shared_ptr< IoBuffer > GetFreeBuffer(int bufsize)=0
virtual void Broadcast(boost::shared_ptr< IoBuffer > data)=0
virtual boost::shared_ptr< IoBuffer > GetReadCache()=0
virtual int GetSessionCount()=0