/
epBaseServerObject.h
161 lines (125 loc) · 4 KB
/
epBaseServerObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*!
@file epBaseServerObject.h
@author Woong Gyu La a.k.a Chris. <juhgiyo@gmail.com>
<http://github.com/juhgiyo/epserverengine>
@date July 20, 2012
@brief Base Server Object Interface
@version 1.0
@section LICENSE
The MIT License (MIT)
Copyright (c) 2012-2013 Woong Gyu La <juhgiyo@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@section DESCRIPTION
An Interface for Base Server Object.
*/
#ifndef __EP_BASE_SERVER_OBJECT_H__
#define __EP_BASE_SERVER_OBJECT_H__
#include "epServerEngine.h"
#include "epServerConf.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
// Need to link with Ws2_32.lib
#pragma comment (lib, "Ws2_32.lib")
namespace epse{
/*!
@class BaseServerObject epBaseServerObject.h
@brief A class for Base Server Object.
*/
class EP_SERVER_ENGINE BaseServerObject:public epl::SmartObject, protected epl::Thread{
public:
/*!
Default Constructor
Initializes the Object
@param[in] waitTimeMilliSec wait time for Thread to terminate
@param[in] lockPolicyType The lock policy
*/
BaseServerObject(unsigned int waitTimeMilliSec=WAITTIME_INIFINITE,epl::LockPolicy lockPolicyType=epl::EP_LOCK_POLICY);
/*!
Default Copy Constructor
Initializes the Object
@param[in] b the second object
*/
BaseServerObject(const BaseServerObject& b);
/*!
Default Destructor
Destroy the Object
*/
virtual ~BaseServerObject();
/*!
Assignment operator overloading
@param[in] b the second object
@return the new copied object
*/
BaseServerObject & operator=(const BaseServerObject&b);
/*!
Set the wait time for the thread termination
@param[in] milliSec the time for waiting in millisecond
*/
virtual void SetWaitTime(unsigned int milliSec);
/*!
Get the wait time for the parser thread termination
@return the current time for waiting in millisecond
*/
unsigned int GetWaitTime();
/*!
Get the IP of client
@param[in] socketAddr the socket address info
@return the IP of client in string
*/
static epl::EpTString GetIP(sockaddr socketAddr);
private:
friend class ServerObjectList;
friend class ParserList;
friend class BasePacketParser;
friend class BaseClient;
friend class BaseServer;
friend class BaseServerWorker;
friend class BaseClientUDP;
friend class BaseServerUDP;
friend class BaseServerWorkerUDP;
/*!
Set Synchronous Policy
@param[in] syncPolicy the synchronous policy to set
*/
void setSyncPolicy(SyncPolicy syncPolicy);
/*!
Set Container
@param[in] container the new container for this object
*/
void setContainer(ServerObjectList *container);
/*!
Remove self from the container
@return true if successfully removed otherwise false
*/
bool removeSelfFromContainer();
private:
/// Synchronous Policy
SyncPolicy m_syncPolicy;
/// Lock Policy
LockPolicy m_lockPolicy;
/// Wait Time in Milliseconds
unsigned int m_waitTime;
/// Container
ServerObjectList *m_container;
/// container lock
epl::BaseLock *m_containerLock;
};
}
#endif //__EP_BASE_SERVER_OBJECT_H__