00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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 };
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 };
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 };
00148
00149 };
00150
00151 #endif
00152