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 FIoFileLock.cpp
20 * @brief This is the implementation file for %FileLock class.
25 #include <unique_ptr.h>
27 #include <FBaseResult.h>
28 #include <FBaseSysLog.h>
29 #include <FIoFileLock.h>
30 #include "FIo_FileImpl.h"
31 #include "FIo_FileLockImpl.h"
33 namespace Tizen { namespace Io
36 FileLock::FileLock(void)
37 : __pFileLockImpl(null)
41 FileLock::~FileLock(void)
43 delete __pFileLockImpl;
47 FileLock::Construct(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid)
49 SysAssertf(__pFileLockImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
51 std::unique_ptr<_FileLockImpl> pFileLockImpl(new (std::nothrow) _FileLockImpl);
52 SysTryReturnResult(NID_IO, pFileLockImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
54 result r = pFileLockImpl->Construct(pFileImpl, lockType, offset, size, pid);
55 SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
57 __pFileLockImpl = pFileLockImpl.release();
62 FileLock::IsShared(void) const
64 SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
65 return __pFileLockImpl->IsShared();
69 FileLock::IsExclusive(void) const
71 SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
72 return __pFileLockImpl->IsExclusive();
76 FileLock::IsValid(void) const
78 SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
79 return __pFileLockImpl->IsValid();