src/common/media-svc-db-utils.c
src/common/media-svc-util.c
src/common/media-svc-debug.c
+ src/common/media-svc-noti.c
)
SET(HASH_SRCS
CONFIGURE_FILE(libmedia-service.pc.in libmedia-service.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmedia-service.pc DESTINATION lib/pkgconfig)
+ADD_SUBDIRECTORY(test)
+
LINK_DIRECTORIES(lib)
ADD_LIBRARY(${MEDIASERVICE-HASH-LIB} SHARED ${HASH_SRCS})
#define MEDIA_INFO_ERROR_SOCKET_RECEIVE -204 /**< Socket receive error */
#define MEDIA_INFO_ERROR_SOCKET_RECEIVE_TIMEOUT -205 /**< Socket time out */
+#define MEDIA_INFO_ERROR_SEND_NOTI_FAIL -301 /**< Sending Notifications fail */
+
#define MEDIA_INFO_ERROR_INTERNAL -998 /**< Internal error */
#define MEDIA_INFO_ERROR_UNKNOWN -999 /**< Unknown error */
#define MEDIA_INFO_ERROR_NOT_IMPLEMENTED -200 /**< Not implemented */
#include "media-svc-types.h"
#include "media-svc-error.h"
-
#ifdef __cplusplus
extern "C" {
#endif
int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path);
-int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt);
+int media_svc_insert_item_begin(MediaSvcHandle *handle, int with_noti, int data_cnt, int from_pid);
int media_svc_insert_item_end(MediaSvcHandle *handle);
-int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type);
+int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type, int is_burst);
int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type);
int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
+int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path);
+
/** @} */
/**
Name: libmedia-service
Summary: Media information service library for multimedia applications.
-Version: 0.2.19
+Version: 0.2.29
Release: 1
Group: System/Libraries
License: Apache License, Version 2.0
return MEDIA_SVC_PLUGIN_ERROR; //not exist
}
-int insert_item_begin(void * handle, int item_cnt, char ** err_msg)
+int insert_item_begin(void * handle, int item_cnt, int with_noti, int from_pid, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
return MEDIA_SVC_PLUGIN_ERROR;
}
- ret = media_svc_insert_item_begin(handle, item_cnt);
+ ret = media_svc_insert_item_begin(handle, item_cnt, with_noti, from_pid);
if(ret < 0) {
__set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
- ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type);
+ ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type, FALSE);
if(ret < 0) {
__set_error_message(ret, err_msg);
return MEDIA_SVC_PLUGIN_ERROR;
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
+int insert_burst_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
+
+ ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type, TRUE);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
int move_item_begin(void * handle, int item_cnt, char ** err_msg)
{
int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
return MEDIA_SVC_PLUGIN_ERROR_NONE;
}
+
+int send_dir_update_noti(void * handle, const char *dir_path, char **err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if (!STRING_VALID(dir_path)) {
+ __set_error_message(ERR_FOLDER_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_send_dir_update_noti(handle, dir_path);
+ if (ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
return MEDIA_INFO_ERROR_NONE;
}
+
+int _media_svc_get_media_count_with_album_id_by_path(sqlite3 *handle, const char *path, int *count)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(path == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+
+ sql = sqlite3_mprintf("select count(media_uuid) from %s INNER JOIN (select album_id from %s where path=%Q and album_id > 0) as album ON album.album_id=media.album_id;", MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("there is no media in relted to this media's album.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_media_count_with_album_id_by_path. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ *count = sqlite3_column_int(sql_stmt, 0);
+ media_svc_debug("Media count : %d", *count);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
height INTEGER DEFAULT -1, \
datetaken TEXT, \
orientation INTEGER DEFAULT -1, \
+ burst_id TEXT, \
played_count INTEGER DEFAULT 0, \
last_played_time INTEGER DEFAULT 0, \
last_played_position INTEGER DEFAULT 0, \
/*Create playlist table*/
sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
playlist_id INTEGER PRIMARY KEY AUTOINCREMENT, \
- name TEXT NOT NULL UNIQUE\
+ name TEXT NOT NULL UNIQUE,\
+ thumbnail_path TEXT\
);",
MEDIA_SVC_DB_TABLE_PLAYLIST);
#include "media-svc-debug.h"
#include "media-svc-util.h"
#include "media-svc-db-utils.h"
+#include "media-svc-noti.h"
typedef struct{
char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
return MEDIA_INFO_ERROR_NONE;
}
-int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, bool stack_query)
+int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query)
{
media_svc_debug("");
int err = -1;
+ char *burst_id = NULL;
char * db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, \
thumbnail_path, title, album_id, album, artist, genre, composer, year, recorded_date, copyright, track_num, description,\
bitrate, samplerate, channel, duration, longitude, latitude, altitude, width, height, datetaken, orientation,\
- rating, is_drm, storage_type";
+ rating, is_drm, storage_type, burst_id";
/* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
/* This code will be removed when sqlite3_mprintf works clearly */
char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
sqlite3_free(test_sql);
+ if (is_burst) {
+ int burst_id_int = 0;
+ err = _media_svc_get_burst_id(handle, &burst_id_int);
+ if (err < 0) {
+ burst_id = NULL;
+ }
+
+ if (burst_id_int > 0) {
+ media_svc_debug("Burst id : %d", burst_id_int);
+ burst_id = sqlite3_mprintf("%d", burst_id_int);
+ }
+ }
+
char *sql = sqlite3_mprintf("INSERT INTO %s (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
%Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
%d, %d, %d, %d, %.2f, %.2f, %.2f, %d, %d, %Q, %d, \
- %d, %d, %d);",
+ %d, %d, %d, %Q);",
MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
content_info->media_uuid,
content_info->path,
content_info->media_meta.orientation,
content_info->media_meta.rating,
content_info->is_drm,
- content_info->storage_type);
+ content_info->storage_type,
+ burst_id);
+
+ if (burst_id) sqlite3_free(burst_id);
+ burst_id = NULL;
if(!stack_query) {
err = _media_svc_sql_query(handle, sql);
SQLITE3_FINALIZE(sql_stmt);
return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_get_burst_id(sqlite3 *handle, int *id)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ int cur_id = -1;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT max(CAST(burst_id AS INTEGER)) FROM %s", MEDIA_SVC_DB_TABLE_MEDIA);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when _media_svc_get_burst_id. err = [%d]", ret);
+ return ret;
+ }
+
+ cur_id = sqlite3_column_int(sql_stmt, 0);
+ *id = ++cur_id;
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ if (item == NULL) {
+ media_svc_error("_media_svc_get_noti_info failed");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ if (update_item == MS_MEDIA_ITEM_FILE) {
+ sql = sqlite3_mprintf("SELECT media_uuid, media_type, mime_type FROM %s", MEDIA_SVC_DB_TABLE_MEDIA);
+ } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
+ sql = sqlite3_mprintf("SELECT folder_uuid FROM %s", MEDIA_SVC_DB_TABLE_FOLDER);
+ } else {
+ media_svc_error("_media_svc_get_noti_info failed : update item");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when _media_svc_get_noti_info. err = [%d]", ret);
+ return ret;
+ }
+
+ *item = calloc(1, sizeof(media_svc_noti_item));
+ if (*item == NULL) {
+ media_svc_error("_media_svc_get_noti_info failed : calloc");
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (update_item == MS_MEDIA_ITEM_FILE) {
+ if (sqlite3_column_text(sql_stmt, 0))
+ (*item)->media_uuid = strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+
+ (*item)->media_type = sqlite3_column_int(sql_stmt, 1);
+
+ if (sqlite3_column_text(sql_stmt, 2))
+ (*item)->mime_type = strdup((const char *)sqlite3_column_text(sql_stmt, 2));
+ } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
+ if (sqlite3_column_text(sql_stmt, 0))
+ (*item)->media_uuid = strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
}
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include "media-svc-noti.h"
+#include "media-svc-util.h"
+
+static __thread media_svc_noti_item *g_inserted_noti_list = NULL;
+static __thread int g_noti_from_pid = -1;
+
+media_svc_noti_item *_media_svc_get_noti_list()
+{
+ return g_inserted_noti_list;
+}
+
+void _media_svc_set_noti_from_pid(int pid)
+{
+ g_noti_from_pid = pid;
+}
+
+int _media_svc_create_noti_list(int count)
+{
+ SAFE_FREE(g_inserted_noti_list);
+
+ g_inserted_noti_list = calloc(count, sizeof(media_svc_noti_item));
+ if (g_inserted_noti_list == NULL) {
+ media_svc_error("Failed to prepare noti items");
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info, int cnt)
+{
+ media_svc_noti_item *noti_list = g_inserted_noti_list;
+
+ if (noti_list && content_info) {
+ noti_list[cnt].pid = g_noti_from_pid;
+ noti_list[cnt].update_item = MS_MEDIA_ITEM_INSERT; // INSERT
+ noti_list[cnt].update_type = MS_MEDIA_ITEM_FILE;
+ noti_list[cnt].media_type = content_info->media_type;
+ if (content_info->media_uuid)
+ noti_list[cnt].media_uuid = strdup(content_info->media_uuid);
+ if (content_info->path)
+ noti_list[cnt].path = strdup(content_info->path);
+ if (content_info->mime_type)
+ noti_list[cnt].mime_type = strdup(content_info->mime_type);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+
+int _media_svc_destroy_noti_list(int all_cnt)
+{
+ int i = 0;
+ media_svc_noti_item *noti_list = g_inserted_noti_list;
+
+ if (noti_list) {
+ for (i = 0; i < all_cnt; i++) {
+ SAFE_FREE(noti_list[i].media_uuid);
+ SAFE_FREE(noti_list[i].path);
+ SAFE_FREE(noti_list[i].mime_type);
+ }
+
+ SAFE_FREE(g_inserted_noti_list);
+ g_inserted_noti_list = NULL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_publish_noti_list(int all_cnt)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+ int i = 0;
+ media_svc_noti_item *noti_list = g_inserted_noti_list;
+
+ if (noti_list) {
+ for (i = 0; i < all_cnt; i++) {
+ err = _media_svc_publish_noti_by_item(&(noti_list[i]));
+ if (err < 0) {
+ media_svc_error("_media_svc_publish_noti failed : %d", err);
+ }
+ }
+ }
+
+ return err;
+}
+
+
+int _media_svc_create_noti_item(media_svc_content_info_s *content_info,
+ int pid,
+ media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ media_svc_noti_item **item)
+{
+ media_svc_noti_item *_item = NULL;
+
+ if (item == NULL || content_info == NULL) {
+ media_svc_error("_media_svc_create_noti_item : invalid param");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ _item = calloc(1, sizeof(media_svc_noti_item));
+
+ if (_item == NULL) {
+ media_svc_error("Failed to prepare noti items");
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ _item->pid = pid;
+ _item->update_item = update_item;
+ _item->update_type = update_type;
+ _item->media_type = content_info->media_type;
+
+ if (content_info->media_uuid)
+ _item->media_uuid = strdup(content_info->media_uuid);
+ if (content_info->path)
+ _item->path = strdup(content_info->path);
+ if (content_info->mime_type)
+ _item->mime_type = strdup(content_info->mime_type);
+
+ *item = _item;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_destroy_noti_item(media_svc_noti_item *item)
+{
+ if (item) {
+ SAFE_FREE(item->media_uuid);
+ SAFE_FREE(item->path);
+ SAFE_FREE(item->mime_type);
+
+ SAFE_FREE(item);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_publish_noti_by_item(media_svc_noti_item *noti_item)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+
+ if (noti_item && noti_item->path) {
+ err = media_db_update_send(noti_item->pid,
+ noti_item->update_item,
+ noti_item->update_type,
+ noti_item->path,
+ noti_item->media_uuid,
+ noti_item->media_type,
+ noti_item->mime_type);
+ if (err < 0) {
+ media_svc_error("media_db_update_send failed : %d [%s]", err, noti_item->path);
+ } else {
+ media_svc_debug("media_db_update_send success");
+ }
+ }
+
+ return err;
+}
+
+int _media_svc_publish_noti(media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ const char *path,
+ media_type_e media_type,
+ const char *uuid,
+ const char *mime_type
+)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+
+ if (path) {
+ err = media_db_update_send(getpid(),
+ update_item,
+ update_type,
+ (char *)path,
+ (char *)uuid,
+ media_type,
+ (char *)mime_type);
+ if (err < 0) {
+ media_svc_error("media_db_update_send failed : %d [%s]", err, path);
+ return MEDIA_INFO_ERROR_SEND_NOTI_FAIL;
+ } else {
+ media_svc_debug("media_db_update_send success");
+ }
+ }
+
+ return err;
+}
if (strlen(description_buf) == 0) {
//media_svc_debug("Use 'No description'");
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
- media_svc_error("strcpy error");
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
} else {
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
if(ret != MEDIA_INFO_ERROR_NONE)
}
if ((!invalid_file) && (license_status != DRM_LICENSE_STATUS_VALID)) {
- invalid_file = TRUE;
if (drm_file_type == DRM_TYPE_OMA_V1) {
if (strlen(contentInfo.title) > 0) {
return MEDIA_INFO_ERROR_NONE;
}
+ else {
+ media_svc_debug("Some Not OMA Content's metadata is not incrypted so fileinfo can extracted metadata");
+ }
}
#if 0
ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, metadata.subBox.genre.str);
media_svc_retv_del_if(ret < 0, ret, content_info);
- media_svc_debug("genre : %s", content_info->media_meta.genre);
- if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
+ //media_svc_debug("genre : %s", content_info->media_meta.genre);
+ /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
+ /*
+ if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
}
+ */
extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_GENRE;
}
media_svc_error("strcpy error");
//media_svc_debug("genre : %s", content_info->media_meta.genre);
+ /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
+ /*
if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
}
+ */
} else {
SAFE_FREE(err_attr_name);
//media_svc_debug("genre - unknown");
{
int ret = MEDIA_INFO_ERROR_NONE;
drm_content_info_s contentInfo;
+ drm_file_type_e file_type = DRM_TYPE_UNDEFINED;
if (path == NULL || mime == NULL)
return MEDIA_INFO_ERROR_INVALID_PARAMETER;
- memset(&contentInfo,0x0,sizeof(drm_content_info_s));
- ret = drm_get_content_info(path, &contentInfo);
+ ret = drm_get_file_type(path, &file_type);
if (ret != DRM_RETURN_SUCCESS) {
- media_svc_error("drm_svc_get_content_info() fails. ");
+ media_svc_error("drm_get_file_type() failed : %d", ret);
return MEDIA_INFO_ERROR_INVALID_MEDIA;
- }
+ } else {
+ if (file_type == DRM_TYPE_OMA_V1
+ || file_type == DRM_TYPE_OMA_V2
+ || file_type == DRM_TYPE_OMA_PD) {
+ memset(&contentInfo,0x0,sizeof(drm_content_info_s));
+ ret = drm_get_content_info(path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ media_svc_error("drm_svc_get_content_info() fails :%d ", ret);
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
+ }
- strncpy(mime, contentInfo.mime_type, MEDIA_SVC_METADATA_LEN_MAX);
- media_svc_debug("DRM contentType : %s", contentInfo.mime_type);
- //media_svc_debug("DRM mime : %s", mime);
+ if (STRING_VALID(contentInfo.mime_type)) {
+ strncpy(mime, contentInfo.mime_type, MEDIA_SVC_METADATA_LEN_MAX);
+ media_svc_debug("DRM contentType : %s", contentInfo.mime_type);
+ } else {
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
+ }
+ } else {
+ media_svc_error("THIS IS DRM BUT YOU SHOULD USE API OF AUL LIBRARY");
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
+ }
+ }
return MEDIA_INFO_ERROR_NONE;
}
#include "media-svc-db-utils.h"
#include "media-svc-media-folder.h"
#include "media-svc-album.h"
-
+#include "media-svc-noti.h"
static __thread int g_media_svc_item_validity_data_cnt = 1;
static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
static __thread int g_media_svc_insert_item_data_cnt = 1;
static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
-
-
+/* Flag for items to be published by notification */
+static __thread int g_insert_with_noti = FALSE;
int media_svc_connect(MediaSvcHandle **handle)
{
if (_media_svc_is_drm_file(path)) {
ret = _media_svc_get_mime_in_drm_info(path, mimetype);
if (ret != MEDIA_INFO_ERROR_NONE) {
- media_svc_error("Fail to get mime");
+ media_svc_error("Fail to get mime in DRM");
+ } else {
return ret;
}
- } else {
- /*in case of normal files */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- media_svc_error("aul_get_mime_from_file fail");
- return MEDIA_INFO_ERROR_INVALID_MEDIA;
- }
+ }
+
+ /*in case of normal files or failure to get mime in drm */
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ media_svc_error("aul_get_mime_from_file fail");
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
}
return MEDIA_INFO_ERROR_NONE;
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt)
+int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt, int with_noti, int from_pid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
g_media_svc_insert_item_data_cnt = data_cnt;
g_media_svc_insert_item_cur_data_cnt = 0;
+ /* Prepare for making noti item list */
+ if (with_noti) {
+ media_svc_debug("making noti list from pid[%d]", from_pid);
+ if (_media_svc_create_noti_list(data_cnt) != MEDIA_INFO_ERROR_NONE) {
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ _media_svc_set_noti_from_pid(from_pid);
+ g_insert_with_noti = TRUE;
+ }
+
return MEDIA_INFO_ERROR_NONE;
}
if (g_media_svc_insert_item_cur_data_cnt > 0) {
ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
+ if (g_insert_with_noti) {
+ media_svc_debug("sending noti list");
+ _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
+ _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
+ g_insert_with_noti = FALSE;
+ _media_svc_set_noti_from_pid(-1);
+ }
}
g_media_svc_insert_item_data_cnt = 1;
}
int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type,
- const char *path, const char *mime_type, media_svc_media_type_e media_type)
+ const char *path, const char *mime_type, media_svc_media_type_e media_type, int is_burst)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
if (g_media_svc_insert_item_data_cnt == 1) {
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ if (g_insert_with_noti)
+ _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt++);
+
} else if(g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, TRUE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ if (g_insert_with_noti)
+ _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
+
g_media_svc_insert_item_cur_data_cnt ++;
} else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, TRUE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ if (g_insert_with_noti)
+ _media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
+
ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ if (g_insert_with_noti) {
+ _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
+ _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt + 1);
+
+ /* Recreate noti list */
+ if (_media_svc_create_noti_list(g_media_svc_insert_item_data_cnt) != MEDIA_INFO_ERROR_NONE) {
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+ }
+
g_media_svc_insert_item_cur_data_cnt = 0;
} else {
media_svc_error("thumbnail_request_from_db failed: %d", ret);
} else {
media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
}
if (content_info.media_meta.width <= 0)
if (content_info.media_meta.height <= 0)
content_info.media_meta.height = height;
-
- ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
- media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
}
#endif
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE);
+
+ if (ret == MEDIA_INFO_ERROR_NONE) {
+ media_svc_debug("Insertion is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
+ }
_media_svc_destroy_content_info(&content_info);
return ret;
SAFE_FREE(file_name);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ media_svc_debug("Move is successful. Sending noti for this");
+
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(handle, dest_path, MS_MEDIA_ITEM_FILE, ¬i_item);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /* Send notification for move */
+ _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
+ _media_svc_destroy_noti_item(noti_item);
+
/*update folder modified_time*/
folder_path = g_path_get_dirname(dest_path);
ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE);
media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
- /*Get thumbnail path to delete*/
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
- media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
+ int media_type = -1;
+ ret = _media_svc_get_media_type_by_path(db_handle, path, &media_type);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE), ret);
+
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ /*Get thumbnail path to delete*/
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
+ } else if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+ int count = 0;
+ ret = _media_svc_get_media_count_with_album_id_by_path(db_handle, path, &count);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE), ret);
+
+ if (count == 1) {
+ /*Get thumbnail path to delete*/
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
+ }
+ }
+
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*Delete item*/
ret = _media_svc_delete_item_by_path(db_handle, path);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ /* Send notification */
+ media_svc_debug("Deletion is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
+ _media_svc_destroy_noti_item(noti_item);
+
/*Delete thumbnail*/
if (strlen(thumb_path) > 0) {
if (_media_svc_remove_file(thumb_path) == FALSE) {
media_svc_error("fail to remove thumbnail file.");
- return MEDIA_INFO_ERROR_INTERNAL;
}
}
media_svc_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
media_svc_content_info_s content_info;
memset(&content_info, 0, sizeof(media_svc_content_info_s));
media_svc_error("thumbnail_request_from_db failed: %d", ret);
} else {
media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
}
if (content_info.media_meta.width <= 0)
if (content_info.media_meta.height <= 0)
content_info.media_meta.height = height;
-
- ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
- media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
}
#endif
ret = _media_svc_update_item_with_data(db_handle, &content_info);
+ if (ret == MEDIA_INFO_ERROR_NONE) {
+ media_svc_debug("Update is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, media_type, noti_item->media_uuid, noti_item->mime_type);
+ _media_svc_destroy_noti_item(noti_item);
+ }
+
_media_svc_destroy_content_info(&content_info);
return ret;
media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(handle, src_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
ret = _media_svc_sql_begin_trans(handle);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
strncpy(media_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
+ media_uuid[sizeof(media_uuid) - 1] = '\0';
} else {
media_svc_error("media UUID is NULL");
return MEDIA_INFO_ERROR_DATABASE_INVALID;
if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
strncpy(media_path, (const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
+ media_path[sizeof(media_path) - 1] = '\0';
} else {
media_svc_error("media path is NULL");
return MEDIA_INFO_ERROR_DATABASE_INVALID;
if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
strncpy(media_thumb_path, (const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
+ media_thumb_path[sizeof(media_thumb_path) - 1] = '\0';
} else {
media_svc_debug("media thumb path doesn't exist in DB");
no_thumb = TRUE;
return ret;
}
+ media_svc_debug("Folder update is successful. Sending noti for this");
+ _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, src_path, -1, noti_item->media_uuid, NULL);
+ _media_svc_destroy_noti_item(noti_item);
+
return MEDIA_INFO_ERROR_NONE;
}
return _media_svc_error_convert(ret);
}
+
+int media_svc_send_dir_update_noti(MediaSvcHandle *handle, const char *dir_path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(!STRING_VALID(dir_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "dir_path is NULL");
+
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(db_handle, dir_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ ret = _media_svc_publish_noti(MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, dir_path, -1, noti_item->media_uuid, NULL);
+ _media_svc_destroy_noti_item(noti_item);
+
+ return ret;
+}
int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int * album_id);
int _media_svc_get_album_art_by_album_id(sqlite3 *handle, int album_id, char **album_art);
int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id);
-
+int _media_svc_get_media_count_with_album_id_by_path(sqlite3 *handle, const char *path, int *count);
#endif /*_MEDIA_SVC_ALBUM_H_*/
#include <stdbool.h>
#include "media-svc-types.h"
#include "media-svc-env.h"
+#include "media-svc-noti.h"
int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count);
-int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, bool stack_query);
+int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, int is_burst, bool stack_query);
int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info);
int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type);
+int _media_svc_get_burst_id(sqlite3 *handle, int *id);
int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path);
int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type);
int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type);
int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type);
int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length);
int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path);
+int _media_svc_get_noti_info(sqlite3 *handle, const char *path, int update_item, media_svc_noti_item **item);
#endif /*_MEDIA_SVC_MEDIA_H_*/
--- /dev/null
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SVC_NOTI_H_
+#define _MEDIA_SVC_NOTI_H_
+
+#include "media-svc-env.h"
+#include "media-svc-debug.h"
+#include "media-svc-error.h"
+#include <media-util-noti.h>
+
+typedef struct _media_svc_noti_item media_svc_noti_item;
+
+struct _media_svc_noti_item {
+ int pid;
+ media_item_type_e update_item;
+ media_item_update_type_e update_type;
+ media_type_e media_type;
+ char *media_uuid;
+ char *path;
+ char *mime_type;
+};
+
+void _media_svc_set_noti_from_pid(int pid);
+
+int _media_svc_create_noti_list(int count);
+int _media_svc_insert_item_to_noti_list(media_svc_content_info_s *content_info, int cnt);
+int _media_svc_destroy_noti_list(int all_cnt);
+int _media_svc_publish_noti_list(int all_cnt);
+
+#if 0
+int _media_svc_create_noti_item(media_svc_content_info_s *content_info,
+ int pid,
+ media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ media_svc_noti_item **item);
+
+#endif
+int _media_svc_destroy_noti_item(media_svc_noti_item *item);
+int _media_svc_publish_noti_by_item(media_svc_noti_item *noti_item);
+
+int _media_svc_publish_noti(media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ const char *path,
+ media_type_e media_type,
+ const char *uuid,
+ const char *mime_type
+);
+
+#endif /*_MEDIA_SVC_NOTI_H_*/
+
--- /dev/null
+SET(fw_name "media-service")
+SET(fw_test "${fw_name}-test")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog libmedia-utils)
+FOREACH(flag ${${fw_test}_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+aux_source_directory(. sources)
+FOREACH(src ${sources})
+ GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
+ MESSAGE("${src_name}")
+ ADD_EXECUTABLE(${src_name} ${src})
+ TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS})
+ENDFOREACH()
--- /dev/null
+#include <stdio.h>
+#include <unistd.h>
+#include <media-svc.h>
+#include <media-svc-noti.h>
+
+GMainLoop *g_loop = NULL;
+MediaSvcHandle *g_db_handle = NULL;
+
+void _noti_cb(int pid,
+ media_item_type_e update_item,
+ media_item_update_type_e update_type,
+ char *path,
+ char *uuid,
+ media_type_e content_type,
+ char *mime_type,
+ void *user_data)
+{
+ media_svc_debug("Noti from PID(%d)", pid);
+
+ if (update_item == MS_MEDIA_ITEM_FILE) {
+ media_svc_debug("Noti item : MS_MEDIA_ITEM_FILE");
+ } else if (update_item == MS_MEDIA_ITEM_DIRECTORY) {
+ media_svc_debug("Noti item : MS_MEDIA_ITEM_DIRECTORY");
+ }
+
+ if (update_type == MS_MEDIA_ITEM_INSERT) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_INSERT");
+ } else if (update_type == MS_MEDIA_ITEM_DELETE) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_DELETE");
+ } else if (update_type == MS_MEDIA_ITEM_UPDATE) {
+ media_svc_debug("Noti type : MS_MEDIA_ITEM_UPDATE");
+ }
+
+ //media_svc_debug("content type : %d", content_type);
+ printf("content type : %d\n", content_type);
+
+ if (path)
+ printf("path : %s\n", path);
+ else
+ printf("path not");
+
+ if (mime_type)
+ printf("mime_type : %s", mime_type);
+ else
+ printf("mime not");
+
+ if (user_data) printf("String : %s\n", (char *)user_data);
+ else
+ printf("user not");
+
+ return;
+}
+
+#if 1
+gboolean _send_noti_batch_operations(gpointer data)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ /* First of all, noti subscription */
+ char *user_str = strdup("hi");
+ media_db_update_subscribe(_noti_cb, (void*)user_str);
+
+ /* 1. media_svc_insert_item_immediately */
+ char *path = "/opt/usr/media/test/image1.jpg";
+
+ media_svc_media_type_e media_type;
+ media_svc_storage_type_e storage_type;
+ char mime_type[255] = {0, };
+
+ ret = media_svc_get_storage_type(path, &storage_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_mime_type(path, mime_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_media_type(path, mime_type, &media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_media_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ int i;
+ char *file_list[10];
+
+ ret = media_svc_insert_item_begin(g_db_handle, 100, TRUE, getpid());
+ //ret = media_svc_insert_item_begin(g_db_handle, 100);
+ for (i = 0; i < 16; i++) {
+ char filepath[255] = {0,};
+ snprintf(filepath, sizeof(filepath), "%s%d.jpg", "/opt/usr/media/test/image", i+1);
+ media_svc_debug("File : %s\n", filepath);
+ file_list[i] = strdup(filepath);
+ ret = media_svc_insert_item_bulk(g_db_handle, storage_type, file_list[i], mime_type, media_type, FALSE);
+ if (ret != 0) {
+ media_svc_error("media_svc_insert_item_bulk[%d] failed", i);
+ } else {
+ media_svc_debug("media_svc_insert_item_bulk[%d] success", i);
+ }
+ }
+
+ ret = media_svc_insert_item_end(g_db_handle);
+
+ return FALSE;
+}
+#endif
+
+gboolean _send_noti_operations(gpointer data)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ /* First of all, noti subscription */
+ char *user_str = strdup("hi");
+ media_db_update_subscribe(_noti_cb, (void*)user_str);
+
+ /* 1. media_svc_insert_item_immediately */
+ char *path = "/opt/usr/media/test/image1.jpg";
+
+ media_svc_media_type_e media_type;
+ media_svc_storage_type_e storage_type;
+ char mime_type[255] = {0, };
+
+ ret = media_svc_get_storage_type(path, &storage_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_storage_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_mime_type(path, mime_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_get_media_type(path, mime_type, &media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_get_media_type failed : %d (%s)", ret, path);
+ return FALSE;
+ }
+
+ ret = media_svc_insert_item_immediately(g_db_handle, storage_type, path, mime_type, media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_insert_item_immediately failed : %d", ret);
+ return FALSE;
+ }
+
+ media_svc_debug("media_svc_insert_item_immediately success");
+
+ /* 2. media_svc_refresh_item */
+ ret = media_svc_refresh_item(g_db_handle, storage_type, path, media_type);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_refresh_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_refresh_item success");
+
+ /* 2. media_svc_move_item */
+ const char *dst_path = "/opt/usr/media/test/image11.jpg";
+ ret = media_svc_move_item(g_db_handle, storage_type, path, storage_type, dst_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_move_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_move_item success");
+
+ ret = media_svc_move_item(g_db_handle, storage_type, dst_path, storage_type, path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_move_item failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_move_item success");
+
+ /* 4. media_svc_delete_item_by_path */
+ ret = media_svc_delete_item_by_path(g_db_handle, path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_delete_item_by_path failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_delete_item_by_path success");
+
+ /* Rename folder */
+ const char *src_folder_path = "/opt/usr/media/test";
+ const char *dst_folder_path = "/opt/usr/media/test_test";
+ ret = media_svc_rename_folder(g_db_handle, src_folder_path, dst_folder_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_rename_folder failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_rename_folder success");
+
+ /* Rename folder again */
+ ret = media_svc_rename_folder(g_db_handle, dst_folder_path, src_folder_path);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_rename_folder failed : %d", ret);
+ return FALSE;
+ }
+ media_svc_debug("media_svc_rename_folder success");
+
+ return FALSE;
+}
+
+int test_noti()
+{
+ GSource *source = NULL;
+ GMainContext *context = NULL;
+
+ g_loop = g_main_loop_new(NULL, FALSE);
+ context = g_main_loop_get_context(g_loop);
+ source = g_idle_source_new();
+#if 0
+ g_source_set_callback (source, _send_noti_operations, NULL, NULL);
+#else
+ g_source_set_callback (source, _send_noti_batch_operations, NULL, NULL);
+#endif
+ g_source_attach (source, context);
+
+ g_main_loop_run(g_loop);
+
+ g_main_loop_unref(g_loop);
+ media_db_update_unsubscribe();
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int main()
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ ret = media_svc_connect(&g_db_handle);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("media_svc_connect failed : %d", ret);
+ } else {
+ media_svc_debug("media_svc_connect success");
+ }
+
+ ret = test_noti();
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("test_noti failed : %d", ret);
+ } else {
+ media_svc_debug("test_noti success");
+ }
+
+ media_svc_disconnect(g_db_handle);
+ return ret;
+}
+