S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_txport_base.h

Go to the documentation of this file.
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 
00031 #ifndef S3_TXPORT_BASE_H
00032 #define S3_TXPORT_BASE_H
00033 
00034 #include <string>
00035 #include <list>
00036 #include <s3fc/s3_fifo_queue.h>
00037 #include <s3fc/s3_event.h>
00038 
00040 typedef int s3_txport_client_id;
00041 
00049 template<typename T_Data>
00050 class s3_txport_data
00051 {
00052 
00054    std::list<s3_txport_client_id> idl;
00055 
00056   public:
00058    T_Data data;
00059 
00061    s3_txport_data(const T_Data& a_data, s3_txport_client_id a_id) :
00062       data(a_data)
00063    {
00064       idl.push_back(a_id);
00065    }
00066 
00068    s3_txport_data(const T_Data& a_data,
00069         const std::list<s3_txport_client_id>& a_idl) :
00070       idl(a_idl), data(a_data)
00071    {}
00072 
00074    s3_txport_data() {};
00075 
00077    void erase_client_ids()
00078    {
00079       idl.clear();
00080    }
00081 
00086    void set_id(const std::list<s3_txport_client_id>& id_list)
00087    {
00088       idl = id_list;
00089    }
00090 
00095    void set_id(s3_txport_client_id id)
00096    {
00097       idl.clear();
00098       idl.push_back(id);
00099    }
00100 
00108    s3_txport_client_id get_id() const
00109    {
00110       if (idl.size() != 1)
00111       {
00112     throw s3_generic_exception("s3_txport_data::get_id()",
00113                 "More than one ID in ID list");
00114       }
00115       return idl.front();
00116    }
00117 
00118    // Returns the list of clients
00119    std::list<s3_txport_client_id> get_id_list() const
00120    {
00121       return idl;
00122    }
00123 };
00124 
00131 struct s3_txport_event
00132 {
00134    enum event_type
00135    {
00137       connect,
00139       disconnect,
00142       metadata,
00144       error,
00146       information,
00148       reject,
00150       null_event
00151    };
00153    event_type event;
00155    s3_txport_client_id id;
00157    std::string message;
00159    s3_txport_event(event_type e, s3_txport_client_id a_id,
00160          const std::string& m) :
00161       event(e), id(a_id), message(m) {};
00162    s3_txport_event() : event(null_event), id(0), message(""){};
00163 };
00164 
00165 
00171 template<class T_Data>
00172 class s3_txport_base : public s3_event_dispatcher<s3_txport_event>
00173 {
00174 
00175   public:
00176 
00178    virtual ~s3_txport_base() {}
00179 
00184    virtual s3_fifo_queue<s3_txport_data<T_Data> >& get_tx_queue() = 0;
00185 
00190    virtual s3_fifo_queue<s3_txport_data<T_Data> >& get_rx_queue() = 0;
00191 
00198    virtual std::list<s3_txport_client_id> get_client_id_list() const = 0;
00199 
00206    virtual void send_metadata(s3_txport_client_id id,
00207                const std::string& metadata) = 0;
00208 
00210    virtual bool is_connected_by_id(s3_txport_client_id id) = 0;
00211 
00216    virtual bool disconnect_by_id(s3_txport_client_id id) = 0;
00217 
00219    virtual void disconnect_all() = 0;
00220 
00222    virtual bool listening() const = 0;
00223 };
00224 
00225 
00226 #endif

Send comments to: s3fc@stonethree.com SourceForge Logo