2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
\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
19 #include <media_content.h>
\r
20 #include <media_info_private.h>
\r
21 #include <audio-svc.h>
\r
22 #include <audio-svc-error.h>
\r
23 #include <audio-svc-types.h>
\r
24 #include <visual-svc-types.h>
\r
25 #include <visual-svc.h>
\r
34 #define LOG_TAG "TIZEN_N_MEDIACONTENT"
\r
36 static MediaSvcHandle* db_handle = NULL;
\r
37 static int ref_count = 0;
\r
39 int media_content_connect()
\r
41 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
45 if(db_handle == NULL)
\r
47 ret = media_svc_connect(&db_handle);
\r
50 ret = _content_error_capi(MEDIA_CONTENT_TYPE,ret);
\r
59 int media_content_disconnect()
\r
61 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
69 LOGE("[%s]DB_FAILED(0x%08x) database is not connected", __FUNCTION__, MEDIA_CONTENT_ERROR_DB_FAILED);
\r
70 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
75 if(db_handle != NULL)
\r
77 ret = media_svc_disconnect(db_handle);
\r
78 ret = _content_error_capi(MEDIA_CONTENT_TYPE,ret);
\r
79 if( ret == MEDIA_CONTENT_ERROR_NONE)
\r
90 MediaSvcHandle* _content_get_db_handle()
\r
96 int _content_query_prepare(sqlite3_stmt** stmt,char* select_query,char* condition_query, char* search_query,char* limit_query,char* order)
\r
101 if(db_handle == NULL)
\r
103 LOGE("[%s]DB_FAILED(0x%08x) database is not connected", __FUNCTION__, MEDIA_CONTENT_ERROR_DB_FAILED);
\r
104 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
107 if((select_query != NULL) && (select_query[0] != 0x00))
\r
109 if((search_query == NULL) || search_query[0] == 0x00)
\r
111 search_query = " ";
\r
113 if((limit_query == NULL) || limit_query[0] == 0x00)
\r
117 if((order == NULL) || order[0] == 0x00)
\r
121 if((condition_query == NULL) ||condition_query[0] == 0x00)
\r
123 condition_query = " ";
\r
126 len_query= strlen(select_query) + 1 + strlen(search_query)+ 1 + strlen(condition_query)+ 1 + strlen(limit_query)+ 1 + strlen(order)+1;
\r
128 query = (char*)calloc(len_query,sizeof(char));
\r
132 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
133 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
136 snprintf(query,len_query,"%s %s %s %s %s",select_query,condition_query,search_query,order,limit_query );
\r
138 LOGV("[%s]Query : %s",__func__,query);
\r
139 if( sqlite3_prepare((sqlite3*)db_handle, query, strlen(query),stmt, NULL) != SQLITE_OK )
\r
141 LOGE("[%s]DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", __FUNCTION__, MEDIA_CONTENT_ERROR_DB_FAILED,sqlite3_errmsg((sqlite3*)db_handle));
\r
148 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
149 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
151 return MEDIA_CONTENT_ERROR_NONE;
\r
157 int _content_error_capi(media_content_type_e type, int content_error)
\r
159 if(type == MEDIA_CONTENT_TYPE)
\r
161 if(content_error == MB_SVC_ERROR_NONE)
\r
162 return MEDIA_CONTENT_ERROR_NONE;
\r
163 else if(content_error == MB_SVC_ERROR_INVALID_PARAMETER || content_error == AUDIO_SVC_ERROR_INVALID_PARAMETER)
\r
164 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
165 else if(content_error == MB_SVC_ERROR_DB_INTERNAL || content_error == AUDIO_SVC_ERROR_DB_INTERNAL)
\r
166 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
167 else if(content_error == MEDIA_INFO_ERROR_DATABASE_CONNECT || content_error == AUDIO_SVC_ERROR_DB_CONNECT)
\r
168 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
169 else if(content_error == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
\r
170 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
173 return MEDIA_CONTENT_ERROR_NONE;
\r
178 int _content_query_sql(char *query_str)
\r
180 int err = MEDIA_CONTENT_ERROR_NONE;
\r
183 if(db_handle == NULL)
\r
185 LOGE("[%s]DB_FAILED(0x%08x) database is not connected",__FUNCTION__, MEDIA_CONTENT_ERROR_DB_FAILED);
\r
186 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
190 err = sqlite3_exec(db_handle, query_str, NULL, NULL, &err_msg);
\r
191 if (SQLITE_OK != err)
\r
195 sqlite3_free(err_msg);
\r
197 LOGE("[%s]DB_FAILED(0x%08x) database operation is failed",__FUNCTION__, MEDIA_CONTENT_ERROR_DB_FAILED);
\r
198 return MEDIA_CONTENT_ERROR_DB_FAILED;
\r
202 sqlite3_free(err_msg);
\r