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