sipxportlib  Version 3.3
UtlRscStore.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 
12 #ifndef _UtlRscStore_h_
13 #define _UtlRscStore_h_
14 
15 #include "utl/UtlRscTrace.h"
16 
17 #ifdef RSC_TEST
18 
19 
20 // SYSTEM INCLUDES
21 #include "os/OsDefs.h"
22 #include "os/OsBSem.h"
23 #include "os/OsRWMutex.h"
24 #include "os/OsStatus.h"
25 
26 // APPLICATION INCLUDES
27 // DEFINES
28 // MACROS
29 // EXTERNAL FUNCTIONS
30 // EXTERNAL VARIABLES
31 // CONSTANTS
32 // STRUCTS
33 // TYPEDEFS
34 // FORWARD DECLARATIONS
35 class UtlRscTrace;
36 
37 //:Database of active Rscs.
38 // The UtlRscStore maintains a database of active Rscs (i.e., those Rscs
39 // that have been started by the low level OsSysRsc class). Since the
40 // OsRscTask is the only task that should be accessing the Rsc database
41 // there is no need to serialize access (and no locking).<br>
42 // <br>
43 // Each entry in the database is a key/value pair where the key corresponds
44 // to a Rsc ID and the value is the pointer to the corresponding OsRsc
45 // object. Duplicate keys are not allowed.
46 class UtlRscStore
47 {
48 friend UtlRscTrace;
49 
50 /* //////////////////////////// PUBLIC //////////////////////////////////// */
51 public:
52 
53  enum StoreInitSize { RSC_STORE_INIT_SIZE = 1000000 };
54 
55 /* ============================ CREATORS ================================== */
56 
57  UtlRscStore(int initialStoreSize = RSC_STORE_INIT_SIZE);
58  //:Default constructor
59 
60  virtual
61  ~UtlRscStore();
62  //:Destructor
63 
64 /* ============================ MANIPULATORS ============================== */
65 
66  OsStatus insert(int RscId, char* pRsc);
67  //:Insert the indicated Rsc into the database of active Rscs.
68  // Return OS_SUCCESS if successful, OS_NAME_IN_USE if the key is
69  // already in the database.
70 
71  OsStatus remove(int RscId);
72  //:Remove the indicated Rsc from the database of active Rscs.
73  // Return OS_SUCCESS if the indicated RscId is found, return
74  // OS_NOT_FOUND if there is no match for the specified key.
75 
76  void cleanUp();
77 
78 /* ============================ ACCESSORS ================================= */
79 
80  int getActiveRscs(char* activeRscs[], int size);
81  //:Get an array of pointers to the Rscs that are currently active.
82  // The caller provides an array that can hold up to <i>size</i> OsRsc
83  // pointers. This method will fill in the <i>activeRscs</i> array with
84  // up to <i>size</i> pointers. The method returns the number of pointers
85  // in the array that were actually filled in.
86 
87  void getStoreStats(unsigned& nInserts, unsigned& nRemoves) const;
88  //:Get the number of insertions and removals for the Rsc database.
89 
90  int numEntries(void) const;
91  //:Return the number of key-value pairs in the name database.
92 
93 /* ============================ INQUIRY =================================== */
94 
95  UtlBoolean isEmpty(void) const;
96  //:Return TRUE if the Rsc database is empty.
97 
98 /* //////////////////////////// PROTECTED ///////////////////////////////// */
99 protected:
100 
101 /* //////////////////////////// PRIVATE /////////////////////////////////// */
102 private:
103  UtlHashMap mDict; // hash table used to store the key/value
104  // pairs
105  unsigned long mNumInserts; // number of insertions into the database
106  unsigned long mNumRemoves; // number of removals from the database
107 
108  OsRWMutex mDictRWLock;
109  UtlRscStore(const UtlRscStore& rUtlRscStore);
110  //:Copy constructor (not implemented for this class)
111 
112  UtlRscStore& operator=(const UtlRscStore& rhs);
113  //:Assignment operator (not implemented for this class)
114 
115 #ifdef TEST
116  static bool sIsTested;
117  //:Set to true after the tests for this class have been executed once
118 
119  void test();
120  //:Verify assertions for this class
121 
122  // Test helper functions
123  void testCreators();
124  void testManipulators();
125  void testAccessors();
126  void testInquiry();
127 
128 #endif TEST
129 };
130 
131 /* ============================ INLINE METHODS ============================ */
132 #endif // RSC_TEST
133 
134 #endif // _UtlRscStore_h_
135 
OsStatus
Definition: OsStatus.h:27
Definition: UtlHashMap.h:46
int UtlBoolean
Definition: UtlDefs.h:41