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_NormalRegistry.cpp
20 * @brief This is the implementation file for _NormalRegistry class.
26 #include <FBaseInteger.h>
27 #include <FBaseDouble.h>
28 #include <FBaseFloat.h>
29 #include <FBaseUuId.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseColIEnumerator.h>
32 #include <FBaseUtilStringTokenizer.h>
33 #include <FBaseResult.h>
34 #include <FBaseSysLog.h>
36 #include <FIoRegistry.h>
38 #include <FBase_StringConverter.h>
39 #include <FIo_FileImpl.h>
40 #include <FIo_NormalRegistry.h>
41 #include <FIo_SecureIoUtil.h>
43 using namespace Tizen::Base;
45 namespace Tizen { namespace Io
48 _NormalRegistry::_NormalRegistry(void)
52 _NormalRegistry::~_NormalRegistry(void)
54 if (_write == true && _FileImpl::IsFileExist(_regPath) == true && _update == true)
59 _sectionList.RemoveAll(true);
61 delete[] _pBuffer; //clear existing buffer
67 _NormalRegistry::Construct(const String& regPath, const char* pOpenMode)
69 SysAssertf(_constructed == false, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
71 bool isValidOpenMode = this->VerifyRegistryOpenMode(pOpenMode);
72 SysTryReturnResult(NID_IO, isValidOpenMode == true, E_INVALID_ARG, "The specified openMode is invalid. (%s)", pOpenMode);
74 result r = this->Load(regPath, pOpenMode);
75 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to load the registry file (%ls).",
76 GetErrorMessage(r), regPath.GetPointer());
78 if (_pBuffer && _length >= SECURE_REG_HEADER_SIZE_V1)
80 r = _SecureIoUtil::CheckSecureRegistryHeader(&_pBuffer, &_length, regPath, false);
81 SysTryReturnResult(NID_IO, !IsFailed(r), E_INVALID_ARG, "Can not open the secure file in normal mode.");
85 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to parse the registry file (%ls).",
86 GetErrorMessage(r), regPath.GetPointer());
90 _regPath.Append(regPath);
96 _NormalRegistry::Flush(void)
98 result r = this->PrepareToWrite();
99 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to prepare to write.", GetErrorMessage(r));
102 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to write registry file.", GetErrorMessage(r));