|
reSIProcate/stack
9694
|
00001 #ifndef RESIP_EventStackThread__hxx 00002 #define RESIP_EventStackThread__hxx 00003 00004 #include <vector> 00005 00006 #include "rutil/ThreadIf.hxx" 00007 #include "rutil/FdPoll.hxx" 00008 #include "rutil/SelectInterruptor.hxx" 00009 00010 namespace resip 00011 { 00012 00013 class SipStackOptions; 00014 class SipStack; 00015 class SelectInterruptor; 00016 class EventThreadInterruptor; 00017 class FdPollGrp; 00018 00040 class EventStackThread : public ThreadIf 00041 { 00042 public: 00043 EventStackThread(EventThreadInterruptor& si, FdPollGrp& pollGrp); 00044 EventStackThread(SipStack& stack, EventThreadInterruptor& si, FdPollGrp& pollGrp); 00045 virtual ~EventStackThread(); 00046 00047 /* 00048 * If you use the 1st constructor form, use this after creating 00049 * the stack to add it into the list to which the thread is providing 00050 * cycles. Even with only one active stack, this approach can 00051 * be used to solve the cyclic initialization problem. 00052 */ 00053 void addStack(SipStack& stack); 00054 00055 virtual void thread(); 00056 virtual void shutdown(); 00057 00058 protected: 00059 /* 00060 * Return time (in milliseconds) until your next timer, or 00061 * ~30sec for infinity. 00062 */ 00063 virtual unsigned int getTimeTillNextProcessMS() const; 00064 00065 /* 00066 * Called after all socket IO and sip stack timers. Process 00067 * any application timers here. 00068 */ 00069 virtual void afterProcess(); 00070 00071 private: 00072 typedef std::vector<SipStack*> StackList; 00073 StackList mStacks; 00074 EventThreadInterruptor& mIntr; 00075 FdPollGrp& mPollGrp; 00076 }; 00077 00078 00079 00080 class EventThreadInterruptor : public SelectInterruptor 00081 { 00082 public: 00083 EventThreadInterruptor(FdPollGrp& pollGrp); 00084 virtual ~EventThreadInterruptor(); 00085 protected: 00086 FdPollGrp& mPollGrp; // used just to remove ourselves 00087 FdPollItemHandle mPollItemHandle; 00088 }; 00089 00109 class EventStackSimpleMgr 00110 { 00111 public: 00112 EventStackSimpleMgr(const char *implName); 00113 ~EventStackSimpleMgr(); 00114 /* 00115 * Configure {options} with our pollGrp and asyncHandler. 00116 * Use this prior to creating your SipStack instance. 00117 */ 00118 void setOptions(SipStackOptions& options); 00119 00120 /* 00121 * Convenience function to create SipStack instance. Will add 00122 * appropriate options, cerate the stack and add the stack to 00123 * the thread. 00124 */ 00125 SipStack& createStack(SipStackOptions& options); 00126 00127 00128 /* 00129 * Thread accessor. 00130 * Use this to invoke addStack(), run(), shutdown(), join(), etc. 00131 */ 00132 EventStackThread& getThread() { assert(mThread); return *mThread; } 00133 00134 /* 00135 * Call to release all owned resources early. Stack must be 00136 * stopped and thread joined prior to releasing. 00137 */ 00138 void release(); 00139 00140 protected: 00141 FdPollGrp* mPollGrp; 00142 EventThreadInterruptor* mIntr; 00143 EventStackThread* mThread; 00144 SipStack* mStack; 00145 }; 00146 00147 } // namespace 00148 00149 #endif 00150 00151 00152 /* ==================================================================== 00153 * The Vovida Software License, Version 1.0 00154 * 00155 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00156 * 00157 * Redistribution and use in source and binary forms, with or without 00158 * modification, are permitted provided that the following conditions 00159 * are met: 00160 * 00161 * 1. Redistributions of source code must retain the above copyright 00162 * notice, this list of conditions and the following disclaimer. 00163 * 00164 * 2. Redistributions in binary form must reproduce the above copyright 00165 * notice, this list of conditions and the following disclaimer in 00166 * the documentation and/or other materials provided with the 00167 * distribution. 00168 * 00169 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00170 * and "Vovida Open Communication Application Library (VOCAL)" must 00171 * not be used to endorse or promote products derived from this 00172 * software without prior written permission. For written 00173 * permission, please contact vocal@vovida.org. 00174 * 00175 * 4. Products derived from this software may not be called "VOCAL", nor 00176 * may "VOCAL" appear in their name, without prior written 00177 * permission of Vovida Networks, Inc. 00178 * 00179 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00180 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00181 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00182 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00183 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00184 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00185 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00186 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00187 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00188 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00189 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00190 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00191 * DAMAGE. 00192 * 00193 * ==================================================================== 00194 * 00195 * This software consists of voluntary contributions made by Vovida 00196 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00197 * Inc. For more information on Vovida Networks, Inc., please see 00198 * <http://www.vovida.org/>. 00199 * 00200 * vi: set shiftwidth=3 expandtab: 00201 */
1.7.5.1