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

main.cpp

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     : main.cpp
00008    Version  : $Revision: 1.15 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/main.cpp,v $
00011    
00012    Abstract : 
00013 
00014     Program entry point
00015 
00016    Copyright notice:
00017 
00018     This program is free software; you can redistribute it and/or
00019     modify it under the terms of the GNU General Public License  
00020     as published by the Free Software Foundation; either version 2
00021     of the License, or (at your option) any later version.
00022    
00023     This program is distributed in the hope that it will be useful,
00024     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00025     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00026     GNU General Public License for more details.
00027    
00028     You should have received a copy of the GNU General Public License
00029     along with this program; if not, write to the Free Software
00030     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00031 
00032 ------------------------------------------------------------------------------*/
00033 
00034 /* ============================================================ include files */
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #ifdef HAVE_STDLIB_H
00041 #include <stdlib.h>
00042 #else
00043 #error needs stdlib.h
00044 #endif
00045 
00046 #include <iostream>
00047 #include <fstream>
00048 
00049 #include "Ref.h"
00050 #include "Exception.h"
00051 #include "Util.h"
00052 #include "DarkIce.h"
00053 
00054 
00055 /* ===================================================  local data structures */
00056 
00057 
00058 /* ================================================  local constants & macros */
00059 
00060 /*------------------------------------------------------------------------------
00061  *  File identity
00062  *----------------------------------------------------------------------------*/
00063 static const char fileid[] = "$Id: main.cpp,v 1.15 2005/04/14 11:24:42 darkeye Exp $";
00064 
00065 
00066 /* ===============================================  local function prototypes */
00067 
00068 /*------------------------------------------------------------------------------
00069  *  Show program usage
00070  *----------------------------------------------------------------------------*/
00071 static void
00072 showUsage (     std::ostream  & os );
00073 
00074 
00075 /* =============================================================  module code */
00076 
00077 /*------------------------------------------------------------------------------
00078  *  Program entry point
00079  *----------------------------------------------------------------------------*/
00080 int
00081 main (
00082     int     argc,
00083     char  * argv[] )
00084 {
00085     int     res = -1;
00086 
00087     std::cout << "DarkIce " << VERSION
00088          << " live audio streamer, http://darkice.sourceforge.net"
00089          << std::endl
00090          << "Copyright (c) 2000-2005, Tyrell Hungary, http://tyrell.hu"
00091          << std::endl << std::endl;
00092 
00093     try {
00094         const char    * configFileName = 0;
00095         unsigned int    verbosity      = 1;
00096         int             i;
00097         const char      opts[] = "hc:v:";
00098 
00099         while ( (i = getopt( argc, argv, opts)) != -1 ) {
00100             switch ( i ) {
00101                 case 'c':
00102                     configFileName = optarg;
00103                     break;
00104 
00105                 case 'v':
00106                     verbosity = Util::strToL( optarg);
00107                     break;
00108 
00109                 default:
00110                 case ':':
00111                 case '?':
00112                 case 'h':
00113                     showUsage( std::cout);
00114                     return 1;
00115             }
00116         }
00117 
00118         if ( !configFileName ) {
00119             showUsage( std::cout);
00120             throw Exception( __FILE__, __LINE__,
00121                              "no configuration file specified");
00122         }
00123 
00124         std::cout << "Using config file: " << configFileName << std::endl;
00125 
00126         std::ifstream       configFile( configFileName);
00127         Reporter::setReportVerbosity( verbosity );
00128         Reporter::setReportOutputStream( std::cout );
00129         Config              config( configFile);
00130         Ref<DarkIce>        di = new DarkIce( config);
00131 
00132         res = di->run();
00133 
00134     } catch ( Exception   & e ) {
00135         std::cout << "DarkIce: " << e << std::endl << std::flush;
00136     }
00137 
00138     return res;
00139 }
00140 
00141 
00142 /*------------------------------------------------------------------------------
00143  *  Show program usage
00144  *----------------------------------------------------------------------------*/
00145 static void
00146 showUsage (     std::ostream      & os )
00147 {
00148     os
00149     << "usage: darkice [-v n] -c config.file"
00150     << std::endl
00151     << std::endl
00152     << "options:"
00153     << std::endl
00154     << "   -c config.file     use configuration file config.file"
00155     << std::endl
00156     << "   -v n               verbosity level (0 = silent, 10 = loud)"
00157     << std::endl
00158     << "   -h                 print this message and exit"
00159     << std::endl
00160     << std::endl;
00161 }
00162 
00163 
00164 /*------------------------------------------------------------------------------
00165  
00166   $Source: /cvsroot/darkice/darkice/src/main.cpp,v $
00167 
00168   $Log: main.cpp,v $
00169   Revision 1.15  2005/04/14 11:24:42  darkeye
00170   updated copyright notice to extend to 2005
00171 
00172   Revision 1.14  2005/04/03 05:10:07  jbebel
00173   Moved initialization of Reporter class so it would happen before
00174   instantiation of Darkice class.  Any logging that might be reported
00175   during the construction of the Darkice class could not function.
00176   Originally the Reporter initialization was done through the instance
00177   of Darkice (which inherits Reporter), but that obviously isn't possible
00178   before Darkice is instantiated.  Since Reporter is largely a static class,
00179   it is reasonable to call it via the scope resolution operator rather
00180   than via an instance of the class, so that's what I did.
00181 
00182   Revision 1.13  2004/02/15 12:06:30  darkeye
00183   added ALSA support, thanks to Christian Forster
00184 
00185   Revision 1.12  2003/02/09 15:09:41  darkeye
00186   for version 0.13
00187 
00188   Revision 1.11  2002/05/28 12:35:41  darkeye
00189   code cleanup: compiles under gcc-c++ 3.1, using -pedantic option
00190 
00191   Revision 1.10  2002/02/20 15:08:52  darkeye
00192   minor changes
00193 
00194   Revision 1.9  2001/09/11 15:05:21  darkeye
00195   added Solaris support
00196 
00197   Revision 1.8  2001/09/02 12:24:29  darkeye
00198   now displays usage info when no command line parameters given
00199 
00200   Revision 1.7  2001/08/30 17:25:56  darkeye
00201   renamed configure.h to config.h
00202 
00203   Revision 1.6  2001/08/26 08:43:13  darkeye
00204   added support for unlimited time encoding
00205 
00206   Revision 1.5  2000/11/15 18:08:43  darkeye
00207   added multiple verbosity-level event reporting and verbosity command
00208   line option
00209 
00210   Revision 1.4  2000/11/13 20:21:29  darkeye
00211   added program version display on startup
00212 
00213   Revision 1.3  2000/11/13 19:38:55  darkeye
00214   moved command line parameter parsing from DarkIce.cpp to main.cpp
00215 
00216   Revision 1.2  2000/11/08 17:29:50  darkeye
00217   added configuration file reader
00218 
00219   Revision 1.1.1.1  2000/11/05 10:05:52  darkeye
00220   initial version
00221 
00222   
00223 ------------------------------------------------------------------------------*/
00224 

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