sync with master
[platform/framework/native/appfw.git] / inc / FIoFileLock.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16
17 /**
18 * @file            FIoFileLock.h
19 * @brief          This is the header file for the %FileLock class.
20 *
21 * This header file contains the declarations of the %FileLock class.
22 */
23
24 #ifndef _FIO_FILE_LOCK_H_
25 #define _FIO_FILE_LOCK_H_
26
27 namespace Tizen { namespace Io
28 {
29
30 class _FileImpl;
31 /**
32 * @enum FileLockType
33 *
34 * Defines the file lock type
35 *
36 * @since         2.1
37 */
38 enum FileLockType
39 {
40         FILE_LOCK_SHARED,               /**< More than one process can hold a shared file lock on a file region.
41                                                       A shared lock prevents any other process from setting an exclusive lock on the file
42                                                       region . */
43         FILE_LOCK_EXCLUSIVE            /**< Only one process can hold an exclusive lock on a file region.
44                                                       An exclusive lock prevents any other process from setting both shared and exclusive
45                                                       lock on the file region. */
46 };
47
48 class _OSP_EXPORT_ FileLock
49         : public Tizen::Base::Object
50 {
51 public:
52         /**
53         * This destructor releases the file lock on the current opened file if acquired
54         *
55         * @since          2.1
56         */
57         virtual ~FileLock(void);
58
59         /**
60         * Checks whether the file lock is shared.
61         *
62         * @since          2.1
63         *
64         * @return         @c true if the file lock is shared, @n
65         *                    else @c false
66         */
67         bool IsShared(void) const;
68
69         /**
70         * Checks whether the file lock is exclusive.
71         *
72         * @since          2.1
73         *
74         * @return         @c true if the file lock is exclusive, @n
75         *                    else @c false
76         */
77         bool IsExclusive(void) const;
78
79         /**
80         * Checks whether the file lock is valid. @n
81         * The lock is valid unless the associated %File has been closed.
82         *
83         * @since          2.1
84         *
85         * @return         @c true if the file lock is valid, @n
86         *                    else @c false
87         */
88         bool IsValid(void) const;
89
90 private:
91         //
92         // This default constructor is intentionally declared as private so that only the platform can create an instance.
93         //
94         FileLock(void);
95
96         //
97         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
98         //
99         FileLock(const FileLock& rhs);
100
101         //
102         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
103         //
104         FileLock& operator =(const FileLock& rhs);
105
106         //
107         // Constructs the instance of this class.
108         //
109         // @since       2.1
110         //
111         // @return          An error code
112         // @param[in]   fileImpl        Am instance of _FileImpl
113         // @param[in]   lockType        The type of file lock to be created
114         // @param[in]   offset          The starting offset for the locked region
115         // @param[in]   size            The size of the locked region in bytes
116         // @param[in]   pid                     process id of the proccess aquiring this lock
117         // @exception   E_SUCCESS               The method is successful.
118         // @exception   E_OUT_OF_MEMORY The memory is insufficient.
119         // @exception   E_SYSTEM                A system error has occurred.
120         //
121         result Construct(const _FileImpl* pFileImpl, FileLockType lockType, int offset, int size, int pid);
122
123         class _FileLockImpl* __pFileLockImpl;
124
125         friend class _FileLockImpl;
126
127 }; // FileLock
128
129 }} // Tizen::Io
130
131 #endif // _FIO_FILE_LOCK_H_