reSIProcate/DialogUsageManager  9694
basicClient.cxx
Go to the documentation of this file.
00001 #if defined(HAVE_CONFIG_HXX)
00002 #include "resip/stack/config.hxx"
00003 #endif
00004 
00005 #include <cstring>
00006 #include <cassert>
00007 
00008 #ifndef __APPLE__
00009 bool TRUE=true;
00010 bool FALSE=false;
00011 #endif
00012 
00013 #include "basicClientUserAgent.hxx"
00014 #include <resip/stack/SipStack.hxx>
00015 #include <resip/stack/Uri.hxx>
00016 #include <rutil/Logger.hxx>
00017 
00018 #ifdef USE_SSL
00019 #include <resip/stack/ssl/Security.hxx>
00020 #endif
00021 
00022 #include <signal.h>
00023 
00024 using namespace resip;
00025 using namespace std;
00026 
00027 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
00028 
00029 static bool exitSignalDetected = false;
00030 
00031 static void
00032 signalHandler(int signo)
00033 {
00034    std::cerr << "Shutting down" << endl;
00035    exitSignalDetected = true;
00036 }
00037 
00038 int
00039 main(int argc, char* argv[])
00040 {
00041 #ifndef _WIN32
00042    if ( signal( SIGPIPE, SIG_IGN) == SIG_ERR)
00043    {
00044       cerr << "Couldn't install signal handler for SIGPIPE" << endl;
00045       exit(-1);
00046    }
00047 #endif
00048 
00049    if ( signal( SIGINT, signalHandler ) == SIG_ERR )
00050    {
00051       cerr << "Couldn't install signal handler for SIGINT" << endl;
00052       exit( -1 );
00053    }
00054 
00055    if ( signal( SIGTERM, signalHandler ) == SIG_ERR )
00056    {
00057       cerr << "Couldn't install signal handler for SIGTERM" << endl;
00058       exit( -1 );
00059    }
00060 
00061    try
00062    {
00063       BasicClientUserAgent ua(argc, argv);
00064       ua.startup();
00065       
00066       InfoLog(<< argv[0] << " starting");
00067 
00068       while(ua.process(1000))  // Look for exit key every 1 second
00069       {
00070          if(exitSignalDetected)
00071          {
00072             ua.shutdown();
00073             exitSignalDetected = false;
00074          }
00075       }
00076    }
00077 #ifdef USE_SSL
00078    catch (BaseSecurity::Exception& e)
00079    {
00080       WarningLog (<< "Couldn't set up security object: " << e);
00081       exit(-1);
00082    }
00083 #endif
00084    catch (BaseException& e)
00085    {
00086       ErrLog (<< "Caught: " << e);
00087       exit(-1);
00088    }
00089    catch( ... )
00090    {
00091       ErrLog( << "Caught non-resip exception" );
00092       exit(-1);
00093    }
00094 
00095    return 0;
00096 }
00097 
00098 /* ====================================================================
00099 
00100  Copyright (c) 2011, SIP Spectrum, Inc.
00101  All rights reserved.
00102 
00103  Redistribution and use in source and binary forms, with or without
00104  modification, are permitted provided that the following conditions are 
00105  met:
00106 
00107  1. Redistributions of source code must retain the above copyright 
00108     notice, this list of conditions and the following disclaimer. 
00109 
00110  2. Redistributions in binary form must reproduce the above copyright
00111     notice, this list of conditions and the following disclaimer in the
00112     documentation and/or other materials provided with the distribution. 
00113 
00114  3. Neither the name of SIP Spectrum nor the names of its contributors 
00115     may be used to endorse or promote products derived from this 
00116     software without specific prior written permission. 
00117 
00118  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00119  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00120  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00121  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00122  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00123  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00124  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00125  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00126  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00127  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00128  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00129 
00130  ==================================================================== */
00131