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