[content] Fix a incorrect line in doxygen
[platform/framework/native/content.git] / src / FCnt_ContentSearchImpl.cpp
1 //\r
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
3 //\r
4 // Licensed under the Apache License, Version 2.0 (the License);\r
5 // you may not use this file except in compliance with the License.\r
6 // You may obtain a copy of the License at\r
7 //\r
8 //     http://www.apache.org/licenses/LICENSE-2.0\r
9 //\r
10 // Unless required by applicable law or agreed to in writing, software\r
11 // distributed under the License is distributed on an "AS IS" BASIS,\r
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13 // See the License for the specific language governing permissions and\r
14 // limitations under the License.\r
15 //\r
16 /**\r
17  * @file                FCnt_ContentSearchImpl.cpp\r
18  * @brief               This is the implementation file for the %_ContentSearchImpl class.\r
19  *\r
20  * This file contains implementation of the %_ContentSearchImpl class.\r
21  */\r
22 \r
23 #include <time.h>\r
24 #include <FBaseSysLog.h>\r
25 #include <FBaseInteger.h>\r
26 #include <FBaseLongLong.h>\r
27 #include <FBaseFloat.h>\r
28 #include <FBaseColIList.h>\r
29 #include <FBaseUtilStringTokenizer.h>\r
30 #include <FCntContentSearch.h>\r
31 #include <FCntContentSearchResult.h>\r
32 #include <FBase_StringConverter.h>\r
33 #include <FBase_LocalizedNumParser.h>\r
34 #include <FCnt_ContentUtility.h>\r
35 #include <FCnt_ContentSearchImpl.h>\r
36 \r
37 using namespace Tizen::Base;\r
38 using namespace Tizen::Base::Collection;\r
39 using namespace Tizen::Base::Utility;\r
40 using namespace Tizen::Io;\r
41 \r
42 namespace Tizen { namespace Content\r
43 {\r
44 \r
45 static const int QUERY_LENGTH = 4096;\r
46 \r
47 // Declaration for Callback function registered to each media info details\r
48 bool MediaItemCb(media_info_h media, void* pUserdata);\r
49 // Declaration for Callback function registered to each column details\r
50 bool GroupItemCb(const char* pGroupName, void* pUserdata);\r
51 // Declaration for Callback function registered to each album details\r
52 bool AlbumItemCb(media_album_h album, void* pUserdata);\r
53 \r
54 // Default constructor\r
55 _ContentSearchImpl::_ContentSearchImpl(void)\r
56         : Object()\r
57         , __contentType(CONTENT_TYPE_UNKNOWN)\r
58         , __pFinalOutList(NULL)\r
59         , __inputExpr(L"")\r
60         , __inputColumnName(L"")\r
61         , __inputSortOrder(SORT_ORDER_NONE)\r
62         , __pFilterHandle(NULL)\r
63 {\r
64         SysLog(NID_CNT, "Enter\n");\r
65 }\r
66 \r
67 \r
68 // Default destructor (disconnects the DB connection)\r
69 _ContentSearchImpl::~_ContentSearchImpl(void)\r
70 {\r
71         SysLog(NID_CNT, "Enter\n");\r
72 \r
73         int ret = MEDIA_CONTENT_ERROR_NONE;\r
74         result r = E_SUCCESS;\r
75 \r
76         ret = media_content_disconnect();\r
77         r = MapCoreErrorToNativeResult(ret);\r
78         SysTryLog(NID_CNT, r == E_SUCCESS, "[%s] Propagated in ~_ContentSearchImpl", GetErrorMessage(r));\r
79 }\r
80 \r
81  _ContentSearchImpl*\r
82  _ContentSearchImpl::GetInstance(ContentSearch& contentSearch)\r
83 {\r
84         return contentSearch.__pImpl;\r
85 }\r
86 \r
87 const _ContentSearchImpl*\r
88 _ContentSearchImpl::GetInstance(const ContentSearch& contentSearch)\r
89 {\r
90         return contentSearch.__pImpl;\r
91 }\r
92 \r
93 //make a connection to DB\r
94 result\r
95 _ContentSearchImpl::Construct(ContentType type)\r
96 {\r
97         SysLog(NID_CNT, "Enter\n");\r
98 \r
99         result r = E_SUCCESS;\r
100         int ret = MEDIA_CONTENT_ERROR_NONE;\r
101 \r
102         ret = media_content_connect();\r
103         SysTryReturnResult(NID_CNT, r == E_SUCCESS , E_SYSTEM, "Failed to perform media_content_connect operation.");\r
104 \r
105         __contentType = type;\r
106 \r
107         return r;\r
108 }\r
109 \r
110 // Creates a filter for the input query string along with content type\r
111 // Initializes filter handle\r
112 // Image - MEDIA_TYPE=0\r
113 // Vide0 - MEDIA_TYPE=1\r
114 // Audio - MEDIA_TYPE=2 or MEDIA_TYPE=3\r
115 // Others - MEDIA_TYPE=4\r
116 // All - none\r
117 // Appends MEDIA_TYPE with "AND" (if the input expression is not empty and content type is not ALL) and  input expression\r
118 // Sets the condition and order.\r
119 // If any argument is not proper E_INVALID_ARG is returned\r
120 result\r
121 _ContentSearchImpl::CreateQueryFilter(bool isAndAppendReq) const\r
122 {\r
123         int ret  = MEDIA_CONTENT_ERROR_NONE;\r
124         result r = E_SUCCESS;\r
125 \r
126         std::unique_ptr<char[]> pInputCond;\r
127         std::unique_ptr<char[]> pSortCol;\r
128 \r
129         String inputCondition;\r
130         String slpColumn;\r
131 \r
132         filter_h tempFilter = NULL;\r
133 \r
134         ret = media_filter_create(&tempFilter);\r
135         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_create operation.");\r
136 \r
137         std::unique_ptr<filter_s, SearchFilterHandleDeleter> pFilterHandle(tempFilter);
138         SysTryReturnResult(NID_CNT, pFilterHandle != null, E_OUT_OF_MEMORY, "pFilterHandle is null.");\r
139 \r
140         switch (__contentType)\r
141         {\r
142                 // Image-0,video-1,sound-2,music-3,other-4\r
143         case CONTENT_TYPE_OTHER:\r
144                 inputCondition = "MEDIA_TYPE=4 ";\r
145                 break;\r
146         case CONTENT_TYPE_IMAGE:\r
147                 inputCondition = "MEDIA_TYPE=0 ";\r
148                 break;\r
149         case CONTENT_TYPE_AUDIO:\r
150                 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";\r
151                 break;\r
152         case CONTENT_TYPE_VIDEO:\r
153                 inputCondition = "MEDIA_TYPE=1 ";\r
154                 break;\r
155         case CONTENT_TYPE_ALL:\r
156                 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty\r
157                 break;\r
158         default:\r
159                 break;\r
160         }\r
161 \r
162         if (!__inputExpr.IsEmpty())\r
163         {\r
164                 if (isAndAppendReq && (!inputCondition.IsEmpty())) //For CONTENT_TYPE_ALL inputCondition is empty\r
165                 {\r
166                         r = inputCondition.Append("AND ");\r
167                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");\r
168                 }\r
169 \r
170                 r = inputCondition.Append(__inputExpr);\r
171                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");\r
172         }\r
173 \r
174         if (!inputCondition.IsEmpty())\r
175         {\r
176                 //CopyToCharArrayN: utility function, converts a osp string to char*\r
177                 pInputCond = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(inputCondition));\r
178                 SysTryReturnResult(NID_CNT, pInputCond, E_OUT_OF_MEMORY, "pInputCond is NULL.");\r
179 \r
180                 SysLog(NID_CNT, "pInputCond = %s", pInputCond.get());\r
181 \r
182                 ret = media_filter_set_condition(pFilterHandle.get(), pInputCond.get(), MEDIA_CONTENT_COLLATE_DEFAULT);\r
183                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_condition operation.");\r
184         }\r
185 \r
186         if (!__inputColumnName.IsEmpty()) // SortColumn is optional in case of SearchN\r
187         {\r
188                 //__inputColumnName (osp column name) is replaced with slpColumn (slp column name).\r
189                 r = GetSlpColumnName(slpColumn);\r
190                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetSlpColumnName operation.");\r
191 \r
192                 //CopyToCharArrayN: utility function, converts a osp string to char*\r
193 \r
194                 pSortCol = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(slpColumn));\r
195                 SysTryReturnResult(NID_CNT, pSortCol, E_OUT_OF_MEMORY, "pSortCol is NULL.");\r
196 \r
197                 if (__inputSortOrder == SORT_ORDER_ASCENDING)\r
198                 {\r
199                         ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_ASC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);\r
200                         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");\r
201                 }\r
202                 else if (__inputSortOrder == SORT_ORDER_DESCENDING)\r
203                 {\r
204                         ret = media_filter_set_order(pFilterHandle.get(), MEDIA_CONTENT_ORDER_DESC, pSortCol.get(), MEDIA_CONTENT_COLLATE_NOCASE);\r
205                         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, E_SYSTEM, "Failed to perform media_filter_set_order operation.");\r
206                 }\r
207         }\r
208 \r
209         __pFilterHandle.reset(pFilterHandle.release());\r
210 \r
211         return r;\r
212 }\r
213 \r
214 // Osp column names are mapped with slp column names\r
215 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns\r
216 // CONTENT_TYPE_VIDEO  (0 - 16 ) are valid columns\r
217 // CONTENT_TYPE_ALL and  CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns\r
218 // if the given osp column is out of the specified range of the type, E_INVALID_ARG is retuned.\r
219 result\r
220 _ContentSearchImpl::GetSlpColumnName(String& inputCol) const\r
221 {\r
222         String          ospColumnName(L"");\r
223         String          slpColumnName(L"");\r
224         String          columnName(__inputColumnName);\r
225         result          r = E_SUCCESS;\r
226         int             maxCols = 0;\r
227         switch (__contentType)\r
228         {\r
229         case CONTENT_TYPE_OTHER:\r
230                 //fall through\r
231         case CONTENT_TYPE_IMAGE:\r
232                 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;\r
233                 break;\r
234         case CONTENT_TYPE_VIDEO:\r
235                 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;\r
236                 break;\r
237         case CONTENT_TYPE_AUDIO:\r
238                 //fall through\r
239         case CONTENT_TYPE_ALL:\r
240                 maxCols = MAX_QUERY_COLUMNS;\r
241                 break;\r
242         default:\r
243                 break;\r
244         }\r
245         for (int colIndex = 0; colIndex < maxCols; colIndex++)\r
246         {\r
247                 ospColumnName.Clear();\r
248                 slpColumnName.Clear();\r
249 \r
250                 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;\r
251                 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;\r
252 \r
253                 ospColumnName.ToUpper();\r
254                 columnName.ToUpper();\r
255                 if (columnName == ospColumnName)\r
256                 {\r
257                         inputCol = slpColumnName;\r
258                         return r;\r
259                 }\r
260         }\r
261         return E_INVALID_ARG;\r
262 }\r
263 \r
264 //If the input expression contains any osp column name, it will be replaced with slp column name.\r
265 // only CONTENT_TYPE_AUDIO and CONTENT_TYPE_ALL allowed to use all given columns\r
266 // so, check for invalid column for CONTENT_TYPE_OTHER,CONTENT_TYPE_IMAGE and CONTENT_TYPE_VIDEO.\r
267 // all the osp columns in the expression should be replaced with slp column names.\r
268 // ' is used as a delimeter in parsing user query. so, \\' is saved as a special@apostrophe string.\r
269 // \\' is replaced with '', which considers ' as normal character.\r
270 \r
271 result\r
272 _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const\r
273 {\r
274         String          ospColumnName(L"");\r
275         String          slpColumnName(L"");\r
276         String          splApostrophe(L"special@apostrophe");\r
277         result          r = E_SUCCESS;\r
278         int             maxCols = 0;\r
279 \r
280         int indexOf = 0;\r
281         \r
282         String strToBeReplaced(L"\\'");\r
283         int strLen = strToBeReplaced.GetLength();\r
284         int startIndex = 0;\r
285 \r
286         while(E_SUCCESS == __inputExpr.IndexOf(strToBeReplaced,startIndex,indexOf))\r
287         {\r
288                 int lenAfterSubStr = indexOf + strLen;\r
289                 while ((lenAfterSubStr < __inputExpr.GetLength()) && (__inputExpr[lenAfterSubStr] == ' '))\r
290                 {\r
291                         lenAfterSubStr++;\r
292                 }\r
293                 if ((lenAfterSubStr < __inputExpr.GetLength()) && ((__inputExpr[lenAfterSubStr] == '\'') ||\r
294                                 ((!__inputExpr.StartsWith(L"AND ", lenAfterSubStr)) && (!__inputExpr.StartsWith(L"OR ", lenAfterSubStr)))))\r
295                 {\r
296                         r = __inputExpr.Remove(indexOf,strLen);\r
297                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Remove operation.");\r
298                         r = __inputExpr.Insert(splApostrophe,indexOf);\r
299                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "Failed to perform Insert operation.");\r
300                         startIndex = indexOf + splApostrophe.GetLength();\r
301                 }\r
302                 else\r
303                 {\r
304                         startIndex = lenAfterSubStr;\r
305                 }\r
306         }\r
307 \r
308         SysLog(NID_CNT, "__inputExpr after splApostrophe append = %ls", __inputExpr.GetPointer());\r
309 \r
310         switch (__contentType)\r
311         {\r
312         case CONTENT_TYPE_OTHER:\r
313                 //fall through\r
314         case CONTENT_TYPE_IMAGE:\r
315                 r = CheckInvalidColumnInQuery();\r
316                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");\r
317                 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;\r
318                 break;\r
319         case CONTENT_TYPE_VIDEO:\r
320                 r = CheckInvalidColumnInQuery();\r
321                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "Invalid Column In QueryString.");\r
322                 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;\r
323                 break;\r
324         case CONTENT_TYPE_AUDIO:\r
325                 //fall through\r
326         case CONTENT_TYPE_ALL:\r
327                 maxCols = MAX_QUERY_COLUMNS;\r
328                 break;\r
329         default:\r
330                 break;\r
331         }\r
332         for (int colIndex = 0; colIndex < maxCols; colIndex++)\r
333         {\r
334                 ospColumnName.Clear();\r
335                 slpColumnName.Clear();\r
336 \r
337                 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;\r
338                 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;\r
339 \r
340                 ReplaceString(ospColumnName,slpColumnName);\r
341         }\r
342 \r
343         // Append ESCAPE '\' for LIKE query\r
344         r = AppendEscapeKeywordForLikeQuery();\r
345         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "AppendEscapeKeywordForLikeQuery failed.");\r
346 \r
347         r = ReplaceDateTimeStringWithInt();\r
348         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "ReplaceDateTimeStringWithInt failed.");\r
349 \r
350         // replace splApostrophe string with actual\r
351         r = __inputExpr.Replace(splApostrophe, "''");\r
352         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string Replace failed.");\r
353 \r
354         return r;\r
355 }\r
356 \r
357 //This function is to appened ESCAPE keyword for _ and % special characters in LIKE query.\r
358 \r
359 result\r
360 _ContentSearchImpl::AppendEscapeKeywordForLikeQuery(void) const\r
361 {\r
362         String  delim = L"'"; //Delimeters  is  ' .\r
363         result r = E_SUCCESS;\r
364         bool isCol = true;\r
365         bool isAppendEscape = false;\r
366         String token;\r
367         String tokenUpper;\r
368         String inputExpr = __inputExpr;\r
369 \r
370         // Create a StringTokenizer instance\r
371         StringTokenizer  strTok(inputExpr, delim);\r
372 \r
373         inputExpr.Clear();\r
374 \r
375         while (strTok.HasMoreTokens())\r
376         {\r
377                 r = strTok.GetNextToken(token);\r
378                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "GetNextToken failed.");\r
379                 if (isCol) //column name\r
380                 {\r
381                         isCol = false;\r
382                         tokenUpper = token;\r
383                         tokenUpper.ToUpper();\r
384                         if (tokenUpper.Contains(" LIKE"))\r
385                         {\r
386                                 isAppendEscape = true;\r
387                         }\r
388                         else\r
389                         {\r
390                                 isAppendEscape = false;\r
391                         }\r
392                         r = inputExpr.Append(token);\r
393                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
394                 }\r
395                 else // value of the column\r
396                 {\r
397                         isCol = true;\r
398                         r = inputExpr.Append("'");\r
399                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
400                         r = inputExpr.Append(token);\r
401                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
402                         r = inputExpr.Append("'");\r
403                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
404 \r
405                         if (isAppendEscape)\r
406                         {\r
407                                 if (token.Contains("\\_") || token.Contains("\\%"))\r
408                                 {\r
409                                         r = inputExpr.Append("ESCAPE'\\'  ");\r
410                                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
411                                 }\r
412                         }\r
413                 }\r
414         }\r
415 \r
416         __inputExpr.Clear();\r
417         r = __inputExpr.Insert(inputExpr, 0);\r
418         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert failed.");\r
419 \r
420         return r;\r
421 }\r
422 \r
423 //This function is to replace DateTime value(osp datetime type is string) which is string with int.(SLP dateTime column type is int)\r
424 \r
425 result\r
426 _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const\r
427 {\r
428         String  delim = L"'"; //Delimeters  is  ' .\r
429         result r = E_SUCCESS;\r
430         bool isCol = true;\r
431         bool isConvertReq = false;\r
432         bool isBetweenExistsInDateTimeQuery = false;\r
433         String token;\r
434         String tokenUpper;\r
435         String inputExpr = __inputExpr;\r
436 \r
437         if(!inputExpr.Contains("MEDIA_ADDED_TIME"))\r
438         {\r
439                 return r;\r
440         }\r
441 \r
442         // Create a StringTokenizer instance\r
443         StringTokenizer  strTok(inputExpr, delim);\r
444 \r
445         inputExpr.Clear();\r
446 \r
447         while (strTok.HasMoreTokens())\r
448         {\r
449                 r = strTok.GetNextToken(token);\r
450                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "GetNextToken failed.");\r
451                 if (isCol) //column name\r
452                 {\r
453                         isCol = false;\r
454                         tokenUpper = token;\r
455                         tokenUpper.ToUpper();\r
456                         if(isBetweenExistsInDateTimeQuery)\r
457                         {\r
458                                 isBetweenExistsInDateTimeQuery = false;\r
459                                 isConvertReq = true;\r
460                         }\r
461                         else\r
462                         {\r
463                                 if (tokenUpper.Contains("MEDIA_ADDED_TIME"))\r
464                                 {\r
465                                         if (tokenUpper.Contains("BETWEEN"))\r
466                                         {\r
467                                                 isBetweenExistsInDateTimeQuery = true;\r
468                                         }\r
469                                         isConvertReq = true;\r
470                                 }\r
471                                 else\r
472                                 {\r
473                                         isConvertReq = false;\r
474                                 }\r
475                         }\r
476 \r
477                         r = inputExpr.Append(token);\r
478                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");\r
479                 }\r
480                 else // value of the column\r
481                 {\r
482                         isCol = true;\r
483                         r = inputExpr.Append("'");\r
484                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");\r
485 \r
486                         if (isConvertReq)\r
487                         {\r
488                                 Tizen::Base::DateTime dt;\r
489                                 r = Tizen::Base::DateTime::Parse(token, dt);\r
490                                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to parse DateTime.");\r
491 \r
492                                 int year = dt.GetYear();\r
493                                 int month = dt.GetMonth(); \r
494                                 int day = dt.GetDay();\r
495                                 int hour = dt.GetHour();\r
496                                 int minute = dt.GetMinute(); \r
497                                 int second = dt.GetSecond();\r
498                                 \r
499                                 time_t rawTime;\r
500                                 struct tm* timeInfo;\r
501 \r
502                                 time(&rawTime);\r
503                                 timeInfo = localtime(&rawTime);\r
504                                 timeInfo->tm_year = year - 1900;\r
505                                 timeInfo->tm_mon = month - 1;\r
506                                 timeInfo->tm_mday = day;\r
507                                 timeInfo->tm_hour = hour;\r
508                                 timeInfo->tm_min = minute;\r
509                                 timeInfo->tm_sec = second;\r
510 \r
511                                 time_t seconds = mktime(timeInfo);\r
512                                 SysTryReturnResult(NID_CNT, seconds != -1, E_INVALID_ARG, "Failed to convert DateTime to broken-down time.");\r
513 \r
514                                 long long ticksInSeconds = (long long)seconds;\r
515 \r
516                                 r = inputExpr.Append(ticksInSeconds);\r
517                                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");\r
518                         }\r
519                         else\r
520                         {\r
521                                 r = inputExpr.Append(token);\r
522                                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");\r
523                         }\r
524 \r
525                         r = inputExpr.Append("'");\r
526                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");\r
527                 }\r
528         }\r
529 \r
530         __inputExpr.Clear();\r
531         r = __inputExpr.Insert(inputExpr, 0);\r
532         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string insert failed.");\r
533 \r
534         return r;\r
535 }\r
536 \r
537 // CONTENT_TYPE_OTHER and CONTENT_TYPE_IMAGE (0 - 13 ) are valid columns\r
538 // CONTENT_TYPE_VIDEO  (0 - 16 ) are valid columns\r
539 // CONTENT_TYPE_ALL and  CONTENT_TYPE_VIDEO (0 - 18 ) are valid columns\r
540 // This functions checks for invalid column in the given input string (only allowed columns should be used by content type other wise\r
541 // E_INVALID_ARG is returned)\r
542 // StringTokenizer is used to parse input expression, by using delimater "'", to differentiate column and value.\r
543 // As values may also contain column names\r
544 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.\r
545 \r
546 result\r
547 _ContentSearchImpl::CheckInvalidColumnInQuery(void) const\r
548 {\r
549         result r = E_SUCCESS;\r
550         int tokenNo = 0;\r
551         String  delim = L"'"; //Delimeters  is  ' .\r
552          bool isColReplaceReq = true;\r
553         String token;\r
554         String inputExpr = __inputExpr;\r
555 \r
556         // Create a StringTokenizer instance\r
557         StringTokenizer  strTok(inputExpr, delim);\r
558 \r
559         inputExpr.Clear();\r
560 \r
561         while (strTok.HasMoreTokens())\r
562         {\r
563                 r = strTok.GetNextToken(token);\r
564                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "strTok GetNextToken failed.");\r
565 \r
566                 SysLog(NID_CNT, "In CheckInvalidColumnInQuery token[%d] = %ls", ++tokenNo, token.GetPointer());\r
567 \r
568                 if (isColReplaceReq)\r
569                 {\r
570                         isColReplaceReq = false;\r
571                         r = inputExpr.Append(token);\r
572                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
573                         token.ToUpper();\r
574                         switch (__contentType)\r
575                         {\r
576                         case CONTENT_TYPE_OTHER:\r
577                                 //fall through\r
578                         case CONTENT_TYPE_IMAGE:\r
579                                 if ((token.Contains("TITLE")) || (token.Contains("ARTIST")) || (token.Contains("GENRE")))\r
580                                 {\r
581                                         SysLog(NID_CNT, "Title or Artist or Genre are not valid cloumns for this content type");\r
582                                         return E_INVALID_ARG;\r
583                                 }\r
584                                 //fall through\r
585                         case CONTENT_TYPE_VIDEO:\r
586                                 if ((token.Contains("COMPOSER")) || (token.Contains("ALBUM")))\r
587                                 {\r
588                                         SysLog(NID_CNT, "Composer or Album  are not valid cloumns for this content type");\r
589                                         return E_INVALID_ARG;\r
590                                 }\r
591                                 break;\r
592                         default:\r
593                                 break;\r
594                         }\r
595                 }\r
596                 else\r
597                 {\r
598                         isColReplaceReq = true;\r
599                         r = inputExpr.Append("'");\r
600                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
601                         r = inputExpr.Append(token);\r
602                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
603                         r = inputExpr.Append("'");\r
604                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
605                 }\r
606         }\r
607         return r;\r
608 }\r
609 \r
610 // It replaces osp column name with slp column name.\r
611 // StringTokenizer is used to parse input expression, by using delimater "'", to differentiate column and value.\r
612 // As values may also contain column names\r
613 // Only column names are replaced but not values(values may contain column names)\r
614 // Ex: 1. where author = syam_author_01 2. where album = jalsa_album_name_01.\r
615 \r
616 result\r
617 _ContentSearchImpl::ReplaceString(String ospColumnName, String slpColumnName) const\r
618 {\r
619         String  delim = L"'"; //Delimeters  is  ' .\r
620         result r = E_SUCCESS;\r
621          bool isColReplaceReq = true;\r
622         String token;\r
623         String inputExpr = __inputExpr;\r
624 \r
625         // Create a StringTokenizer instance\r
626         StringTokenizer  strTok(inputExpr, delim);\r
627 \r
628         inputExpr.Clear();\r
629 \r
630         while (strTok.HasMoreTokens())\r
631         {\r
632                 r = strTok.GetNextToken(token);         // Osp, StringTokenizer, Sample, code\r
633                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string GetNextToken() failed.");\r
634                 if (isColReplaceReq) //column name\r
635                 {\r
636                         isColReplaceReq = false;\r
637                         r = token.Replace(ospColumnName, slpColumnName);\r
638                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string replace() failed.");\r
639                         r = inputExpr.Append(token);\r
640                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
641                 }\r
642                 else // value of the column\r
643                 {\r
644                         isColReplaceReq = true;\r
645                         r = inputExpr.Append("'");\r
646                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
647                         r = inputExpr.Append(token);\r
648                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
649                         r = inputExpr.Append("'");\r
650                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");\r
651                 }\r
652         }\r
653         __inputExpr.Clear();\r
654         r = __inputExpr.Insert(inputExpr, 0);\r
655         SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert() failed.");\r
656 \r
657         return r;\r
658 }\r
659 \r
660 //Retuns list of search result for the given expression and content type.\r
661 Collection::IList*\r
662 _ContentSearchImpl::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr, const String& sortColumn, SortOrder sortOrder) const\r
663 {\r
664         SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, whereExpr = %ls", pageNo, countPerPage, whereExpr.GetPointer());\r
665 \r
666         ClearLastResult();\r
667 \r
668         result r        = E_SUCCESS;\r
669         int ret         = MEDIA_CONTENT_ERROR_NONE;\r
670         int offset      = 0;\r
671 \r
672         __inputColumnName.Clear();\r
673         __inputExpr.Clear();\r
674         __inputColumnName = sortColumn;\r
675         __inputSortOrder = sortOrder;\r
676         totalPageCount = 0;\r
677         totalCount = 0;\r
678 \r
679         if (!whereExpr.IsEmpty()) // copy whereExpr if not empty to class variable __inputExpr\r
680         {\r
681                 //r = __inputExpr.Format(QUERY_LENGTH, L"%ls", whereExpr.GetPointer());\r
682                 r = __inputExpr.Append(whereExpr);\r
683                 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] __inputExpr.Append Failed as whereExpr is not empty.", GetErrorMessage(r));\r
684 \r
685                 r = ReplaceOspColumnNameWithSlp();\r
686                 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] ReplaceOspColumnNameWithSlp for InputExpr Failed.", GetErrorMessage(r));\r
687 \r
688                 SysLog(NID_CNT, "After replace __inputExpr = %ls", __inputExpr.GetPointer());\r
689         }\r
690         if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))\r
691         {\r
692                 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");\r
693                 SetLastResult(E_INVALID_ARG);\r
694                 return null;\r
695         }\r
696         else\r
697         {\r
698                 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());\r
699                 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");\r
700 \r
701                 r = pFinalOutList->Construct();\r
702                 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));\r
703 \r
704                 __pFinalOutList = std::move(pFinalOutList);\r
705 \r
706                 r = CreateQueryFilter(true);\r
707                 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to perform CreateQueryFilter operation.", GetErrorMessage(r));\r
708 \r
709                 ret = media_info_get_media_count_from_db(__pFilterHandle.get(), &totalCount);\r
710                 r = MapCoreErrorToNativeResult(ret);\r
711                 SysTryReturn(NID_CNT, r == E_SUCCESS , NULL, r, "[%s] Failed to perform media_info_get_media_count_from_db operation.", GetErrorMessage(r));\r
712 \r
713                 SysLog(NID_CNT, "totalCount is [%d] for media_info_get_media_count_from_db", totalCount);\r
714 \r
715                 if (totalCount > 0)\r
716                 {\r
717                         if ((totalCount % countPerPage) == 0)\r
718                         {\r
719                                 totalPageCount = totalCount / countPerPage;\r
720                         }\r
721                         else\r
722                         {\r
723                                 totalPageCount = (totalCount / countPerPage) + 1;\r
724                         }\r
725 \r
726                         SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");\r
727 \r
728                         offset = (pageNo * countPerPage) - countPerPage;\r
729 \r
730                         SysLog(NID_CNT, " SearchN   totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",\r
731                                         totalCount, totalPageCount, countPerPage, pageNo, offset);\r
732 \r
733                         ret = media_filter_set_offset(__pFilterHandle.get(), offset, countPerPage);\r
734                         r = MapCoreErrorToNativeResult(ret);\r
735                         SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r,\r
736                         "[%s] Failed to perform media_filter_set_offset operation.", GetErrorMessage(r));\r
737 \r
738                         r = ExecuteAndFillFinalOutList();\r
739                         SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, E_SYSTEM, "[E_SYSTEM] ExecuteAndFillFinalOutList Failed.");\r
740                 }\r
741                 else if (pageNo > 1)\r
742                 {\r
743                         r = E_INVALID_ARG;\r
744                         SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] (pageNo > 1) and  (totalcount = 0).");\r
745                 }\r
746         }\r
747         SetLastResult(r);\r
748         return __pFinalOutList.release();\r
749 }\r
750 \r
751 // Fills final result list\r
752 result\r
753 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const\r
754 {\r
755         SysLog(NID_CNT, "Enter\n");\r
756 \r
757         int ret                                         = MEDIA_CONTENT_ERROR_NONE;\r
758         result r                                        = E_SUCCESS;\r
759 \r
760         std::unique_ptr<GList, SearchGListDeleter> pItemList;\r
761         GList* pTemp = NULL;\r
762         std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;\r
763 \r
764         ContentInfo::_ContentData* pContentData = null;\r
765         ImageContentInfo::_ImageContentData* pImageContentData = null;\r
766         AudioContentInfo::_AudioContentData* pAudioContentData = null;\r
767         VideoContentInfo::_VideoContentData* pVideoContentData = null;\r
768 \r
769         std::unique_ptr<ImageContentInfo> pImageContentInfo;\r
770         std::unique_ptr<AudioContentInfo> pAudioContentInfo;\r
771         std::unique_ptr<VideoContentInfo> pVideoContentInfo;\r
772         std::unique_ptr<OtherContentInfo> pOtherContentInfo;\r
773 \r
774         std::unique_ptr<ContentSearchResult> pContentSearchResult;\r
775 \r
776         pTemp = pItemList.get();\r
777 \r
778         ret = media_info_foreach_media_from_db(__pFilterHandle.get(), MediaItemCb, &pTemp);\r
779         r = MapCoreErrorToNativeResult(ret);\r
780         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_info_foreach_media_from_db operation.");\r
781 \r
782         SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");\r
783 \r
784         media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;\r
785 \r
786         for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)\r
787         {\r
788                 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));\r
789 \r
790                 ret = media_info_get_media_type(pMediaHandle.get(), &mediaType);\r
791                 r = MapCoreErrorToNativeResult(ret);\r
792                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_info_get_media_type.");\r
793 \r
794                 switch (mediaType)\r
795                 {\r
796                 case MEDIA_CONTENT_TYPE_OTHERS:\r
797                         //memset(&contentData, 0, sizeof(contentData));\r
798 \r
799                         pOtherContentInfo = std::unique_ptr<OtherContentInfo>(new (std::nothrow) OtherContentInfo);\r
800                         SysTryReturnResult(NID_CNT, pOtherContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pOtherContentInfo.");\r
801 \r
802                         pContentData = pOtherContentInfo->GetContentData();\r
803                         SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
804 \r
805                         r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);\r
806                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");\r
807 \r
808 \r
809                         pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);\r
810                         SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");\r
811 \r
812                         pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);\r
813                         pContentSearchResult->SetContentInfo(pOtherContentInfo.release());\r
814 \r
815                         // Shallow copy, adds just the pointer: not the element\r
816 \r
817                         r = __pFinalOutList->Add(*(pContentSearchResult.release()));\r
818                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");\r
819 \r
820                         //pOtherContentInfo = null;\r
821                         //pContentSearchResult = null;\r
822                         //_ContentUtility::DeleteContentData(&contentData);\r
823                         break;\r
824                 case MEDIA_CONTENT_TYPE_IMAGE:\r
825                         //memset(&contentData, 0, sizeof(contentData));\r
826                         //memset(&imageContentData, 0, sizeof(imageContentData));\r
827 \r
828                         pImageContentInfo = std::unique_ptr<ImageContentInfo>(new (std::nothrow) ImageContentInfo);\r
829                         SysTryReturnResult(NID_CNT, pImageContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pImageContentInfo.");\r
830 \r
831                         pContentData = pImageContentInfo->GetContentData();\r
832                         SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
833 \r
834                         pImageContentData = pImageContentInfo->GetImageContentData();\r
835                         SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
836 \r
837                         r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);\r
838                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");\r
839 \r
840                         r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentData);\r
841                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");\r
842 \r
843                         pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);\r
844                         SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");\r
845 \r
846                         pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);\r
847                         pContentSearchResult->SetContentInfo(pImageContentInfo.release());\r
848 \r
849                         // Shallow copy, adds just the pointer: not the element\r
850 \r
851                         r = __pFinalOutList->Add(*(pContentSearchResult.release()));\r
852                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");\r
853                         //pImageContentInfo = null;\r
854                         //pContentSearchResult = null;\r
855                         //_ContentUtility::DeleteContentData(&contentData);\r
856                         break;\r
857                 case MEDIA_CONTENT_TYPE_MUSIC:\r
858                         //fall through\r
859                 case MEDIA_CONTENT_TYPE_SOUND:\r
860                         //memset(&contentData, 0, sizeof(contentData));\r
861                         //memset(&audioContentData, 0, sizeof(audioContentData));\r
862 \r
863                         pAudioContentInfo = std::unique_ptr<AudioContentInfo>(new (std::nothrow) AudioContentInfo);\r
864                         SysTryReturnResult(NID_CNT, pAudioContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pAudioContentInfo.");\r
865 \r
866                         pContentData = pAudioContentInfo->GetContentData();\r
867                         SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
868 \r
869                         pAudioContentData = pAudioContentInfo->GetAudioContentData();\r
870                         SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
871 \r
872                         r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);\r
873                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");\r
874 \r
875                         r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentData);\r
876                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");\r
877 \r
878                         pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);\r
879                         SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");\r
880 \r
881                         pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);\r
882                         pContentSearchResult->SetContentInfo(pAudioContentInfo.release());\r
883 \r
884                         // Shallow copy, adds just the pointer: not the element\r
885 \r
886                         r = __pFinalOutList->Add(*(pContentSearchResult.release()));\r
887                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");\r
888 \r
889                         //pAudioContentInfo = null;\r
890                         //pContentSearchResult = null;\r
891                         //_ContentUtility::DeleteContentData(&contentData);\r
892                         //_ContentUtility::DeleteAudioContentData(&audioContentData);\r
893                         break;\r
894                 case MEDIA_CONTENT_TYPE_VIDEO:\r
895                         //memset(&contentData, 0, sizeof(contentData));\r
896                         //memset(&videoContentData, 0, sizeof(videoContentData));\r
897 \r
898                         pVideoContentInfo = std::unique_ptr<VideoContentInfo>(new (std::nothrow) VideoContentInfo);\r
899                         SysTryReturnResult(NID_CNT, pVideoContentInfo.get() != null, E_OUT_OF_MEMORY, "Failed to create pVideoContentInfo.");\r
900 \r
901                         pContentData = pVideoContentInfo->GetContentData();\r
902                         SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
903 \r
904                         pVideoContentData = pVideoContentInfo->GetVideoContentData();\r
905                         SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");\r
906 \r
907                         r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);\r
908                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");\r
909 \r
910                         r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentData);\r
911                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");\r
912 \r
913                         pContentSearchResult = std::unique_ptr<ContentSearchResult>(new (std::nothrow) ContentSearchResult);\r
914                         SysTryReturnResult(NID_CNT, pContentSearchResult.get() != null, E_OUT_OF_MEMORY, "Failed to create pContentSearchResult.");\r
915 \r
916                         pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);\r
917                         pContentSearchResult->SetContentInfo(pVideoContentInfo.release());\r
918 \r
919                         // Shallow copy, adds just the pointer: not the element\r
920 \r
921                         r = __pFinalOutList->Add(*(pContentSearchResult.release()));\r
922                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");\r
923 \r
924                         //pVideoContentInfo = null;\r
925                         //pContentSearchResult = null;\r
926                         //_ContentUtility::DeleteContentData(&contentData);\r
927                         //_ContentUtility::DeleteVideoContentData(&videoContentData);\r
928                         break;\r
929                 default:\r
930                         break;\r
931                 }\r
932         }\r
933         return r;\r
934 }\r
935 \r
936 // returns  given column value list in the requested order\r
937 Collection::IList*\r
938 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)\r
939 {\r
940         SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());\r
941         ClearLastResult();\r
942 \r
943         result r        = E_SUCCESS;\r
944         int colIndex    = 0;\r
945         int maxCols     = 0;\r
946 \r
947         __inputColumnName.Clear();\r
948         __inputExpr.Clear();\r
949 \r
950         __inputColumnName = sortColumn;\r
951         __inputSortOrder  = sortOrder;\r
952 \r
953         String          ospColumnName(L"");\r
954         String          slpColumnName(L"");\r
955 \r
956         String          columnName(__inputColumnName);\r
957 \r
958         if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))\r
959         {\r
960                 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");\r
961                 SetLastResult(E_INVALID_ARG);\r
962                 return null;\r
963         }\r
964         else\r
965         {\r
966                 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());\r
967                 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");\r
968 \r
969                 r = pFinalOutList->Construct();\r
970                 SysTryReturn(NID_CNT, !IsFailed(r), NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");\r
971 \r
972                 __pFinalOutList = std::move(pFinalOutList);\r
973 \r
974                 switch (__contentType)\r
975                 {\r
976                 case CONTENT_TYPE_OTHER:\r
977                         //fall through\r
978                 case CONTENT_TYPE_IMAGE:\r
979                         maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;\r
980                         break;\r
981                 case CONTENT_TYPE_VIDEO:\r
982                         maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;\r
983                         break;\r
984                 case CONTENT_TYPE_AUDIO:\r
985                         //fall through\r
986                 case CONTENT_TYPE_ALL:\r
987                         maxCols = MAX_QUERY_COLUMNS;\r
988                         break;\r
989                 default:\r
990                         break;\r
991                 }\r
992 \r
993                 for (colIndex = 0; colIndex < maxCols; colIndex++)\r
994                 {\r
995                         ospColumnName.Clear();\r
996                         slpColumnName.Clear();\r
997 \r
998                         ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;\r
999                         slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;\r
1000 \r
1001                         ospColumnName.ToUpper();\r
1002                         columnName.ToUpper();\r
1003                         if (columnName == ospColumnName)\r
1004                         {\r
1005                                 r = FillColumnsList(colIndex);\r
1006                                 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));\r
1007                                 break;\r
1008                         }\r
1009                 }\r
1010                 if (colIndex == maxCols)\r
1011                 {\r
1012                         r = E_INVALID_ARG;\r
1013                         SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");\r
1014                 }\r
1015         }\r
1016         SetLastResult(r);\r
1017         return __pFinalOutList.release();\r
1018 }\r
1019 \r
1020 // returns  given column value list in the requested order\r
1021 Collection::IList*\r
1022 _ContentSearchImpl::GetValueListN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& sortColumn, SortOrder sortOrder) const\r
1023 {\r
1024         SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());\r
1025 \r
1026         ClearLastResult();\r
1027 \r
1028         result r        = E_SUCCESS;\r
1029         int colIndex    = 0;\r
1030         int maxCols     = 0;\r
1031 \r
1032         __inputColumnName.Clear();\r
1033         __inputExpr.Clear();\r
1034 \r
1035         __inputColumnName = sortColumn;\r
1036         __inputSortOrder  = sortOrder;\r
1037 \r
1038         String          ospColumnName(L"");\r
1039         String          slpColumnName(L"");\r
1040 \r
1041         String          columnName(__inputColumnName);\r
1042 \r
1043         if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))\r
1044         {\r
1045                 SysLog(NID_CNT, "sort column name is empty and sort oder is not none. so,E_INVALID_ARG occured.");\r
1046                 SetLastResult(E_INVALID_ARG);\r
1047                 return null;\r
1048         }\r
1049         else\r
1050         {\r
1051                 std::unique_ptr<ArrayList, AllElementsDeleter> pFinalOutList(new (std::nothrow) ArrayList());\r
1052                 SysTryReturn(NID_CNT, pFinalOutList.get() != null, NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to construct ArrayList.");\r
1053 \r
1054                 r = pFinalOutList->Construct();\r
1055                 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));\r
1056 \r
1057                 __pFinalOutList = std::move(pFinalOutList);\r
1058 \r
1059                 switch (__contentType)\r
1060                 {\r
1061                 case CONTENT_TYPE_OTHER:\r
1062                         //fall through\r
1063                 case CONTENT_TYPE_IMAGE:\r
1064                         maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;\r
1065                         break;\r
1066                 case CONTENT_TYPE_VIDEO:\r
1067                         maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;\r
1068                         break;\r
1069                 case CONTENT_TYPE_AUDIO:\r
1070                         //fall through\r
1071                 case CONTENT_TYPE_ALL:\r
1072                         maxCols = MAX_QUERY_COLUMNS;\r
1073                         break;\r
1074                 default:\r
1075                         break;\r
1076                 }\r
1077 \r
1078                 for (colIndex = 0; colIndex < maxCols; colIndex++)\r
1079                 {\r
1080                         ospColumnName.Clear();\r
1081                         slpColumnName.Clear();\r
1082 \r
1083                         ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;\r
1084                         slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;\r
1085 \r
1086                         ospColumnName.ToUpper();\r
1087                         columnName.ToUpper();\r
1088                         if (columnName == ospColumnName)\r
1089                         {\r
1090                                 r = FillColumnsList(pageNo, countPerPage, totalPageCount, totalCount, colIndex);\r
1091                                 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));\r
1092                                 break;\r
1093                         }\r
1094                 }\r
1095                 if (colIndex == maxCols)\r
1096                 {\r
1097                         r = E_INVALID_ARG;\r
1098                         SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");\r
1099                 }\r
1100         }\r
1101         SetLastResult(r);\r
1102         return __pFinalOutList.release();\r
1103 }\r
1104 \r
1105 // prepares query expression to be used in group api. colIndex is mapped to actual group value.\r
1106 media_group_e\r
1107 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const\r
1108 {\r
1109         media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;\r
1110         switch (colIndex)\r
1111         {\r
1112         case 0://"ContentType", "MEDIA_TYPE"\r
1113                 groupIndex = MEDIA_CONTENT_GROUP_TYPE;\r
1114                 __inputExpr = "MEDIA_TYPE IS NOT NULL";\r
1115                 break;\r
1116         case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"\r
1117                 groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;\r
1118                 __inputExpr = "MEDIA_DISPLAY_NAME IS NOT NULL";\r
1119                 break;\r
1120         case 2://"ContentName", "MEDIA_CONTENT_NAME"\r
1121                 groupIndex = MEDIA_CONTENT_GROUP_CONTENT_NAME;\r
1122                 __inputExpr = "MEDIA_CONTENT_NAME IS NOT NULL";\r
1123                 break;\r
1124         case 3://"Category", "MEDIA_CATEGORY"\r
1125                 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;\r
1126                 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";\r
1127                 break;\r
1128         case 4://"Author", "MEDIA_AUTHOR"\r
1129                 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;\r
1130                 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";\r
1131                 break;\r
1132         case 5://"keyword", "MEDIA_KEYWORD"\r
1133                 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;\r
1134                 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";\r
1135                 break;\r
1136         case 6://"Provider", "MEDIA_PROVIDER"\r
1137                 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;\r
1138                 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";\r
1139                 break;\r
1140         case 7://"Rating", "MEDIA_AGE_RATING"\r
1141                 groupIndex = MEDIA_CONTENT_GROUP_AGE_RATING;\r
1142                 __inputExpr = "MEDIA_AGE_RATING IS NOT NULL";\r
1143                 break;\r
1144         case 8://"LocationTag", "MEDIA_LOCATION_TAG"\r
1145                 groupIndex = MEDIA_CONTENT_GROUP_LOCATION_TAG;\r
1146                 __inputExpr = "MEDIA_LOCATION_TAG IS NOT NULL";\r
1147                 break;\r
1148         case 9://"ContentSize", "MEDIA_SIZE"\r
1149                 groupIndex = MEDIA_CONTENT_GROUP_SIZE;\r
1150                 __inputExpr = "MEDIA_SIZE IS NOT NULL";\r
1151                 break;\r
1152         case 10://"DateTime", "MEDIA_ADDED_TIME"\r
1153                 groupIndex = MEDIA_CONTENT_GROUP_ADDED_TIME;\r
1154                 __inputExpr = "MEDIA_ADDED_TIME IS NOT NULL";\r
1155                 break;\r
1156         case 11://"Latitude", "MEDIA_LATITUDE"\r
1157                 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;\r
1158                 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";\r
1159                 break;\r
1160         case 12://"Longitude", "MEDIA_LONGITUDE"\r
1161                 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;\r
1162                 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";\r
1163                 break;\r
1164         case 13://"Altitude", "MEDIA_ALTITUDE"\r
1165                 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;\r
1166                 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";\r
1167                 break;\r
1168         case 14://"Title", "MEDIA_TITLE"\r
1169                 groupIndex = MEDIA_CONTENT_GROUP_TITLE;\r
1170                 __inputExpr = "MEDIA_TITLE IS NOT NULL";\r
1171                 break;\r
1172         case 15://"Artist", "MEDIA_ARTIST"\r
1173                 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;\r
1174                 __inputExpr = "MEDIA_ARTIST IS NOT NULL";\r
1175                 break;\r
1176         case 16://"Genre", "MEDIA_GENRE"\r
1177                 groupIndex = MEDIA_CONTENT_GROUP_GENRE;\r
1178                 __inputExpr = "MEDIA_GENRE IS NOT NULL";\r
1179                 break;\r
1180         case 17://"Year", "MEDIA_YEAR"\r
1181                 groupIndex = MEDIA_CONTENT_GROUP_YEAR;\r
1182                 __inputExpr = "MEDIA_YEAR IS NOT NULL";\r
1183                 break;\r
1184         case 18://"Composer", "MEDIA_COMPOSER"\r
1185                 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;\r
1186                 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";\r
1187                 break;\r
1188         case 19://"Album", "MEDIA_ALBUM"\r
1189                 __inputExpr = "MEDIA_ALBUM IS NOT NULL";\r
1190                 break;\r
1191         default:\r
1192                 break;\r
1193         }\r
1194         return groupIndex;\r
1195 }\r
1196 \r
1197 // Fills  given column value list and destroys filter handle\r
1198 result\r
1199 _ContentSearchImpl::FillColumnsList(int colIndex) const\r
1200 {\r
1201         result r        = E_SUCCESS;\r
1202         int ret         = MEDIA_CONTENT_ERROR_NONE;\r
1203         int totalCount  = 0;\r
1204         media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);\r
1205 \r
1206         r = CreateQueryFilter(true);\r
1207         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");\r
1208 \r
1209         if (colIndex == ALBUM_COLUMN_NUM)\r
1210         {\r
1211                 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);\r
1212         }\r
1213         else\r
1214         {\r
1215                 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);\r
1216         }\r
1217         r = MapCoreErrorToNativeResult(ret);\r
1218         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");\r
1219 \r
1220         SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);\r
1221 \r
1222         if (totalCount > 0)\r
1223         {\r
1224                 if (colIndex == ALBUM_COLUMN_NUM)\r
1225                 {\r
1226                         r = ExecuteAndFillAlbumValues();\r
1227                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");\r
1228                 }\r
1229                 else\r
1230                 {\r
1231                         r = ExecuteAndFillGetValueListN(groupIndex, colIndex);\r
1232                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");\r
1233                 }\r
1234         }\r
1235         return r;\r
1236 }\r
1237 \r
1238 // prepares input expression to be sent for create filter and fills  given column value list\r
1239 result\r
1240 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const\r
1241 {\r
1242         result r        = E_SUCCESS;\r
1243         int ret         = MEDIA_CONTENT_ERROR_NONE;\r
1244         int offset      = 0;\r
1245         totalPageCount = 0;\r
1246         totalCount = 0;\r
1247         media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);\r
1248 \r
1249         r = CreateQueryFilter(true);\r
1250         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");\r
1251 \r
1252         if (colIndex == ALBUM_COLUMN_NUM)\r
1253         {\r
1254                 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);\r
1255         }\r
1256         else\r
1257         {\r
1258                 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);\r
1259         }\r
1260         r = MapCoreErrorToNativeResult(ret);\r
1261         SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "Failed to perform media_album/group count_from_db operation.");\r
1262 \r
1263         SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);\r
1264 \r
1265         if (totalCount > 0)\r
1266         {\r
1267                 if ((totalCount % countPerPage) == 0)\r
1268                 {\r
1269                         totalPageCount = totalCount / countPerPage;\r
1270                 }\r
1271                 else\r
1272                 {\r
1273                         totalPageCount = (totalCount / countPerPage) + 1;\r
1274                 }\r
1275 \r
1276                 if ((pageNo < 1) || (pageNo > totalPageCount))\r
1277                 {\r
1278                         r = E_INVALID_ARG;\r
1279                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo < 1) || (pageNo > totalPageCount).");\r
1280                 }\r
1281 \r
1282                 offset = (pageNo * countPerPage) - countPerPage;\r
1283 \r
1284                 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",\r
1285                                 totalCount, totalPageCount, countPerPage, pageNo, offset);\r
1286 \r
1287                 ret = media_filter_set_offset(__pFilterHandle.get(),offset,countPerPage);\r
1288                 r = MapCoreErrorToNativeResult(ret);\r
1289                 SysTryReturnResult(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, r, "failed to perform media_filter_set_offset operation.");\r
1290 \r
1291                 if (colIndex == ALBUM_COLUMN_NUM)\r
1292                 {\r
1293                         r = ExecuteAndFillAlbumValues();\r
1294                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");\r
1295                 }\r
1296                 else\r
1297                 {\r
1298                         r = ExecuteAndFillGetValueListN(groupIndex, colIndex);\r
1299                         SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");\r
1300                 }\r
1301 \r
1302         }\r
1303         else if (pageNo > 1)\r
1304         {\r
1305                 r = E_INVALID_ARG;\r
1306                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo > 1) and  (totalcount = 0).");\r
1307         }\r
1308 \r
1309         return r;\r
1310 }\r
1311 \r
1312 //  fills  given column value list for GetValuelistN api\r
1313 result\r
1314 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const\r
1315 {\r
1316         SysLog(NID_CNT, "Enter\n");\r
1317 \r
1318         int ret                     = MEDIA_CONTENT_ERROR_NONE;\r
1319         result r                    = E_SUCCESS;\r
1320         result res                  = E_SUCCESS;\r
1321         std::unique_ptr<GList, SearchGListDeleter> pItemList;\r
1322         GList* pTemp = NULL;\r
1323 \r
1324         std::unique_ptr<Object> pValue;\r
1325 \r
1326         DateTime dateTime;\r
1327 \r
1328         long long contentSize = 0;\r
1329         long long addedTime     = 0;\r
1330 \r
1331         double dVal     = 0;\r
1332         char *pColumnVal = null;\r
1333         int contentType = 0;\r
1334 \r
1335         pTemp = pItemList.get();\r
1336 \r
1337         ret = media_group_foreach_group_from_db(__pFilterHandle.get(), groupIndex, GroupItemCb, &pTemp);\r
1338         r = MapCoreErrorToNativeResult(ret);\r
1339         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_group_foreach_group_from_db operation.");\r
1340 \r
1341         SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");\r
1342 \r
1343         for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)\r
1344         {\r
1345                 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));\r
1346 \r
1347                 pColumnVal = (char *)g_list_nth_data(pTemp, idx);\r
1348 \r
1349                 String strColVal(pColumnVal);\r
1350 \r
1351                 _ContentUtility::DoSafeFree(pColumnVal);\r
1352 \r
1353                 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());\r
1354 \r
1355                 switch (colIndex)\r
1356                 {\r
1357                 case 0://"ContentType", "MEDIA_TYPE"\r
1358                         if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))\r
1359                         {\r
1360                                 res = Integer::Parse(strColVal, contentType);\r
1361                                 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));\r
1362                         }\r
1363                         switch ((media_content_type_e)contentType)\r
1364                         {\r
1365                         case MEDIA_CONTENT_TYPE_OTHERS:\r
1366                                 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_OTHER));\r
1367                                 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_OTHER");\r
1368                                 break;\r
1369                         case MEDIA_CONTENT_TYPE_IMAGE:\r
1370                                 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_IMAGE));\r
1371                                 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_IMAGE");\r
1372                                 break;\r
1373                         case MEDIA_CONTENT_TYPE_SOUND:\r
1374                                 //fall through\r
1375                         case MEDIA_CONTENT_TYPE_MUSIC:\r
1376                                 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_AUDIO));\r
1377                                 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_AUDIO");\r
1378                                 break;\r
1379                         case MEDIA_CONTENT_TYPE_VIDEO:\r
1380                                 pValue.reset(new (std::nothrow) String(CONTENT_TYPE_VIDEO));\r
1381                                 SysLog(NID_CNT, "mediaType = CONTENT_TYPE_VIDEO");\r
1382                                 break;\r
1383                         default:\r
1384                                 break;\r
1385                         }\r
1386                         break;\r
1387                 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"\r
1388                 //fall through\r
1389                 case 2://"ContentName", "MEDIA_CONTENT_NAME"\r
1390                 //fall through\r
1391                 case 3://"Category", "MEDIA_CATEGORY"\r
1392                 //fall through\r
1393                 case 4://"Author", "MEDIA_AUTHOR"\r
1394                 //fall through\r
1395                 case 5://"keyword", "MEDIA_KEYWORD"\r
1396                 //fall through\r
1397                 case 6://"Provider", "MEDIA_PROVIDER"\r
1398                 //fall through\r
1399                 case 7://"Rating", "MEDIA_AGE_RATING"\r
1400                 //fall through\r
1401                 case 8://"LocationTag", "MEDIA_LOCATION_TAG"\r
1402                 //fall through\r
1403                 case 14://"Title", "MEDIA_TITLE"\r
1404                 //fall through\r
1405                 case 15://"Artist", "MEDIA_ARTIST"\r
1406                 //fall through\r
1407                 case 16://"Genre", "MEDIA_GENRE"\r
1408                 //fall through\r
1409                 case 17://"Year", "MEDIA_YEAR"\r
1410                 //fall through\r
1411                 case 18://"Composer", "MEDIA_COMPOSER"\r
1412 \r
1413                         pValue.reset(new (std::nothrow) String(strColVal));\r
1414                         break;\r
1415 \r
1416                 case 9://"ContentSize", "MEDIA_SIZE" \r
1417                         if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))\r
1418                         {\r
1419                                 res = LongLong::Parse(strColVal, contentSize);\r
1420                                 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));\r
1421                         }\r
1422 \r
1423                         pValue.reset(new (std::nothrow) LongLong(contentSize));\r
1424                         break;\r
1425                 case 10://"DateTime", "MEDIA_ADDED_TIME" \r
1426                         if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))\r
1427                         {\r
1428                                 res = LongLong::Parse(strColVal, addedTime);\r
1429                                 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));\r
1430                         }\r
1431 \r
1432                         res = dateTime.SetValue(1970, 1, 1);\r
1433                         SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));\r
1434 \r
1435                         res = dateTime.AddSeconds(addedTime);\r
1436                         SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));\r
1437 \r
1438                         SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());\r
1439 \r
1440                         pValue.reset(new (std::nothrow) DateTime(dateTime));\r
1441 \r
1442                         break;\r
1443                 case 11://"Latitude", "MEDIA_LATITUDE"\r
1444                         //fall through\r
1445                 case 12://"Longitude", "MEDIA_LONGITUDE"\r
1446                         //fall through\r
1447                 case 13://"Altitude", "MEDIA_ALTITUDE"\r
1448                         if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))\r
1449                         {
1450                                 dVal = _LocalizedNumParser::ToDouble(strColVal, "C");\r
1451                                 r = GetLastResult();\r
1452                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Failed to perform ToDouble operation.");
1453                         }\r
1454                         pValue.reset(new (std::nothrow) Double(dVal));\r
1455                         break;\r
1456 \r
1457                 case 19://"Album", "MEDIA_ALBUM"\r
1458                         break;\r
1459                 default:\r
1460                         break;\r
1461                 }\r
1462                 if (pValue.get() != NULL)\r
1463                 {\r
1464                         r = __pFinalOutList->Add(*(pValue.release()));\r
1465                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");\r
1466                 }\r
1467         }\r
1468 \r
1469         return r;\r
1470 }\r
1471 \r
1472 result\r
1473 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const\r
1474 {\r
1475         int ret = MEDIA_CONTENT_ERROR_NONE;\r
1476         result r = E_SUCCESS;\r
1477         std::unique_ptr<GList, SearchGListDeleter> pItemList;\r
1478         GList* pTemp = NULL;\r
1479         std::unique_ptr<media_album_s, AlbumHandleDeleter> pAlbumHandle;\r
1480         std::unique_ptr<media_album_s, AlbumHandleDeleter> pTempAlbumHandle;\r
1481 \r
1482         char* pName = NULL;\r
1483         std::unique_ptr<char, CharDeleter> pAlbumName;\r
1484         std::unique_ptr< String > pValue;\r
1485         int lastIndex = 0;\r
1486 \r
1487         pTemp = pItemList.get();\r
1488 \r
1489         ret = media_album_foreach_album_from_db(__pFilterHandle.get(), AlbumItemCb, &pTemp);\r
1490         r = MapCoreErrorToNativeResult(ret);\r
1491         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform media_album_foreach_album_from_db operation.");\r
1492         SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");\r
1493 \r
1494         for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)\r
1495         {\r
1496                 pAlbumHandle.reset(static_cast<media_album_h>(g_list_nth_data(pTemp, idx)));\r
1497                 ret = media_album_get_name(pAlbumHandle.get(), &pName);\r
1498                 r = MapCoreErrorToNativeResult(ret);\r
1499                 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform media_album_get_name.");\r
1500                 \r
1501                 if (pName != NULL)\r
1502                 {\r
1503                         SysLog(NID_CNT, "pColumnVal = %s", pName);\r
1504 \r
1505                         pAlbumName.reset(pName);\r
1506                         pValue.reset(new (std::nothrow) String(pAlbumName.get()));\r
1507                         SysTryReturnResult(NID_CNT, pValue != NULL, E_OUT_OF_MEMORY, "media_info_foreach_media_from_db pTemp is null.");\r
1508 \r
1509                         if (idx == 0)\r
1510                         {\r
1511                                 r = __pFinalOutList->Add(pValue.get());\r
1512                                 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");\r
1513                                 pValue.release();\r
1514                         }\r
1515                         else\r
1516                         {\r
1517                                 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));\r
1518 \r
1519                                 if (pValue->CompareTo(*pTempNameList) != 0)\r
1520                                 {\r
1521                                         r = __pFinalOutList->Add(pValue.get());\r
1522                                         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");\r
1523 \r
1524                                         pValue.release();\r
1525                                         lastIndex++;\r
1526                                 }\r
1527                         }\r
1528                 }\r
1529         }\r
1530 \r
1531         return r;\r
1532 }\r
1533 \r
1534 result\r
1535 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const\r
1536 {\r
1537         result r = E_SUCCESS;\r
1538 \r
1539         switch (reason)\r
1540         {\r
1541         case MEDIA_CONTENT_ERROR_NONE:\r
1542                 r = E_SUCCESS;\r
1543                 break;\r
1544 \r
1545         case MEDIA_CONTENT_ERROR_INVALID_PARAMETER:\r
1546                 r = E_INVALID_ARG;\r
1547                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_INVALID_PARAMETER");\r
1548                 break;\r
1549 \r
1550         case MEDIA_CONTENT_ERROR_DB_FAILED:\r
1551                 r = E_SYSTEM;\r
1552                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");\r
1553                 break;\r
1554 \r
1555         case MEDIA_CONTENT_ERROR_OUT_OF_MEMORY:\r
1556                 r = E_OUT_OF_MEMORY;\r
1557                 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_OUT_OF_MEMORY");\r
1558                 break;\r
1559 \r
1560         default:\r
1561                 SysLog(NID_CNT, "default");\r
1562                 r = E_SYSTEM;\r
1563                 break;\r
1564         }\r
1565         return r;\r
1566 }\r
1567 \r
1568 //Callback function registered to each media info details\r
1569 // all items are appened to the list\r
1570 bool\r
1571 MediaItemCb(media_info_h media, void* pUserdata)\r
1572 {\r
1573         int ret  = MEDIA_CONTENT_ERROR_NONE;\r
1574         media_info_h new_media = NULL;\r
1575         ret = media_info_clone(&new_media, media);\r
1576         SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_info_clone");\r
1577 \r
1578         GList** pList = (GList**)pUserdata;\r
1579         *pList = g_list_append(*pList, new_media);\r
1580 \r
1581         return true;\r
1582 }\r
1583 \r
1584 //Callback function registered for column values\r
1585 // all items are appened to the list\r
1586 bool\r
1587 GroupItemCb(const char* pGroupName, void* pUserdata)\r
1588 {\r
1589         char* pGrpName = strdup(pGroupName);\r
1590         GList** pList = (GList**)pUserdata;\r
1591         *pList = g_list_append(*pList, pGrpName);\r
1592 \r
1593         return true;\r
1594 }\r
1595 \r
1596 //Callback function registered to each media info details\r
1597 // all items are appened to the list\r
1598 bool\r
1599 AlbumItemCb(media_album_h album, void* pUserdata)\r
1600 {\r
1601         int ret  = MEDIA_CONTENT_ERROR_NONE;\r
1602         media_album_h new_album = NULL;\r
1603         ret = media_album_clone(&new_album, album);\r
1604         SysTryLog(NID_CNT, ret == MEDIA_CONTENT_ERROR_NONE, "[E_SYSTEM] Failed to perform media_album_clone");\r
1605 \r
1606         GList** pList = (GList**)pUserdata;\r
1607         *pList = g_list_append(*pList, new_album);\r
1608 \r
1609         return true;\r
1610 }\r
1611 \r
1612 }}\r