channel_info.h
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:2k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- */
- #ifndef _channel_info_h_
- #define _channel_info_h_
- #include <map>
- #include "playback_window.h"
- class channel_info;
- /** map: key = "Id", value = pointer to channel_info instance */
- typedef map< int, channel_info * > channel_infos_mapT;
- /** this class holds information about a particular channel */
- class channel_info
- {
- int portnum;
- bool active;
- string description;
- bool changed;
- public:
- channel_info( int _port, bool _active, const string _description )
- : portnum( _port ), active( _active ), description( _description ),
- changed( true )
- {}
- /** scan all items and reset flags "changed" and "active" in each */
- static void reset_before_adding( channel_infos_mapT &ch_map )
- {
- channel_infos_mapT::iterator it;
- for( it = ch_map.begin(); it != ch_map.end(); it++ )
- {
- (*it).second->changed = false;
- (*it).second->active = false;
- }
- }
- /** check if this channel exists and than keep "changed" flag false
- ( set previously by "reset_before_adding" and set "active" back to
- true; if not
- exists or some fields are different - set "changed" to true */
- static void add_new_channel_info( channel_infos_mapT &ch_map, int Id,
- int _port, bool _active,
- const string &_description )
- {
- channel_infos_mapT::iterator it = ch_map.find( Id );
- if( it != ch_map.end() )
- {
- // we have it. check
- channel_info &chi = *(*it).second;
- if( chi.portnum == _port && chi.active == _active &&
- !chi.description.compare( _description ) )
- {
- // keep the old one
- chi.changed = false;
- chi.active = _active;
- return;
- }
- // trash old, put new
- delete (*it).second;
- ch_map[ Id ] = new channel_info( _port, _active, _description );
- return;
- }
- // create new
- ch_map[ Id ] = new channel_info( _port, _active, _description );
- }
- const string &get_description() const { return description; }
- const bool is_active() const { return active; }
- /** MpegTV plays channels by URL: construct url for this entry */
- string get_url() const {
- // construct the url for broadcast
- string url = plugin_url_prefix;
- // port number
- {
- char tmp_buf[10];
- snprintf( tmp_buf, sizeof( tmp_buf ), "%d", portnum );
- url = url + string( tmp_buf );
- }
- return url;
- }
- };
- #endif // _channel_info_h_