Entity.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_ENTITY_H
00020 #define ADCHPP_ENTITY_H
00021 
00022 #include "forward.h"
00023 #include "Buffer.h"
00024 #include "AdcCommand.h"
00025 #include "Plugin.h"
00026 #include "CID.h"
00027 
00028 namespace adchpp {
00029 
00030 class ADCHPP_VISIBLE Entity : private boost::noncopyable {
00031 public:
00032     enum State {
00034         STATE_PROTOCOL,
00036         STATE_IDENTIFY,
00038         STATE_VERIFY,
00040         STATE_NORMAL,
00042         STATE_DATA
00043     };
00044 
00045     enum Flag {
00046         FLAG_BOT = 0x01,
00047         FLAG_REGISTERED = 0x02,
00048         FLAG_OP = 0x04,
00049         FLAG_SU = 0x08,
00050         FLAG_OWNER = 0x10,
00051         FLAG_HUB = 0x20,
00052         FLAG_HIDDEN = 0x40,
00053         MASK_CLIENT_TYPE = FLAG_BOT | FLAG_REGISTERED | FLAG_OP | FLAG_SU | FLAG_OWNER | FLAG_HUB | FLAG_HIDDEN,
00054 
00055         FLAG_PASSWORD = 0x100,
00056 
00058         FLAG_EXT_AWAY = 0x200,
00059 
00062         FLAG_OK_IP = 0x400,
00063 
00065         FLAG_GHOST = 0x800
00066     };
00067 
00068 
00069     Entity(uint32_t sid_) : sid(sid_), state(STATE_PROTOCOL) { }
00070 
00071     void send(const AdcCommand& cmd) { send(cmd.getBuffer()); }
00072     virtual void send(const BufferPtr& cmd) = 0;
00073 
00074     ADCHPP_DLL virtual void inject(AdcCommand& cmd);
00075 
00076     ADCHPP_DLL const std::string& getField(const char* name) const;
00077     ADCHPP_DLL bool hasField(const char* name) const;
00078     ADCHPP_DLL void setField(const char* name, const std::string& value);
00079 
00081     ADCHPP_DLL bool getAllFields(AdcCommand& cmd) const throw();
00082     ADCHPP_DLL const BufferPtr& getINF() const;
00083 
00084     ADCHPP_DLL bool addSupports(uint32_t feature);
00085     ADCHPP_DLL StringList getSupportList() const;
00086     ADCHPP_DLL bool hasSupport(uint32_t feature) const;
00087     ADCHPP_DLL bool removeSupports(uint32_t feature);
00088 
00089     ADCHPP_DLL const BufferPtr& getSUP() const;
00090 
00091     uint32_t getSID() const { return sid; }
00092 
00093     ADCHPP_DLL bool isFiltered(const std::string& features) const;
00094 
00095     ADCHPP_DLL void updateFields(const AdcCommand& cmd);
00096     ADCHPP_DLL void updateSupports(const AdcCommand& cmd) throw();
00097 
00106     ADCHPP_DLL void setPluginData(const PluginDataHandle& handle, void* data) throw();
00107 
00112     ADCHPP_DLL void* getPluginData(const PluginDataHandle& handle) const throw();
00113 
00117     ADCHPP_DLL void clearPluginData(const PluginDataHandle& handle) throw();
00118 
00119     const CID& getCID() const { return cid; }
00120     void setCID(const CID& cid_) { cid = cid_; }
00121 
00122     State getState() const { return state; }
00123     void setState(State state_) { state = state_; }
00124 
00125     bool isSet(size_t aFlag) const { return flags.isSet(aFlag); }
00126     bool isAnySet(size_t aFlag) const { return flags.isAnySet(aFlag); }
00127     ADCHPP_DLL void setFlag(size_t aFlag);
00128     ADCHPP_DLL void unsetFlag(size_t aFlag);
00129 
00130     ADCHPP_DLL virtual void disconnect(Util::Reason reason) = 0;
00131 
00133     ADCHPP_DLL virtual size_t getQueuedBytes() const;
00134 
00136     ADCHPP_DLL virtual time_t getOverflow() const;
00137 
00138 protected:
00139     virtual ~Entity();
00140 
00141     typedef std::map<PluginDataHandle, void*> PluginDataMap;
00142 
00143     CID cid;
00144     uint32_t sid;
00145     Flags flags;
00146     State state;
00147 
00149     std::vector<uint32_t> supports;
00150 
00152     std::vector<uint32_t> filters;
00153 
00155     FieldMap fields;
00156 
00158     PluginDataMap pluginData;
00159 
00161     mutable BufferPtr INF;
00162 
00164     mutable BufferPtr SUP;
00165 };
00166 
00167 }
00168 
00169 #endif /* ADCHPP_ENTITY_H */
Generated on Sat Nov 27 23:37:53 2010 for adchpp by  doxygen 1.6.3