00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : CommPipe 00006 * Package : Zeus.ZeusBase.Messaging 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef CommPipeH 00033 #define CommPipeH 00034 00035 #include <zeusbase/Messaging/Interfaces/IOwnCommPipe.hpp> 00036 #include <zeusbase/Remote/AbstractRemoteObject.h> 00037 #include <zeusbase/Net/ServerSocket.h> 00038 #include <zeusbase/System/Time.h> 00039 #include <zeusbase/System/Thread.h> 00040 #include <zeusbase/System/SingleLinkedList.hpp> 00041 00042 BEGIN_NAMESPACE_Zeus 00043 00044 class TCommPipe_Skel; 00045 class TCriticalSection; 00046 class TSemaphore; 00047 00048 /*****************************************************************************/ 00053 /*****************************************************************************/ 00054 zeusbase_class TCommPipe : public TAbstractRemoteObject, public IOwnCommPipe 00055 { 00056 public : 00057 TCommPipe(const TString& rName, bool bBlocking = false); 00058 TCommPipe(Uint uiPriority, const TString& rName, bool bBlocking = false); 00059 00060 //Interface ICommPipe 00061 virtual Retval MQUALIFIER sendMessage(IMessage& rMessage); 00062 virtual void MQUALIFIER getPipeName(IString& rName) const; 00063 virtual Uint MQUALIFIER getPriority() const; 00064 virtual bool MQUALIFIER isLocked() const; 00065 virtual bool MQUALIFIER hasRemoteAccess() const; 00066 00067 //Methods of IOwnCommPipe 00068 virtual void MQUALIFIER lock(); 00069 virtual void MQUALIFIER unlock(); 00070 virtual void MQUALIFIER flush(); 00071 virtual Retval MQUALIFIER getMessage(IMessage*& rpMessage); 00072 virtual Retval MQUALIFIER peekMessage(IMessage*& rpMessage); 00073 virtual bool MQUALIFIER isEmpty() const; 00074 virtual Int MQUALIFIER getCount() const; 00075 00076 //Methods of IRemoteObject 00077 REMOTE_OBJECT_DECL 00078 00079 //Methods of IZUnknown 00080 MEMORY_MANAGER_DECL 00081 00082 protected: 00083 virtual ~TCommPipe(); 00084 00085 //------------------------------------------------------------------------ 00086 /*************************************************************************/ 00090 /*************************************************************************/ 00091 class TPipeContainer 00092 { 00093 public : 00094 /*********************************************************************/ 00098 /*********************************************************************/ 00099 inline TPipeContainer(IMessage& rMsg) 00100 { 00101 m_pPrevContainer = NULL; 00102 m_ptrData.assign(&rMsg); 00103 } 00104 //--------------------------------------------------------------------- 00105 00106 /*********************************************************************/ 00110 /*********************************************************************/ 00111 inline virtual ~TPipeContainer() 00112 { 00113 } 00114 //--------------------------------------------------------------------- 00115 00116 /*********************************************************************/ 00124 /*********************************************************************/ 00125 Retval getData(IMessage*& rpData) 00126 { 00127 Retval ulRetval = RET_REQUEST_FAILED; 00128 #ifndef _MSC_VER 00129 rpData = m_ptrData; 00130 #else 00131 rpData = m_ptrData.getPointer(); 00132 #endif 00133 if (rpData != NULL) 00134 { 00135 rpData->addRef(); 00136 ulRetval = RET_NOERROR; 00137 } 00138 return ulRetval; 00139 } 00140 //--------------------------------------------------------------------- 00141 00142 /*********************************************************************/ 00146 /*********************************************************************/ 00147 inline void setData(IMessage& rMsg) 00148 { 00149 m_ptrData.assign(&rMsg); 00150 } 00151 00152 /*********************************************************************/ 00156 /*********************************************************************/ 00157 inline TPipeContainer* getPrev() { return m_pPrevContainer; } 00158 //--------------------------------------------------------------------- 00159 00160 /*********************************************************************/ 00164 /*********************************************************************/ 00165 inline void setPrev(TPipeContainer* pPrev) { m_pPrevContainer = pPrev; } 00166 //--------------------------------------------------------------------- 00167 00168 private: 00170 TAutoPtr<IMessage> m_ptrData; 00172 TPipeContainer* m_pPrevContainer; 00173 }; 00174 00176 TPipeContainer* m_pHeadElement; 00178 TPipeContainer* m_pTailElement; 00180 TCriticalSection& m_rLock; 00182 TSemaphore* m_pSemaphore; 00183 00184 private: 00186 Uint m_uiPriority; 00188 bool m_bLockFlag; 00190 Int m_iSize; 00191 }; 00192 00193 //INLINE METHODS 00194 /*****************************************************************************/ 00197 /*****************************************************************************/ 00198 inline bool MQUALIFIER TCommPipe::hasRemoteAccess() const 00199 { 00200 return (m_ptrSkeleton != NULL); 00201 } 00202 00203 /*****************************************************************************/ 00206 /*****************************************************************************/ 00207 inline void MQUALIFIER TCommPipe::lock() 00208 { 00209 m_bLockFlag = true; 00210 } 00211 00212 //----------------------------------------------------------------------------- 00213 00214 /*****************************************************************************/ 00217 /*****************************************************************************/ 00218 inline void MQUALIFIER TCommPipe::unlock() 00219 { 00220 m_bLockFlag = false; 00221 } 00222 //----------------------------------------------------------------------------- 00223 00224 /*****************************************************************************/ 00227 /*****************************************************************************/ 00228 inline bool MQUALIFIER TCommPipe::isLocked() const 00229 { 00230 return m_bLockFlag; 00231 } 00232 00233 00234 /*****************************************************************************/ 00239 /*****************************************************************************/ 00240 inline bool MQUALIFIER TCommPipe::isEmpty() const 00241 { 00242 return (m_pHeadElement == NULL); 00243 } 00244 //----------------------------------------------------------------------------- 00245 00246 /*****************************************************************************/ 00249 /*****************************************************************************/ 00250 inline void MQUALIFIER TCommPipe::getPipeName(IString& rName) const 00251 { 00252 rName.assignStr(getObjName()); 00253 } 00254 00255 /*****************************************************************************/ 00258 /*****************************************************************************/ 00259 inline Uint MQUALIFIER TCommPipe::getPriority() const 00260 { 00261 return m_uiPriority; 00262 } 00263 //----------------------------------------------------------------------------- 00264 00265 /*****************************************************************************/ 00269 /*****************************************************************************/ 00270 inline Int MQUALIFIER TCommPipe::getCount() const 00271 { return m_iSize; } 00272 //----------------------------------------------------------------------------- 00273 00274 END_NAMESPACE_Zeus 00275 00276 //--------------------------------------------------------------------------- 00277 #endif