Client.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006-2010 Jacek Sieka, arnetheduck on gmail point com
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef ADCHPP_CLIENT_H
00020 #define ADCHPP_CLIENT_H
00021 
00022 #include "common.h"
00023 
00024 #include "ManagedSocket.h"
00025 #include "FastAlloc.h"
00026 #include "AdcCommand.h"
00027 #include "CID.h"
00028 #include "Entity.h"
00029 
00030 namespace adchpp {
00031 
00035 class ADCHPP_VISIBLE Client : public Entity, public FastAlloc<Client> {
00036 public:
00037     static Client* create(const ManagedSocketPtr& ms_, uint32_t sid_) throw();
00038 
00039     using Entity::send;
00040 
00041     virtual void send(const BufferPtr& command) throw() { socket->write(command); }
00042 
00044     ADCHPP_DLL virtual void disconnect(Util::Reason reason) throw();
00045     const std::string& getIp() const throw() { return socket->getIp(); }
00046 
00051     typedef std::function<void (Client&, const uint8_t*, size_t)> DataFunction;
00052     void setDataMode(const DataFunction& handler, int64_t aBytes) { dataHandler = handler; dataBytes = aBytes; }
00053 
00054     static void setDefaultMaxCommandSize(size_t newSize) { defaultMaxCommandSize = newSize; }
00055     static size_t getDefaultMaxCommandSize() { return defaultMaxCommandSize; }
00056 
00057     void setMaxCommandSize(size_t newSize) { maxCommandSize = newSize; }
00058     size_t getMaxCommandSize() { return maxCommandSize; }
00059 
00060     virtual size_t getQueuedBytes() const { return socket->getQueuedBytes(); }
00061     virtual time_t getOverflow() const { return socket->getOverflow(); }
00062 private:
00063     static size_t defaultMaxCommandSize;
00064 
00065     Client(uint32_t sid_) throw();
00066     virtual ~Client();
00067 
00068     bool disconnecting;
00069 
00070     BufferPtr buffer;
00071     ManagedSocketPtr socket;
00072     int64_t dataBytes;
00073 
00074     size_t maxCommandSize;
00075 
00076     DataFunction dataHandler;
00077     void setSocket(const ManagedSocketPtr& aSocket) throw();
00078 
00079     void onConnected() throw();
00080     void onData(const BufferPtr&) throw();
00081     void onFailed(const boost::system::error_code& ec) throw();
00082 
00083 };
00084 
00085 }
00086 
00087 #endif // CLIENT_H
Generated on Sat Nov 27 23:37:53 2010 for adchpp by  doxygen 1.6.3