1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 #ifndef NSCATEGORYMANAGER_H
40 #define NSCATEGORYMANAGER_H
45 #include "nsClassHashtable.h"
46 #include "nsICategoryManager.h"
48 #define NS_CATEGORYMANAGER_CLASSNAME "Category Manager"
50 /* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
51 #define NS_CATEGORYMANAGER_CID \
52 { 0x16d222a6, 0x1dd2, 0x11b2, \
53 {0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
56 * a "leaf-node", managed by the nsCategoryNode hashtable.
58 * we need to keep a "persistent value" (which will be written to the registry)
59 * and a non-persistent value (for the current runtime): these are usually
60 * the same, except when aPersist==PR_FALSE. The strings are permanently arena-
61 * allocated, and will never go away.
63 class CategoryLeaf
: public nsDepCharHashKey
66 CategoryLeaf(const char* aKey
)
67 : nsDepCharHashKey(aKey
),
71 const char* nonpValue
;
76 * CategoryNode keeps a hashtable of its entries.
77 * the CategoryNode itself is permanently allocated in
83 NS_METHOD
GetLeaf(const char* aEntryName
,
86 NS_METHOD
AddLeaf(const char* aEntryName
,
93 NS_METHOD
DeleteLeaf(const char* aEntryName
,
104 PRUint32 tCount
= mTable
.Count();
109 NS_METHOD
Enumerate(nsISimpleEnumerator
** _retval
);
111 PRBool
WritePersistentEntries(PRFileDesc
* fd
, const char* aCategoryName
);
113 // CategoryNode is arena-allocated, with the strings
114 static CategoryNode
* Create(PLArenaPool
* aArena
);
116 void operator delete(void*) { }
120 void* operator new(size_t aSize
, PLArenaPool
* aArena
);
122 nsTHashtable
<CategoryLeaf
> mTable
;
128 * The main implementation of nsICategoryManager.
130 * This implementation is thread-safe.
132 class nsCategoryManager
133 : public nsICategoryManager
137 NS_DECL_NSICATEGORYMANAGER
140 * Write the categories to the XPCOM persistent registry.
141 * This is to be used by nsComponentManagerImpl (and NO ONE ELSE).
143 NS_METHOD
WriteCategoryManagerToRegistry(PRFileDesc
* fd
);
146 * Suppress or unsuppress notifications of category changes to the
147 * observer service. This is to be used by nsComponentManagerImpl
148 * on startup while reading the stored category list.
150 NS_METHOD
SuppressNotifications(PRBool aSuppress
);
153 : mSuppressNotifications(PR_FALSE
) { }
155 friend class nsCategoryManagerFactory
;
156 static nsCategoryManager
* Create();
158 ~nsCategoryManager();
160 CategoryNode
* get_category(const char* aName
);
161 void NotifyObservers(const char* aTopic
,
162 const char* aCategoryName
,
163 const char* aEntryName
);
166 nsClassHashtable
<nsDepCharHashKey
, CategoryNode
> mTable
;
168 PRBool mSuppressNotifications
;