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