Back to index

lightning-sunbird  0.9+nobinonly
nsCategoryManager.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 
00039 #ifndef NSCATEGORYMANAGER_H
00040 #define NSCATEGORYMANAGER_H
00041 
00042 #include "prio.h"
00043 #include "prlock.h"
00044 #include "plarena.h"
00045 #include "nsClassHashtable.h"
00046 #include "nsICategoryManager.h"
00047 
00048 #define NS_CATEGORYMANAGER_CLASSNAME     "Category Manager"
00049 
00050 /* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
00051 #define NS_CATEGORYMANAGER_CID \
00052 { 0x16d222a6, 0x1dd2, 0x11b2, \
00053   {0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
00054 
00063 class CategoryLeaf : public nsDepCharHashKey
00064 {
00065 public:
00066   CategoryLeaf(const char* aKey)
00067     : nsDepCharHashKey(aKey),
00068       pValue(nsnull),
00069       nonpValue(nsnull) { }
00070   const char* pValue;
00071   const char* nonpValue;
00072 };
00073 
00074 
00080 class CategoryNode
00081 {
00082 public:
00083   NS_METHOD GetLeaf(const char* aEntryName,
00084                     char** _retval);
00085 
00086   NS_METHOD AddLeaf(const char* aEntryName,
00087                     const char* aValue,
00088                     PRBool aPersist,
00089                     PRBool aReplace,
00090                     char** _retval,
00091                     PLArenaPool* aArena);
00092 
00093   NS_METHOD DeleteLeaf(const char* aEntryName,
00094                        PRBool aDontPersist);
00095 
00096   void Clear() {
00097     PR_Lock(mLock);
00098     mTable.Clear();
00099     PR_Unlock(mLock);
00100   }
00101 
00102   PRUint32 Count() {
00103     PR_Lock(mLock);
00104     PRUint32 tCount = mTable.Count();
00105     PR_Unlock(mLock);
00106     return tCount;
00107   }
00108 
00109   NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
00110 
00111   PRBool WritePersistentEntries(PRFileDesc* fd, const char* aCategoryName);
00112 
00113   // CategoryNode is arena-allocated, with the strings
00114   static CategoryNode* Create(PLArenaPool* aArena);
00115   ~CategoryNode();
00116   void operator delete(void*) { }
00117 
00118 private:
00119   CategoryNode() { }
00120   void* operator new(size_t aSize, PLArenaPool* aArena);
00121 
00122   nsTHashtable<CategoryLeaf> mTable;
00123   PRLock* mLock;
00124 };
00125 
00126 
00132 class nsCategoryManager
00133   : public nsICategoryManager
00134 {
00135 public:
00136   NS_DECL_ISUPPORTS
00137   NS_DECL_NSICATEGORYMANAGER
00138 
00143   NS_METHOD WriteCategoryManagerToRegistry(PRFileDesc* fd);
00144 
00150   NS_METHOD SuppressNotifications(PRBool aSuppress);
00151 
00152   nsCategoryManager()
00153     : mSuppressNotifications(PR_FALSE) { }
00154 private:
00155   friend class nsCategoryManagerFactory;
00156   static nsCategoryManager* Create();
00157 
00158   ~nsCategoryManager();
00159 
00160   CategoryNode* get_category(const char* aName);
00161   void NotifyObservers(const char* aTopic,
00162                        const char* aCategoryName,
00163                        const char* aEntryName);
00164 
00165   PLArenaPool mArena;
00166   nsClassHashtable<nsDepCharHashKey, CategoryNode> mTable;
00167   PRLock* mLock;
00168   PRBool mSuppressNotifications;
00169 };
00170 
00171 #endif