00001 /* Glass - a distributed computing library 00002 Copyright (C) 2003-2009 Bruno Barberi Gnecco 00003 Copyright (C) 2009-2010 Corollarium Technologies 00004 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #ifndef _GLASS_PROTOCOL_HH_ 00022 #define _GLASS_PROTOCOL_HH_ 00023 00024 #include "types.h" 00025 00026 namespace libglass { 00027 00028 class Packet; 00029 class Glass; 00030 00035 class Protocol { 00036 public: 00040 typedef enum { None, Server, Client } connectionType; 00041 00042 private: 00043 Glass *owner; 00045 protected: 00046 connectionType type; 00048 friend class Glass; 00049 00059 void setOwner(const Glass *g); 00060 00070 nodeFD IdToFD(nodeId id); 00071 00081 nodeId FDToId(nodeFD fd); 00082 00092 nodeId registerNode(nodeFD fd); 00093 00102 bool unregisterNode(nodeId id); 00103 00111 bool unregisterNode(nodeFD fd); 00112 00113 #ifdef TODO 00114 virtual bool registerGroup(XXXX groupname, std::set<nodeFD> &list) = 0; 00115 virtual bool addToGroup(groupname, FD) = 0; 00116 virtual bool removeFromGroup(groupname, FD) = 0; 00117 virtual bool deleteGroup(); 00118 #endif 00119 00120 00125 virtual int _listen(unsigned int port) = 0; 00126 00131 virtual nodeFD _accept(void) = 0; 00132 00137 virtual nodeFD _connect(const char *host, unsigned int port) = 0; 00138 00143 virtual void _disconnect(nodeFD node) = 0; 00144 00149 virtual bool _send(Packet &p) = 0; 00150 00155 virtual int _recv(Packet &p) = 0; 00156 00157 public: 00158 00162 Protocol(); 00163 00168 virtual ~Protocol(); 00169 00174 connectionType getConnectionType(void) const; 00175 00187 int listen(unsigned int port = 0); 00188 00201 nodeFD accept(void); 00202 00213 nodeFD connect(const char *host, unsigned int port = 0); 00214 00221 void disconnect(nodeFD node = -1); 00222 00236 bool send(Packet &p); 00237 00254 int recv(Packet &p); 00255 00260 virtual nodeId getUniqueId(void) = 0; 00261 }; 00262 00263 }// namespace 00264 00265 #endif