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