Fix : Remove exception handling codes at the sample code
[platform/framework/native/content.git] / src / FCntContentDirectory.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FCntContentDirectory.cpp
18  * @brief               This is the implementation file for the %ContentDirectory class.
19  *
20  * This is the implementation file for %ContentDirectory class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntContentDirectory.h>
25 #include <FBaseColIList.h>
26 #include <FIoFile.h>
27 #include <FCnt_ContentDirectoryImpl.h>
28
29 using namespace Tizen::Io;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33 namespace Tizen { namespace Content
34 {
35
36 ContentDirectory::ContentDirectory(void)
37         : Object()
38         , __pImpl(null)
39 {
40 }
41
42 ContentDirectory::~ContentDirectory(void)
43 {
44         if (__pImpl != null)
45         {
46                 delete __pImpl;
47                 __pImpl = null;
48         }
49 }
50
51 result
52 ContentDirectory::Construct(ContentType type)
53 {
54         result r = E_SUCCESS;
55
56         SysAssertf(__pImpl == null,
57                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
58
59         SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
60
61         _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
62         SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
63
64         r = pContentDirectoryImpl->Construct(type);
65         SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
66
67         __pImpl = pContentDirectoryImpl;
68
69         return E_SUCCESS;;
70
71 CATCH:
72         if (pContentDirectoryImpl != NULL)
73         {
74                 delete pContentDirectoryImpl;
75                 pContentDirectoryImpl = null;
76         }
77         return r;
78 }
79
80 result
81 ContentDirectory::Construct(const Tizen::Base::Collection::IListT<ContentType>& contentTypeList)
82 {
83         result r = E_SUCCESS;
84         ContentType type = CONTENT_TYPE_UNKNOWN;
85         int listCount = contentTypeList.GetCount();
86
87         SysAssertf(__pImpl == null,
88                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
89
90         SysTryReturnResult(NID_CNT, ((listCount > MIN_CONTENTTYPE_LIST_COUNT) && (listCount < MAX_CONTENTTYPE_LIST_COUNT)), E_INVALID_ARG, "Construct failed.");
91
92         for(int index = 0; index < listCount; index++)
93         {
94                 contentTypeList.GetAt(index, type);
95                 SysTryReturnResult(NID_CNT, type != CONTENT_TYPE_UNKNOWN && type != CONTENT_TYPE_ALL, E_INVALID_ARG, "Construct failed.");
96         }
97
98         _ContentDirectoryImpl* pContentDirectoryImpl = new (std::nothrow) _ContentDirectoryImpl();
99         SysTryReturnResult(NID_CNT, pContentDirectoryImpl != null, E_OUT_OF_MEMORY, "Construct failed.");
100
101         if (listCount == CONTENTTYPE_LIST_COUNT_ONE)
102         {
103                 r = pContentDirectoryImpl->Construct(type);
104                 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
105         }
106         else
107         {
108                 r = pContentDirectoryImpl->Construct(contentTypeList);
109                 SysTryCatch(NID_CNT, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Construct failed.");
110         }
111
112         __pImpl = pContentDirectoryImpl;
113
114         return E_SUCCESS;;
115
116 CATCH:
117         if (pContentDirectoryImpl != NULL)
118         {
119                 delete pContentDirectoryImpl;
120                 pContentDirectoryImpl = null;
121         }
122         return r;
123 }
124
125 int
126 ContentDirectory::GetContentDirectoryCount(void) const
127 {
128         ClearLastResult();
129
130         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         return __pImpl->GetContentDirectoryCount();
133 }
134
135 IList*
136 ContentDirectory::GetContentDirectoryPathListN(Tizen::Base::SortOrder sortOrder) const
137 {
138         ClearLastResult();
139
140         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
141
142         return __pImpl->GetContentDirectoryPathListN(sortOrder);
143 }
144
145 int
146 ContentDirectory::GetContentDirectoryItemCount(const Tizen::Base::String& contentDirectoryPath) const
147 {
148         ClearLastResult();
149
150         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
151
152         SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
153
154         SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
155
156         return __pImpl->GetContentDirectoryItemCount(contentDirectoryPath);
157 }
158
159 IList*
160 ContentDirectory::GetContentDirectoryItemListN(const Tizen::Base::String& contentDirectoryPath, int pageNo, int countPerPage,
161                                                     const Tizen::Base::String& column, Tizen::Base::SortOrder sortOrder) const
162 {
163         ClearLastResult();
164
165         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
166
167         if(sortOrder != SORT_ORDER_NONE)
168         {
169                 SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is empty.");
170         }
171
172         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetContentDirectoryItemListN failed.");
173
174         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetContentDirectoryItemListN failed.");
175
176         SysTryReturn(NID_CNT, !contentDirectoryPath.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath is empty.");
177
178         SysTryReturn(NID_CNT, File::IsFileExist(contentDirectoryPath) == true, null, E_INVALID_ARG, "[E_INVALID_ARG] The contentDirectoryPath doesn't exist.");
179
180         return __pImpl->GetContentDirectoryItemListN(contentDirectoryPath, pageNo, countPerPage, column, sortOrder);
181 }
182
183 }}