Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

CastSink.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : CastSink.h
00008    Version  : $Revision: 1.8 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/CastSink.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ------------------------------------------------------------------------------*/
00029 #ifndef CAST_SINK_H
00030 #define CAST_SINK_H
00031 
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035 
00036 
00037 /* ============================================================ include files */
00038 
00039 #include "Ref.h"
00040 #include "Reporter.h"
00041 #include "Sink.h"
00042 #include "TcpSocket.h"
00043 #include "BufferedSink.h"
00044 
00045 
00046 /* ================================================================ constants */
00047 
00048 
00049 /* =================================================================== macros */
00050 
00051 
00052 /* =============================================================== data types */
00053 
00062 class CastSink : public Sink, public virtual Reporter
00063 {
00064     private:
00065 
00069         Ref<TcpSocket>      socket;
00070 
00074         Ref<BufferedSink>   bufferedSink;
00075 
00079         Ref<Sink>           streamDump;
00080 
00084         unsigned int        bufferDuration;
00085 
00089         char              * password;
00090 
00094         char              * name;
00095 
00099         char              * url;
00100 
00104         char              * genre;
00105 
00109         unsigned int        bitRate;
00110 
00114         bool                isPublic;
00115 
00130         void
00131         init (  TcpSocket             * socket,
00132                 Sink                  * streamDump,
00133                 const char            * password,
00134                 unsigned int            bitRate,
00135                 const char            * name,
00136                 const char            * url,
00137                 const char            * genre,
00138                 bool                    isPublic,
00139                 unsigned int            bufferDuration )
00140                                                     throw ( Exception );
00141 
00147         void
00148         strip ( void )                              throw ( Exception );
00149 
00150 
00151     protected:
00152 
00158         inline
00159         CastSink ( void )                           throw ( Exception )
00160         {
00161             throw Exception( __FILE__, __LINE__);
00162         }
00163 
00170         virtual bool
00171         sendLogin ( void )              throw ( Exception )         = 0;
00172 
00178         inline Sink *
00179         getSink ( void ) const                      throw ()
00180         {
00181             return bufferedSink.get();
00182         }
00183 
00189         inline TcpSocket *
00190         getSocket ( void ) const                    throw ()
00191         {
00192             return socket.get();
00193         }
00194 
00195 
00196     public:
00197 
00213         inline
00214         CastSink (  TcpSocket         * socket,
00215                     const char        * password,
00216                     unsigned int        bitRate,
00217                     const char        * name           = 0,
00218                     const char        * url            = 0,
00219                     const char        * genre          = 0,
00220                     bool                isPublic       = false,
00221                     Sink              * streamDump     = 0,
00222                     unsigned int        bufferDuration = 10 )
00223                                                         throw ( Exception )
00224         {
00225             init( socket,
00226                   streamDump,
00227                   password,
00228                   bitRate,
00229                   name,
00230                   url,
00231                   genre,
00232                   isPublic,
00233                   bufferDuration );
00234         }
00235 
00241         inline
00242         CastSink(   const CastSink &    cs )        throw ( Exception )
00243                 : Sink( cs )
00244         {
00245             init( cs.socket.get(),
00246                   cs.streamDump.get(),
00247                   cs.password,
00248                   cs.bitRate,
00249                   cs.name,
00250                   cs.url,
00251                   cs.genre,
00252                   cs.isPublic,
00253                   cs.bufferDuration );
00254         }
00255 
00261         inline virtual
00262         ~CastSink( void )                           throw ( Exception )
00263         {
00264             strip();
00265         }
00266 
00274         inline virtual CastSink &
00275         operator= ( const CastSink &    cs )        throw ( Exception )
00276         {
00277             if ( this != &cs ) {
00278                 strip();
00279                 Sink::operator=( cs );
00280                 init( cs.socket.get(),
00281                       cs.streamDump.get(),
00282                       cs.password,
00283                       cs.bitRate,
00284                       cs.name,
00285                       cs.url,
00286                       cs.genre,
00287                       cs.isPublic,
00288                       cs.bufferDuration );
00289             }
00290             return *this;
00291         }
00292 
00300         virtual bool
00301         open ( void )                               throw ( Exception );
00302 
00308         inline virtual bool
00309         isOpen ( void ) const                       throw ()
00310         {
00311             return bufferedSink != NULL ? bufferedSink->isOpen() : false;
00312         }
00313 
00324         inline virtual bool
00325         canWrite (     unsigned int    sec,
00326                        unsigned int    usec )       throw ( Exception )
00327         {
00328             return getSink()->canWrite( sec, usec);
00329         }
00330 
00339         inline virtual unsigned int
00340         write (        const void    * buf,
00341                        unsigned int    len )        throw ( Exception )
00342         {
00343             if ( streamDump != 0 ) {
00344                 streamDump->write( buf, len);
00345             }
00346 
00347             return getSink()->write( buf, len);
00348         }
00349 
00355         inline virtual void
00356         flush ( void )                              throw ( Exception )
00357         {
00358             if ( streamDump != 0 ) {
00359                 streamDump->flush();
00360             }
00361 
00362             return getSink()->flush();
00363         }
00364 
00370         inline virtual void
00371         close ( void )                              throw ( Exception )
00372         {
00373             if ( streamDump != 0 ) {
00374                 streamDump->close();
00375             }
00376 
00377             return getSink()->close();
00378         }
00379 
00385         inline const char *
00386         getPassword ( void ) const                  throw ()
00387         {
00388             return password;
00389         }
00390 
00396         inline const char *
00397         getName ( void ) const                      throw ()
00398         {
00399             return name;
00400         }
00401 
00407         inline const char *
00408         getUrl ( void ) const                       throw ()
00409         {
00410             return url;
00411         }
00412 
00418         inline const char *
00419         getGenre ( void ) const                     throw ()
00420         {
00421             return genre;
00422         }
00423 
00429         inline unsigned int
00430         getBitRate ( void ) const                   throw ()
00431         {
00432             return bitRate;
00433         }
00434 
00440         inline bool
00441         getIsPublic ( void ) const                  throw ()
00442         {
00443             return isPublic;
00444         }
00445 
00451         inline unsigned int
00452         getBufferDuration ( void ) const            throw ()
00453         {
00454             return bufferDuration;
00455         }
00456 };
00457 
00458 
00459 /* ================================================= external data structures */
00460 
00461 
00462 /* ====================================================== function prototypes */
00463 
00464 
00465 
00466 #endif  /* CAST_SINK_H */
00467 
00468 
00469 /*------------------------------------------------------------------------------
00470  
00471   $Source: /cvsroot/darkice/darkice/src/CastSink.h,v $
00472 
00473   $Log: CastSink.h,v $
00474   Revision 1.8  2004/01/05 12:00:00  darkeye
00475   fixed possible null pointer problem when destroying the object
00476 
00477   Revision 1.7  2002/02/20 11:54:11  darkeye
00478   added local dump file possibility
00479 
00480   Revision 1.6  2001/09/09 11:27:31  darkeye
00481   added support for ShoutCast servers
00482 
00483   Revision 1.5  2001/08/29 21:08:30  darkeye
00484   made some description options in the darkice config file optional
00485 
00486   Revision 1.4  2000/11/12 14:54:50  darkeye
00487   added kdoc-style documentation comments
00488 
00489   Revision 1.3  2000/11/10 20:14:11  darkeye
00490   added support for remote dump file
00491 
00492   Revision 1.2  2000/11/05 17:37:24  darkeye
00493   removed clone() functions
00494 
00495   Revision 1.1.1.1  2000/11/05 10:05:48  darkeye
00496   initial version
00497 
00498   
00499 ------------------------------------------------------------------------------*/
00500 

Generated on Thu Apr 14 13:59:12 2005 for DarkIce by  doxygen 1.4.1