reSIProcate/stack  9694
testRSP-2.cxx
Go to the documentation of this file.
00001 #include "resip/stack/SipStack.hxx"
00002 #include "resip/stack/SipMessage.hxx"
00003 #include "rutil/Logger.hxx"
00004 #include "rutil/Subsystem.hxx"
00005 #include "resip/stack/Helper.hxx"
00006 
00007 #ifndef WIN32
00008 #include <pthread.h>
00009 #endif
00010 
00011 class TestSS : public resip::Subsystem
00012 {
00013 public:
00014   static const TestSS RSP2;
00015 private:
00016   TestSS(const resip::Data& rhs) : resip::Subsystem(resip::Data("TestSS")+rhs){};
00017   TestSS& operator=(const resip::Data& rhs);
00018 }
00019 
00020 const TestSS::RSP2("RSP2");
00021 
00022 using namespace std;
00023 using namespace resip;
00024 
00025 bool g_stop_poller = false;
00026 
00027 void *poller(void *arg)
00028 {
00029   int i = 0;
00030   SipStack *stack1 = (SipStack*)arg;
00031   while (!g_stop_poller)
00032     {
00033       FdSet fdset;
00034       stack1->buildFdSet(fdset);
00035       fdset.selectMilliSeconds(100);
00036       stack1->process(fdset);
00037       SipMessage *msg = stack1->receive();
00038       if (msg)
00039         {
00040           cerr << "Got a message" << endl;
00041           SipMessage *resp = Helper::makeResponse(*msg,604);
00042           stack1->send(*resp);
00043           delete resp;
00044           delete msg;
00045         }
00046       else
00047         {
00048           ++i;
00049           if (!(i%10))
00050             cerr << "Nothing there " << i/10 << '\r';
00051         }
00052     }
00053   return NULL;
00054 }
00055 
00056 #define RESIPROCATE_SUBSYSTEM TestSS::RSP2
00057 
00058 int main(int argc, char* argv[])
00059 {
00060   resip::Log::initialize(Log::Cout, Log::Stack, *argv);
00061   SipStack stack1;  
00062   //pthread_t tid;
00063   stack1.addTransport(UDP, 5060, V4, StunDisabled, Data::Empty, Data::Empty, Data::Empty, SecurityTypes::TLSv1);
00064   stack1.addTransport(TCP, 5060, V4, StunDisabled, Data::Empty, Data::Empty, Data::Empty, SecurityTypes::TLSv1);
00065   //pthread_create(&tid, NULL, poller, &stack1);
00066   //pthread_join(tid, &retval);
00067   poller((void*)&stack1);
00068 }
00069 
00070 /* ====================================================================
00071  * The Vovida Software License, Version 1.0 
00072  * 
00073  * Copyright (c) 2000-2005 Vovida Networks, Inc.  All rights reserved.
00074  * 
00075  * Redistribution and use in source and binary forms, with or without
00076  * modification, are permitted provided that the following conditions
00077  * are met:
00078  * 
00079  * 1. Redistributions of source code must retain the above copyright
00080  *    notice, this list of conditions and the following disclaimer.
00081  * 
00082  * 2. Redistributions in binary form must reproduce the above copyright
00083  *    notice, this list of conditions and the following disclaimer in
00084  *    the documentation and/or other materials provided with the
00085  *    distribution.
00086  * 
00087  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00088  *    and "Vovida Open Communication Application Library (VOCAL)" must
00089  *    not be used to endorse or promote products derived from this
00090  *    software without prior written permission. For written
00091  *    permission, please contact vocal@vovida.org.
00092  *
00093  * 4. Products derived from this software may not be called "VOCAL", nor
00094  *    may "VOCAL" appear in their name, without prior written
00095  *    permission of Vovida Networks, Inc.
00096  * 
00097  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00098  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00099  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00100  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00101  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00102  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00103  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00104  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00105  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00106  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00107  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00108  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00109  * DAMAGE.
00110  * 
00111  * ====================================================================
00112  * 
00113  * This software consists of voluntary contributions made by Vovida
00114  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00115  * Inc.  For more information on Vovida Networks, Inc., please see
00116  * <http://www.vovida.org/>.
00117  *
00118  */