Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 178 lines (135 sloc) 4.316 kb
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
/*!
@file epBasePacketParser.h
@author Woong Gyu La a.k.a Chris. <juhgiyo@gmail.com>
<http://github.com/juhgiyo/epserverengine>
@date July 20, 2012
@brief Base Packet Parser 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 Packet Parser.

*/
#ifndef __EP_BASE_PACKET_PARSER_H__
#define __EP_BASE_PACKET_PARSER_H__

#include "epServerEngine.h"
#include "epPacket.h"
#include "epBaseServerSendObject.h"
#include "epServerConf.h"

namespace epse
{
/*!
@class BasePacketParser epBasePacketParser.h
@brief A class for Base Packet Parser.
*/
class EP_SERVER_ENGINE BasePacketParser:public BaseServerObject
{
public:
/*!
Default Constructor

Initializes the Parser
@param[in] waitTimeMilliSec the wait time in millisecond for terminating
@param[in] lockPolicyType The lock policy
*/
BasePacketParser(unsigned int waitTimeMilliSec=WAITTIME_INIFINITE,epl::LockPolicy lockPolicyType=epl::EP_LOCK_POLICY);

/*!
Default Copy Constructor

Initializes the BasePacketParser
@param[in] b the second object
*/
BasePacketParser(const BasePacketParser& b);

/*!
Default Destructor

Destroy the Parser
*/
virtual ~BasePacketParser();

/*!
Assignment operator overloading
@param[in] b the second object
@return the new copied object
*/
BasePacketParser & operator=(const BasePacketParser&b);

/*!
Send the packet to the client
@param[in] packet the packet to be sent
@param[in] waitTimeInMilliSec wait time for sending the packet in millisecond
@return sent byte size
@remark return -1 if error occurred
*/
int Send(const Packet &packet, unsigned int waitTimeInMilliSec=WAITTIME_INIFINITE);

/*!
Parse the given packet and do relevant operation
@remark Subclasses must implement this
@param[in] packet the packet to parse
*/
virtual void ParsePacket(const Packet &packet)=0;


/*!
Get the owner object of this parser object.
@return the pointer to the owner object.
*/
BaseServerSendObject *GetOwner() const;

/*!
Return the packet received.
@return the packet received.
*/
const Packet* GetPacketReceived() const;



protected:

/// Thread Stop Event
/// @remark if this is raised, the thread should quickly stop.
epl::EventEx m_threadStopEvent;

private:
friend class BaseClient;
friend class BaseServerWorker;
friend class BaseClientUDP;
friend class BaseServerWorkerUDP;

/*!
@struct PacketPassUnit epBasePacketParser.h
@brief A class for Packet Passing Unit for Packet Parsing Thread.
*/
struct PacketPassUnit{
/// BaseServerWorkerEx Object
BaseServerSendObject *m_owner;
/// Packet to parse
Packet *m_packet;
};

/*!
Set PacketPassUnit
@param[in] packetPassUnit PacketPassUnit to set
*/
void setPacketPassUnit(const PacketPassUnit& packetPassUnit);


/*!
thread loop function
*/
virtual void execute();

/*!
Reset Parser
*/
void resetParser();


private:

        /// Owner
BaseServerSendObject *m_owner;



/// Packet received
Packet * m_packetReceived;

/// Lock Policy
epl::LockPolicy m_lockPolicy;

/// general lock
epl::BaseLock *m_generalLock;

};

}

#endif //__EP_BASE_PACKET_PARSER_H__
Something went wrong with that request. Please try again.