2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIo_RegistryImpl.cpp
20 * @brief This is the implementation file for _RegistryImpl class.
25 #include <unique_ptr.h>
27 #include <FBaseInteger.h>
28 #include <FBaseDouble.h>
29 #include <FBaseFloat.h>
30 #include <FBaseUuId.h>
31 #include <FBaseByteBuffer.h>
32 #include <FBaseColHashMap.h>
33 #include <FBaseColIEnumerator.h>
34 #include <FBaseUtilStringTokenizer.h>
35 #include <FBaseResult.h>
36 #include <FBaseSysLog.h>
38 #include <FIoRegistry.h>
40 #include <FBase_StringConverter.h>
41 #include <FIo_FileImpl.h>
42 #include <FIo_RegistryImpl.h>
43 #include <FIo_NormalRegistry.h>
44 #include <FIo_SecureRegistry.h>
45 #include <FIo_SecureIoUtil.h>
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Utility;
50 using namespace Tizen::Base::Collection;
52 namespace Tizen { namespace Io
55 static const int _MAX_REG_OPENMODE_LENGTH = 2;
57 _RegistryImpl::_RegistryImpl(void)
58 : __pRegistryCore(null)
62 _RegistryImpl::~_RegistryImpl(void)
64 delete __pRegistryCore;
68 _RegistryImpl::ConvertRegistryOpenMode(long legacyMode, char* pOpenMode)
72 case REG_OPEN_READ_ONLY:
73 strcpy(pOpenMode, "r\0");
75 case REG_OPEN_READ_WRITE:
76 strcpy(pOpenMode, "r+\0");
78 case (REG_OPEN_READ_WRITE | REG_OPEN_CREATE):
79 strcpy(pOpenMode, "a+\0");
82 SysLog(NID_IO, "[E_INVALID_ARG] The specified openMode is invalid.");
88 // This method will be removed in a future release.
90 _RegistryImpl::Construct(const String& regPath, long legacyMode, const ByteBuffer* pSecretKey)
92 SysAssertf(__pRegistryCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
94 unique_ptr<char[]> pOpenMode(new char[_MAX_REG_OPENMODE_LENGTH + 1]);
95 SysTryReturnResult(NID_IO, pOpenMode != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
97 bool isValid = _RegistryImpl::ConvertRegistryOpenMode(legacyMode, pOpenMode.get());
98 SysTryReturnResult(NID_IO, isValid == true, E_INVALID_ARG, "The specified openMode is invalid.");
100 return Construct(regPath, pOpenMode.get(), pSecretKey);
104 _RegistryImpl::Construct(const String& regPath, const char* pOpenMode, const ByteBuffer* pSecretKey)
106 SysAssertf(__pRegistryCore == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
108 result r = E_SUCCESS;
111 unique_ptr<_NormalRegistry> pNormalRegistry(new (std::nothrow) _NormalRegistry());
112 SysTryReturnResult(NID_IO, pNormalRegistry != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
114 r = pNormalRegistry->Construct(regPath, pOpenMode);
117 SysLogException(NID_IO, r, "[%s] Propagated.", GetErrorMessage(r));
120 __pRegistryCore = pNormalRegistry.release();
124 unique_ptr<_SecureRegistry> pSecureRegistry(new (std::nothrow) _SecureRegistry());
125 SysTryReturnResult(NID_IO, pSecureRegistry != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
127 r = pSecureRegistry->Construct(regPath, pOpenMode, pSecretKey);
130 SysLogException(NID_IO, r, "[%s] Propagated.", GetErrorMessage(r));
133 __pRegistryCore = pSecureRegistry.release();
140 _RegistryImpl::Remove(const String& regPath)
142 return _FileImpl::Remove(regPath);
146 _RegistryImpl::AddSection(const String& sectionName)
148 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
149 return __pRegistryCore->AddSection(sectionName);
153 _RegistryImpl::RemoveSection(const String& sectionName)
155 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
156 return __pRegistryCore->RemoveSection(sectionName);
160 _RegistryImpl::GetSectionListN(IList** pRetList)
162 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
163 return __pRegistryCore->GetSectionListN(pRetList);
168 _RegistryImpl::GetEntryList(const String& sectionName, Collection::HashMap& retMap)
170 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
171 return __pRegistryCore->GetEntryList(sectionName, retMap);
176 _RegistryImpl::GetEntryListN(const String& sectionName, HashMap** pRetList)
178 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
179 return __pRegistryCore->GetEntryListN(sectionName, pRetList);
183 _RegistryImpl::GetAllEntriesN(const String& sectionName) const
185 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
186 return __pRegistryCore->GetAllEntriesN(sectionName);
190 _RegistryImpl::GetAllEntryNamesN(const String& sectionName) const
192 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
193 return __pRegistryCore->GetAllEntryNamesN(sectionName);
197 _RegistryImpl::GetValue(const String& sectionName, const String& entryName, String& valStr)
199 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
200 return __pRegistryCore->GetValue(sectionName, entryName, valStr);
204 _RegistryImpl::AddValue(const String& sectionName, const String& entryName, const String& valStr)
206 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
207 return __pRegistryCore->AddValue(sectionName, entryName, valStr);
211 _RegistryImpl::SetValue(const String& sectionName, const String& entryName, const String& valStr)
213 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
214 return __pRegistryCore->SetValue(sectionName, entryName, valStr);
218 _RegistryImpl::RemoveValue(const String& sectionName, const String& entryName)
220 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
221 return __pRegistryCore->RemoveValue(sectionName, entryName);
225 _RegistryImpl::Flush(void)
227 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
228 return __pRegistryCore->Flush();
232 _RegistryImpl::ConvertToSecureRegistry(const String& plainRegPath, const String& secureRegPath, const ByteBuffer* pKey)
234 return _SecureRegistry::ConvertToSecureRegistry(plainRegPath, secureRegPath, pKey);
238 _RegistryImpl::GetSectionIndex(const String& sectionName)
240 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
241 return __pRegistryCore->GetSectionIndex(sectionName);
245 _RegistryImpl::Removekey(const String& sectionName, const String& keyName)
247 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
248 __pRegistryCore->Removekey(sectionName, keyName);
252 _RegistryImpl::GetAllSectionCount(void)
254 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
255 return __pRegistryCore->GetAllSectionCount();
260 _RegistryImpl::GetAllEntryCount(int sectionIndex)
262 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
263 return __pRegistryCore->GetAllEntryCount(sectionIndex);
267 _RegistryImpl::RemoveEntry(int sectionIndex, int entryIndex)
269 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
270 __pRegistryCore->RemoveEntry(sectionIndex, entryIndex);
274 _RegistryImpl::ModifyEntryValue(int sectionIndex, int entryIndex, _RegValueType type, const void* pValue, int size)
276 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
277 __pRegistryCore->ModifyEntryValue(sectionIndex, entryIndex, type, pValue, size);
281 _RegistryImpl::GetEntryIndex(int sectionIndex, const String& entryName)
283 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
284 return __pRegistryCore->GetEntryIndex(sectionIndex, entryName);
288 _RegistryImpl::GetEntryName(int sectionIndex, int entryIndex)
290 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
291 return __pRegistryCore->GetEntryName(sectionIndex, entryIndex);
295 _RegistryImpl::GetEntryValue(int sectionIndex, int entryIndex, _RegValueType type, void* pValue, int* pSize)
297 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
298 __pRegistryCore->GetEntryValue(sectionIndex, entryIndex, type, pValue, pSize);
302 _RegistryImpl::GetSectionName(int sectionIndex)
304 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
305 return __pRegistryCore->GetSectionName(sectionIndex);
309 _RegistryImpl::GetSectionByIndex(int sectionIndex)
311 SysAssertf(__pRegistryCore != null, "Not yet constructed. Construct() should be called before use.\n");
312 return __pRegistryCore->GetSectionByIndex(sectionIndex);
316 _RegistryImpl::GetInstance(Registry& registry)
318 return registry.__pRegistryImpl;
322 _RegistryImpl::GetInstance(const Registry& registry)
324 return registry.__pRegistryImpl;