channel_info.h
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:2k
源码类别:

mpeg/mp3

开发平台:

C/C++

  1. /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
  2.    Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
  3.    Software license is located in file "COPYING"
  4. */
  5. #ifndef _channel_info_h_
  6. #define _channel_info_h_
  7. #include <map>
  8. #include "playback_window.h"
  9. class channel_info;
  10. /** map: key = "Id", value = pointer to channel_info instance */
  11. typedef map< int, channel_info * > channel_infos_mapT;
  12. /** this class holds information about a particular channel */
  13. class channel_info 
  14. {
  15.   int portnum;
  16.   bool active;
  17.   string description;
  18.   bool changed;
  19. public:
  20.   channel_info( int _port, bool _active, const string _description )
  21.     : portnum( _port ), active( _active ), description( _description ),
  22.       changed( true )
  23.     {}
  24.   /** scan all items and reset flags "changed" and "active" in each */
  25.   static void reset_before_adding( channel_infos_mapT &ch_map )
  26.     {
  27.       channel_infos_mapT::iterator it;
  28.       for( it = ch_map.begin(); it != ch_map.end(); it++ )
  29. {
  30.   (*it).second->changed = false;
  31.   (*it).second->active = false;
  32. }
  33.     }
  34.   /** check if this channel exists and than keep "changed" flag false
  35.       ( set previously by "reset_before_adding" and set "active" back to 
  36.       true; if not
  37.       exists or some fields are different - set "changed" to true */
  38.   static void add_new_channel_info( channel_infos_mapT &ch_map, int Id,
  39.     int _port, bool _active, 
  40.     const string &_description )
  41.     {
  42.       channel_infos_mapT::iterator it = ch_map.find( Id );
  43.       if( it != ch_map.end() )
  44. {
  45.   // we have it. check
  46.   channel_info &chi = *(*it).second;
  47.   if( chi.portnum == _port && chi.active == _active &&
  48.       !chi.description.compare( _description ) )
  49.     {
  50.       // keep the old one
  51.       chi.changed = false;
  52.       chi.active = _active;
  53.       return;
  54.     }
  55.   // trash old, put new
  56.   delete (*it).second;
  57.   ch_map[ Id ] = new channel_info( _port, _active, _description );
  58.   return;
  59. }
  60.       // create new
  61.       ch_map[ Id ] = new channel_info( _port, _active, _description );
  62.     }
  63.   const string &get_description() const { return description; }
  64.   const bool is_active() const { return active; }
  65.   /** MpegTV plays channels by URL: construct url for this entry */
  66.   string get_url() const {
  67.     // construct the url for broadcast
  68.     string url = plugin_url_prefix;
  69.     // port number
  70.     {
  71.       char tmp_buf[10];
  72.       snprintf( tmp_buf, sizeof( tmp_buf ), "%d", portnum );
  73.       url = url + string( tmp_buf );
  74.     }
  75.     return url;
  76.   }
  77. };
  78. #endif //  _channel_info_h_