dataserver.h

00001 /***************************************************************************
00002 *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003 *   rvinyard@cs.nmsu.edu                                                  *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU Lesser General Public License as        *
00007 *   published by the Free Software Foundation version 2.1.                *
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 Lesser General Public      *
00015 *   License along with this library; if not, write to the                 *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018 ***************************************************************************/
00019 #ifndef CONEXUSDATASERVER_H
00020 #define CONEXUSDATASERVER_H
00021 
00022 #include <set>
00023 #include <queue>
00024 
00025 #include <sys/select.h>
00026 
00027 #include <glibmm/dispatcher.h>
00028 #include <glibmm/thread.h>
00029 
00030 #include <conexus/enums.h>
00031 #include <conexus/object.h>
00032 #include <conexus/data.h>
00033 
00034 namespace Conexus {
00035 
00039   class DataServer : public Object {
00040     public:
00041       DataServer();
00042 
00043       virtual ~DataServer();
00044 
00060       virtual void start( ReadWrite rw = READ );
00061       
00066       virtual void start( ReadWrite rw, bool use_dispatcher );
00067       
00072       virtual void stop( ReadWrite rw = READ );
00073 
00079       sigc::signal<void, const Data&> signal_data();
00080       
00086       sigc::signal<void, size_t> signal_data_received();
00087       
00093       sigc::signal<void, size_t> signal_data_transmitted();
00094 
00106       virtual void set_responsiveness(long r);
00107 
00111       virtual long responsiveness();
00112 
00114       virtual bool is_running();
00115       
00117       virtual bool is_read_running();
00118       
00120       virtual bool is_write_running();
00121 
00123       virtual const std::string& object_type() { static std::string s("Conexus::DataServer"); return s; }
00124 
00125     protected:
00126       bool m_running[ 2 ];
00127       Glib::Thread* m_thread[ 2 ];
00128       bool m_terminate;
00129       struct timeval m_timeval;
00130 
00131       Glib::Mutex m_mutex_queue[ 2 ];
00132       Glib::Mutex m_mutex_can_start[ 2 ];
00133 
00134       Glib::Dispatcher* m_dispatcher;
00135       bool m_use_dispatcher;
00136       sigc::connection m_dispatcher_connection;
00137 
00138       sigc::signal<void, const Data&> m_signal_data;
00139       sigc::signal<void, size_t> m_signal_data_received;
00140       sigc::signal<void, size_t> m_signal_data_transmitted;
00141       std::queue<Data> m_read_queue;
00142       std::queue<Data> m_write_queue;
00143 
00144       virtual void read_thread_main();
00145       virtual void read_thread_cleanup();
00146       virtual void write_thread_main();
00147       virtual void write_thread_cleanup();
00148 
00149       void queue_received_data( const Data& d );
00150       void queue_write_data( const Data& d );
00151       void emit_received_data( );
00152 
00153   };
00154 
00155 }
00156 
00157 #endif

Generated on Sat Aug 26 17:34:53 2006 by  doxygen 1.4.6