rstpclient.h

00001 /* libradar_stp
00002  * <http://www.k9nl.net/radar/> <radar@k9nl.net>
00003  * 
00004  * rstpclient.h - RSTP client class
00005  *
00006  * THIS FILE IS NOT MEANT FOR LIBRARY CLIENT USE
00007  *
00008  * Copyright (C) 2007 Nicholas J. Luther
00009  *
00010  * This program is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License,
00012  * version 2, as published by the Free Software Foundation.
00013  * 
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022  * You may contact the author by writing to Nick Luther, 1655 South
00023  * Westhaven Drive, Oshkosh, Wisconsin 54904, USA.
00024  * 
00025  */
00026  
00027  
00028 #ifndef _LIBRSTP_INC_RSTPCLIENT_H
00029 #define _LIBRSTP_INC_RSTPCLIENT_H
00030  
00031  
00032 #include <string>
00033 #include <queue>
00034 #include <set>
00035 
00036 #include "lplproj.h"
00037 #include "thread/thread.h"
00038 #include "thread/mutex.h"
00039 #include "socket/tcpsocket.h"
00040 
00041 namespace libradar_stp {
00042 
00043 // CAUTION: be careful copying RSTPClients
00044 class RSTPClient : public LPORTLIB_NAMESPACE::thread::Thread {
00045 public:
00046   
00047   RSTPClient();
00048   ~RSTPClient();
00049   
00050   bool connect( const std::string& addr, unsigned short port, const std::string& login = "",
00051                 const std::string& pass = "" );
00052   void quit();
00053   
00054   void addStream( const std::string& stream );
00055   void dropStream( const std::string& stream );
00056   
00057   
00058   typedef void (*CBFUNC)( void*, const std::string&, const std::string& );
00059   typedef void (*CBFUNC2)( void* );
00060 
00061   void setDataCallback( CBFUNC func, void* arg = 0 );
00062   void setConnLossCallback( CBFUNC2 func, void* arg = 0 );
00063   
00064   std::string getError();
00065   unsigned int getLastDataTime() const;
00066   
00067 protected:
00068 
00069   void beginThread();
00070   
00071 private:
00072 
00073   LPORTLIB_NAMESPACE::socket::TCPSocket m_sock;
00074   bool m_quit_request;
00075   unsigned int m_lh;
00076   unsigned int m_last_data;
00077   bool m_nop;
00078   
00079   CBFUNC m_data_cb;
00080   void* m_data_arg;
00081   CBFUNC2 m_cl_cb;
00082   void* m_cl_arg;  
00083   
00084   std::string m_error;
00085   
00086   std::queue< std::string > m_sadd_queue;
00087   LPORTLIB_NAMESPACE::thread::Mutex m_sadd_queue_mutex;
00088   std::queue< std::string > m_sdrp_queue;
00089   LPORTLIB_NAMESPACE::thread::Mutex m_sdrp_queue_mutex;
00090   
00091 }; // class
00092 
00094 class RedundantRSTPClient : public LPORTLIB_NAMESPACE::thread::Thread {
00095 public:
00096 
00097   RedundantRSTPClient();
00098   ~RedundantRSTPClient();
00099   
00100   void addStream( const std::string& stream );
00101   void addServer( const std::string& addr, unsigned short port, unsigned int timeout = 1000,
00102                   const std::string& login = "", const std::string& pass = "" );
00103   
00104   void start();               
00105   void quit();
00106   
00107   typedef void (*CBFUNC)( void*, const std::string&, const std::string& );
00108   typedef void (*CBFUNC3)( void*, const std::string& );
00109   void setDataCallback( CBFUNC func, void* arg = 0 );
00110   void setErrorCallback( CBFUNC3 func, void* arg = 0 );
00111 
00112    
00113 protected:
00114   
00115   void beginThread();
00116   
00117 private:
00118 
00119   bool m_quit_request;
00120   bool m_started_thread;
00121 
00122   struct Server {
00123     RSTPClient* rstp_client;
00124     std::string addr;
00125     unsigned short port;
00126     unsigned int timeout;
00127     unsigned int last_attempt;
00128     std::string login;
00129     std::string pass;
00130     bool join_now;
00131   }; // struct
00132   
00133   std::vector< Server* > m_servers;
00134   std::set< std::string > m_streams;
00135   LPORTLIB_NAMESPACE::thread::Mutex m_streams_mutex;
00136   CBFUNC m_data_cb;
00137   CBFUNC3 m_error_cb;
00138   void* m_data_cb_arg;
00139   void* m_error_cb_arg;
00140   
00141   bool m_running;
00142   
00143 public:
00144 
00145   static void _cl_cb ( void* arg );
00146   
00147 }; // class
00148 
00149 };// namespace
00150 
00151 #endif
00152 

Generated on Tue Jul 1 20:25:26 2008 for libradar_stp by  doxygen 1.4.7