tProtocol.cxx
上传用户:sy_wanhua
上传日期:2013-07-25
资源大小:3048k
文件大小:7k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

C/C++

  1. /* ====================================================================
  2.  * The Vovida Software License, Version 1.0 
  3.  * 
  4.  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
  5.  * 
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in
  15.  *    the documentation and/or other materials provided with the
  16.  *    distribution.
  17.  * 
  18.  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
  19.  *    and "Vovida Open Communication Application Library (VOCAL)" must
  20.  *    not be used to endorse or promote products derived from this
  21.  *    software without prior written permission. For written
  22.  *    permission, please contact vocal@vovida.org.
  23.  *
  24.  * 4. Products derived from this software may not be called "VOCAL", nor
  25.  *    may "VOCAL" appear in their name, without prior written
  26.  *    permission of Vovida Networks, Inc.
  27.  * 
  28.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
  29.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  31.  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
  32.  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
  33.  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
  34.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  35.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  36.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  37.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39.  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  40.  * DAMAGE.
  41.  * 
  42.  * ====================================================================
  43.  * 
  44.  * This software consists of voluntary contributions made by Vovida
  45.  * Networks, Inc. and many individuals on behalf of Vovida Networks,
  46.  * Inc.  For more information on Vovida Networks, Inc., please see
  47.  * <http://www.vovida.org/>.
  48.  *
  49.  */
  50. static const char* const tProtocol_cxx_Version = 
  51. "$Id$";
  52. #include "Application.hxx"
  53. #include "Thread.hxx"
  54. #include "VLog.hxx"
  55. #include "SignalHandler.hxx"
  56. #include "TPKTClientProtocol.hxx"
  57. #include "TPKTClientSocket.hxx"
  58. #include "PollFifoService.hxx"
  59. #include "PollFifo.hxx"
  60. #include "Sptr.hxx"
  61. #include "Event.hxx"
  62. using Vocal::Application;
  63. using Vocal::Runnable;
  64. using Vocal::ReturnCode;
  65. using Vocal::SUCCESS;
  66. using Vocal::Threads::Thread;
  67. using Vocal::Process::SignalHandler;
  68. using Vocal::Logging::VLog;
  69. using Vocal::Transport::TPKTClientProtocol;
  70. using Vocal::Transport::TPKTClientSocket;
  71. using Vocal::Services::Event;
  72. using Vocal::Services::PollFifoService;
  73. using Vocal::IO::FileDescriptor;
  74. class Q931ProtocolBase : public TPKTClientProtocol
  75. {
  76.     public:
  77.     
  78.         Q931ProtocolBase(
  79.             PollFifoService       &   service,
  80.          Sptr<TPKTClientSocket>      q931Socket,
  81.          const char            *   name = 0
  82.      );
  83.      virtual ~Q931ProtocolBase();
  84.         virtual const FileDescriptor& getFileDescriptor() const;
  85.      virtual TPKTClientSocket& getTPKTClientSocket();
  86.      virtual void onTPKTArrived(vector<u_int8_t>& message);
  87.     private:
  88.      PollFifoService          & service_;
  89.         Sptr<TPKTClientSocket>      q931Socket_;
  90. };
  91. class Q931Protocol : public Q931ProtocolBase
  92. {
  93.     public:
  94.     
  95.         Q931Protocol(
  96.             PollFifoService       &   service,
  97.          Sptr<TPKTClientSocket>      q931Socket
  98.      )
  99.     : Q931ProtocolBase(service, q931Socket)
  100.      {
  101. }
  102.      virtual ~Q931Protocol()
  103. {
  104.      }
  105. };
  106. class tApplication : public Application
  107. {
  108.     public:
  109.      tApplication() {}
  110. ~tApplication() {}
  111.      ReturnCode       init(int argc, char ** argv, char ** arge);
  112. void          uninit();
  113.      ReturnCode       run();
  114. };
  115. Q931ProtocolBase::Q931ProtocolBase(
  116.     PollFifoService       &   service,
  117.     Sptr<TPKTClientSocket>      q931Socket,
  118.     const char            *   name
  119. )
  120.     : TPKTClientProtocol(name),
  121.      service_(service),
  122. q931Socket_(q931Socket)
  123. {
  124.     awaitIncoming(true);
  125.     service_.registerProtocol(*this);
  126. }
  127. Q931ProtocolBase::~Q931ProtocolBase()
  128. {
  129.     service_.unregisterProtocol(*this);
  130. }
  131. const FileDescriptor &
  132. Q931ProtocolBase::getFileDescriptor() const
  133. {
  134.     return ( *q931Socket_ );
  135. }
  136. TPKTClientSocket & 
  137. Q931ProtocolBase::getTPKTClientSocket()
  138. {
  139.     return ( *q931Socket_ );
  140. }
  141. void 
  142. Q931ProtocolBase::onTPKTArrived(vector<u_int8_t>& message)
  143. {
  144. }
  145. ReturnCode
  146. tApplication::init(int argc, char ** argv, char ** arge)
  147. {
  148.     Thread::init();
  149.     VLog::init(LOG_DEBUG);
  150.     SignalHandler::init();
  151.     VLog::on(LOG_VERBOSE);
  152.     VLog::on(LOG_DEBUG);
  153.     VLog::on(LOG_INFO);
  154.         
  155.     return ( SUCCESS );
  156. }
  157. void
  158. tApplication::uninit()
  159. {
  160.     SignalHandler::uninit();
  161.     VLog::uninit();
  162.     Thread::uninit();
  163. }
  164. Application * Application::create()
  165. {
  166.     return ( new tApplication );
  167. }
  168. ReturnCode
  169. tApplication::run()
  170. {
  171.     PollFifo< Sptr<Event> > fifo;
  172.     PollFifoService      service(fifo);
  173.     
  174.     Sptr<TPKTClientSocket>  q931Socket0 = new TPKTClientSocket;
  175.     Sptr<Q931Protocol>      q931Protocol0 = new Q931Protocol(service, q931Socket0);
  176.     Sptr<TPKTClientSocket>  q931Socket1 = new TPKTClientSocket;
  177.     Sptr<Q931Protocol>      q931Protocol1 = new Q931Protocol(service, q931Socket1);
  178.     
  179.     Sptr<TPKTClientSocket>  q931Socket2 = new TPKTClientSocket;
  180.     Sptr<Q931Protocol>      q931Protocol2 = new Q931Protocol(service, q931Socket2);
  181.     
  182.     Sptr<TPKTClientSocket>  q931Socket3 = new TPKTClientSocket;
  183.     Sptr<Q931Protocol>      q931Protocol3 = new Q931Protocol(service, q931Socket3);
  184.     
  185.     Sptr<TPKTClientSocket>  q931Socket4 = new TPKTClientSocket;
  186.     Sptr<Q931Protocol>      q931Protocol4 = new Q931Protocol(service, q931Socket4);
  187.     
  188.     Sptr<TPKTClientSocket>  q931Socket5 = new TPKTClientSocket;
  189.     Sptr<Q931Protocol>      q931Protocol5 = new Q931Protocol(service, q931Socket5);
  190.     
  191.     Sptr<TPKTClientSocket>  q931Socket6 = new TPKTClientSocket;
  192.     Sptr<Q931Protocol>      q931Protocol6 = new Q931Protocol(service, q931Socket6);
  193.     
  194.     Sptr<TPKTClientSocket>  q931Socket7 = new TPKTClientSocket;
  195.     Sptr<Q931Protocol>      q931Protocol7 = new Q931Protocol(service, q931Socket7);
  196.     
  197.     Sptr<TPKTClientSocket>  q931Socket8 = new TPKTClientSocket;
  198.     Sptr<Q931Protocol>      q931Protocol8 = new Q931Protocol(service, q931Socket8);
  199.     
  200.     fifo.block(1000);
  201.     q931Protocol0 = 0;
  202.     q931Protocol1 = 0;
  203.     q931Protocol2 = 0;
  204.     q931Protocol3 = 0;
  205.     q931Protocol4 = 0;
  206.     q931Protocol5 = 0;
  207.     q931Protocol6 = 0;
  208.     q931Protocol7 = 0;
  209.     q931Protocol8 = 0;
  210.     return ( 0 );
  211. }
  212. int main(int argc, char ** argv, char ** arge)
  213. {
  214.     return ( Application::main(argc, argv, arge) );
  215. }