// limitations under the License.
/**
-* @file FIoFileLock.h
-* @brief This is the header file for the %FileLock class.
-*
-* This header file contains the declarations of the %FileLock class.
-*/
+ * @file FIoFileLock.h
+ * @brief This is the header file for the %FileLock class.
+ *
+ * This header file contains the declarations of the %FileLock class.
+ */
#ifndef _FIO_FILE_LOCK_H_
#define _FIO_FILE_LOCK_H_
namespace Tizen { namespace Io
{
-class _FileImpl;
/**
-* @enum FileLockType
-*
-* Defines the file lock type
-*
-* @since 2.1
-*/
+ * @enum FileLockType
+ *
+ * Defines the file lock type
+ *
+ * @since 2.1
+ */
enum FileLockType
{
- FILE_LOCK_SHARED, /**< More than one process can hold a shared file lock on a file region.
- A shared lock prevents any other process from setting an exclusive lock on the file
- region . */
- FILE_LOCK_EXCLUSIVE /**< Only one process can hold an exclusive lock on a file region.
- An exclusive lock prevents any other process from setting both shared and exclusive
- lock on the file region. */
+ FILE_LOCK_SHARED, /**< More than one process can hold a shared file lock on a file region.
+ A shared lock prevents any other process from setting an exclusive lock on the file
+ region . */
+ FILE_LOCK_EXCLUSIVE /**< Only one process can hold an exclusive lock on a file region.
+ An exclusive lock prevents any other process from setting both shared and exclusive
+ lock on the file region. */
};
+/**
+ * @class FileLock
+ * @brief This class provides methods to check %FileLock type and release it.
+ *
+ * @since 2.1
+ *
+ * @final This class is not intended for extension.
+ *
+ * The %FileLock class provides methods to check %FileLock type and release it.
+ *
+ * @see Tizen::Io::File
+ * @see Tizen::Io::Registry
+ */
class _OSP_EXPORT_ FileLock
: public Tizen::Base::Object
{
+
public:
/**
* This destructor releases the file lock on the current opened file if acquired
//
// This default constructor is intentionally declared as private so that only the platform can create an instance.
//
+ // @since 2.1
+ //
FileLock(void);
//
// The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
//
+ // @since 2.1
+ //
FileLock(const FileLock& rhs);
//
// The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
//
- FileLock& operator =(const FileLock& rhs);
-
- //
- // Constructs the instance of this class.
- //
// @since 2.1
//
- // @return An error code
- // @param[in] fileImpl Am instance of _FileImpl
- // @param[in] lockType The type of file lock to be created
- // @param[in] offset The starting offset for the locked region
- // @param[in] size The size of the locked region in bytes
- // @param[in] pid process id of the proccess aquiring this lock
- // @exception E_SUCCESS The method is successful.
- // @exception E_OUT_OF_MEMORY The memory is insufficient.
- // @exception E_SYSTEM A system error has occurred.
- //
- result Construct(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid);
+ FileLock& operator =(const FileLock& rhs);
class _FileLockImpl* __pFileLockImpl;
FileLock::FileLock(void)
: __pFileLockImpl(null)
{
+ __pFileLockImpl = new (std::nothrow) _FileLockImpl();
+ SysTryReturnVoidResult(NID_IO, __pFileLockImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
}
FileLock::~FileLock(void)
delete __pFileLockImpl;
}
-result
-FileLock::Construct(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid)
-{
- SysAssertf(__pFileLockImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class\n");
-
- std::unique_ptr<_FileLockImpl> pFileLockImpl(new (std::nothrow) _FileLockImpl);
- SysTryReturnResult(NID_IO, pFileLockImpl != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
-
- result r = pFileLockImpl->Construct(pFileImpl, lockType, offset, size, pid);
- SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
-
- __pFileLockImpl = pFileLockImpl.release();
- return r;
-}
-
bool
FileLock::IsShared(void) const
{
- SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
return __pFileLockImpl->IsShared();
}
bool
FileLock::IsExclusive(void) const
{
- SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
return __pFileLockImpl->IsExclusive();
}
bool
FileLock::IsValid(void) const
{
- SysAssertf(__pFileLockImpl != null, "Not yet constructed. Construct() should be called before use.\n");
return __pFileLockImpl->IsValid();
}
}} // Tizen::Io
+
{
std::unique_ptr<FileLock> pFileLock(new (std::nothrow) FileLock());
SysTryReturn(NID_IO, pFileLock != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+ _FileLockImpl* pFileLockImpl = _FileLockImpl::GetInstance(*pFileLock);
- result r = pFileLock->Construct(pFileImpl, lockType, offset, size, pid);
+ result r = pFileLockImpl->Construct(pFileImpl, lockType, offset, size, pid);
SysTryReturn(NID_IO, !IsFailed(r), null, r, "[%s] Propagating to caller...", GetErrorMessage(r));
SetLastResult(E_SUCCESS);
*/
bool IsValid(void) const;
+ //
+ // Constructs the instance of this class.
+ //
+ // @since 2.1
+ //
+ // @return An error code
+ // @param[in] pFile An instance of %File
+ // @param[in] lockType The type of file lock to be created
+ // @param[in] offset The starting offset for the locked region
+ // @param[in] size The size of the locked region in bytes
+ // @param[in] pid process id of the proccess aquiring this lock
+ // @exception E_SUCCESS The method is successful.
+ // @exception E_OUT_OF_MEMORY The memory is insufficient.
+ // @exception E_SYSTEM A system error has occurred.
+ //
result Construct(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid);
static FileLock* CreateFileLockInstanceN(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid);