1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <registry/registry.hxx>
23 #include "keyimpl.hxx"
24 #include "regimpl.hxx"
33 static void REGISTRY_CALLTYPE
acquire(RegHandle hReg
)
35 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
41 static void REGISTRY_CALLTYPE
release(RegHandle hReg
)
43 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
45 if (pReg
&& pReg
->release() == 0)
52 static RegError REGISTRY_CALLTYPE
getName(RegHandle hReg
, rtl_uString
** pName
)
56 ORegistry
* pReg
= static_cast<ORegistry
*>(hReg
);
59 rtl_uString_assign(pName
, pReg
->getName().pData
);
60 return RegError::NO_ERROR
;
63 rtl_uString_new(pName
);
64 return RegError::REGISTRY_NOT_OPEN
;
68 rtl_uString_new(pName
);
69 return RegError::INVALID_REGISTRY
;
72 static sal_Bool REGISTRY_CALLTYPE
isReadOnly(RegHandle hReg
)
75 return static_cast<ORegistry
*>(hReg
)->isReadOnly();
80 static RegError REGISTRY_CALLTYPE
createRegistry(rtl_uString
* registryName
,
81 RegHandle
* phRegistry
)
85 ORegistry
* pReg
= new ORegistry();
86 if ((ret
= pReg
->initRegistry(registryName
, RegAccessMode::READWRITE
, true/*bCreate*/)) != RegError::NO_ERROR
)
89 *phRegistry
= nullptr;
95 return RegError::NO_ERROR
;
98 static RegError REGISTRY_CALLTYPE
openRootKey(RegHandle hReg
,
99 RegKeyHandle
* phRootKey
)
105 pReg
= static_cast<ORegistry
*>(hReg
);
107 return RegError::REGISTRY_NOT_OPEN
;
111 return RegError::INVALID_REGISTRY
;
114 *phRootKey
= pReg
->getRootKey();
116 return RegError::NO_ERROR
;
119 static RegError REGISTRY_CALLTYPE
openRegistry(rtl_uString
* registryName
,
120 RegHandle
* phRegistry
,
121 RegAccessMode accessMode
)
125 ORegistry
* pReg
= new ORegistry();
126 if ((_ret
= pReg
->initRegistry(registryName
, accessMode
)) != RegError::NO_ERROR
)
128 *phRegistry
= nullptr;
136 return RegError::NO_ERROR
;
139 static RegError REGISTRY_CALLTYPE
closeRegistry(RegHandle hReg
)
143 ORegistry
*pReg
= static_cast<ORegistry
*>(hReg
);
145 return RegError::REGISTRY_NOT_OPEN
;
147 RegError ret
= RegError::NO_ERROR
;
148 if (pReg
->release() == 0)
154 ret
= pReg
->closeRegistry();
159 return RegError::INVALID_REGISTRY
;
163 static RegError REGISTRY_CALLTYPE
destroyRegistry(RegHandle hReg
,
164 rtl_uString
* registryName
)
168 ORegistry
*pReg
= static_cast<ORegistry
*>(hReg
);
170 return RegError::INVALID_REGISTRY
;
172 RegError ret
= pReg
->destroyRegistry(registryName
);
173 if (ret
== RegError::NO_ERROR
)
175 if (!registryName
->length
)
184 return RegError::INVALID_REGISTRY
;
191 static RegError REGISTRY_CALLTYPE
dumpRegistry(RegHandle hReg
,
194 ORegistry
* pReg
= static_cast< ORegistry
* >(hReg
);
196 return RegError::INVALID_REGISTRY
;
198 return RegError::REGISTRY_NOT_OPEN
;
200 ORegKey
* pKey
= static_cast< ORegKey
* >(hKey
);
202 return RegError::INVALID_KEY
;
203 if (pKey
->getRegistry() != pReg
)
204 return RegError::INVALID_KEY
;
205 if (pKey
->isDeleted())
206 return RegError::INVALID_KEY
;
208 return pReg
->dumpRegistry(hKey
);
211 Registry_Api
* REGISTRY_CALLTYPE
initRegistry_Api()
213 static Registry_Api aApi
= {&acquire
,
235 &setUnicodeListValue
,
240 &getUnicodeListValue
,
251 RegError REGISTRY_CALLTYPE
reg_openRootKey(RegHandle hRegistry
,
252 RegKeyHandle
* phRootKey
)
254 return openRootKey(hRegistry
, phRootKey
);
257 RegError REGISTRY_CALLTYPE
reg_openRegistry(rtl_uString
* registryName
,
258 RegHandle
* phRegistry
)
262 ORegistry
* pReg
= new ORegistry();
263 if ((_ret
= pReg
->initRegistry(registryName
, RegAccessMode::READONLY
)) != RegError::NO_ERROR
)
266 *phRegistry
= nullptr;
272 return RegError::NO_ERROR
;
275 RegError REGISTRY_CALLTYPE
reg_closeRegistry(RegHandle hRegistry
)
279 ORegistry
* pReg
= static_cast<ORegistry
*>(hRegistry
);
281 return RegError::NO_ERROR
;
284 return RegError::REGISTRY_NOT_OPEN
;
288 RegError REGISTRY_CALLTYPE
reg_dumpRegistry(RegKeyHandle hKey
)
293 pKey
= static_cast<ORegKey
*>(hKey
);
295 return RegError::INVALID_KEY
;
297 return dumpRegistry(pKey
->getRegistry(), hKey
);
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */