movie_item.cc
上传用户: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"
- */
- #include "movie_item.h"
- const MovieFile *MovieItem::findFileByTime( const struct tm &_t ) const
- {
- time_t _t_t = mktime( (struct tm *)&_t );
- for( int i = 0; i < movieFiles.size(); i++ )
- {
- const MovieFile &mf = movieFiles[i];
- time_t t = mktime( (struct tm *) &mf.stop );
- if( t < _t_t )
- continue;
- time_t t0 = mktime( (struct tm *) &mf.start );
- if( t0 > _t_t )
- return NULL;
- return &mf;
- }
- return NULL;
- }
- void MovieItem::findFileListByTime( const struct tm &_t, MovieFilesT &mfs )
- const
- {
- const MovieFile *mf = findFileByTime( _t );
- if( !mf )
- return;
- for( int i = 0; i < movieFiles.size(); i++ )
- {
- if( mf != &movieFiles[i] )
- continue;
- // copy this file and all next files to mfs
- for( int j = i; j < movieFiles.size(); j++ )
- mfs.push_back( movieFiles[j] );
- break;
- }
- }
- void MovieItem::addMovieFile( const string &fname, int id,
- const string &ipaddr, int control_port,
- const struct tm &start, const struct tm &stop )
- {
- movieFiles.push_back( MovieFile( fname, id, ipaddr, control_port,
- start, stop ));
- }
- void MovieItem::filterBestPushServ( const vector< string > &best_ips )
- {
- MovieFilesT::iterator it;
- vector< string >::const_iterator s_it;
- string chosen_ip;
-
- for( s_it = best_ips.begin(); s_it != best_ips.end(); s_it++ )
- {
- for( it = movieFiles.begin(); it != movieFiles.end(); it++ )
- {
- MovieFile &mf = *it;
- if( mf.ip_is_equal( *s_it ) )
- {
- chosen_ip = *s_it;
- break;
- }
- }
- if( chosen_ip.length() )
- break;
- }
- // if no preferred ip found just pickup the random one
- if( !chosen_ip.length() )
- {
- int i = rand() % movieFiles.size();
- chosen_ip = movieFiles[ i ].ipaddress;
- }
- // now drop out everything that is not this selected ip address
- for( it = movieFiles.begin(); it != movieFiles.end(); it++ )
- {
- // i know that not efficient, but this is interactive
- if( false == (*it).ip_is_equal( chosen_ip ) )
- it = movieFiles.erase( it );
- }
- }