2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
\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
8 // http://www.apache.org/licenses/LICENSE-2.0
\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
17 * @file FCnt_ContentSearchImpl.cpp
\r
18 * @brief This is the implementation file for the %_ContentSearchImpl class.
\r
20 * This file contains implementation of the %_ContentSearchImpl class.
\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
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
42 namespace Tizen { namespace Content
\r
45 static const int QUERY_LENGTH = 4096;
\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
54 // Default constructor
\r
55 _ContentSearchImpl::_ContentSearchImpl(void)
\r
57 , __contentType(CONTENT_TYPE_UNKNOWN)
\r
58 , __pFinalOutList(NULL)
\r
60 , __inputColumnName(L"")
\r
61 , __inputSortOrder(SORT_ORDER_NONE)
\r
62 , __pFilterHandle(NULL)
\r
64 SysLog(NID_CNT, "Enter\n");
\r
68 // Default destructor (disconnects the DB connection)
\r
69 _ContentSearchImpl::~_ContentSearchImpl(void)
\r
71 SysLog(NID_CNT, "Enter\n");
\r
73 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
74 result r = E_SUCCESS;
\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
82 _ContentSearchImpl::GetInstance(ContentSearch& contentSearch)
\r
84 return contentSearch.__pImpl;
\r
87 const _ContentSearchImpl*
\r
88 _ContentSearchImpl::GetInstance(const ContentSearch& contentSearch)
\r
90 return contentSearch.__pImpl;
\r
93 //make a connection to DB
\r
95 _ContentSearchImpl::Construct(ContentType type)
\r
97 SysLog(NID_CNT, "Enter\n");
\r
99 result r = E_SUCCESS;
\r
100 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
102 ret = media_content_connect();
\r
103 SysTryReturnResult(NID_CNT, r == E_SUCCESS , E_SYSTEM, "Failed to perform media_content_connect operation.");
\r
105 __contentType = type;
\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
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
121 _ContentSearchImpl::CreateQueryFilter(bool isAndAppendReq) const
\r
123 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
124 result r = E_SUCCESS;
\r
126 std::unique_ptr<char[]> pInputCond;
\r
127 std::unique_ptr<char[]> pSortCol;
\r
129 String inputCondition;
\r
132 filter_h tempFilter = NULL;
\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
137 std::unique_ptr<filter_s, SearchFilterHandleDeleter> pFilterHandle(tempFilter);
138 SysTryReturnResult(NID_CNT, pFilterHandle != null, E_OUT_OF_MEMORY, "pFilterHandle is null.");
\r
140 switch (__contentType)
\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
146 case CONTENT_TYPE_IMAGE:
\r
147 inputCondition = "MEDIA_TYPE=0 ";
\r
149 case CONTENT_TYPE_AUDIO:
\r
150 inputCondition = "(MEDIA_TYPE=2 or MEDIA_TYPE=3) ";
\r
152 case CONTENT_TYPE_VIDEO:
\r
153 inputCondition = "MEDIA_TYPE=1 ";
\r
155 case CONTENT_TYPE_ALL:
\r
156 //If content type is CONTENT_TYPE_ALL, then MEDIA_TYPE is empty
\r
162 if (!__inputExpr.IsEmpty())
\r
164 if (isAndAppendReq && (!inputCondition.IsEmpty())) //For CONTENT_TYPE_ALL inputCondition is empty
\r
166 r = inputCondition.Append("AND ");
\r
167 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
\r
170 r = inputCondition.Append(__inputExpr);
\r
171 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform append operation.");
\r
174 if (!inputCondition.IsEmpty())
\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
180 SysLog(NID_CNT, "pInputCond = %s", pInputCond.get());
\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
186 if (!__inputColumnName.IsEmpty()) // SortColumn is optional in case of SearchN
\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
192 //CopyToCharArrayN: utility function, converts a osp string to char*
\r
194 pSortCol = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(slpColumn));
\r
195 SysTryReturnResult(NID_CNT, pSortCol, E_OUT_OF_MEMORY, "pSortCol is NULL.");
\r
197 if (__inputSortOrder == SORT_ORDER_ASCENDING)
\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
202 else if (__inputSortOrder == SORT_ORDER_DESCENDING)
\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
209 __pFilterHandle.reset(pFilterHandle.release());
\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
220 _ContentSearchImpl::GetSlpColumnName(String& inputCol) const
\r
222 String ospColumnName(L"");
\r
223 String slpColumnName(L"");
\r
224 String columnName(__inputColumnName);
\r
225 result r = E_SUCCESS;
\r
227 switch (__contentType)
\r
229 case CONTENT_TYPE_OTHER:
\r
231 case CONTENT_TYPE_IMAGE:
\r
232 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
\r
234 case CONTENT_TYPE_VIDEO:
\r
235 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
\r
237 case CONTENT_TYPE_AUDIO:
\r
239 case CONTENT_TYPE_ALL:
\r
240 maxCols = MAX_QUERY_COLUMNS;
\r
245 for (int colIndex = 0; colIndex < maxCols; colIndex++)
\r
247 ospColumnName.Clear();
\r
248 slpColumnName.Clear();
\r
250 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
\r
251 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
\r
253 ospColumnName.ToUpper();
\r
254 columnName.ToUpper();
\r
255 if (columnName == ospColumnName)
\r
257 inputCol = slpColumnName;
\r
261 return E_INVALID_ARG;
\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
272 _ContentSearchImpl::ReplaceOspColumnNameWithSlp(void) const
\r
274 String ospColumnName(L"");
\r
275 String slpColumnName(L"");
\r
276 String splApostrophe(L"special@apostrophe");
\r
277 result r = E_SUCCESS;
\r
282 String strToBeReplaced(L"\\'");
\r
283 int strLen = strToBeReplaced.GetLength();
\r
284 int startIndex = 0;
\r
286 while(E_SUCCESS == __inputExpr.IndexOf(strToBeReplaced,startIndex,indexOf))
\r
288 int lenAfterSubStr = indexOf + strLen;
\r
289 while ((lenAfterSubStr < __inputExpr.GetLength()) && (__inputExpr[lenAfterSubStr] == ' '))
\r
293 if ((lenAfterSubStr < __inputExpr.GetLength()) && ((__inputExpr[lenAfterSubStr] == '\'') ||
\r
294 ((!__inputExpr.StartsWith(L"AND ", lenAfterSubStr)) && (!__inputExpr.StartsWith(L"OR ", lenAfterSubStr)))))
\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
304 startIndex = lenAfterSubStr;
\r
308 SysLog(NID_CNT, "__inputExpr after splApostrophe append = %ls", __inputExpr.GetPointer());
\r
310 switch (__contentType)
\r
312 case CONTENT_TYPE_OTHER:
\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
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
324 case CONTENT_TYPE_AUDIO:
\r
326 case CONTENT_TYPE_ALL:
\r
327 maxCols = MAX_QUERY_COLUMNS;
\r
332 for (int colIndex = 0; colIndex < maxCols; colIndex++)
\r
334 ospColumnName.Clear();
\r
335 slpColumnName.Clear();
\r
337 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
\r
338 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
\r
340 ReplaceString(ospColumnName,slpColumnName);
\r
343 // Append ESCAPE '\' for LIKE query
\r
344 r = AppendEscapeKeywordForLikeQuery();
\r
345 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "AppendEscapeKeywordForLikeQuery failed.");
\r
347 r = ReplaceDateTimeStringWithInt();
\r
348 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_INVALID_ARG, "ReplaceDateTimeStringWithInt failed.");
\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
357 //This function is to appened ESCAPE keyword for _ and % special characters in LIKE query.
\r
360 _ContentSearchImpl::AppendEscapeKeywordForLikeQuery(void) const
\r
362 String delim = L"'"; //Delimeters is ' .
\r
363 result r = E_SUCCESS;
\r
365 bool isAppendEscape = false;
\r
368 String inputExpr = __inputExpr;
\r
370 // Create a StringTokenizer instance
\r
371 StringTokenizer strTok(inputExpr, delim);
\r
375 while (strTok.HasMoreTokens())
\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
382 tokenUpper = token;
\r
383 tokenUpper.ToUpper();
\r
384 if (tokenUpper.Contains(" LIKE"))
\r
386 isAppendEscape = true;
\r
390 isAppendEscape = false;
\r
392 r = inputExpr.Append(token);
\r
393 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
\r
395 else // value of the column
\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
405 if (isAppendEscape)
\r
407 if (token.Contains("\\_") || token.Contains("\\%"))
\r
409 r = inputExpr.Append("ESCAPE'\\' ");
\r
410 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
\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
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
426 _ContentSearchImpl::ReplaceDateTimeStringWithInt(void) const
\r
428 String delim = L"'"; //Delimeters is ' .
\r
429 result r = E_SUCCESS;
\r
431 bool isConvertReq = false;
\r
432 bool isBetweenExistsInDateTimeQuery = false;
\r
435 String inputExpr = __inputExpr;
\r
437 if(!inputExpr.Contains("MEDIA_ADDED_TIME"))
\r
442 // Create a StringTokenizer instance
\r
443 StringTokenizer strTok(inputExpr, delim);
\r
447 while (strTok.HasMoreTokens())
\r
449 r = strTok.GetNextToken(token);
\r
450 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "GetNextToken failed.");
\r
451 if (isCol) //column name
\r
454 tokenUpper = token;
\r
455 tokenUpper.ToUpper();
\r
456 if(isBetweenExistsInDateTimeQuery)
\r
458 isBetweenExistsInDateTimeQuery = false;
\r
459 isConvertReq = true;
\r
463 if (tokenUpper.Contains("MEDIA_ADDED_TIME"))
\r
465 if (tokenUpper.Contains("BETWEEN"))
\r
467 isBetweenExistsInDateTimeQuery = true;
\r
469 isConvertReq = true;
\r
473 isConvertReq = false;
\r
477 r = inputExpr.Append(token);
\r
478 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
\r
480 else // value of the column
\r
483 r = inputExpr.Append("'");
\r
484 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
\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
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
500 struct tm* timeInfo;
\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
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
514 long long ticksInSeconds = (long long)seconds;
\r
516 r = inputExpr.Append(ticksInSeconds);
\r
517 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
\r
521 r = inputExpr.Append(token);
\r
522 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
\r
525 r = inputExpr.Append("'");
\r
526 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string append failed.");
\r
530 __inputExpr.Clear();
\r
531 r = __inputExpr.Insert(inputExpr, 0);
\r
532 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "string insert failed.");
\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
547 _ContentSearchImpl::CheckInvalidColumnInQuery(void) const
\r
549 result r = E_SUCCESS;
\r
551 String delim = L"'"; //Delimeters is ' .
\r
552 bool isColReplaceReq = true;
\r
554 String inputExpr = __inputExpr;
\r
556 // Create a StringTokenizer instance
\r
557 StringTokenizer strTok(inputExpr, delim);
\r
561 while (strTok.HasMoreTokens())
\r
563 r = strTok.GetNextToken(token);
\r
564 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "strTok GetNextToken failed.");
\r
566 SysLog(NID_CNT, "In CheckInvalidColumnInQuery token[%d] = %ls", ++tokenNo, token.GetPointer());
\r
568 if (isColReplaceReq)
\r
570 isColReplaceReq = false;
\r
571 r = inputExpr.Append(token);
\r
572 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string append failed.");
\r
574 switch (__contentType)
\r
576 case CONTENT_TYPE_OTHER:
\r
578 case CONTENT_TYPE_IMAGE:
\r
579 if ((token.Contains("TITLE")) || (token.Contains("ARTIST")) || (token.Contains("GENRE")))
\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
585 case CONTENT_TYPE_VIDEO:
\r
586 if ((token.Contains("COMPOSER")) || (token.Contains("ALBUM")))
\r
588 SysLog(NID_CNT, "Composer or Album are not valid cloumns for this content type");
\r
589 return E_INVALID_ARG;
\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
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
617 _ContentSearchImpl::ReplaceString(String ospColumnName, String slpColumnName) const
\r
619 String delim = L"'"; //Delimeters is ' .
\r
620 result r = E_SUCCESS;
\r
621 bool isColReplaceReq = true;
\r
623 String inputExpr = __inputExpr;
\r
625 // Create a StringTokenizer instance
\r
626 StringTokenizer strTok(inputExpr, delim);
\r
630 while (strTok.HasMoreTokens())
\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
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
642 else // value of the column
\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
653 __inputExpr.Clear();
\r
654 r = __inputExpr.Insert(inputExpr, 0);
\r
655 SysTryReturnResult(NID_CNT, r == E_SUCCESS, E_SYSTEM, "string insert() failed.");
\r
660 //Retuns list of search result for the given expression and content type.
\r
662 _ContentSearchImpl::SearchN(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, const String& whereExpr, const String& sortColumn, SortOrder sortOrder) const
\r
664 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, whereExpr = %ls", pageNo, countPerPage, whereExpr.GetPointer());
\r
668 result r = E_SUCCESS;
\r
669 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
672 __inputColumnName.Clear();
\r
673 __inputExpr.Clear();
\r
674 __inputColumnName = sortColumn;
\r
675 __inputSortOrder = sortOrder;
\r
676 totalPageCount = 0;
\r
679 if (!whereExpr.IsEmpty()) // copy whereExpr if not empty to class variable __inputExpr
\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
685 r = ReplaceOspColumnNameWithSlp();
\r
686 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] ReplaceOspColumnNameWithSlp for InputExpr Failed.", GetErrorMessage(r));
\r
688 SysLog(NID_CNT, "After replace __inputExpr = %ls", __inputExpr.GetPointer());
\r
690 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
\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
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
701 r = pFinalOutList->Construct();
\r
702 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
\r
704 __pFinalOutList = std::move(pFinalOutList);
\r
706 r = CreateQueryFilter(true);
\r
707 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to perform CreateQueryFilter operation.", GetErrorMessage(r));
\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
713 SysLog(NID_CNT, "totalCount is [%d] for media_info_get_media_count_from_db", totalCount);
\r
715 if (totalCount > 0)
\r
717 if ((totalCount % countPerPage) == 0)
\r
719 totalPageCount = totalCount / countPerPage;
\r
723 totalPageCount = (totalCount / countPerPage) + 1;
\r
726 SysTryReturn(NID_CNT, ((pageNo >= 1) && (pageNo <= totalPageCount)) , NULL, E_INVALID_ARG, "[E_INVALID_ARG] (pageNo < 1) || (pageNo > totalPageCount).");
\r
728 offset = (pageNo * countPerPage) - countPerPage;
\r
730 SysLog(NID_CNT, " SearchN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
\r
731 totalCount, totalPageCount, countPerPage, pageNo, offset);
\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
738 r = ExecuteAndFillFinalOutList();
\r
739 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, E_SYSTEM, "[E_SYSTEM] ExecuteAndFillFinalOutList Failed.");
\r
741 else if (pageNo > 1)
\r
744 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] (pageNo > 1) and (totalcount = 0).");
\r
748 return __pFinalOutList.release();
\r
751 // Fills final result list
\r
753 _ContentSearchImpl::ExecuteAndFillFinalOutList(void) const
\r
755 SysLog(NID_CNT, "Enter\n");
\r
757 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
758 result r = E_SUCCESS;
\r
760 std::unique_ptr<GList, SearchGListDeleter> pItemList;
\r
761 GList* pTemp = NULL;
\r
762 std::unique_ptr<media_info_s, SearchMediaHandleDeleter> pMediaHandle;
\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
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
774 std::unique_ptr<ContentSearchResult> pContentSearchResult;
\r
776 pTemp = pItemList.get();
\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
782 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
\r
784 media_content_type_e mediaType = MEDIA_CONTENT_TYPE_OTHERS;
\r
786 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
\r
788 pMediaHandle.reset(static_cast<media_info_h>(g_list_nth_data(pTemp, idx)));
\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
796 case MEDIA_CONTENT_TYPE_OTHERS:
\r
797 //memset(&contentData, 0, sizeof(contentData));
\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
802 pContentData = pOtherContentInfo->GetContentData();
\r
803 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
805 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
\r
806 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
\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
812 pContentSearchResult->SetContentType(CONTENT_TYPE_OTHER);
\r
813 pContentSearchResult->SetContentInfo(pOtherContentInfo.release());
\r
815 // Shallow copy, adds just the pointer: not the element
\r
817 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
\r
818 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
\r
820 //pOtherContentInfo = null;
\r
821 //pContentSearchResult = null;
\r
822 //_ContentUtility::DeleteContentData(&contentData);
\r
824 case MEDIA_CONTENT_TYPE_IMAGE:
\r
825 //memset(&contentData, 0, sizeof(contentData));
\r
826 //memset(&imageContentData, 0, sizeof(imageContentData));
\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
831 pContentData = pImageContentInfo->GetContentData();
\r
832 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
834 pImageContentData = pImageContentInfo->GetImageContentData();
\r
835 SysTryReturnResult(NID_CNT, pImageContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
837 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
\r
838 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
\r
840 r = _ContentUtility::FillImageContentData(pMediaHandle.get(), pImageContentData);
\r
841 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform GetDataFromImageTable operation.");
\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
846 pContentSearchResult->SetContentType(CONTENT_TYPE_IMAGE);
\r
847 pContentSearchResult->SetContentInfo(pImageContentInfo.release());
\r
849 // Shallow copy, adds just the pointer: not the element
\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
857 case MEDIA_CONTENT_TYPE_MUSIC:
\r
859 case MEDIA_CONTENT_TYPE_SOUND:
\r
860 //memset(&contentData, 0, sizeof(contentData));
\r
861 //memset(&audioContentData, 0, sizeof(audioContentData));
\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
866 pContentData = pAudioContentInfo->GetContentData();
\r
867 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
869 pAudioContentData = pAudioContentInfo->GetAudioContentData();
\r
870 SysTryReturnResult(NID_CNT, pAudioContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
872 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
\r
873 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
\r
875 r = _ContentUtility::FillAudioContentData(pMediaHandle.get(), pAudioContentData);
\r
876 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillAudioContentData operation.");
\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
881 pContentSearchResult->SetContentType(CONTENT_TYPE_AUDIO);
\r
882 pContentSearchResult->SetContentInfo(pAudioContentInfo.release());
\r
884 // Shallow copy, adds just the pointer: not the element
\r
886 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
\r
887 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
\r
889 //pAudioContentInfo = null;
\r
890 //pContentSearchResult = null;
\r
891 //_ContentUtility::DeleteContentData(&contentData);
\r
892 //_ContentUtility::DeleteAudioContentData(&audioContentData);
\r
894 case MEDIA_CONTENT_TYPE_VIDEO:
\r
895 //memset(&contentData, 0, sizeof(contentData));
\r
896 //memset(&videoContentData, 0, sizeof(videoContentData));
\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
901 pContentData = pVideoContentInfo->GetContentData();
\r
902 SysTryReturnResult(NID_CNT, pContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
904 pVideoContentData = pVideoContentInfo->GetVideoContentData();
\r
905 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
\r
907 r = _ContentUtility::FillContentData(pMediaHandle.get(), pContentData);
\r
908 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillContentData operation.");
\r
910 r = _ContentUtility::FillVideoContentData(pMediaHandle.get(), pVideoContentData);
\r
911 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform FillVideoContentData operation.");
\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
916 pContentSearchResult->SetContentType(CONTENT_TYPE_VIDEO);
\r
917 pContentSearchResult->SetContentInfo(pVideoContentInfo.release());
\r
919 // Shallow copy, adds just the pointer: not the element
\r
921 r = __pFinalOutList->Add(*(pContentSearchResult.release()));
\r
922 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Failed to perform Add operation for ArrayList.");
\r
924 //pVideoContentInfo = null;
\r
925 //pContentSearchResult = null;
\r
926 //_ContentUtility::DeleteContentData(&contentData);
\r
927 //_ContentUtility::DeleteVideoContentData(&videoContentData);
\r
936 // returns given column value list in the requested order
\r
938 _ContentSearchImpl::GetValueListN(const String& sortColumn, SortOrder sortOrder)
\r
940 SysLog(NID_CNT, "inputColumn = %ls", sortColumn.GetPointer());
\r
943 result r = E_SUCCESS;
\r
947 __inputColumnName.Clear();
\r
948 __inputExpr.Clear();
\r
950 __inputColumnName = sortColumn;
\r
951 __inputSortOrder = sortOrder;
\r
953 String ospColumnName(L"");
\r
954 String slpColumnName(L"");
\r
956 String columnName(__inputColumnName);
\r
958 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
\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
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
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
972 __pFinalOutList = std::move(pFinalOutList);
\r
974 switch (__contentType)
\r
976 case CONTENT_TYPE_OTHER:
\r
978 case CONTENT_TYPE_IMAGE:
\r
979 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
\r
981 case CONTENT_TYPE_VIDEO:
\r
982 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
\r
984 case CONTENT_TYPE_AUDIO:
\r
986 case CONTENT_TYPE_ALL:
\r
987 maxCols = MAX_QUERY_COLUMNS;
\r
993 for (colIndex = 0; colIndex < maxCols; colIndex++)
\r
995 ospColumnName.Clear();
\r
996 slpColumnName.Clear();
\r
998 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
\r
999 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
\r
1001 ospColumnName.ToUpper();
\r
1002 columnName.ToUpper();
\r
1003 if (columnName == ospColumnName)
\r
1005 r = FillColumnsList(colIndex);
\r
1006 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[%s] FillColumnsList Failed.", GetErrorMessage(r));
\r
1010 if (colIndex == maxCols)
\r
1012 r = E_INVALID_ARG;
\r
1013 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");
\r
1017 return __pFinalOutList.release();
\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
1024 SysLog(NID_CNT, "pageNo = %d, countPerPage = %d, inputColumn = %ls", pageNo, countPerPage, sortColumn.GetPointer());
\r
1026 ClearLastResult();
\r
1028 result r = E_SUCCESS;
\r
1032 __inputColumnName.Clear();
\r
1033 __inputExpr.Clear();
\r
1035 __inputColumnName = sortColumn;
\r
1036 __inputSortOrder = sortOrder;
\r
1038 String ospColumnName(L"");
\r
1039 String slpColumnName(L"");
\r
1041 String columnName(__inputColumnName);
\r
1043 if ((__inputColumnName.IsEmpty()) && ((__inputSortOrder == SORT_ORDER_ASCENDING) || (__inputSortOrder == SORT_ORDER_DESCENDING)))
\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
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
1054 r = pFinalOutList->Construct();
\r
1055 SysTryReturn(NID_CNT, !IsFailed(r), NULL, r, "[%s] Failed to construct ArrayList.", GetErrorMessage(r));
\r
1057 __pFinalOutList = std::move(pFinalOutList);
\r
1059 switch (__contentType)
\r
1061 case CONTENT_TYPE_OTHER:
\r
1063 case CONTENT_TYPE_IMAGE:
\r
1064 maxCols = MAX_QUERY_COLUMNS_FOR_IMAGE_OTHERS;
\r
1066 case CONTENT_TYPE_VIDEO:
\r
1067 maxCols = MAX_QUERY_COLUMNS_FOR_VIDEO;
\r
1069 case CONTENT_TYPE_AUDIO:
\r
1071 case CONTENT_TYPE_ALL:
\r
1072 maxCols = MAX_QUERY_COLUMNS;
\r
1078 for (colIndex = 0; colIndex < maxCols; colIndex++)
\r
1080 ospColumnName.Clear();
\r
1081 slpColumnName.Clear();
\r
1083 ospColumnName = dbfieldinfo[colIndex].dbFieldOspName ;
\r
1084 slpColumnName = dbfieldinfo[colIndex].dbFieldSlpName ;
\r
1086 ospColumnName.ToUpper();
\r
1087 columnName.ToUpper();
\r
1088 if (columnName == ospColumnName)
\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
1095 if (colIndex == maxCols)
\r
1097 r = E_INVALID_ARG;
\r
1098 SysTryReturn(NID_CNT, r == E_SUCCESS, NULL, r, "[E_INVALID_ARG] invalid column.");
\r
1102 return __pFinalOutList.release();
\r
1105 // prepares query expression to be used in group api. colIndex is mapped to actual group value.
\r
1107 _ContentSearchImpl::GetIndexAndCreateQueryExp(int colIndex) const
\r
1109 media_group_e groupIndex = MEDIA_CONTENT_GROUP_DISPLAY_NAME;;
\r
1112 case 0://"ContentType", "MEDIA_TYPE"
\r
1113 groupIndex = MEDIA_CONTENT_GROUP_TYPE;
\r
1114 __inputExpr = "MEDIA_TYPE IS NOT NULL";
\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
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
1124 case 3://"Category", "MEDIA_CATEGORY"
\r
1125 groupIndex = MEDIA_CONTENT_GROUP_CATEGORY;
\r
1126 __inputExpr = "MEDIA_CATEGORY IS NOT NULL";
\r
1128 case 4://"Author", "MEDIA_AUTHOR"
\r
1129 groupIndex = MEDIA_CONTENT_GROUP_AUTHOR;
\r
1130 __inputExpr = "MEDIA_AUTHOR IS NOT NULL";
\r
1132 case 5://"keyword", "MEDIA_KEYWORD"
\r
1133 groupIndex = MEDIA_CONTENT_GROUP_KEYWORD;
\r
1134 __inputExpr = "MEDIA_KEYWORD IS NOT NULL";
\r
1136 case 6://"Provider", "MEDIA_PROVIDER"
\r
1137 groupIndex = MEDIA_CONTENT_GROUP_PROVIDER;
\r
1138 __inputExpr = "MEDIA_PROVIDER IS NOT NULL";
\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
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
1148 case 9://"ContentSize", "MEDIA_SIZE"
\r
1149 groupIndex = MEDIA_CONTENT_GROUP_SIZE;
\r
1150 __inputExpr = "MEDIA_SIZE IS NOT NULL";
\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
1156 case 11://"Latitude", "MEDIA_LATITUDE"
\r
1157 groupIndex = MEDIA_CONTENT_GROUP_LATITUDE;
\r
1158 __inputExpr = "MEDIA_LATITUDE IS NOT NULL";
\r
1160 case 12://"Longitude", "MEDIA_LONGITUDE"
\r
1161 groupIndex = MEDIA_CONTENT_GROUP_LONGITUDE;
\r
1162 __inputExpr = "MEDIA_LONGITUDE IS NOT NULL";
\r
1164 case 13://"Altitude", "MEDIA_ALTITUDE"
\r
1165 groupIndex = MEDIA_CONTENT_GROUP_ALTITUDE;
\r
1166 __inputExpr = "MEDIA_ALTITUDE IS NOT NULL";
\r
1168 case 14://"Title", "MEDIA_TITLE"
\r
1169 groupIndex = MEDIA_CONTENT_GROUP_TITLE;
\r
1170 __inputExpr = "MEDIA_TITLE IS NOT NULL";
\r
1172 case 15://"Artist", "MEDIA_ARTIST"
\r
1173 groupIndex = MEDIA_CONTENT_GROUP_ARTIST;
\r
1174 __inputExpr = "MEDIA_ARTIST IS NOT NULL";
\r
1176 case 16://"Genre", "MEDIA_GENRE"
\r
1177 groupIndex = MEDIA_CONTENT_GROUP_GENRE;
\r
1178 __inputExpr = "MEDIA_GENRE IS NOT NULL";
\r
1180 case 17://"Year", "MEDIA_YEAR"
\r
1181 groupIndex = MEDIA_CONTENT_GROUP_YEAR;
\r
1182 __inputExpr = "MEDIA_YEAR IS NOT NULL";
\r
1184 case 18://"Composer", "MEDIA_COMPOSER"
\r
1185 groupIndex = MEDIA_CONTENT_GROUP_COMPOSER;
\r
1186 __inputExpr = "MEDIA_COMPOSER IS NOT NULL";
\r
1188 case 19://"Album", "MEDIA_ALBUM"
\r
1189 __inputExpr = "MEDIA_ALBUM IS NOT NULL";
\r
1194 return groupIndex;
\r
1197 // Fills given column value list and destroys filter handle
\r
1199 _ContentSearchImpl::FillColumnsList(int colIndex) const
\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
1206 r = CreateQueryFilter(true);
\r
1207 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
\r
1209 if (colIndex == ALBUM_COLUMN_NUM)
\r
1211 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
\r
1215 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
\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
1220 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
\r
1222 if (totalCount > 0)
\r
1224 if (colIndex == ALBUM_COLUMN_NUM)
\r
1226 r = ExecuteAndFillAlbumValues();
\r
1227 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
\r
1231 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
\r
1232 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
\r
1238 // prepares input expression to be sent for create filter and fills given column value list
\r
1240 _ContentSearchImpl::FillColumnsList(int pageNo, int countPerPage, int& totalPageCount, int& totalCount, int colIndex) const
\r
1242 result r = E_SUCCESS;
\r
1243 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
1245 totalPageCount = 0;
\r
1247 media_group_e groupIndex = GetIndexAndCreateQueryExp(colIndex);
\r
1249 r = CreateQueryFilter(true);
\r
1250 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "CreateQueryFilter Failed.");
\r
1252 if (colIndex == ALBUM_COLUMN_NUM)
\r
1254 ret = media_album_get_album_count_from_db(__pFilterHandle.get(), &totalCount);
\r
1258 ret = media_group_get_group_count_from_db(__pFilterHandle.get(), groupIndex, &totalCount);
\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
1263 SysLog(NID_CNT, "totalCount = %d for media_album/group count_from_db", totalCount);
\r
1265 if (totalCount > 0)
\r
1267 if ((totalCount % countPerPage) == 0)
\r
1269 totalPageCount = totalCount / countPerPage;
\r
1273 totalPageCount = (totalCount / countPerPage) + 1;
\r
1276 if ((pageNo < 1) || (pageNo > totalPageCount))
\r
1278 r = E_INVALID_ARG;
\r
1279 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo < 1) || (pageNo > totalPageCount).");
\r
1282 offset = (pageNo * countPerPage) - countPerPage;
\r
1284 SysLog(NID_CNT, "GetValueListN totalCount [%d] totalPageCount[%d] __countPerPage[%d] __pageNo[%d] offset[%d]",
\r
1285 totalCount, totalPageCount, countPerPage, pageNo, offset);
\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
1291 if (colIndex == ALBUM_COLUMN_NUM)
\r
1293 r = ExecuteAndFillAlbumValues();
\r
1294 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillAlbumValues Failed.");
\r
1298 r = ExecuteAndFillGetValueListN(groupIndex, colIndex);
\r
1299 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "ExecuteAndFillGetValueListN Failed.");
\r
1303 else if (pageNo > 1)
\r
1305 r = E_INVALID_ARG;
\r
1306 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "(pageNo > 1) and (totalcount = 0).");
\r
1312 // fills given column value list for GetValuelistN api
\r
1314 _ContentSearchImpl::ExecuteAndFillGetValueListN(media_group_e groupIndex, int colIndex) const
\r
1316 SysLog(NID_CNT, "Enter\n");
\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
1324 std::unique_ptr<Object> pValue;
\r
1326 DateTime dateTime;
\r
1328 long long contentSize = 0;
\r
1329 long long addedTime = 0;
\r
1332 char *pColumnVal = null;
\r
1333 int contentType = 0;
\r
1335 pTemp = pItemList.get();
\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
1341 SysTryReturnResult(NID_CNT, pTemp != NULL, r, "media_info_foreach_media_from_db pTemp is null.");
\r
1343 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
\r
1345 SysLog(NID_CNT, "idx = %d and (int)g_list_length(pItemList) = %d", idx, (int)g_list_length(pTemp));
\r
1347 pColumnVal = (char *)g_list_nth_data(pTemp, idx);
\r
1349 String strColVal(pColumnVal);
\r
1351 _ContentUtility::DoSafeFree(pColumnVal);
\r
1353 SysLog(NID_CNT, "pColumnVal = %ls", strColVal.GetPointer());
\r
1357 case 0://"ContentType", "MEDIA_TYPE"
\r
1358 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
\r
1360 res = Integer::Parse(strColVal, contentType);
\r
1361 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] Integer parse failed.", GetErrorMessage(res));
\r
1363 switch ((media_content_type_e)contentType)
\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
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
1373 case MEDIA_CONTENT_TYPE_SOUND:
\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
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
1387 case 1://"ContentFileName", "MEDIA_DISPLAY_NAME"
\r
1389 case 2://"ContentName", "MEDIA_CONTENT_NAME"
\r
1391 case 3://"Category", "MEDIA_CATEGORY"
\r
1393 case 4://"Author", "MEDIA_AUTHOR"
\r
1395 case 5://"keyword", "MEDIA_KEYWORD"
\r
1397 case 6://"Provider", "MEDIA_PROVIDER"
\r
1399 case 7://"Rating", "MEDIA_AGE_RATING"
\r
1401 case 8://"LocationTag", "MEDIA_LOCATION_TAG"
\r
1403 case 14://"Title", "MEDIA_TITLE"
\r
1405 case 15://"Artist", "MEDIA_ARTIST"
\r
1407 case 16://"Genre", "MEDIA_GENRE"
\r
1409 case 17://"Year", "MEDIA_YEAR"
\r
1411 case 18://"Composer", "MEDIA_COMPOSER"
\r
1413 pValue.reset(new (std::nothrow) String(strColVal));
\r
1416 case 9://"ContentSize", "MEDIA_SIZE"
\r
1417 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
\r
1419 res = LongLong::Parse(strColVal, contentSize);
\r
1420 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
\r
1423 pValue.reset(new (std::nothrow) LongLong(contentSize));
\r
1425 case 10://"DateTime", "MEDIA_ADDED_TIME"
\r
1426 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
\r
1428 res = LongLong::Parse(strColVal, addedTime);
\r
1429 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] LongLong parse failed.", GetErrorMessage(res));
\r
1432 res = dateTime.SetValue(1970, 1, 1);
\r
1433 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.SetValue failed.", GetErrorMessage(res));
\r
1435 res = dateTime.AddSeconds(addedTime);
\r
1436 SysTryLog(NID_CNT, res == E_SUCCESS, "[%s] dateTime.AddSeconds failed.", GetErrorMessage(res));
\r
1438 SysLog(NID_CNT, "DateTime : %ls", dateTime.ToString().GetPointer());
\r
1440 pValue.reset(new (std::nothrow) DateTime(dateTime));
\r
1443 case 11://"Latitude", "MEDIA_LATITUDE"
\r
1445 case 12://"Longitude", "MEDIA_LONGITUDE"
\r
1447 case 13://"Altitude", "MEDIA_ALTITUDE"
\r
1448 if ((strColVal.CompareTo(L"Unknown") != 0) && (!strColVal.IsEmpty()))
\r
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.");
1454 pValue.reset(new (std::nothrow) Double(dVal));
\r
1457 case 19://"Album", "MEDIA_ALBUM"
\r
1462 if (pValue.get() != NULL)
\r
1464 r = __pFinalOutList->Add(*(pValue.release()));
\r
1465 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
\r
1473 _ContentSearchImpl::ExecuteAndFillAlbumValues(void) const
\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
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
1487 pTemp = pItemList.get();
\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
1494 for (int idx = 0; idx < (int)g_list_length(pTemp); idx++)
\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
1501 if (pName != NULL)
\r
1503 SysLog(NID_CNT, "pColumnVal = %s", pName);
\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
1511 r = __pFinalOutList->Add(pValue.get());
\r
1512 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
\r
1517 String* pTempNameList(static_cast< String* >(__pFinalOutList->GetAt(lastIndex)));
\r
1519 if (pValue->CompareTo(*pTempNameList) != 0)
\r
1521 r = __pFinalOutList->Add(pValue.get());
\r
1522 SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "Failed to perform arraylist Add operation.");
\r
1535 _ContentSearchImpl::MapCoreErrorToNativeResult(int reason) const
\r
1537 result r = E_SUCCESS;
\r
1541 case MEDIA_CONTENT_ERROR_NONE:
\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
1550 case MEDIA_CONTENT_ERROR_DB_FAILED:
\r
1552 SysLog(NID_CNT, "MEDIA_CONTENT_ERROR_DB_FAILED");
\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
1561 SysLog(NID_CNT, "default");
\r
1568 //Callback function registered to each media info details
\r
1569 // all items are appened to the list
\r
1571 MediaItemCb(media_info_h media, void* pUserdata)
\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
1578 GList** pList = (GList**)pUserdata;
\r
1579 *pList = g_list_append(*pList, new_media);
\r
1584 //Callback function registered for column values
\r
1585 // all items are appened to the list
\r
1587 GroupItemCb(const char* pGroupName, void* pUserdata)
\r
1589 char* pGrpName = strdup(pGroupName);
\r
1590 GList** pList = (GList**)pUserdata;
\r
1591 *pList = g_list_append(*pList, pGrpName);
\r
1596 //Callback function registered to each media info details
\r
1597 // all items are appened to the list
\r
1599 AlbumItemCb(media_album_h album, void* pUserdata)
\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
1606 GList** pList = (GList**)pUserdata;
\r
1607 *pList = g_list_append(*pList, new_album);
\r