LCOV - code coverage report
Current view: directory - xpcom/components - nsCategoryManager.h (source / functions) Found Hit Coverage
Test: app.info Lines: 15 7 46.7 %
Date: 2012-06-02 Functions: 6 4 66.7 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      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.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      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.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : 
      39                 : #ifndef NSCATEGORYMANAGER_H
      40                 : #define NSCATEGORYMANAGER_H
      41                 : 
      42                 : #include "prio.h"
      43                 : #include "plarena.h"
      44                 : #include "nsClassHashtable.h"
      45                 : #include "nsICategoryManager.h"
      46                 : #include "mozilla/Mutex.h"
      47                 : 
      48                 : #define NS_CATEGORYMANAGER_CLASSNAME     "Category Manager"
      49                 : 
      50                 : /* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
      51                 : #define NS_CATEGORYMANAGER_CID \
      52                 : { 0x16d222a6, 0x1dd2, 0x11b2, \
      53                 :   {0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
      54                 : 
      55                 : /**
      56                 :  * a "leaf-node", managed by the nsCategoryNode hashtable.
      57                 :  *
      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==false. The strings are permanently arena-
      61                 :  * allocated, and will never go away.
      62                 :  */
      63                 : class CategoryLeaf : public nsDepCharHashKey
      64          418803 : {
      65                 : public:
      66          418803 :   CategoryLeaf(const char* aKey)
      67                 :     : nsDepCharHashKey(aKey),
      68          418803 :       value(NULL) { }
      69                 :   const char* value;
      70                 : };
      71                 : 
      72                 : 
      73                 : /**
      74                 :  * CategoryNode keeps a hashtable of its entries.
      75                 :  * the CategoryNode itself is permanently allocated in
      76                 :  * the arena.
      77                 :  */
      78                 : class CategoryNode
      79                 : {
      80                 : public:
      81                 :   NS_METHOD GetLeaf(const char* aEntryName,
      82                 :                     char** _retval);
      83                 : 
      84                 :   NS_METHOD AddLeaf(const char* aEntryName,
      85                 :                     const char* aValue,
      86                 :                     bool aReplace,
      87                 :                     char** _retval,
      88                 :                     PLArenaPool* aArena);
      89                 : 
      90                 :   void DeleteLeaf(const char* aEntryName);
      91                 : 
      92               0 :   void Clear() {
      93               0 :     mozilla::MutexAutoLock lock(mLock);
      94               0 :     mTable.Clear();
      95               0 :   }
      96                 : 
      97               0 :   PRUint32 Count() {
      98               0 :     mozilla::MutexAutoLock lock(mLock);
      99               0 :     PRUint32 tCount = mTable.Count();
     100               0 :     return tCount;
     101                 :   }
     102                 : 
     103                 :   NS_METHOD Enumerate(nsISimpleEnumerator** _retval);
     104                 : 
     105                 :   // CategoryNode is arena-allocated, with the strings
     106                 :   static CategoryNode* Create(PLArenaPool* aArena);
     107                 :   ~CategoryNode();
     108           48253 :   void operator delete(void*) { }
     109                 : 
     110                 : private:
     111           48253 :   CategoryNode()
     112           48253 :     : mLock("CategoryLeaf")
     113           48253 :   { }
     114                 : 
     115                 :   void* operator new(size_t aSize, PLArenaPool* aArena);
     116                 : 
     117                 :   nsTHashtable<CategoryLeaf> mTable;
     118                 :   mozilla::Mutex mLock;
     119                 : };
     120                 : 
     121                 : 
     122                 : /**
     123                 :  * The main implementation of nsICategoryManager.
     124                 :  *
     125                 :  * This implementation is thread-safe.
     126                 :  */
     127                 : class nsCategoryManager
     128                 :   : public nsICategoryManager
     129                 : {
     130                 : public:
     131                 :   NS_DECL_ISUPPORTS
     132                 :   NS_DECL_NSICATEGORYMANAGER
     133                 : 
     134                 :   /**
     135                 :    * Suppress or unsuppress notifications of category changes to the
     136                 :    * observer service. This is to be used by nsComponentManagerImpl
     137                 :    * on startup while reading the stored category list.
     138                 :    */
     139                 :   NS_METHOD SuppressNotifications(bool aSuppress);
     140                 : 
     141                 :   void AddCategoryEntry(const char* aCategory,
     142                 :                         const char* aKey,
     143                 :                         const char* aValue,
     144                 :                         bool aReplace = true,
     145                 :                         char** aOldValue = NULL);
     146                 : 
     147                 :   static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
     148                 : 
     149                 :   static nsCategoryManager* GetSingleton();
     150                 :   static void Destroy();
     151                 : 
     152                 : private:
     153                 :   static nsCategoryManager* gCategoryManager;
     154                 : 
     155                 :   nsCategoryManager();
     156                 :   ~nsCategoryManager();
     157                 : 
     158                 :   CategoryNode* get_category(const char* aName);
     159                 :   void NotifyObservers(const char* aTopic,
     160                 :                        const char* aCategoryName, // must be a static string
     161                 :                        const char* aEntryName);
     162                 : 
     163                 :   PLArenaPool mArena;
     164                 :   nsClassHashtable<nsDepCharHashKey, CategoryNode> mTable;
     165                 :   mozilla::Mutex mLock;
     166                 :   bool mSuppressNotifications;
     167                 : };
     168                 : 
     169                 : #endif

Generated by: LCOV version 1.7