LibreOffice Module registry (master)  1
regimpl.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_REGISTRY_SOURCE_REGIMPL_HXX
21 #define INCLUDED_REGISTRY_SOURCE_REGIMPL_HXX
22 
23 #include <unordered_map>
24 
25 #include <regapi.hxx>
26 #include <registry/regtype.h>
27 #include <rtl/ustring.hxx>
28 #include <osl/mutex.hxx>
29 #include <store/store.hxx>
30 
31 // 5 bytes = 1 (byte for the type) + 4 (bytes for the size of the data)
32 #define VALUE_HEADERSIZE 5
33 #define VALUE_TYPEOFFSET 1
34 #define VALUE_HEADEROFFSET 5
35 
36 #define REG_GUARD(mutex) \
37  osl::Guard< osl::Mutex > aGuard( mutex );
38 
39 class ORegKey;
40 class RegistryTypeReader;
41 
42 class ORegistry
43 {
44 public:
45  ORegistry();
46 
47  sal_uInt32 acquire()
48  { return ++m_refCount; }
49 
50  sal_uInt32 release()
51  { return --m_refCount; }
52 
53  RegError initRegistry(const OUString& name,
54  RegAccessMode accessMode,
55  bool bCreate = false);
56 
58 
59  RegError destroyRegistry(const OUString& name);
60 
63 
65  const OUString& keyName,
66  RegKeyHandle* phNewKey);
67 
69  const OUString& keyName,
70  RegKeyHandle* phOpenKey);
71 
73 
74  RegError deleteKey(RegKeyHandle hKey, const OUString& keyName);
75 
77  const OUString& regFileName,
78  bool bWarnings,
79  bool bReport);
80 
82 
83  ~ORegistry();
84 
85  bool isReadOnly() const
86  { return m_readOnly; }
87 
88  bool isOpen() const
89  { return m_isOpen; }
90 
92 
94  { return m_file; }
95 
96  const OUString& getName() const
97  { return m_name; }
98 
99  friend class ORegKey;
100 
101 private:
102  RegError eraseKey(ORegKey* pKey, const OUString& keyName);
103 
105 
106  static RegError loadAndSaveValue(ORegKey* pTargetKey,
107  ORegKey const * pSourceKey,
108  const OUString& valueName,
109  sal_uInt32 nCut,
110  bool bWarnings,
111  bool bReport);
112 
113  static RegError checkBlop(store::OStoreStream& rValue,
114  const OUString& sTargetPath,
115  sal_uInt32 srcValueSize,
116  sal_uInt8 const * pSrcBuffer,
117  bool bReport);
118 
119  static RegError mergeModuleValue(store::OStoreStream& rTargetValue,
120  RegistryTypeReader const & reader,
121  RegistryTypeReader const & reader2);
122 
123  RegError loadAndSaveKeys(ORegKey* pTargetKey,
124  ORegKey* pSourceKey,
125  const OUString& keyName,
126  sal_uInt32 nCut,
127  bool bWarnings,
128  bool bReport);
129 
130  RegError dumpValue(const OUString& sPath,
131  const OUString& sName,
132  sal_Int16 nSpace) const;
133 
134  RegError dumpKey(const OUString& sPath,
135  const OUString& sName,
136  sal_Int16 nSpace) const;
137 
138  typedef std::unordered_map< OUString, ORegKey* > KeyMap;
139 
140  sal_uInt32 m_refCount;
141  osl::Mutex m_mutex;
143  bool m_isOpen;
144  OUString m_name;
147 
148  static constexpr OUStringLiteral ROOT { "/" };
149 };
150 
151 #endif
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt32 acquire()
Definition: regimpl.hxx:47
RegistryTypeReades reads a binary type blob.
Definition: reflread.hxx:37
sal_uInt32 m_refCount
Definition: regimpl.hxx:140
RegAccessMode
defines the open/access mode of the registry.
Definition: regtype.h:41
const OUString & getName() const
Definition: regimpl.hxx:96
RegError acquireKey(RegKeyHandle hKey)
Definition: regimpl.cxx:577
RegError deleteKey(RegKeyHandle hKey, const OUString &keyName)
Definition: regimpl.cxx:736
RegError createKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phNewKey)
Definition: regimpl.cxx:604
ORegKey * getRootKey()
Definition: regimpl.cxx:1248
bool isReadOnly() const
Definition: regimpl.hxx:85
RegError closeRegistry()
Definition: regimpl.cxx:502
enum SAL_DLLPUBLIC_RTTI RegError
specifies the possible error codes which can occur using the registry API.
Definition: regtype.h:80
std::unordered_map< OUString, ORegKey * > KeyMap
Definition: regimpl.hxx:138
store::OStoreFile m_file
Definition: regimpl.hxx:145
osl::Mutex m_mutex
Definition: regimpl.hxx:141
bool m_readOnly
Definition: regimpl.hxx:142
bool isOpen() const
Definition: regimpl.hxx:88
static RegError loadAndSaveValue(ORegKey *pTargetKey, ORegKey const *pSourceKey, const OUString &valueName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:894
RegError dumpRegistry(RegKeyHandle hKey) const
Definition: regimpl.cxx:1254
OUString m_name
Definition: regimpl.hxx:144
RegError loadKey(RegKeyHandle hKey, const OUString &regFileName, bool bWarnings, bool bReport)
Definition: regimpl.cxx:851
RegError dumpValue(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1290
~ORegistry()
Definition: regimpl.cxx:429
static RegError checkBlop(store::OStoreStream &rValue, const OUString &sTargetPath, sal_uInt32 srcValueSize, sal_uInt8 const *pSrcBuffer, bool bReport)
Definition: regimpl.cxx:1005
unsigned char sal_uInt8
RegError eraseKey(ORegKey *pKey, const OUString &keyName)
Definition: regimpl.cxx:751
void * RegKeyHandle
defines the type of a registry key handle used in the C API.
Definition: regtype.h:30
RegError releaseKey(RegKeyHandle hKey)
Definition: regimpl.cxx:589
RegError closeKey(RegKeyHandle hKey)
Definition: regimpl.cxx:706
KeyMap m_openKeyTable
Definition: regimpl.hxx:146
RegError loadAndSaveKeys(ORegKey *pTargetKey, ORegKey *pSourceKey, const OUString &keyName, sal_uInt32 nCut, bool bWarnings, bool bReport)
Definition: regimpl.cxx:1183
RegError dumpKey(const OUString &sPath, const OUString &sName, sal_Int16 nSpace) const
Definition: regimpl.cxx:1518
sal_uInt32 release()
Definition: regimpl.hxx:50
RegError initRegistry(const OUString &name, RegAccessMode accessMode, bool bCreate=false)
Definition: regimpl.cxx:439
RegError deleteSubkeysAndValues(ORegKey *pKey)
Definition: regimpl.cxx:814
RegError destroyRegistry(const OUString &name)
Definition: regimpl.cxx:518
static RegError mergeModuleValue(store::OStoreStream &rTargetValue, RegistryTypeReader const &reader, RegistryTypeReader const &reader2)
Definition: regimpl.cxx:1117
static constexpr OUStringLiteral ROOT
Definition: regimpl.hxx:148
const store::OStoreFile & getStoreFile() const
Definition: regimpl.hxx:93
bool m_isOpen
Definition: regimpl.hxx:143
RegError openKey(RegKeyHandle hKey, const OUString &keyName, RegKeyHandle *phOpenKey)
Definition: regimpl.cxx:661