NetLink Sockets C++ 1.0.0
Networking C++ Library @ Get NetLink Sockets C++ Library at SourceForge.net. Fast, secure and Free Open Source software downloads

include/netlink/socket_group.h

00001 /*
00002     NetLink Sockets: Networking C++ library
00003     Copyright 2012 Pedro Francisco Pareja Ruiz (PedroPareja@Gmail.com)
00004 
00005     This file is part of NetLink Sockets.
00006 
00007     NetLink Sockets is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     NetLink Sockets is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with NetLink Sockets. If not, see <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00022 #ifndef __NL_SOCKET_GROUP
00023 #define __NL_SOCKET_GROUP
00024 
00025 #include <netlink/core.h>
00026 #include <netlink/socket.h>
00027 
00028 NL_NAMESPACE
00029 
00030 using std::vector;
00031 
00032 
00033 class SocketGroup;
00034 
00041 class SocketGroupCmd {
00042 
00043     public:
00044 
00054         virtual void exec(Socket* socket, SocketGroup* group, void* reference)=0;
00055 };
00056 
00057 
00064 class SocketGroup {
00065 
00066     private:
00067 
00068         vector<Socket*> _vSocket;
00069 
00070         SocketGroupCmd* _cmdOnAccept;
00071         SocketGroupCmd* _cmdOnRead;
00072         SocketGroupCmd* _cmdOnDisconnect;
00073 
00074     public:
00075 
00076         SocketGroup();
00077 
00078         void add(Socket* socket);
00079         Socket* get(unsigned index) const;
00080         void remove(unsigned index);
00081         void remove(Socket* socket);
00082 
00083         size_t size() const;
00084 
00085         void setCmdOnAccept(SocketGroupCmd* cmd);
00086         void setCmdOnRead(SocketGroupCmd* cmd);
00087         void setCmdOnDisconnect(SocketGroupCmd* cmd);
00088 
00089         bool listen(unsigned milisec=0, void* reference = NULL);
00090 };
00091 
00092 #include <netlink/socket_group.inline.h>
00093 
00094 NL_NAMESPACE_END
00095 
00096 #endif
 All Classes Namespaces Files Functions Enumerations Enumerator