sipxmedialib  Version 3.3
BaseClass.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2006 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 // Border Guard
14 #ifndef _BaseClass_h /* [ */
15 #define _BaseClass_h
16 
17 #include "rtcp/RtcpConfig.h"
18 #include "os/OsSysLog.h"
19 
20 // Includes
21 #ifdef WIN32 /* [ */
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #include <objbase.h>
25 #include <stdio.h>
26 
27 #ifdef PINGTEL_PRINTF
28 #include "os/OsDefs.h"
29 #else
30 #define osPrintf printf
31 #endif
32 
33 // Required for VC7 compatibility
34 #if _MSC_VER >= 1300
35 #ifndef interface
36  #define interface __interface
37 #endif
38 #endif
39 
40 #endif /* WIN32 ] */
41 
42 #ifdef _VXWORKS /* [ */
43 #include <vxworks.h>
44 #include <stdio.h>
45 #include <inetLib.h>
46 #include <hostLib.h>
47 #include <string.h>
48 #include "os/OsDefs.h"
49 
50 // Windows Compatability
51 #define interface struct
52 
53 // Make sure that WAIT FOREVER is defined
54 #ifndef WAIT_FOREVER
55 #define WAIT_FOREVER VX_WAIT_FOREVER
56 #endif /* WAIT_FOREVER */
57 
58 #endif /* _VXWORKS ] */
59 
60 
61 // Static Declarations
62 // static unsigned long sulTotalReferenceCount = 0;
63 extern bool bPingtelDebug;
64 
65 
66 #ifndef WIN32 /* [ */
67 
68 #ifdef __pingtel_on_posix__ /* [ */
69 #include <os/OsBSem.h>
70 typedef OsBSem * CRITICAL_SECTION;
71 #define interface struct
72 #endif /* __pingtel_on_posix__ ] */
73 
74 #ifdef _VXWORKS /* [ */
75 #include <semLib.h>
76 typedef SEM_ID CRITICAL_SECTION;
77 #endif /* _VXWORKS ] */
78 
79 
80 /*|><|************************************************************************
81 *
82 * Functions: CriticalSection support
83 *
84 *
85 * Inputs: CRITICAL_SECTION *csSynchronized
86 *
87 * Outputs: None
88 *
89 * Returns: None
90 *
91 * Description: Compatability functions that map to
92 * complementary calls under Win32.
93 *
94 *
95 *************************************************************************|<>|*/
96 void InitializeCriticalSection(CRITICAL_SECTION *csSynchronized);
97 void EnterCriticalSection(CRITICAL_SECTION *csSynchronized);
98 void LeaveCriticalSection(CRITICAL_SECTION *csSynchronized);
99 void DeleteCriticalSection(CRITICAL_SECTION *csSynchronized);
100 #endif /* NOT _WIN32 ] */
101 
102 
119 {
120 
121 // Public Methods
122 public:
123 
142  CBaseClass CBASECLASS_PROTO_ARGS((const char* pDerivedType = "Unknown", int callLineNum = 0));
143 
144 
145 
164  virtual ~CBaseClass(void);
165 
184  virtual bool Initialize(void);
185 
204  bool IsInitialized(void);
205 
206  void setAutomatic(bool);
207 
225  virtual unsigned long AddRef ADD_RELEASE_PROTO_ARGS((int callLineNum));
226 
244  virtual unsigned long Release ADD_RELEASE_PROTO_ARGS((int callLineNum));
245 
246 static bool AllowDeletes(void);
247 static void s_SetAllowDeletes(int v);
248 
249 // protected:
261 
263 
275 
276 #ifdef RTCP_DEBUG_REFCOUNTS /* [ */
277  const char* m_DerivedType;
278  int m_Line;
279 #endif /* RTCP_DEBUG_REFCOUNTS ] */
280 
281  static bool s_bAllowDeletes;
282 
283 };
284 
303 inline bool CBaseClass::Initialize(void)
304 {
305 
306 // Set initialization flag to TRUE
308 
309  return(TRUE);
310 
311 }
312 
313 
332 inline bool CBaseClass::IsInitialized(void)
333 {
334 
335  return(m_bInitialized);
336 
337 }
338 
339 inline void CBaseClass::setAutomatic(bool yesNo)
340 {
341  m_bAutomatic = yesNo;
342 }
343 
344 inline bool CBaseClass::AllowDeletes(void)
345 {
346  return(s_bAllowDeletes);
347 }
348 
349 
368 #define DECLARE_IBASE_M \
369  unsigned long AddRef ADD_RELEASE_PROTO_ARGS((int callLineNum)) \
370  { \
371  if (callLineNum > 0) OsSysLog::add(FAC_MP, PRI_DEBUG, __FILE__ " %p->AddRef(%d), count: %d", this, callLineNum, m_ulReferences); \
372  return CBaseClass::AddRef(ADD_RELEASE_CALL_ARGS(callLineNum)); \
373  } \
374  unsigned long Release ADD_RELEASE_PROTO_ARGS((int callLineNum)) \
375  { \
376  int ulRefCount; \
377  if((ulRefCount = CBaseClass::Release(ADD_RELEASE_CALL_ARGS(callLineNum))) == 0) \
378  { \
379  if (CBaseClass::AllowDeletes()) { \
380  delete this; \
381  } else { \
382  if (callLineNum > 0) OsSysLog::add(FAC_MP, PRI_DEBUG, __FILE__ " %p->Release(%d) [would delete this]", this, callLineNum); \
383  } \
384  } \
385  if (callLineNum > 0) OsSysLog::add(FAC_MP, PRI_DEBUG, __FILE__ " %p->Release(%d), count: %d", this, callLineNum, ulRefCount); \
386  return(ulRefCount); \
387  }
388 #endif /* ] */
void * SEM_ID
Definition: MpTypes.h:41
void setAutomatic(bool)
Definition: BaseClass.h:339
static bool s_bAllowDeletes
Definition: BaseClass.h:281
int m_ulReferences
Definition: BaseClass.h:274
virtual unsigned long AddRef ADD_RELEASE_PROTO_ARGS((int callLineNum))
#define callLineNum
Definition: RtcpConfig.h:78
virtual ~CBaseClass(void)
Definition: BaseClass.cpp:85
void EnterCriticalSection(CRITICAL_SECTION *csSynchronized)
void DeleteCriticalSection(CRITICAL_SECTION *csSynchronized)
bool bPingtelDebug
void LeaveCriticalSection(CRITICAL_SECTION *csSynchronized)
CBaseClass CBASECLASS_PROTO_ARGS((const char *pDerivedType="Unknown", int callLineNum=0))
static void s_SetAllowDeletes(int v)
Definition: BaseClass.cpp:27
bool m_bInitialized
Definition: BaseClass.h:260
bool m_bAutomatic
Definition: BaseClass.h:262
bool IsInitialized(void)
Definition: BaseClass.h:332
Definition: BaseClass.h:118
void InitializeCriticalSection(CRITICAL_SECTION *csSynchronized)
static bool AllowDeletes(void)
Definition: BaseClass.h:344
virtual bool Initialize(void)
Definition: BaseClass.h:303
#define TRUE
Definition: PlgDefsV1.h:41