sipxportlib  Version 3.3
OsNameDb.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 _OsNameDb_h_
13 #define _OsNameDb_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include "os/OsBSem.h"
19 #include "os/OsRWMutex.h"
20 #include "os/OsStatus.h"
21 #include "utl/UtlHashMap.h"
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 class UtlString;
32 
33 //:Name service maintaining mappings between string names and integer values
34 // The OsNameDb is a singleton object that maintains a dictionary of
35 // mappings between string names and the associated integer values.
36 // Duplicate names are not allowed.
37 
38 class OsNameDb
39 {
40 /* //////////////////////////// PUBLIC //////////////////////////////////// */
41 public:
42 
43 /* ============================ CREATORS ================================== */
44 
45  static OsNameDb* getNameDb();
46  //:Return a pointer to the singleton object, creating it if necessary
47 
48 /* ============================ MANIPULATORS ============================== */
49 
50  OsStatus insert(const UtlString& rKey,
51  const intptr_t value);
52  //:Add the key-value pair to the name database
53  // Return OS_SUCCESS if successful, OS_NAME_IN_USE if the key is
54  // already in the database.
55 
56  OsStatus remove(const UtlString& rKey,
57  intptr_t* pValue = NULL);
58  //:Remove the indicated key-value pair from the name database
59  // If pValue is non-NULL, the value for the key-value pair is returned
60  // via pValue.<br>
61  // Return OS_SUCCESS if the lookup is successful, return
62  // OS_NOT_FOUND if there is no match for the specified key.
63 
64 /* ============================ ACCESSORS ================================= */
65 
66  OsStatus lookup(const UtlString& rKey,
67  intptr_t* pValue = NULL);
68  //:Retrieve the value associated with the specified key
69  // If pValue is non-NULL, the value is returned via pValue. <br>
70  // Return OS_SUCCESS if the lookup is successful, return
71  // OS_NOT_FOUND if there is no match for the specified key.
72 
73  int numEntries();
74  //: Return the number of key-value pairs in the name database
75 
76 /* ============================ INQUIRY =================================== */
77 
79  //:Return TRUE if the name database is empty
80 
81 /* //////////////////////////// PROTECTED ///////////////////////////////// */
82 protected:
83  friend class OsNameDBInit;
84 
85  OsNameDb();
86  //:Default constructor (only callable from within this class)
87  // This class implements the singleton pattern and therefore the
88  // class constructor will not be called from outside the class.
89  // We identify this as a protected (rather than a private) method so
90  // that gcc doesn't complain that the class only defines a private
91  // constructor and has no friends.
92 
93  virtual
94  ~OsNameDb();
95  //:Destructor
96 
97 /* //////////////////////////// PRIVATE /////////////////////////////////// */
98 private:
99  static OsNameDb* spInstance; // pointer to the single instance of the
100  // OsNameDb class
101  UtlHashMap mDict; // hash table used to store the name/value
102  // mappings
103  OsRWMutex mRWLock; // R/W mutex used to coordinate access to
104  // the name database by multiple tasks
105  OsNameDb(const OsNameDb& rOsNameDb);
106  //:Copy constructor (not supported for this class)
107 
108  OsNameDb& operator=(const OsNameDb& rhs);
109  //:Assignment operator (not supported for this class)
110 
111 };
112 
113 /* ============================ INLINE METHODS ============================ */
114 
115 #endif // _OsNameDb_h_
116 
Definition: OsNameDb.h:38
virtual ~OsNameDb()
Definition: OsNameDb.cpp:50
OsStatus
Definition: OsStatus.h:27
#define NULL
Definition: UtlDefs.h:29
static OsNameDb * getNameDb()
Definition: OsNameDb.cpp:42
OsNameDb()
Definition: OsNameDb.cpp:173
Definition: UtlString.h:48
OsStatus lookup(const UtlString &rKey, intptr_t *pValue=NULL)
Definition: OsNameDb.cpp:130
UtlBoolean isEmpty()
Definition: OsNameDb.cpp:163
OsStatus insert(const UtlString &rKey, const intptr_t value)
Definition: OsNameDb.cpp:60
Definition: UtlHashMap.h:46
int UtlBoolean
Definition: UtlDefs.h:41
OsNameDB initializer class. Solves the problem with ordering of constructors & destructors.
Definition: OsNameDbInit.h:44
_W64 signed int intptr_t
Definition: stdint.h:118
int numEntries()
Definition: OsNameDb.cpp:153