Back to index

texmacs  1.0.7.15
socket_notifier.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : socket_notifier.hpp
00004 * DESCRIPTION: Notifiers for socket activity
00005 * COPYRIGHT  : (C) 2009 Massimiliano Gubinelli
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef SOCKET_NOTIFIER_H
00013 #define SOCKET_NOTIFIER_H
00014 
00015 #include "basic.hpp"
00016 #include "hashset.hpp"
00017 #include "command.hpp"
00018 
00019 struct socket_notifier_rep: concrete_struct {
00020   int fd; // file descriptor for the socket
00021   command cmd;
00022   
00023 public:
00024   socket_notifier_rep (int _fd, command _cmd):
00025     fd (_fd), cmd (_cmd) {}
00026   void notify () { if (!is_nil (cmd)) cmd->apply (); } 
00027 };
00028 
00029 class socket_notifier {
00030 CONCRETE_NULL(socket_notifier);
00031   inline socket_notifier (int _fd, void (*_cb) (void*, void*),
00032                        void *_obj, void *_info = NULL):
00033     rep (tm_new<socket_notifier_rep> (_fd, command (_cb, _obj, _info))) {}
00034   friend bool operator == (socket_notifier sn1, socket_notifier sn2) {
00035     return (sn1.rep == sn2.rep); }
00036   friend int hash (socket_notifier sn) {
00037     return hash (sn.rep); }
00038 };
00039 CONCRETE_NULL_CODE(socket_notifier);
00040 
00041 inline tm_ostream& operator << (tm_ostream& out, socket_notifier sn) {
00042   if (is_nil (sn)) return out << "nil socket_notifier";
00043 else return out << "some socket_notifier"; }
00044 
00045 
00046 void perform_select ();
00047 void add_notifier (socket_notifier);
00048 void remove_notifier (socket_notifier);
00049 
00050 #endif // SOCKET_NOTIFIER_H