[content] Fix remove item bug on PlayList
[platform/framework/native/content.git] / src / FCntContentSearch.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  * @file                FCntContentSearch.cpp
19  * @brief               This is the implementation file for the %ContentSearch class.
20  *
21  * This is the implementation file for %ContentSearch class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntContentSearch.h>
26 #include <FBaseColIList.h>
27 #include <FCnt_ContentSearchImpl.h>
28 #include <FSec_AccessController.h>
29
30 using namespace Tizen::Io;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Content
36 {
37
38 static const int MAX_QUERY_PATH = 512;
39
40 ContentSearch::ContentSearch(void)
41         : Object()
42         , __pImpl(null)
43 {
44 }
45
46 ContentSearch::~ContentSearch(void)
47 {
48         if (__pImpl != null)
49         {
50                 delete __pImpl;
51                 __pImpl = null;
52         }
53 }
54
55 result
56 ContentSearch::Construct(ContentType type)
57 {
58         result r = E_SUCCESS;
59
60         SysAssertf(__pImpl == null,
61                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
62
63         SysTryReturn(NID_CNT, type != CONTENT_TYPE_UNKNOWN, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Construct failed.");
64
65         _ContentSearchImpl* pContentSearchImpl = new (std::nothrow) _ContentSearchImpl();
66         SysTryReturn(NID_CNT, pContentSearchImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
67
68         r = pContentSearchImpl->Construct(type);
69         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
70
71         __pImpl = pContentSearchImpl;
72
73         return E_SUCCESS;;
74
75 CATCH:
76         delete pContentSearchImpl;
77         pContentSearchImpl = null;
78
79         return r;
80 }
81
82 IList*
83 ContentSearch::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr,
84 const String& sortColumn, SortOrder sortOrder) const
85 {
86         ClearLastResult();
87
88         totalPageCount = 0;
89         totalCount = 0;
90
91         // Checks the privilege
92         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
93         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
94                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
95
96         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
97
98         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0 : SearchN failed.");
99         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: SearchN failed.");
100         SysTryReturn(NID_CNT, whereExpr.GetLength() <= MAX_QUERY_PATH, null, E_INVALID_ARG, "[E_INVALID_ARG] Exceeds query max size : SearchN failed.");
101
102
103         return __pImpl->SearchN(pageNo, countPerPage, totalPageCount, totalCount, whereExpr, sortColumn, sortOrder);
104
105 }
106
107 IList*
108 ContentSearch::GetValueListN(const String& column, SortOrder sortOrder)
109 {
110         ClearLastResult();
111
112         // Checks the privilege
113         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
114         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
115                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
116
117         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
118
119         SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is invalid.");
120
121         return __pImpl->GetValueListN(column, sortOrder);
122 }
123
124 IList*
125 ContentSearch::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount,
126 const String& column, SortOrder sortOrder) const
127 {
128         ClearLastResult();
129
130         totalPageCount = 0;
131         totalCount = 0;
132
133         // Checks the privilege
134         result r = _AccessController::CheckUserPrivilege(_PRV_CONTENT_READ);
135         SysTryReturn(NID_CNT, r == E_SUCCESS, null, E_PRIVILEGE_DENIED,
136                         "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
137
138         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
139
140         SysTryReturn(NID_CNT, !column.IsEmpty(), null, E_INVALID_ARG, "[E_INVALID_ARG] The column name is invalid: GetValueListN failed.");
141         SysTryReturn(NID_CNT, pageNo > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] pageNo <=0: GetValueListN failed.");
142         SysTryReturn(NID_CNT, countPerPage > 0, null, E_INVALID_ARG, "[E_INVALID_ARG] countPerPage <=0: GetValueListN failed.");
143
144         return __pImpl->GetValueListN(pageNo, countPerPage, totalPageCount, totalCount, column, sortOrder);
145 }
146
147 }}