S3FC project page | S3FC home page |
00001 /* 00002 * Stone Three Foundation Class (s3fc) provides a number of utility classes. 00003 * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd. 00004 * 00005 * Authored by Stone Three Signal Processing (Pty) Ltd. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library 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 GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * Please see the file 'COPYING' in the source root directory. 00022 */ 00023 00033 #ifndef S3_TXPORT_LOCAL_H 00034 #define S3_TXPORT_LOCAL_H 00035 00036 #include <s3fc/s3_thread_base.h> 00037 #include <s3fc/s3_periodic_notifier.h> 00038 #include <s3fc/s3_semaphore.h> 00039 #include <s3fc/s3_mutex.h> 00040 #include <s3fc/s3_txport_base.h> 00041 #include <map> 00042 #include <list> 00043 00051 template<class T_Data> 00052 class s3_txport_local : public s3_txport_base<T_Data>, public s3_thread_base 00053 { 00055 s3_fifo_queue<s3_txport_data<T_Data> > rx_queue; 00056 00058 s3_fifo_queue<s3_txport_data<T_Data> > tx_queue; 00059 00061 s3_semaphore terminate; 00062 00064 s3_semaphore sem; 00065 00067 s3_txport_client_id connect_id; 00068 00070 typedef std::map<s3_txport_client_id, s3_txport_local<T_Data>* > c_map; 00071 00073 c_map connections; 00074 00076 s3_periodic_notifier pn; 00077 00079 s3_mutex connection_mutex; 00080 00087 s3_txport_local* register_me(s3_txport_local *remote); 00088 00093 void deregister_me(const s3_txport_local *remote); 00094 00096 s3_txport_client_id next_id() 00097 { 00098 // Arbitrary limit on the number of connections 00099 if (connect_id > 10000000) 00100 connect_id = 1; 00101 else 00102 connect_id++; 00103 return connect_id; 00104 } 00106 void cleanup(); 00107 00108 public: 00109 00114 s3_txport_local( unsigned int queue_size = 4); 00115 00117 ~s3_txport_local(); 00118 00123 s3_fifo_queue<s3_txport_data<T_Data> >& get_tx_queue(); 00124 00129 s3_fifo_queue<s3_txport_data<T_Data> >& get_rx_queue(); 00130 00137 std::list<s3_txport_client_id> get_client_id_list() const; 00138 00145 void send_metadata(s3_txport_client_id id, const std::string& metadata); 00146 00148 bool is_connected_by_id(s3_txport_client_id id); 00149 00154 bool disconnect_by_id(s3_txport_client_id id); 00155 00157 void disconnect_all(); 00158 00160 bool listening() const; 00161 00171 s3_txport_client_id connect(s3_txport_local<T_Data> *listener); 00172 00178 bool listen(); 00179 00180 // Listener thread's main loop 00181 void main_loop(); 00182 00184 int num_connections() const; 00185 00186 }; 00187 00188 #include <s3fc/s3_txport_local.tcc> 00189 00190 00191 #endif
Send comments to: s3fc@stonethree.com |
|