sync with tizen_2.0
[platform/framework/native/appfw.git] / src / io / FIo_FileAttributesImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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 /**
19  * @file        FIo_FileAttributesImpl.cpp
20  * @brief       This is the implementation file for _FileAttributesImpl class.
21  */
22
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <errno.h>
26
27 #include <FBaseString.h>
28 #include <FBaseResult.h>
29 #include <FIoFile.h>
30 #include <FBaseSysLog.h>
31
32 #include <FBase_StringConverter.h>
33 #include <FBase_NativeError.h>
34 #include <FIo_FileAttributesImpl.h>
35
36 using namespace Tizen::Base;
37
38 namespace Tizen { namespace Io
39 {
40
41 _FileAttributesImpl::_FileAttributesImpl(void)
42         : __fileSize(0)
43         , __directory(false)
44         , __hidden(false)
45         , __readOnly(false)
46 {
47 }
48
49 _FileAttributesImpl::~_FileAttributesImpl(void)
50 {
51 }
52
53 _FileAttributesImpl::_FileAttributesImpl(const _FileAttributesImpl& fileAttributesImpl)
54         : __fileSize(0)
55         , __directory(false)
56         , __hidden(false)
57         , __readOnly(false)
58 {
59         __fileSize = fileAttributesImpl.__fileSize;
60         __directory = fileAttributesImpl.__directory;
61         __hidden = fileAttributesImpl.__hidden;
62         __readOnly = fileAttributesImpl.__readOnly;
63         __creationTime = fileAttributesImpl.__creationTime;
64         __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
65 }
66
67 _FileAttributesImpl&
68 _FileAttributesImpl::operator =(const _FileAttributesImpl& fileAttributesImpl)
69 {
70         if (&fileAttributesImpl != this)
71         {
72                 __fileSize = fileAttributesImpl.__fileSize;
73                 __directory = fileAttributesImpl.__directory;
74                 __hidden = fileAttributesImpl.__hidden;
75                 __readOnly = fileAttributesImpl.__readOnly;
76                 __creationTime = fileAttributesImpl.__creationTime;
77                 __lastModifiedTime = fileAttributesImpl.__lastModifiedTime;
78         }
79
80         return *this;
81 }
82
83 _FileAttributesImpl*
84 _FileAttributesImpl::GetInstance(FileAttributes& fileAttributes)
85 {
86         return fileAttributes.__pFileAttributesImpl;
87 }
88
89 const _FileAttributesImpl*
90 _FileAttributesImpl::GetInstance(const FileAttributes& fileAttributes)
91 {
92         return fileAttributes.__pFileAttributesImpl;
93 }
94
95 bool
96 _FileAttributesImpl::Equals(const Object& object) const
97 {
98         const _FileAttributesImpl* pOther = dynamic_cast< const _FileAttributesImpl* >(&object);
99         if (pOther == null)
100         {
101                 return false;
102         }
103
104         if (__fileSize == pOther->__fileSize && __directory == pOther->__directory &&
105                         __hidden == pOther->__hidden && __readOnly == pOther->__readOnly &&
106                         __creationTime == pOther->__creationTime && __lastModifiedTime == pOther->__lastModifiedTime)
107         {
108                 return true;
109         }
110
111         return false;
112 }
113
114 int
115 _FileAttributesImpl::GetHashCode(void) const
116 {
117         String hashCode;
118
119         hashCode.Append(static_cast< long >(__fileSize));
120         hashCode.Append(static_cast< int >(__directory));
121         hashCode.Append(static_cast< int >(__hidden));
122         hashCode.Append(static_cast< int >(__readOnly));
123         hashCode.Append(__creationTime.ToString());
124         hashCode.Append(__lastModifiedTime.ToString());
125
126         return hashCode.GetHashCode();
127 }
128
129 long long
130 _FileAttributesImpl::GetFileSize(void) const
131 {
132         SetLastResult(E_SUCCESS);
133         return __fileSize;
134 }
135
136 DateTime
137 _FileAttributesImpl::GetDateTime(void) const
138 {
139         SetLastResult(E_SUCCESS);
140         return __creationTime;
141 }
142
143 DateTime
144 _FileAttributesImpl::GetLastModifiedTime(void) const
145 {
146         SetLastResult(E_SUCCESS);
147         return __lastModifiedTime;
148 }
149
150 bool
151 _FileAttributesImpl::IsDirectory(void) const
152 {
153         SetLastResult(E_SUCCESS);
154         return __directory;
155 }
156
157 bool
158 _FileAttributesImpl::IsHidden(void) const
159 {
160         SetLastResult(E_SUCCESS);
161         return __hidden;
162 }
163
164 bool
165 _FileAttributesImpl::IsReadOnly(void) const
166 {
167         SetLastResult(E_SUCCESS);
168         return __readOnly;
169 }
170
171 void
172 _FileAttributesImpl::Set(const DateTime& dateTime, const DateTime& modifiedTime, long long fileSize,
173                                                  unsigned long attribute, bool hidden)
174 {
175         __fileSize = fileSize;
176         __directory = S_ISDIR(attribute) ? true : false;
177         __hidden = hidden;
178         __readOnly = (attribute & (S_IWUSR)) ? false : true;
179
180         __creationTime = dateTime;
181         __lastModifiedTime = modifiedTime;
182
183         SetLastResult(E_SUCCESS);
184 }
185
186 }} // Tizen::Io
187