xref: /trunk/main/registry/source/regimpl.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*5a5f4a75SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5a5f4a75SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5a5f4a75SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5a5f4a75SAndrew Rist  * distributed with this work for additional information
6*5a5f4a75SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5a5f4a75SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5a5f4a75SAndrew Rist  * "License"); you may not use this file except in compliance
9*5a5f4a75SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5a5f4a75SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5a5f4a75SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5a5f4a75SAndrew Rist  * software distributed under the License is distributed on an
15*5a5f4a75SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5a5f4a75SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5a5f4a75SAndrew Rist  * specific language governing permissions and limitations
18*5a5f4a75SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5a5f4a75SAndrew Rist  *************************************************************/
21*5a5f4a75SAndrew Rist 
22*5a5f4a75SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _REGIMPL_HXX_
25cdf0e10cSrcweir #define _REGIMPL_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <set>
28cdf0e10cSrcweir #include <hash_map>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include    <registry/registry.h>
31cdf0e10cSrcweir #include    <rtl/ustring.hxx>
32cdf0e10cSrcweir #include    <osl/mutex.hxx>
33cdf0e10cSrcweir #include    <store/store.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #define REG_PAGESIZE 512
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define REG_MODE_CREATE     store_AccessCreate
38cdf0e10cSrcweir #define REG_MODE_OPEN       store_AccessReadWrite
39cdf0e10cSrcweir #define REG_MODE_OPENREAD   store_AccessReadOnly
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #define KEY_MODE_CREATE     store_AccessCreate
42cdf0e10cSrcweir #define KEY_MODE_OPEN       store_AccessReadWrite
43cdf0e10cSrcweir #define KEY_MODE_OPENREAD   store_AccessReadOnly
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #define VALUE_MODE_CREATE   store_AccessCreate
47cdf0e10cSrcweir #define VALUE_MODE_OPEN     store_AccessReadWrite
48cdf0e10cSrcweir #define VALUE_MODE_OPENREAD store_AccessReadOnly
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // 5 Bytes = 1 (Byte fuer den Typ) + 4 (Bytes fuer die Groesse der Daten)
51cdf0e10cSrcweir #define VALUE_HEADERSIZE    5
52cdf0e10cSrcweir #define VALUE_TYPEOFFSET    1
53cdf0e10cSrcweir #define VALUE_HEADEROFFSET  5
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #define REG_CREATE      0x0004  // allow write accesses
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #define REG_GUARD(mutex) \
58cdf0e10cSrcweir     osl::Guard< osl::Mutex > aGuard( mutex );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // @@@ using namespace rtl;
61cdf0e10cSrcweir // @@@ using namespace osl;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir class ORegKey;
64cdf0e10cSrcweir class RegistryTypeReader;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir class ORegistry
67cdf0e10cSrcweir {
68cdf0e10cSrcweir public:
69cdf0e10cSrcweir     ORegistry();
70cdf0e10cSrcweir 
acquire()71cdf0e10cSrcweir     sal_uInt32  acquire()
72cdf0e10cSrcweir         { return ++m_refCount; }
73cdf0e10cSrcweir 
release()74cdf0e10cSrcweir     sal_uInt32  release()
75cdf0e10cSrcweir         { return --m_refCount; }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     RegError    initRegistry(const rtl::OUString& name,
78cdf0e10cSrcweir                              RegAccessMode accessMode);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     RegError    closeRegistry();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     RegError    destroyRegistry(const rtl::OUString& name);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     RegError    acquireKey(RegKeyHandle hKey);
85cdf0e10cSrcweir     RegError    releaseKey(RegKeyHandle hKey);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     RegError    createKey(RegKeyHandle hKey,
88cdf0e10cSrcweir                           const rtl::OUString& keyName,
89cdf0e10cSrcweir                           RegKeyHandle* phNewKey);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     RegError    openKey(RegKeyHandle hKey,
92cdf0e10cSrcweir                         const rtl::OUString& keyName,
93cdf0e10cSrcweir                         RegKeyHandle* phOpenKey);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     RegError    closeKey(RegKeyHandle hKey);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     RegError    deleteKey(RegKeyHandle hKey, const rtl::OUString& keyName);
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     RegError    loadKey(RegKeyHandle hKey,
100cdf0e10cSrcweir                         const rtl::OUString& regFileName,
101cdf0e10cSrcweir                         sal_Bool bWarings=sal_False,
102cdf0e10cSrcweir                         sal_Bool bReport=sal_False);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     RegError    saveKey(RegKeyHandle hKey,
105cdf0e10cSrcweir                         const rtl::OUString& regFileName,
106cdf0e10cSrcweir                         sal_Bool bWarings=sal_False,
107cdf0e10cSrcweir                         sal_Bool bReport=sal_False);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     RegError    dumpRegistry(RegKeyHandle hKey) const;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     ~ORegistry();
112cdf0e10cSrcweir 
isReadOnly() const113cdf0e10cSrcweir     sal_Bool            isReadOnly() const
114cdf0e10cSrcweir         { return m_readOnly; }
115cdf0e10cSrcweir 
isOpen() const116cdf0e10cSrcweir     sal_Bool            isOpen() const
117cdf0e10cSrcweir         { return m_isOpen; }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     ORegKey*    getRootKey();
120cdf0e10cSrcweir 
getStoreFile()121cdf0e10cSrcweir     const store::OStoreFile& getStoreFile()
122cdf0e10cSrcweir         { return m_file; }
123cdf0e10cSrcweir 
getName() const124cdf0e10cSrcweir     const rtl::OUString&    getName() const
125cdf0e10cSrcweir         { return m_name; }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     friend class ORegKey;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir private:
130cdf0e10cSrcweir     RegError    eraseKey(ORegKey* pKey, const rtl::OUString& keyName);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     RegError    deleteSubkeysAndValues(ORegKey* pKey);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     RegError    loadAndSaveValue(ORegKey* pTargetKey,
135cdf0e10cSrcweir                                  ORegKey* pSourceKey,
136cdf0e10cSrcweir                                  const rtl::OUString& valueName,
137cdf0e10cSrcweir                                  sal_uInt32 nCut,
138cdf0e10cSrcweir                                  sal_Bool bWarnings=sal_False,
139cdf0e10cSrcweir                                  sal_Bool bReport=sal_False);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     RegError    checkBlop(store::OStoreStream& rValue,
142cdf0e10cSrcweir                           const rtl::OUString& sTargetPath,
143cdf0e10cSrcweir                           sal_uInt32 srcValueSize,
144cdf0e10cSrcweir                           sal_uInt8* pSrcBuffer,
145cdf0e10cSrcweir                           sal_Bool bReport=sal_False);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     RegError    mergeModuleValue(store::OStoreStream& rTargetValue,
148cdf0e10cSrcweir                                  RegistryTypeReader& reader,
149cdf0e10cSrcweir                                  RegistryTypeReader& reader2);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     RegError    loadAndSaveKeys(ORegKey* pTargetKey,
152cdf0e10cSrcweir                                 ORegKey* pSourceKey,
153cdf0e10cSrcweir                                 const rtl::OUString& keyName,
154cdf0e10cSrcweir                                 sal_uInt32 nCut,
155cdf0e10cSrcweir                                 sal_Bool bWarnings=sal_False,
156cdf0e10cSrcweir                                 sal_Bool bReport=sal_False);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     RegError    dumpValue(const rtl::OUString& sPath,
159cdf0e10cSrcweir                           const rtl::OUString& sName,
160cdf0e10cSrcweir                           sal_Int16 nSpace) const;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     RegError    dumpKey(const rtl::OUString& sPath,
163cdf0e10cSrcweir                         const rtl::OUString& sName,
164cdf0e10cSrcweir                         sal_Int16 nSpace) const;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     typedef std::hash_map< rtl::OUString, ORegKey*, rtl::OUStringHash > KeyMap;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     sal_uInt32      m_refCount;
169cdf0e10cSrcweir     osl::Mutex          m_mutex;
170cdf0e10cSrcweir     sal_Bool        m_readOnly;
171cdf0e10cSrcweir     sal_Bool        m_isOpen;
172cdf0e10cSrcweir     rtl::OUString       m_name;
173cdf0e10cSrcweir     store::OStoreFile   m_file;
174cdf0e10cSrcweir     KeyMap          m_openKeyTable;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     const rtl::OUString ROOT;
177cdf0e10cSrcweir };
178cdf0e10cSrcweir 
179cdf0e10cSrcweir #endif
180