xref: /trunk/main/registry/source/regimpl.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _REGIMPL_HXX_
29 #define _REGIMPL_HXX_
30 
31 #include <set>
32 #include <hash_map>
33 
34 #include    <registry/registry.h>
35 #include    <rtl/ustring.hxx>
36 #include    <osl/mutex.hxx>
37 #include    <store/store.hxx>
38 
39 #define REG_PAGESIZE 512
40 
41 #define REG_MODE_CREATE     store_AccessCreate
42 #define REG_MODE_OPEN       store_AccessReadWrite
43 #define REG_MODE_OPENREAD   store_AccessReadOnly
44 
45 #define KEY_MODE_CREATE     store_AccessCreate
46 #define KEY_MODE_OPEN       store_AccessReadWrite
47 #define KEY_MODE_OPENREAD   store_AccessReadOnly
48 
49 
50 #define VALUE_MODE_CREATE   store_AccessCreate
51 #define VALUE_MODE_OPEN     store_AccessReadWrite
52 #define VALUE_MODE_OPENREAD store_AccessReadOnly
53 
54 // 5 Bytes = 1 (Byte fuer den Typ) + 4 (Bytes fuer die Groesse der Daten)
55 #define VALUE_HEADERSIZE    5
56 #define VALUE_TYPEOFFSET    1
57 #define VALUE_HEADEROFFSET  5
58 
59 #define REG_CREATE      0x0004  // allow write accesses
60 
61 #define REG_GUARD(mutex) \
62     osl::Guard< osl::Mutex > aGuard( mutex );
63 
64 // @@@ using namespace rtl;
65 // @@@ using namespace osl;
66 
67 class ORegKey;
68 class RegistryTypeReader;
69 
70 class ORegistry
71 {
72 public:
73     ORegistry();
74 
75     sal_uInt32  acquire()
76         { return ++m_refCount; }
77 
78     sal_uInt32  release()
79         { return --m_refCount; }
80 
81     RegError    initRegistry(const rtl::OUString& name,
82                              RegAccessMode accessMode);
83 
84     RegError    closeRegistry();
85 
86     RegError    destroyRegistry(const rtl::OUString& name);
87 
88     RegError    acquireKey(RegKeyHandle hKey);
89     RegError    releaseKey(RegKeyHandle hKey);
90 
91     RegError    createKey(RegKeyHandle hKey,
92                           const rtl::OUString& keyName,
93                           RegKeyHandle* phNewKey);
94 
95     RegError    openKey(RegKeyHandle hKey,
96                         const rtl::OUString& keyName,
97                         RegKeyHandle* phOpenKey);
98 
99     RegError    closeKey(RegKeyHandle hKey);
100 
101     RegError    deleteKey(RegKeyHandle hKey, const rtl::OUString& keyName);
102 
103     RegError    loadKey(RegKeyHandle hKey,
104                         const rtl::OUString& regFileName,
105                         sal_Bool bWarings=sal_False,
106                         sal_Bool bReport=sal_False);
107 
108     RegError    saveKey(RegKeyHandle hKey,
109                         const rtl::OUString& regFileName,
110                         sal_Bool bWarings=sal_False,
111                         sal_Bool bReport=sal_False);
112 
113     RegError    dumpRegistry(RegKeyHandle hKey) const;
114 
115     ~ORegistry();
116 
117     sal_Bool            isReadOnly() const
118         { return m_readOnly; }
119 
120     sal_Bool            isOpen() const
121         { return m_isOpen; }
122 
123     ORegKey*    getRootKey();
124 
125     const store::OStoreFile& getStoreFile()
126         { return m_file; }
127 
128     const rtl::OUString&    getName() const
129         { return m_name; }
130 
131     friend class ORegKey;
132 
133 private:
134     RegError    eraseKey(ORegKey* pKey, const rtl::OUString& keyName);
135 
136     RegError    deleteSubkeysAndValues(ORegKey* pKey);
137 
138     RegError    loadAndSaveValue(ORegKey* pTargetKey,
139                                  ORegKey* pSourceKey,
140                                  const rtl::OUString& valueName,
141                                  sal_uInt32 nCut,
142                                  sal_Bool bWarnings=sal_False,
143                                  sal_Bool bReport=sal_False);
144 
145     RegError    checkBlop(store::OStoreStream& rValue,
146                           const rtl::OUString& sTargetPath,
147                           sal_uInt32 srcValueSize,
148                           sal_uInt8* pSrcBuffer,
149                           sal_Bool bReport=sal_False);
150 
151     RegError    mergeModuleValue(store::OStoreStream& rTargetValue,
152                                  RegistryTypeReader& reader,
153                                  RegistryTypeReader& reader2);
154 
155     RegError    loadAndSaveKeys(ORegKey* pTargetKey,
156                                 ORegKey* pSourceKey,
157                                 const rtl::OUString& keyName,
158                                 sal_uInt32 nCut,
159                                 sal_Bool bWarnings=sal_False,
160                                 sal_Bool bReport=sal_False);
161 
162     RegError    dumpValue(const rtl::OUString& sPath,
163                           const rtl::OUString& sName,
164                           sal_Int16 nSpace) const;
165 
166     RegError    dumpKey(const rtl::OUString& sPath,
167                         const rtl::OUString& sName,
168                         sal_Int16 nSpace) const;
169 
170     typedef std::hash_map< rtl::OUString, ORegKey*, rtl::OUStringHash > KeyMap;
171 
172     sal_uInt32      m_refCount;
173     osl::Mutex          m_mutex;
174     sal_Bool        m_readOnly;
175     sal_Bool        m_isOpen;
176     rtl::OUString       m_name;
177     store::OStoreFile   m_file;
178     KeyMap          m_openKeyTable;
179 
180     const rtl::OUString ROOT;
181 };
182 
183 #endif
184 
185