hib_directory = /etc/rc.d/rc5.d
install-data-hook:
- mkdir $(DESTDIR)/usr/local/bin/ -p
- cp -a $(CURDIR)/reset_mediadb.sh $(DESTDIR)/usr/local/bin/
mkdir $(DESTDIR)$(nor_directory) -p
ln -s ../init.d/mediasvr S99mediasvr
mv ./S99mediasvr $(DESTDIR)$(nor_directory)
media-scanner \
mediadb-update
-media_server_SOURCES = common/media-server-dbus.c \
- common/media-server-drm.c \
- common/media-server-utils.c \
- common/media-server-external-storage.c \
- common/media-server-db-svc.c \
- common/media-server-inotify-internal.c \
- common/media-server-inotify.c \
- common/media-server-db.c \
- common/media-server-socket.c \
- common/media-server-thumb.c \
- common/media-server-scanner.c \
- common/media-server-main.c
-
-media_server_CFLAGS = -I${srcdir}/common/include \
+media_server_SOURCES = src/common/media-common-drm.c \
+ src/common/media-common-utils.c \
+ src/common/media-common-external-storage.c \
+ src/server/media-server-db-svc.c \
+ src/server/media-server-db.c \
+ src/server/media-server-socket.c \
+ src/server/media-server-thumb.c \
+ src/server/media-server-scanner.c \
+ src/server/media-server-main.c
+
+media_server_CFLAGS = -I${srcdir}/src/common/include \
+ -I${srcdir}/src/server/include \
-I${srcdir}/lib/include \
$(GTHREAD_CFLAGS) \
$(GLIB_CFLAGS) \
-ldl \
$(STATUS_LIBS)
-media_scanner_SOURCES = common/scanner/media-scanner-drm.c \
- common/scanner/media-scanner-utils.c \
- common/scanner/media-scanner-db-svc.c \
- common/scanner/media-scanner-scan.c \
- common/scanner/media-scanner-socket.c \
- common/scanner/media-scanner.c
-
-media_scanner_CFLAGS = -I${srcdir}/common/scanner/include \
- -I${srcdir}/lib/include \
- -I${srcdir}/common/include \
+media_scanner_SOURCES = src/common/media-common-utils.c \
+ src/common/media-common-external-storage.c \
+ src/common/media-common-drm.c \
+ src/scanner/media-scanner-db-svc.c \
+ src/scanner/media-scanner-scan.c \
+ src/scanner/media-scanner-socket.c \
+ src/scanner/media-scanner.c
+
+media_scanner_CFLAGS = -I${srcdir}/lib/include \
+ -I${srcdir}/src/common/include \
+ -I${srcdir}/src/scanner/include \
$(GTHREAD_CFLAGS) \
$(GLIB_CFLAGS) \
$(PHONESTATUS_CFLAGS) \
$(AUL_CFLAG)\
$(LIBPMCONTROL_CFLAGS) \
$(HEYNOTI_CFLAGS) \
- $(DBUS_CFLAGS)
+ $(DBUS_CFLAGS) \
+ $(STATUS_CFLAGS)
media_scanner_LDADD = libmedia-utils.la \
$(GLIB_LIBS) \
$(THUMB_GEN_LIBS) \
$(HEYNOTI_LIBS) \
$(DBUS_LIBS) \
- -ldl #this is for using dlsym
+ -ldl \
+ $(STATUS_LIBS)
-mediadb_update_SOURCES = common/mediadb-update.c
+mediadb_update_SOURCES = src/mediadb-update.c
mediadb_update_CFLAGS = -I${srcdir}/lib/include \
$(GTHREAD_CFLAGS) \
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-db-svc.h
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-#ifndef _MEDIA_SERVER_DB_SVC_H_
-#define _MEDIA_SERVER_DB_SVC_H_
-
-#include "media-server-types.h"
-#if MS_INOTI_ENABLE
-typedef int (*CHECK_ITEM)(const char*, const char*, char **);
-typedef int (*CONNECT)(void**, char **);
-typedef int (*DISCONNECT)(void*, char **);
-typedef int (*CHECK_ITEM_EXIST)(void*, const char*, int, char **);
-typedef int (*INSERT_ITEM_BEGIN)(void*, int, char **);
-typedef int (*INSERT_ITEM_END)(void*, char **);
-typedef int (*INSERT_ITEM)(void*, const char*, int, const char*, char **);
-typedef int (*INSERT_ITEM_IMMEDIATELY)(void*, const char*, int, const char*, char **);
-typedef int (*MOVE_ITEM_BEGIN)(void*, int, char **);
-typedef int (*MOVE_ITEM_END)(void*, char **);
-typedef int (*MOVE_ITEM)(void*, const char*, int, const char*, int, const char*, char **);
-typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
-typedef int (*SET_ITEM_VALIDITY_BEGIN)(void*, int, char **);
-typedef int (*SET_ITEM_VALIDITY_END)(void*, char **);
-typedef int (*SET_ITEM_VALIDITY)(void*, const char*, int, const char*, int, char **);
-typedef int (*DELETE_ITEM)(void*, const char*, int, char **);
-typedef int (*DELETE_ALL_ITEMS_IN_STORAGE)(void*, int, char **);
-typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void*, int, char **);
-typedef int (*UPDATE_BEGIN)(char **);
-typedef int (*UPDATE_END)(char **);
-typedef int (*REFRESH_ITEM)(void*, const char *, int, const char*, char**);
-
-int
-ms_load_functions(void);
-
-void
-ms_unload_functions(void);
-
-int
-ms_connect_db(void ***handle);
-
-int
-ms_disconnect_db(void ***handle);
-
-int
-ms_validate_item(void **handle, char *path);
-
-int
-ms_register_file(void **handle, const char *path, GAsyncQueue* queue);
-
-int
-ms_insert_item_batch(void **handle, const char *path);
-
-int
-ms_insert_item(void **handle, const char *path);
-
-int
-ms_delete_item(void **handle, const char *full_file_path);
-
-int
-ms_move_item(void **handle,
- ms_storage_type_t src_store_type,
- ms_storage_type_t dest_store_type,
- const char *src_file_full_path,
- const char *dest_file_full_path);
-
-bool
-ms_delete_all_items(void **handle, ms_storage_type_t store_type);
-
-int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type);
-
-bool
-ms_delete_invalid_items(void **handle, ms_storage_type_t store_type);
-
-int
-ms_refresh_item(void **handle, const char *path);
-
-int
-ms_check_exist(void **handle, const char *path);
-
-/****************************************************************************************************
-FOR BULK COMMIT
-*****************************************************************************************************/
-
-void
-ms_register_start(void **handle);
-
-void
-ms_register_end(void **handle);
-
-void
-ms_move_start(void **handle);
-
-void
-ms_move_end(void **handle);
-
-void
-ms_validate_start(void **handle);
-
-void
-ms_validate_end(void **handle);
-#else
-typedef int (*CHECK_ITEM)(const char*, const char*, char **);
-typedef int (*CONNECT)(void**, char **);
-typedef int (*DISCONNECT)(void*, char **);
-typedef int (*CHECK_ITEM_EXIST)(void*, const char*, int, char **);
-typedef int (*INSERT_ITEM_IMMEDIATELY)(void*, const char*, int, const char*, char **);
-typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
-
-int
-ms_load_functions(void);
-
-void
-ms_unload_functions(void);
-
-int
-ms_connect_db(void ***handle);
-
-int
-ms_disconnect_db(void ***handle);
-
-int
-ms_insert_item(void **handle, const char *path);
-
-int
-ms_register_file(void **handle, const char *path);
-
-int
-ms_check_exist(void **handle, const char *path);
-
-int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type);
-#endif
-
-#endif /*_MEDIA_SERVER_DB_SVC_H_*/
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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_SERVER_DBUS_TYPES_H_
-#define _MEDIA_SERVER_DBUS_TYPES_H_
-
-#define MS_DBUS_PATH "/com/mediaserver/dbus/notify"
-#define MS_DBUS_INTERFACE "com.mediaserver.dbus.Signal"
-#define MS_DBUS_NAME "ms_db_updated"
-#define MS_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
-
-typedef enum {
- MS_DBUS_DB_UPDATED
-} ms_dbus_noti_type_t;
-
-#endif /*_MEDIA_SERVER_DBUS_TYPES_H_*/
\ No newline at end of file
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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_SERVER_DBUS_H__
-#define _MEDIA_SERVER_DBUS_H__
-
-#include "media-server-dbus-type.h"
-
-void ms_dbus_init(void);
-
-gboolean ms_dbus_send_noti(ms_dbus_noti_type_t data);
-
-#endif/*_MEDIA_SERVER_DBUS_H__*/
\ No newline at end of file
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-inotify-internal.h
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-#ifndef _MEDIA_SERVER_INOTIFY_INTERNAL_H_
-#define _MEDIA_SERVER_INOTIFY_INTERNAL_H_
-
-#include <sys/inotify.h>
-#include "media-server-types.h"
-#if MS_INOTI_ENABLE
-#define INOTI_EVENT_SIZE (sizeof(struct inotify_event))
-#define INOTI_BUF_LEN (1024*(INOTI_EVENT_SIZE+16))
-#define INOTI_FOLDER_COUNT_MAX 1024
-
-typedef struct ms_inoti_dir_data {
- char *name;
- int wd;
- struct ms_inoti_dir_data *next;
-} ms_inoti_dir_data;
-
-typedef struct ms_create_file_info {
- char *name;
- int wd;
- struct ms_create_file_info *previous;
- struct ms_create_file_info *next;
-} ms_create_file_info;
-
-int _ms_inoti_add_create_file_list(int wd, char *name);
-
-int _ms_inoti_delete_create_file_list(ms_create_file_info *node);
-
-ms_create_file_info *_ms_inoti_find_create_file_list(int wd, char *name);
-
-bool _ms_inoti_full_path(int wd, char *name, char *path, int sizeofpath);
-
-bool _ms_inoti_get_full_path(int wd, char *name, char *path, int sizeofpath);
-#endif
-#endif /*_MEDIA_SERVER_INOTIFY_INTERNAL_H_*/
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-inotify.h
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-
-#ifndef _MEDIA_SERVER_INOTI_H_
-#define _MEDIA_SERVER_INOTI_H_
-
-#include <glib.h>
-#include "media-server-types.h"
-
-#if MS_INOTI_ENABLE
-
-typedef struct ms_ignore_file_info {
- char *path;
- struct ms_ignore_file_info *previous;
- struct ms_ignore_file_info *next;
-} ms_ignore_file_info;
-
-int ms_inoti_init(void);
-
-gboolean ms_inoti_thread(gpointer data);
-
-void ms_inoti_add_watch(char *path);
-
-int ms_inoti_add_watch_with_node(ms_dir_scan_info * const current_node, int depth);
-
-void ms_inoti_remove_watch_recursive(char *path);
-
-void ms_inoti_remove_watch(char *path);
-
-void ms_inoti_modify_watch(char *path_from, char *path_to);
-
-int ms_inoti_add_ignore_file(const char *path);
-
-int ms_inoti_delete_ignore_file(ms_ignore_file_info * delete_node);
-
-ms_ignore_file_info *ms_inoti_find_ignore_file(const char *path);
-
-void ms_inoti_delete_mmc_ignore_file(void);
-
-void ms_inoti_add_watch_all_directory(ms_storage_type_t storage_type);
-
-#endif
-#endif/* _MEDIA_SERVER_INOTI_H_ */
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-db-svc.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief This file implements main database operation.
- */
-
-#include <dlfcn.h>
-#include <aul/aul.h>
-
-#include "media-util.h"
-
-#include "media-server-dbg.h"
-#include "media-server-utils.h"
-#include "media-server-inotify.h"
-#include "media-server-drm.h"
-#include "media-server-db-svc.h"
-#if MS_INOTI_ENABLE
-GAsyncQueue* soc_queue;
-GArray *reg_list;
-GMutex *list_mutex;
-GMutex *queue_mutex;
-GMutex * db_mutex;
-
-#define MS_REGISTER_COUNT 100 /*For bundle commit*/
-#define MS_VALID_COUNT 100 /*For bundle commit*/
-#define MS_MOVE_COUNT 100 /*For bundle commit*/
-
-void **func_handle = NULL; /*dlopen handel*/
-
-enum func_list {
- eCHECK,
- eCONNECT,
- eDISCONNECT,
- eEXIST,
- eINSERT_BEGIN,
- eINSERT_END,
- eINSERT_BATCH,
- eINSERT,
- eMOVE_BEGIN,
- eMOVE_END,
- eMOVE,
- eSET_ALL_VALIDITY,
- eSET_VALIDITY_BEGIN,
- eSET_VALIDITY_END,
- eSET_VALIDITY,
- eDELETE,
- eDELETE_ALL,
- eDELETE_INVALID_ITEMS,
- eUPDATE_BEGIN,
- eUPDATE_END,
- eREFRESH_ITEM,
- eFUNC_MAX
-};
-
-static void
-_ms_insert_reg_list(const char *path)
-{
- char *reg_path = strdup(path);
-
- g_mutex_lock(list_mutex);
-
- g_array_append_val(reg_list, reg_path);
-
- g_mutex_unlock(list_mutex);
-}
-
-static bool
-_ms_find_reg_list(const char *path)
-{
- int list_index;
- int len = reg_list->len;
- char *data;
- bool res = false;
-
- g_mutex_lock(list_mutex);
- MS_DBG("array length : %d", len);
-
- for(list_index = 0; list_index < len; list_index++) {
- data = g_array_index (reg_list, char*, list_index);
- if(!strcmp(data, path))
- res = true;
- }
-
- g_mutex_unlock(list_mutex);
-
- return res;
-}
-
-static void
-_ms_delete_reg_list(const char *path)
-{
- int list_index;
- int len = reg_list->len;
- char *data;
-
- MS_DBG("Delete : %s", path);
- g_mutex_lock(list_mutex);
-
- for(list_index = 0; list_index < len; list_index++) {
- data = g_array_index (reg_list, char*, list_index);
- if(!strcmp(data, path)) {
- MS_DBG("Delete complete : %s", data);
- MS_SAFE_FREE(data);
- g_array_remove_index(reg_list, list_index);
- break;
- }
- }
-
- g_mutex_unlock(list_mutex);
-}
-
-static int
-_ms_get_mime(const char *path, char *mimetype)
-{
- int ret = 0;
-
- if (path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /*get content type and mime type from file. */
- /*in case of drm file. */
- if (ms_is_drm_file(path)) {
-#if MS_INOTI_ENABLE
- ms_inoti_add_ignore_file(path);
-#endif
- ret = ms_get_mime_in_drm_info(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("Fail to get mime");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- } else {
- /*in case of normal files */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- MS_DBG_ERR("aul_get_mime_from_file fail");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-#define CONFIG_PATH "/opt/usr/data/file-manager-service/plugin-config"
-#define EXT ".so"
-#define EXT_LEN 3
-
-GArray *so_array;
-void ***func_array;
-int lib_num;
-
-static int
-_ms_check_category(const char *path, const char *mimetype, int index)
-{
- int ret;
- char *err_msg = NULL;
-
- ret = ((CHECK_ITEM)func_array[index][eCHECK])(path, mimetype, &err_msg);
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, index), err_msg, path);
- MS_SAFE_FREE(err_msg);
- }
-
- return ret;
-}
-
-static int
-_ms_token_data(char *buf, char **name)
-{
- int len;
- char* pos = NULL;
-
- pos = strstr(buf, EXT);
- if (pos == NULL) {
- MS_DBG_ERR("This is not shared object library.");
- name = NULL;
- return -1;
- } else {
- len = pos - buf + EXT_LEN;
- *name = strndup(buf, len);
- MS_DBG("%s", *name);
- }
-
- return 0;
-}
-
-
-static bool
-_ms_load_config()
-{
- int ret;
- FILE *fp;
- char *so_name = NULL;
- char buf[256] = {0};
-
- fp = fopen(CONFIG_PATH, "rt");
- if (fp == NULL) {
- MS_DBG_ERR("fp is NULL");
- return MS_MEDIA_ERR_FILE_OPEN_FAIL;
- }
- while(1) {
- if (fgets(buf, 256, fp) == NULL) {
- MS_DBG_ERR("fgets failed");
- break;
- }
-
- ret = _ms_token_data(buf, &so_name);
- if (ret == 0) {
- /*add to array*/
- g_array_append_val(so_array, so_name);
- so_name = NULL;
- }
- }
-
- fclose(fp);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_load_functions(void)
-{
- int lib_index = 0, func_index;
- char func_list[eFUNC_MAX][40] = {
- "check_item",
- "connect",
- "disconnect",
- "check_item_exist",
- "insert_item_begin",
- "insert_item_end",
- "insert_item",
- "insert_item_immediately",
- "move_item_begin",
- "move_item_end",
- "move_item",
- "set_all_storage_items_validity",
- "set_item_validity_begin",
- "set_item_validity_end",
- "set_item_validity",
- "delete_item",
- "delete_all_items_in_storage",
- "delete_all_invalid_items_in_storage",
- "update_begin",
- "update_end",
- "refresh_item"
- };
- /*init array for adding name of so*/
- so_array = g_array_new(FALSE, FALSE, sizeof(char*));
-
- /*load information of so*/
- _ms_load_config();
-
- if(so_array->len == 0) {
- MS_DBG("There is no information for functions");
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
-
- /*the number of functions*/
- lib_num = so_array->len;
-
- MS_DBG("The number of information of so : %d", lib_num);
- MS_MALLOC(func_handle, sizeof(void*) * lib_num);
- if (func_handle == NULL) {
- MS_DBG_ERR("malloc failed");
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
-
- while(lib_index < lib_num) {
- /*get handle*/
- MS_DBG("[name of so : %s]", g_array_index(so_array, char*, lib_index));
- func_handle[lib_index] = dlopen(g_array_index(so_array, char*, lib_index), RTLD_LAZY);
- if (!func_handle[lib_index]) {
- MS_DBG_ERR("%s", dlerror());
- MS_SAFE_FREE(func_handle);
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
- lib_index++;
- }
-
- dlerror(); /* Clear any existing error */
-
- /*allocate for array of functions*/
- MS_MALLOC(func_array, sizeof(void*) * lib_num);
- if (func_array == NULL) {
- MS_DBG_ERR("malloc failed");
- MS_SAFE_FREE(func_handle);
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
-
- for(lib_index = 0 ; lib_index < lib_num; lib_index ++) {
- MS_MALLOC(func_array[lib_index], sizeof(void*) * eFUNC_MAX);
- if (func_array[lib_index] == NULL) {
- int index;
-
- for (index = 0; index < lib_index; index ++) {
- MS_SAFE_FREE(func_array[index]);
- }
- MS_SAFE_FREE(func_array);
- MS_SAFE_FREE(func_handle);
-
- MS_DBG_ERR("malloc failed");
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
- }
-
- /*add functions to array */
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- for (func_index = 0; func_index < eFUNC_MAX ; func_index++) {
- func_array[lib_index][func_index] = dlsym(func_handle[lib_index], func_list[func_index]);
- if (func_array[lib_index][func_index] == NULL) {
- int index;
-
- for (index = 0; index < lib_index; index ++) {
- MS_SAFE_FREE(func_array[index]);
- }
- MS_SAFE_FREE(func_array);
- MS_SAFE_FREE(func_handle);
-
- MS_DBG_ERR("dlsym failed");
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void
-ms_unload_functions(void)
-{
- int lib_index;
-
- for (lib_index = 0; lib_index < lib_num; lib_index ++)
- dlclose(func_handle[lib_index]);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (func_array[lib_index]) {
- MS_SAFE_FREE(func_array[lib_index]);
- }
- }
-
- MS_SAFE_FREE (func_array);
- MS_SAFE_FREE (func_handle);
- if (so_array) g_array_free(so_array, TRUE);
-}
-
-int
-ms_connect_db(void ***handle)
-{
- int lib_index;
- int ret;
- char * err_msg = NULL;
-
- /*Lock mutex for openning db*/
- g_mutex_lock(db_mutex);
-
- MS_MALLOC(*handle, sizeof (void*) * lib_num);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- g_mutex_unlock(db_mutex);
-
- return MS_MEDIA_ERR_DB_CONNECT_FAIL;
- }
- }
-
- MS_DBG("connect Media DB");
-
- g_mutex_unlock(db_mutex);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_disconnect_db(void ***handle)
-{
- int lib_index;
- int ret;
- char * err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DISCONNECT)func_array[lib_index][eDISCONNECT])((*handle)[lib_index], &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- return MS_MEDIA_ERR_DB_DISCONNECT_FAIL;
- }
- }
-
- MS_SAFE_FREE(*handle);
-
- MS_DBG("Disconnect Media DB");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_validate_item(void **handle, char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char *err_msg = NULL;
- char mimetype[255] = {0};
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- storage_type = ms_get_storage_type_by_full(path);
-
- MS_DBG("[%s] %s", mimetype, path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(path, mimetype, lib_index)) {
- /*check exist in Media DB, If file is not exist, insert data in DB. */
- ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG("not exist in %d. insert data", lib_index);
- MS_SAFE_FREE(err_msg);
-
- ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_INSERT_FAIL;
- }
- } else {
- /*if meta data of file exist, change valid field to "1" */
- ret = ((SET_ITEM_VALIDITY)func_array[lib_index][eSET_VALIDITY])(handle[lib_index], path, true, mimetype, true, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- }
- }
- }
- }
-
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- }
-
- return res;
-}
-
-int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char *err_msg = NULL;
- MS_DBG("");
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- }
- }
- MS_DBG("");
- return res;
-}
-
-int
-ms_register_file(void **handle, const char *path, GAsyncQueue* queue)
-{
- MS_DBG("[%d]register file : %s", syscall(__NR_gettid), path);
-
- int res = MS_MEDIA_ERR_NONE;
- int ret;
-
- if (path == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /*check item in DB. If it exist in DB, return directly.*/
- ret = ms_check_exist(handle, path);
- if (ret == MS_MEDIA_ERR_NONE) {
- MS_DBG("Already exist");
- return MS_MEDIA_ERR_NONE;
- }
-
- g_mutex_lock(queue_mutex);
- /*first request for this file*/
- if(!_ms_find_reg_list(path)) {
- /*insert registering file list*/
- _ms_insert_reg_list(path);
- } else {
- MS_DBG("______________________ALREADY INSERTING");
- if(queue != NULL) {
- MS_DBG("Need reply");
- soc_queue = queue;
- }
- g_mutex_unlock(queue_mutex);
- return MS_MEDIA_ERR_NOW_REGISTER_FILE;
- }
- g_mutex_unlock(queue_mutex);
-
- ret = ms_insert_item(handle, path);
- if (ret != MS_MEDIA_ERR_NONE) {
- int lib_index;
- char mimetype[255];
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- res = MS_MEDIA_ERR_MIME_GET_FAIL;
- goto END;
- }
- storage_type = ms_get_storage_type_by_full(path);
-
- MS_DBG("[%s] %s", mimetype, path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- /*check item is already inserted*/
- if (!_ms_check_category(path, mimetype, lib_index)) {
- char *err_msg = NULL;
-
- ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret == 0) {
- res = MS_MEDIA_ERR_NONE;
- } else {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_INSERT_FAIL;
- }
- }
- }
- }
-END:
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- }
-
- g_mutex_lock(queue_mutex);
-
- _ms_delete_reg_list(path);
-
- if (soc_queue != NULL) {
- MS_DBG("%d", res);
- g_async_queue_push(soc_queue, GINT_TO_POINTER(res+MS_MEDIA_ERR_MAX));
- MS_DBG("Return OK");
- }
- soc_queue = NULL;
- g_mutex_unlock(queue_mutex);
-
- return res;
-}
-
-int
-ms_insert_item_batch(void **handle, const char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char mimetype[255] = {0};
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- storage_type = ms_get_storage_type_by_full(path);
-
- MS_DBG("[%s] %s", mimetype, path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(path, mimetype, lib_index)) {
- ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_INSERT_FAIL;
- }
- }
- }
-
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- res = ret;
- }
-
- return res;
-}
-
-int
-ms_insert_item(void **handle, const char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char mimetype[255] = {0};
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- storage_type = ms_get_storage_type_by_full(path);
-
- MS_DBG("[%s] %s", mimetype, path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(path, mimetype, lib_index)) {
- ret = ((INSERT_ITEM_IMMEDIATELY)func_array[lib_index][eINSERT])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_INSERT_FAIL;
- }
- }
- }
-
- return res;
-}
-
-int
-ms_delete_item(void **handle, const char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- storage_type = ms_get_storage_type_by_full(path);
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret == 0) {
- ret = ((DELETE_ITEM)func_array[lib_index][eDELETE])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret !=0 ) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_DELETE_FAIL;
- }
- } else {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_DELETE_FAIL;
- }
- }
-
- if (ms_is_drm_file(path)) {
- ms_drm_unregister(path);
- }
-
- return res;
-}
-
-int
-ms_move_item(void **handle,
- ms_storage_type_t src_store, ms_storage_type_t dst_store,
- const char *src_path, const char *dst_path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char mimetype[255];
- char *err_msg = NULL;
-
- ret = _ms_get_mime(dst_path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- MS_DBG("[%s] %s", mimetype, dst_path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(dst_path, mimetype, lib_index)) {
- ret = ((MOVE_ITEM)func_array[lib_index][eMOVE])(handle[lib_index], src_path, src_store,
- dst_path, dst_store, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- }
- }
- }
-
- return res;
-}
-
-bool
-ms_delete_all_items(void **handle, ms_storage_type_t store_type)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- /* To reset media db when differnet mmc is inserted. */
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_ITEMS_IN_STORAGE)func_array[lib_index][eDELETE_ALL])(handle[lib_index], store_type, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- return false;
- }
- }
-
- return true;
-}
-
-bool
-ms_delete_invalid_items(void **handle, ms_storage_type_t store_type)
-{
- int lib_index;
- int ret;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DELETE_ALL_INVALID_ITMES_IN_STORAGE)func_array[lib_index][eDELETE_INVALID_ITEMS])(handle[lib_index], store_type, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- return false;
- }
- }
-
- return true;
-}
-
-int
-ms_refresh_item(void **handle, const char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char mimetype[255];
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- MS_DBG("[%s] %s", mimetype, path);
-
- storage_type = ms_get_storage_type_by_full(path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(path, mimetype, lib_index)) {
- ret = ((REFRESH_ITEM)func_array[lib_index][eREFRESH_ITEM])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- }
- }
- }
-
- return res;
-}
-
-int
-ms_check_exist(void **handle, const char *path)
-{
- int lib_index;
- int ret;
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- storage_type = ms_get_storage_type_by_full(path);
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret != 0) {
- return MS_MEDIA_ERR_DB_EXIST_ITEM_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-/****************************************************************************************************
-FOR BULK COMMIT
-*****************************************************************************************************/
-
-void
-ms_register_start(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((INSERT_ITEM_BEGIN)func_array[lib_index][eINSERT_BEGIN])(handle[lib_index], MS_REGISTER_COUNT, &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-
-void
-ms_register_end(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((INSERT_ITEM_END)func_array[lib_index][eINSERT_END])(handle[lib_index], &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-
-void
-ms_validate_start(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ITEM_VALIDITY_BEGIN)func_array[lib_index][eSET_VALIDITY_BEGIN])(handle[lib_index], MS_VALID_COUNT, &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-
-void
-ms_validate_end(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ITEM_VALIDITY_END)func_array[lib_index][eSET_VALIDITY_END])(handle[lib_index], &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-
-void
-ms_move_start(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((MOVE_ITEM_BEGIN)func_array[lib_index][eMOVE_BEGIN])(handle[lib_index], MS_MOVE_COUNT, &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-
-void
-ms_move_end(void **handle)
-{
- int lib_index;
- int ret = 0;
- char *err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((MOVE_ITEM_END)func_array[lib_index][eMOVE_END])(handle[lib_index], &err_msg);/*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- }
- }
-}
-#else
-
-GMutex * db_mutex;
-#define CONFIG_PATH "/opt/usr/data/file-manager-service/plugin-config"
-#define EXT ".so"
-#define EXT_LEN 3
-
-GArray *so_array;
-void ***func_array;
-int lib_num;
-
-void **func_handle = NULL; /*dlopen handle*/
-
-enum func_list {
- eCHECK,
- eCONNECT,
- eDISCONNECT,
- eEXIST,
- eINSERT,
- eSET_ALL_VALIDITY,
- eFUNC_MAX
-};
-
-static int
-_ms_get_mime(const char *path, char *mimetype)
-{
- int ret = 0;
-
- if (path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /*get content type and mime type from file. */
- /*in case of drm file. */
- if (ms_is_drm_file(path)) {
-#if MS_INOTI_ENABLE
- ms_inoti_add_ignore_file(path);
-#endif
- ret = ms_get_mime_in_drm_info(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("Fail to get mime");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- } else {
- /*in case of normal files */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- MS_DBG_ERR("aul_get_mime_from_file fail");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int
-_ms_check_category(const char *path, const char *mimetype, int index)
-{
- int ret;
- char *err_msg = NULL;
-
- ret = ((CHECK_ITEM)func_array[index][eCHECK])(path, mimetype, &err_msg);
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, index), err_msg, path);
- MS_SAFE_FREE(err_msg);
- }
-
- return ret;
-}
-
-static int
-_ms_token_data(char *buf, char **name)
-{
- int len;
- char* pos = NULL;
-
- pos = strstr(buf, EXT);
- if (pos == NULL) {
- MS_DBG_ERR("This is not shared object library.");
- name = NULL;
- return -1;
- } else {
- len = pos - buf + EXT_LEN;
- *name = strndup(buf, len);
- MS_DBG("%s", *name);
- }
-
- return 0;
-}
-
-static bool
-_ms_load_config()
-{
- int ret;
- FILE *fp;
- char *so_name = NULL;
- char buf[256] = {0};
-
- fp = fopen(CONFIG_PATH, "rt");
- if (fp == NULL) {
- MS_DBG_ERR("fp is NULL");
- return MS_MEDIA_ERR_FILE_OPEN_FAIL;
- }
- while(1) {
- if (fgets(buf, 256, fp) == NULL) {
- MS_DBG_ERR("fgets failed");
- break;
- }
-
- ret = _ms_token_data(buf, &so_name);
- if (ret == 0) {
- /*add to array*/
- g_array_append_val(so_array, so_name);
- so_name = NULL;
- }
- }
-
- fclose(fp);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_load_functions(void)
-{
- int lib_index = 0, func_index;
- char func_list[eFUNC_MAX][40] = {
- "check_item",
- "connect",
- "disconnect",
- "check_item_exist",
- "insert_item_immediately",
- "set_all_storage_items_validity",
- };
- /*init array for adding name of so*/
- so_array = g_array_new(FALSE, FALSE, sizeof(char*));
-
- /*load information of so*/
- _ms_load_config();
-
- if(so_array->len == 0) {
- MS_DBG("There is no information for functions");
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
-
- /*the number of functions*/
- lib_num = so_array->len;
-
- MS_DBG("The number of information of so : %d", lib_num);
- MS_MALLOC(func_handle, sizeof(void*) * lib_num);
- if (func_handle == NULL) {
- MS_DBG_ERR("malloc failed");
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
-
- while(lib_index < lib_num) {
- /*get handle*/
- MS_DBG("[name of so : %s]", g_array_index(so_array, char*, lib_index));
- func_handle[lib_index] = dlopen(g_array_index(so_array, char*, lib_index), RTLD_LAZY);
- if (!func_handle[lib_index]) {
- MS_DBG_ERR("%s", dlerror());
- MS_SAFE_FREE(func_handle);
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
- lib_index++;
- }
-
- dlerror(); /* Clear any existing error */
-
- /*allocate for array of functions*/
- MS_MALLOC(func_array, sizeof(void*) * lib_num);
- if (func_array == NULL) {
- MS_DBG_ERR("malloc failed");
- MS_SAFE_FREE(func_handle);
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
-
- for(lib_index = 0 ; lib_index < lib_num; lib_index ++) {
- MS_MALLOC(func_array[lib_index], sizeof(void*) * eFUNC_MAX);
- if (func_array[lib_index] == NULL) {
- int index;
-
- for (index = 0; index < lib_index; index ++) {
- MS_SAFE_FREE(func_array[index]);
- }
- MS_SAFE_FREE(func_array);
- MS_SAFE_FREE(func_handle);
-
- MS_DBG_ERR("malloc failed");
- return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
- }
-
- /*add functions to array */
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- for (func_index = 0; func_index < eFUNC_MAX ; func_index++) {
- func_array[lib_index][func_index] = dlsym(func_handle[lib_index], func_list[func_index]);
- if (func_array[lib_index][func_index] == NULL) {
- int index;
-
- for (index = 0; index < lib_index; index ++) {
- MS_SAFE_FREE(func_array[index]);
- }
- MS_SAFE_FREE(func_array);
- MS_SAFE_FREE(func_handle);
-
- MS_DBG_ERR("dlsym failed");
- return MS_MEDIA_ERR_DYNAMIC_LINK;
- }
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void
-ms_unload_functions(void)
-{
- int lib_index;
-
- for (lib_index = 0; lib_index < lib_num; lib_index ++)
- dlclose(func_handle[lib_index]);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (func_array[lib_index]) {
- MS_SAFE_FREE(func_array[lib_index]);
- }
- }
-
- MS_SAFE_FREE (func_array);
- MS_SAFE_FREE (func_handle);
- if (so_array) g_array_free(so_array, TRUE);
-}
-
-int
-ms_connect_db(void ***handle)
-{
- int lib_index;
- int ret;
- char * err_msg = NULL;
-
- /*Lock mutex for openning db*/
- g_mutex_lock(db_mutex);
-
- MS_MALLOC(*handle, sizeof (void*) * lib_num);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- g_mutex_unlock(db_mutex);
-
- return MS_MEDIA_ERR_DB_CONNECT_FAIL;
- }
- }
-
- MS_DBG("connect Media DB");
-
- g_mutex_unlock(db_mutex);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_disconnect_db(void ***handle)
-{
- int lib_index;
- int ret;
- char * err_msg = NULL;
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((DISCONNECT)func_array[lib_index][eDISCONNECT])((*handle)[lib_index], &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- return MS_MEDIA_ERR_DB_DISCONNECT_FAIL;
- }
- }
-
- MS_SAFE_FREE(*handle);
-
- MS_DBG("Disconnect Media DB");
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_check_exist(void **handle, const char *path)
-{
- int lib_index;
- int ret;
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- storage_type = ms_get_storage_type_by_full(path);
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], path, storage_type, &err_msg); /*dlopen*/
- if (ret != 0) {
- return MS_MEDIA_ERR_DB_EXIST_ITEM_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-ms_insert_item(void **handle, const char *path)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char mimetype[255] = {0};
- char *err_msg = NULL;
- ms_storage_type_t storage_type;
-
- ret = _ms_get_mime(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("err : _ms_get_mime [%d]", ret);
- return ret;
- }
- storage_type = ms_get_storage_type_by_full(path);
-
- MS_DBG("[%s] %s", mimetype, path);
-
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- if (!_ms_check_category(path, mimetype, lib_index)) {
- ret = ((INSERT_ITEM_IMMEDIATELY)func_array[lib_index][eINSERT])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_INSERT_FAIL;
- }
- }
- }
-
- return res;
-}
-
-int
-ms_register_file(void **handle, const char *path)
-{
- MS_DBG("[%d]register file : %s", syscall(__NR_gettid), path);
-
- int res = MS_MEDIA_ERR_NONE;
- int ret;
-
- if (path == NULL) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /*check item in DB. If it exist in DB, return directly.*/
- ret = ms_check_exist(handle, path);
- if (ret == MS_MEDIA_ERR_NONE) {
- MS_DBG("Already exist");
- return MS_MEDIA_ERR_NONE;
- }
-
- ret = ms_insert_item(handle, path);
- if (ret != MS_MEDIA_ERR_NONE) {
- res = ret;
- MS_DBG_ERR("ms_insert_item failed [%d]", ret);
- }
-
- if (ms_is_drm_file(path)) {
- ret = ms_drm_register(path);
- }
-
- return res;
-}
-
-int
-ms_invalidate_all_items(void **handle, ms_storage_type_t store_type)
-{
- int lib_index;
- int res = MS_MEDIA_ERR_NONE;
- int ret;
- char *err_msg = NULL;
- MS_DBG("");
- for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
- if (ret != 0) {
- MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
- MS_SAFE_FREE(err_msg);
- res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
- }
- }
- MS_DBG("");
- return res;
-}
-
-#endif
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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 <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-
-#include "media-server-dbg.h"
-#include "media-server-types.h"
-#include "media-server-dbus.h"
-
-void ms_dbus_init(void)
-{
- DBusConnection *bus;
- DBusError error;
-
- /* Get a connection to the session bus */
- dbus_error_init (&error);
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus) {
- MS_DBG ("Failed to connect to the D-BUS daemon: %s", error.message);
- dbus_error_free (&error);
- return;
- }
-
- /* Set up this connection to work in a GLib event loop */
- dbus_connection_setup_with_g_main (bus, NULL);
-}
-
-gboolean ms_dbus_send_noti(ms_dbus_noti_type_t data)
-{
- MS_DBG("");
- DBusMessage *message;
- DBusConnection *bus;
- DBusError error;
- dbus_uint16_t noti_type = data;
-
- /* Get a connection to the session bus */
- dbus_error_init (&error);
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
- if (!bus) {
- MS_DBG ("Failed to connect to the D-BUS daemon: %s", error.message);
- dbus_error_free (&error);
- return false;
- }
-
- /* Create a new signal on the "MS_DBUS_INTERFACE" interface,
- * from the object "MS_DBUS_PATH". */
- message = dbus_message_new_signal (MS_DBUS_PATH, MS_DBUS_INTERFACE, MS_DBUS_NAME);
-
- /* Append the notification type to the signal */
- dbus_message_append_args (message, DBUS_TYPE_UINT16, ¬i_type, DBUS_TYPE_INVALID);
-
- /* Send the signal */
- dbus_connection_send (bus, message, NULL);
-
- /* Free the signal now we have finished with it */
- dbus_message_unref (message);
-
- /* Return TRUE to tell the event loop we want to be called again */
- return true;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-inotify-internal.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief23
- */
-#include "media-util.h"
-
-#include "media-server-dbg.h"
-#include "media-server-utils.h"
-#include "media-server-inotify-internal.h"
-#if MS_INOTI_ENABLE
-int inoti_fd;
-ms_create_file_info *latest_create_file;
-extern ms_inoti_dir_data *first_inoti_node;
-
-int _ms_inoti_add_create_file_list(int wd, char *name)
-{
- ms_create_file_info *new_node;
-
- new_node = malloc(sizeof(ms_create_file_info));
- new_node->name = strdup(name);
- new_node->wd = wd;
-
- /*first created file */
- if (latest_create_file == NULL) {
- latest_create_file = malloc(sizeof(ms_create_file_info));
- new_node->previous = NULL;
- } else {
- latest_create_file->next = new_node;
- new_node->previous = latest_create_file;
- }
- new_node->next = NULL;
-
- latest_create_file = new_node;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _ms_inoti_delete_create_file_list(ms_create_file_info *node)
-{
- if (node->previous != NULL)
- node->previous->next = node->next;
- if (node->next != NULL)
- node->next->previous = node->previous;
-
- if (node == latest_create_file) {
- latest_create_file = node->previous;
- }
-
- MS_SAFE_FREE(node->name);
- MS_SAFE_FREE(node);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-ms_create_file_info *_ms_inoti_find_create_file_list(int wd, char *name)
-{
- ms_create_file_info *node = NULL;
- node = latest_create_file;
-
- while (node != NULL) {
- if ((node->wd == wd) && (strcmp(node->name, name) == 0)) {
- return node;
- }
-
- node = node->previous;
- }
-
- return NULL;
-}
-
-bool _ms_inoti_get_full_path(int wd, char *name, char *path, int sizeofpath)
-{
- int err;
- ms_inoti_dir_data *node = NULL;
-
- if (name == NULL || path == NULL)
- return false;
-
- if (first_inoti_node != NULL) {
- node = first_inoti_node;
- while (node->next != NULL) {
- if (wd == node->wd) {
- break;
- }
- node = node->next;
- }
- } else {
- return false;
- }
-
- err = ms_strappend(path, sizeofpath, "%s/%s", node->name, name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend error : %d", err);
- return false;
- }
- MS_DBG("full path : %s", path);
- return true;
-}\r
-
-#endif
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-inotify.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-#include <errno.h>
-#include <dirent.h>
-#include <malloc.h>
-#include <vconf.h>
-
-#include "media-util.h"
-#include "media-server-dbg.h"
-#include "media-server-utils.h"
-#include "media-server-db-svc.h"
-#include "media-server-inotify-internal.h"
-#include "media-server-inotify.h"
-
-#if MS_INOTI_ENABLE
-
-bool power_off;
-extern int inoti_fd;
-extern int mmc_state;
-ms_inoti_dir_data *first_inoti_node;
-ms_ignore_file_info *latest_ignore_file;
-
-int _ms_inoti_directory_scan_and_register_file(void **handle, char *dir_path)
-{
- struct dirent ent;
- struct dirent *res = NULL;
- DIR *dp = NULL;
- char path[MS_FILE_PATH_LEN_MAX] = { 0 };
- int err;
-
- if (dir_path == NULL)
- return MS_MEDIA_ERR_INVALID_PATH;
-
- dp = opendir(dir_path);
- if (dp == NULL) {
- MS_DBG_ERR("Fail to open dir %s", dir_path);
- return MS_MEDIA_ERR_DIR_OPEN_FAIL;
- }
-
- ms_inoti_add_watch(dir_path);
-
- while (!readdir_r(dp, &ent, &res)) {
- if (res == NULL)
- break;
-
- if (ent.d_name[0] == '.')
- continue;
-
- err = ms_strappend(path, sizeof(path), "%s/%s", dir_path, ent.d_name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend error : %d", err);
- continue;
- }
-
- /*in case of directory */
- if (ent.d_type == DT_DIR) {
- _ms_inoti_directory_scan_and_register_file(handle, path);
- } else {
- err = ms_register_file(handle, path, NULL);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_register_file error : %d", err);
- continue;
- }
- }
- }
-
- closedir(dp);
-
- return 0;
-}
-
-int _ms_inoti_scan_renamed_folder(void **handle, char *org_path, char *chg_path)
-{
- int err = -1;
- struct dirent ent;
- struct dirent *res = NULL;
-
- DIR *dp = NULL;
- char path_from[MS_FILE_PATH_LEN_MAX] = { 0 };
- char path_to[MS_FILE_PATH_LEN_MAX] = { 0 };
- ms_storage_type_t src_storage = 0;
- ms_storage_type_t des_storage = 0;
-
- if (org_path == NULL || chg_path == NULL) {
- MS_DBG_ERR("Parameter is wrong");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- dp = opendir(chg_path);
- if (dp == NULL) {
- MS_DBG_ERR("Fail to open dir %s", chg_path);
- return MS_MEDIA_ERR_DIR_OPEN_FAIL;
- } else {
- MS_DBG("Modify added watch");
- ms_inoti_modify_watch(org_path, chg_path);
- }
-
- while (!readdir_r(dp, &ent, &res)) {
- if (res == NULL)
- break;
-
- if (ent.d_name[0] == '.')
- continue;
-
- err = ms_strappend(path_from, sizeof(path_from), "%s/%s", org_path, ent.d_name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend error : %d", err);
- continue;
- }
-
- err = ms_strappend(path_to, sizeof(path_to), "%s/%s", chg_path, ent.d_name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend error : %d", err);
- continue;
- }
-
- /*in case of directory */
- if (ent.d_type == DT_DIR) {
- _ms_inoti_scan_renamed_folder(handle, path_from, path_to);
- }
-
- /*in case of file */
- if (ent.d_type == DT_REG) {
- src_storage = ms_get_storage_type_by_full(path_from);
- des_storage = ms_get_storage_type_by_full(path_to);
-
- if ((src_storage != MS_MEDIA_ERR_INVALID_PATH)
- && (des_storage != MS_MEDIA_ERR_INVALID_PATH))
- ms_move_item(handle, src_storage, des_storage, path_from, path_to);
- else {
- MS_DBG_ERR("src_storage : %s", src_storage);
- MS_DBG_ERR("des_storage : %s", des_storage);
- }
- }
- }
-
- closedir(dp);
-
- return 0;
-}
-
-int ms_inoti_add_ignore_file(const char *path)
-{
- ms_ignore_file_info *new_node;
-
- new_node = ms_inoti_find_ignore_file(path);
- if (new_node != NULL)
- return MS_MEDIA_ERR_NONE;
-
- new_node = malloc(sizeof(ms_ignore_file_info));
- new_node->path = strdup(path);
-
- /*first created file */
- if (latest_ignore_file == NULL) {
- latest_ignore_file = malloc(sizeof(ms_ignore_file_info));
- new_node->previous = NULL;
- } else {
- latest_ignore_file->next = new_node;
- new_node->previous = latest_ignore_file;
- }
- new_node->next = NULL;
-
- latest_ignore_file = new_node;
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int ms_inoti_delete_ignore_file(ms_ignore_file_info * delete_node)
-{
- if (delete_node->previous != NULL)
- delete_node->previous->next = delete_node->next;
- if (delete_node->next != NULL)
- delete_node->next->previous = delete_node->previous;
-
- if (delete_node == latest_ignore_file) {
- latest_ignore_file = delete_node->previous;
- }
-
- MS_SAFE_FREE(delete_node->path);
- MS_SAFE_FREE(delete_node);
-
-
- return MS_MEDIA_ERR_NONE;
-}
-
-ms_ignore_file_info *ms_inoti_find_ignore_file(const char *path)
-{
- ms_ignore_file_info *node = NULL;
-
- node = latest_ignore_file;
- while (node != NULL) {
- if (strcmp(node->path, path) == 0) {
- return node;
- }
-
- node = node->previous;
- }
-
- return NULL;
-}
-
-void ms_inoti_delete_mmc_ignore_file(void)
-{
- ms_ignore_file_info *prv_node = NULL;
- ms_ignore_file_info *cur_node = NULL;
- ms_ignore_file_info *del_node = NULL;
-
- if (latest_ignore_file != NULL) {
- cur_node = latest_ignore_file;
- while (cur_node != NULL) {
- if (strstr(cur_node->path, MEDIA_ROOT_PATH_SDCARD) != NULL) {
- if (prv_node != NULL) {
- prv_node->previous = cur_node->previous;
- }
-
- if (cur_node == latest_ignore_file)
- latest_ignore_file = latest_ignore_file->previous;
-
- del_node = cur_node;
- } else {
- prv_node = cur_node;
- }
-
- cur_node = cur_node->previous;
-
- if (del_node != NULL) {
- MS_SAFE_FREE(del_node->path);
- MS_SAFE_FREE(del_node);
- }
- }
- }
-
- /*active flush */
- malloc_trim(0);
-}
-
-int ms_inoti_init(void)
-{
- inoti_fd = inotify_init();
- if (inoti_fd < 0) {
- perror("inotify_init");
- MS_DBG_ERR("inotify_init failed");
- return inoti_fd;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void ms_inoti_add_watch(char *path)
-{
- ms_inoti_dir_data *current_dir = NULL;
- ms_inoti_dir_data *prv_node = NULL;
- ms_inoti_dir_data *last_node = NULL;
-
- /*find same folder */
- if (first_inoti_node != NULL) {
- last_node = first_inoti_node;
- while (last_node != NULL) {
- if (strcmp(path, last_node->name) == 0) {
- MS_DBG("watch is already added: %s", path);
- return;
- }
- prv_node = last_node;
- last_node = last_node->next;
- }
- }
-
- /*there is no same path. */
- current_dir = malloc(sizeof(ms_inoti_dir_data));
- current_dir->wd = inotify_add_watch(inoti_fd, path,
- IN_CLOSE_WRITE | IN_CREATE | IN_DELETE |
- IN_MOVED_FROM | IN_MOVED_TO);
-
- if (current_dir->wd > 0) {
- current_dir->name = strdup(path);
- current_dir->next = NULL;
-
- if (first_inoti_node == NULL) {
- first_inoti_node = current_dir;
- } else {
- /*if next node of current node is NULL, it is the lastest node. */
- prv_node->next = current_dir;
- }
- MS_DBG("add watch : %s", path);
- } else {
- MS_DBG_ERR("inotify_add_watch failed");
- MS_SAFE_FREE(current_dir);
- }
-}
-
-int ms_inoti_add_watch_with_node(ms_dir_scan_info * const node, int depth)
-{
- int err;
- char full_path[MS_FILE_PATH_LEN_MAX] = { 0 };
- ms_inoti_dir_data *current_dir = NULL;
- ms_inoti_dir_data *prv_node = NULL;
- ms_inoti_dir_data *last_node = NULL;
-
- err = ms_get_full_path_from_node(node, full_path, depth);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INVALID_PATH;
-
- /*find same folder */
- if (first_inoti_node != NULL) {
- last_node = first_inoti_node;
- while (last_node != NULL) {
- if (strcmp(full_path, last_node->name) == 0) {
- return MS_MEDIA_ERR_NONE;
- }
- prv_node = last_node;
- last_node = last_node->next;
- }
- }
-
- /*there is no same path. */
- current_dir = malloc(sizeof(ms_inoti_dir_data));
- current_dir->wd = inotify_add_watch(inoti_fd, full_path,
- IN_CLOSE_WRITE | IN_CREATE | IN_DELETE |
- IN_MOVED_FROM | IN_MOVED_TO);
- if( current_dir->wd > 0) {
- current_dir->name = strdup(full_path);
- current_dir->next = NULL;
-
- if (first_inoti_node == NULL) {
- first_inoti_node = current_dir;
- } else {
- /*if next node of current node is NULL, it is the lastest node. */
- prv_node->next = current_dir;
- }
- MS_DBG("add watch : %s", full_path);
- } else {
- MS_DBG_ERR("inotify_add_watch failed : %d", current_dir->wd);
- MS_SAFE_FREE(current_dir);
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-void ms_inoti_remove_watch_recursive(char *path)
-{
- ms_inoti_dir_data *prv_node = NULL;
- ms_inoti_dir_data *cur_node = NULL;
- ms_inoti_dir_data *del_node = NULL;
-
- if (first_inoti_node != NULL) {
- cur_node = first_inoti_node;
- while (cur_node != NULL) {
- if (strstr(cur_node->name, path) != NULL) {
- if (prv_node != NULL) {
- prv_node->next =
- cur_node->next;
- }
-
- if (cur_node == first_inoti_node)
- first_inoti_node =
- first_inoti_node->next;
-
- del_node = cur_node;
- } else {
- prv_node = cur_node;
- }
-
- cur_node = cur_node->next;
-
- if (del_node != NULL) {
- MS_SAFE_FREE(del_node->name);
- MS_SAFE_FREE(del_node);
- }
- }
- }
-
- /*active flush */
- malloc_trim(0);
-}
-
-void ms_inoti_remove_watch(char *path)
-{
- ms_inoti_dir_data *del_node = NULL;
- ms_inoti_dir_data *prv_node = NULL;
-
- if (strcmp(first_inoti_node->name, path) == 0) {
- del_node = first_inoti_node;
- first_inoti_node = first_inoti_node->next;
- } else {
- /*find same folder */
- if (first_inoti_node != NULL) {
- del_node = first_inoti_node;
- while (del_node != NULL) {
- MS_DBG("current node %s", del_node->name);
- if (strcmp(path, del_node->name) == 0) {
- MS_DBG("find delete node: %s", del_node->name);
- if (prv_node != NULL) {
- MS_DBG("previous_node : %s", prv_node->name);
- prv_node->next = del_node->next;
- }
- /*free deleted node */
- MS_SAFE_FREE(del_node->name);
- MS_SAFE_FREE(del_node);
- break;
- }
- prv_node = del_node;
- del_node = del_node->next;
- }
- }
- }
-
- /*active flush */
- malloc_trim(0);
-}
-
-void ms_inoti_modify_watch(char *path_from, char *path_to)
-{
- bool find = false;
- ms_inoti_dir_data *mod_node;
-
- if (strcmp(first_inoti_node->name, path_from) == 0) {
- mod_node = first_inoti_node;
- } else {
- /*find same folder */
- if (first_inoti_node != NULL) {
- mod_node = first_inoti_node;
- while (mod_node != NULL) {
- /*find previous directory*/
- if (strcmp(path_from, mod_node->name) == 0) {
- /*change path of directory*/
- /*free previous name of node */
- MS_SAFE_FREE(mod_node->name);
-
- /*add new name */
- mod_node->name = strdup(path_to);
-
- /*active flush */
- malloc_trim(0);
-
- find = true;
- break;
- }
- mod_node = mod_node->next;
- }
- }
- }
-
- /*this is new directory*/
- if (find == false) {
- ms_inoti_add_watch(path_to);
- }
-}
-
-#define STOP_INOTI "stop_inoti"
-
-gboolean ms_inoti_thread(void *data)
-{
- uint32_t i;
- int length;
- int err;
- int prev_mask = 0;
- int prev_wd = -1;
- bool res;
- char name[MS_FILE_NAME_LEN_MAX + 1] = { 0 };
- char prev_name[MS_FILE_NAME_LEN_MAX + 1] = { 0 };
- char buffer[INOTI_BUF_LEN] = { 0 };
- char path[MS_FILE_PATH_LEN_MAX] = { 0 };
- struct inotify_event *event;
- void **handle = NULL;
-
- MS_DBG("START INOTIFY");
-
- err = ms_connect_db(&handle);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR(" INOTIFY : sqlite3_open: ret = %d", err);
- return false;
- }
-
- while (1) {
- i = 0;
- length = read(inoti_fd, buffer, sizeof(buffer) - 1);
-
- if (length < 0 || length > sizeof(buffer)) { /*this is error */
- continue;
- }
-
- while (i < length && i < INOTI_BUF_LEN) {
- /*check poweroff status*/
- if(power_off) {
- MS_DBG("power off");
- goto _POWEROFF;
- }
-
- /*it's possible that ums lets reset phone data... */
- event = (struct inotify_event *)&buffer[i];
-
- if (strcmp(event->name, POWEROFF_DIR_NAME) == 0) {
- MS_DBG("power off");
- goto _POWEROFF;
- } else if (strcmp(event->name, STOP_INOTI) == 0) {
- MS_DBG("stop inotify thread");
- goto _POWEROFF;
- } else if (event->name[0] == '.') {
- /*event of hidden folder is ignored */
- goto NEXT_INOTI_EVENT;
- } else if (event->wd < 1) {
- /*this is error */
- MS_DBG_ERR("invalid wd : %d", event->wd);
- goto NEXT_INOTI_EVENT;
- }
-
- /*start of one event */
- if (event->len && (event->len <= MS_FILE_NAME_LEN_MAX + 1)) {
- /*Add for fixing prevent defect 2011-02-15 */
- err = ms_strcopy(name, sizeof(name), "%s", event->name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strcopy error : %d", err);
- goto NEXT_INOTI_EVENT;
- }
-
- /*get full path of file or directory */
- res = _ms_inoti_get_full_path(event->wd, name, path, sizeof(path));
- if (res == false) {
- MS_DBG_ERR("_ms_inoti_get_full_path error");
- goto NEXT_INOTI_EVENT;
- }
-
- MS_DBG("INOTIFY[%d : %s]", event->wd, name);
- if (event->mask & IN_ISDIR) {
- MS_DBG("DIRECTORY INOTIFY");
-
- if (event->mask & IN_MOVED_FROM) {
- MS_DBG("MOVED_FROM");
-
- prev_mask = event->mask;
- prev_wd = event->wd;
-
- err = ms_strcopy(prev_name, sizeof(prev_name), "%s", event->name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strcopy fail");
- goto NEXT_INOTI_EVENT;
- }
- }
- else if (event->mask & IN_MOVED_TO) {
- MS_DBG("MOVED_TO");
-
- char full_path_from[MS_FILE_PATH_LEN_MAX] = { 0 };
-
- res = _ms_inoti_get_full_path(prev_wd, prev_name, full_path_from, sizeof(full_path_from));
- if (res == false) {
- MS_DBG_ERR("_ms_inoti_get_full_path error");
- goto NEXT_INOTI_EVENT;
- }
- /*enable bundle commit*/
- ms_move_start(handle);
-
- /*need update file information under renamed directory */
- _ms_inoti_scan_renamed_folder(handle, full_path_from, path);
-
- /*disable bundle commit*/
- ms_move_end(handle);
-
- prev_mask = prev_wd = 0; /*reset */
- }
- else if (event->mask & IN_CREATE) {
- MS_DBG("CREATE");
-
- _ms_inoti_directory_scan_and_register_file(handle, path);
- prev_mask = event->mask;
- }
- else if (event->mask & IN_DELETE) {
- MS_DBG("DELETE");
-
- ms_inoti_remove_watch(path);
- }
- }
- else {
- MS_DBG("FILE INOTIFY");
-
- if (event->mask & IN_MOVED_FROM) {
- MS_DBG("MOVED_FROM");
-
- err = ms_delete_item(handle, path);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_media_db_delete fail error : %d", err);
- }
- }
- else if (event->mask & IN_MOVED_TO) {
- MS_DBG("MOVED_TO");
-
- err = ms_register_file(handle, path, NULL);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_register_file error : %d", err);
- }
- }
- else if (event->mask & IN_CREATE) {
- MS_DBG("CREATE");
-
- _ms_inoti_add_create_file_list(event->wd, name);
- }
- else if (event->mask & IN_DELETE) {
- MS_DBG("DELETE");
-
- err = ms_delete_item(handle, path);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_media_db_delete error : %d", err);
- }
- }
- else if (event->mask & IN_CLOSE_WRITE) {
- MS_DBG("CLOSE_WRITE");
- ms_create_file_info *node;
-
- node = _ms_inoti_find_create_file_list (event->wd, name);
- if (node != NULL || ((prev_mask & IN_ISDIR) & IN_CREATE)) {
- err = ms_register_file(handle, path, NULL);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_register_file error : %d", err);
- }
- if (node != NULL)
- _ms_inoti_delete_create_file_list(node);
- }
- else {
- ms_ignore_file_info *ignore_file;
-
- ignore_file = ms_inoti_find_ignore_file(path);
- if (ignore_file == NULL) {
- /*in case of replace */
- MS_DBG("This case is replacement or changing meta data.");
- err = ms_refresh_item(handle, path);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_refresh_item error : %d", err);
- goto NEXT_INOTI_EVENT;
- }
- } else {
- /*This is ignore case*/
- }
- }
- prev_mask = prev_wd = 0; /*reset */
- }
- }
- } /*end of one event */
- else {
- /*This is ignore case*/
- if (event->mask & IN_IGNORED) {
- MS_DBG("This case is ignored");
- }
- }
- NEXT_INOTI_EVENT: ;
- i += INOTI_EVENT_SIZE + event->len;
- }
-
- /*Active flush */
- malloc_trim(0);
- }
-_POWEROFF:
- ms_inoti_remove_watch_recursive(MEDIA_ROOT_PATH_INTERNAL);
- ms_inoti_remove_watch_recursive(MEDIA_ROOT_PATH_SDCARD);
-
- close(inoti_fd);
-
- if (handle) ms_disconnect_db(&handle);
-
- return false;
-}
-
-int _ms_get_path_from_current_node(int find_folder,
- ms_dir_scan_info **current_root,
- ms_dir_scan_info **real_root, char **path, int *depth)
-{
- int err = MS_MEDIA_ERR_NONE;
- char get_path[FAT_FILEPATH_LEN_MAX] = { 0 };
-
- if (find_folder == 0) {
- if ((*current_root)->Rbrother != NULL) {
- *current_root = (*current_root)->Rbrother;
- } else {
- while (1) {
- if ((*current_root)->parent == *real_root
- || (*current_root)->parent == NULL) {
- *current_root = NULL;
- *depth = 0;
- return MS_MEDIA_ERR_NONE;
- } else if ((*current_root)->parent->Rbrother == NULL) {
- *current_root = (*current_root)->parent;
- (*depth) --;
- } else {
- *current_root = (*current_root)->parent->Rbrother;
- (*depth) --;
- break;
- }
- }
- }
- (*depth) --;
- }
-
- err = ms_get_full_path_from_node(*current_root, get_path, *depth);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INVALID_PATH;
-
- *path = strdup(get_path);
-
- return err;
-}
-
-void ms_inoti_add_watch_all_directory(ms_storage_type_t storage_type)
-{
- int err = 0;
- int depth = 0;
- int find_folder = 0;
- char get_path[MS_FILE_PATH_LEN_MAX] = { 0 };
- char *path = NULL;
- DIR *dp = NULL;
- struct dirent entry;
- struct dirent *result;
-
- ms_dir_scan_info *root;
- ms_dir_scan_info *tmp_root = NULL;
- ms_dir_scan_info *cur_node = NULL; /*current node*/
- ms_dir_scan_info *prv_node = NULL; /*previous node*/
- ms_dir_scan_info *next_node = NULL;
-
- root = malloc(sizeof(ms_dir_scan_info));
- if (root == NULL) {
- MS_DBG_ERR("malloc fail");
- return;
- }
-
- if (storage_type == MS_STORAGE_INTERNAL)
- root->name = strdup(MEDIA_ROOT_PATH_INTERNAL);
- else
- root->name = strdup(MEDIA_ROOT_PATH_SDCARD);
- if (root->name == NULL) {
- MS_DBG_ERR("strdup fail");
- MS_SAFE_FREE(root);
- return;
- }
-
- root->parent = NULL;
- root->Rbrother = NULL;
- root->next = NULL;
- tmp_root = root;
- prv_node = root;
-
- path = malloc(sizeof(char) * MS_FILE_PATH_LEN_MAX);
-
- err = ms_get_full_path_from_node(tmp_root, path, depth);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_SAFE_FREE(path);
- MS_SAFE_FREE(root);
- return;
- }
-
- ms_inoti_add_watch_with_node(root, depth);
-
- while (1) {
- /*check poweroff status*/
- if (power_off) {
- MS_DBG("Power off");
- goto FREE_RESOURCES;
- }
-
- /*check SD card in out*/
- if ((mmc_state != VCONFKEY_SYSMAN_MMC_MOUNTED) && (storage_type == MS_STORAGE_EXTERNAL))
- goto FREE_RESOURCES;
-
- depth ++;
- dp = opendir(path);
- if (dp == NULL) {
- MS_DBG_ERR("%s folder opendir fails", path);
- goto NEXT_DIR;
- }
-
- while (!readdir_r(dp, &entry, &result)) {
- /*check poweroff status*/
- if (power_off) {
- MS_DBG("Power off");
- goto FREE_RESOURCES;
- }
-
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
- continue;
-
- /*check SD card in out*/
- if ((mmc_state != VCONFKEY_SYSMAN_MMC_MOUNTED) && (storage_type == MS_STORAGE_EXTERNAL)) {
- goto FREE_RESOURCES;
- }
-
- if (entry.d_type & DT_DIR) {
- DIR *tmp_dp = NULL;
- err = ms_strappend(get_path, sizeof(get_path), "%s/%s",path, entry.d_name);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strappend error");
- continue;
- }
-
- tmp_dp = opendir(get_path);
- if (tmp_dp == NULL) {
- MS_DBG_ERR("%s folder opendir fails", get_path);
- MS_DBG("error : %d, %s", errno ,strerror(errno));
- continue;
- }
- else
- closedir(tmp_dp);
-
- cur_node = malloc(sizeof(ms_dir_scan_info));
- if (cur_node == NULL) {
- MS_DBG_ERR("malloc fail");
-
- goto FREE_RESOURCES;
- }
-
- cur_node->name = strdup(entry.d_name);
- cur_node->Rbrother = NULL;
- cur_node->next = NULL;
-
- /*1. 1st folder */
- if (find_folder == 0) {
- cur_node->parent = tmp_root;
- tmp_root = cur_node;
- } else {
- cur_node->parent = tmp_root->parent;
- prv_node->Rbrother = cur_node;
- }
- prv_node->next = cur_node;
-
- /*add watch */
- ms_inoti_add_watch_with_node(cur_node, depth);
-
- /*change previous */
- prv_node = cur_node;
- find_folder++;
- }
- }
-NEXT_DIR:
- if (dp) closedir(dp);
- MS_SAFE_FREE(path);
- dp = NULL;
- path = NULL;
-
- err = _ms_get_path_from_current_node(find_folder, &tmp_root, &root, &path, &depth);
- if (err != MS_MEDIA_ERR_NONE)
- break;
-
- if (tmp_root == NULL)
- break;
-
- find_folder = 0;
- }
-
-FREE_RESOURCES:
- /*free allocated memory */
- if (dp) closedir(dp);
- MS_SAFE_FREE(path);
-
- cur_node = root;
- while (cur_node != NULL) {
- next_node = cur_node->next;
- MS_SAFE_FREE(cur_node->name);
- MS_SAFE_FREE(cur_node);
- cur_node = next_node;
- }
-}
-
-#endif
\ No newline at end of file
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-utils.h
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief
- */
-
-#ifndef _MEDIA_SCANNER_UTILS_H__
-#define _MEDIA_SCANNER_UTILS_H__
-
-#include "media-server-types.h"
-
-bool
-msc_is_mmc_inserted(void);
-
-int
-msc_update_mmc_info(void);
-
-void
-msc_mmc_vconf_cb(void *data);
-
-int
-msc_get_full_path_from_node(ms_dir_scan_info * const node, char *ret_path, int depth);
-
-ms_storage_type_t
-msc_get_storage_type_by_full(const char *path);
-
-int
-msc_strappend(char *res, const int size, const char *pattern,
- const char *str1, const char *str2);
-
-int
-msc_strcopy(char *res, const int size, const char *pattern,
- const char *str1);
-
-bool
-msc_config_get_int(const char *key, int *value);
-
-bool
-msc_config_set_int(const char *key, int value);
-
-bool
-msc_config_get_str(const char *key, char *value);
-
-bool
-msc_config_set_str(const char *key, const char *value);
-
-#ifdef FMS_PERF
-void
-msc_check_start_time(struct timeval *start_time);
-
-void
-msc_check_end_time(struct timeval *end_time);
-
-void
-msc_check_time_diff(struct timeval *start_time, struct timeval *end_time);
-#endif/*FMS_PERF */
-
-/**
- * @}
- */
-#endif/*_MEDIA_SCANNER_UTILS_H__*/
-
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-drm.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief This file implements main database operation.
- */
-#include <drm_client_types.h>
-#include <drm_client.h>
-
-#include "media-util.h"
-
-#include "media-scanner-dbg.h"
-#include "media-server-types.h"
-#include "media-scanner-drm.h"
-
-bool
-msc_is_drm_file(const char *path)
-{
- int ret;
- drm_bool_type_e is_drm_file = DRM_UNKNOWN;
-
- ret = drm_is_drm_file(path,&is_drm_file);
- if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
- return true;
-
- return false;
-}
-
-int
-msc_get_mime_in_drm_info(const char *path, char *mime)
-{
- int ret;
- drm_content_info_s contentInfo;
-
- if (path == NULL || mime == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- memset(&contentInfo,0x0,sizeof(drm_content_info_s));
- ret = drm_get_content_info(path, &contentInfo);
- if (ret != DRM_RETURN_SUCCESS) {
- MSC_DBG_ERR("drm_svc_get_content_info() failed");
- MSC_DBG_ERR("%s [%d]", path, ret);
- return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
- }
-
- strncpy(mime, contentInfo.mime_type, 100);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-msc_drm_register(const char* path)
-{
- int res = MS_MEDIA_ERR_NONE;
- int ret;
-
- ret = drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, (void *)path, NULL);
- if (ret != DRM_RETURN_SUCCESS) {
- MSC_DBG_ERR("drm_svc_register_file error : %d %s", ret, path);
- res = MS_MEDIA_ERR_DRM_REGISTER_FAIL;
- }
-
- return res;
-}
-
-void
-msc_drm_unregister(const char* path)
-{
- int ret;
-
- ret = drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_FILE, (void *)path, NULL);
- if (ret != DRM_RETURN_SUCCESS)
- MSC_DBG_ERR("drm_process_request error : %d", ret);
-}
-
-void
-msc_drm_unregister_all(void)
-{
- if (drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_ALL_FILES , NULL, NULL) == DRM_RETURN_SUCCESS)
- MSC_DBG_INFO("drm_svc_unregister_all_contents OK");
-}
-
-bool
-msc_drm_insert_ext_memory(void)
-{
- if (drm_process_request(DRM_REQUEST_TYPE_INSERT_EXT_MEMORY, NULL, NULL) != DRM_RETURN_SUCCESS)
- return false;
-
- return true;
-}
-
-bool
-msc_drm_extract_ext_memory(void)
-{
- if (drm_process_request(DRM_REQUEST_TYPE_EXTRACT_EXT_MEMORY , NULL, NULL) != DRM_RETURN_SUCCESS)
- return false;
-
- return true;
-}
-
+++ /dev/null
-/*
- * Media Server
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Yong Yeon Kim <yy9875.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.
- *
- */
-
-/**
- * This file defines api utilities of contents manager engines.
- *
- * @file media-server-utils.c
- * @author Yong Yeon Kim(yy9875.kim@samsung.com)
- * @version 1.0
- * @brief This file implements main database operation.
- */
-
-#include <dirent.h>
-#include <malloc.h>
-#include <vconf.h>
-
-#include "media-util.h"
-#include "media-scanner-dbg.h"
-#include "media-scanner-utils.h"
-#include "media-scanner-drm.h"
-
-#ifdef FMS_PERF
-#include <sys/time.h>
-#define MILLION 1000000L
-struct timeval g_mmc_start_time;
-struct timeval g_mmc_end_time;
-#endif
-
-#define MMC_INFO_SIZE 256
-
-extern int mmc_state;
-extern GAsyncQueue *storage_queue;
-extern GAsyncQueue *scan_queue;
-
-
-
-#ifdef FMS_PERF
-void
-msc_check_start_time(struct timeval *start_time)
-{
- gettimeofday(start_time, NULL);
-}
-
-void
-msc_check_end_time(struct timeval *end_time)
-{
- gettimeofday(end_time, NULL);
-}
-
-void
-msc_check_time_diff(struct timeval *start_time, struct timeval *end_time)
-{
- struct timeval time;
- long difftime;
-
- time.tv_sec = end_time->tv_sec - start_time->tv_sec;
- time.tv_usec = end_time->tv_usec - start_time->tv_usec;
- difftime = MILLION * time.tv_sec + time.tv_usec;
- MSC_DBG_INFO("The function_to_time took %ld microseconds or %f seconds.",
- difftime, difftime / (double)MILLION);
-}
-#endif
-
-bool
-msc_is_mmc_inserted(void)
-{
- int data = -1;
- msc_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &data);
- if (data != VCONFKEY_SYSMAN_MMC_MOUNTED) {
- return false;
- } else {
- return true;
- }
-}
-
-int
-_msc_update_mmc_info(const char *cid)
-{
- bool res;
-
- if (cid == NULL) {
- MSC_DBG_ERR("Parameters are invalid");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- res = msc_config_set_str(MS_MMC_INFO_KEY, cid);
- if (!res) {
- MSC_DBG_ERR("fail to get MS_MMC_INFO_KEY");
- return MS_MEDIA_ERR_VCONF_SET_FAIL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int
-_msc_get_contents(const char *filename, char *buf)
-{
- FILE *fp;
-
- fp = fopen(filename, "rt");
- if (fp == NULL) {
- MSC_DBG_ERR("fp is NULL. file name : %s", filename);
- return MS_MEDIA_ERR_FILE_OPEN_FAIL;
- }
-
- if (fgets(buf, 255, fp) == NULL)
- MSC_DBG_ERR("fgets failed");
-
- fclose(fp);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-/*need optimize*/
-int
-_msc_get_mmc_info(char *cid)
-{
- int i;
- int j;
- int len;
- int err = -1;
- bool getdata = false;
- bool bHasColon = false;
- char path[MS_FILE_PATH_LEN_MAX] = { 0 };
- char mmcpath[MS_FILE_PATH_LEN_MAX] = { 0 };
-
- DIR *dp;
- struct dirent ent;
- struct dirent *res = NULL;
-
- /* mmcblk0 and mmcblk1 is reserved for movinand */
- for (j = 1; j < 3; j++) {
- len = snprintf(mmcpath, MS_FILE_PATH_LEN_MAX, "/sys/class/mmc_host/mmc%d/", j);
- if (len < 0) {
- MSC_DBG_ERR("FAIL : snprintf");
- return MS_MEDIA_ERR_INTERNAL;
- }
- else {
- mmcpath[len] = '\0';
- }
-
- dp = opendir(mmcpath);
- if (dp == NULL) {
- MSC_DBG_ERR("dp is NULL");
- return MS_MEDIA_ERR_DIR_OPEN_FAIL;
- }
-
- while (!readdir_r(dp, &ent, &res)) {
- /*end of read dir*/
- if (res == NULL)
- break;
-
- bHasColon = false;
- if (ent.d_name[0] == '.')
- continue;
-
- if (ent.d_type == DT_DIR) {
- /*ent->d_name is including ':' */
- for (i = 0; i < strlen(ent.d_name); i++) {
- if (ent.d_name[i] == ':') {
- bHasColon = true;
- break;
- }
- }
-
- if (bHasColon) {
- /*check serial */
- err = msc_strappend(path, sizeof(path), "%s%s/cid", mmcpath, ent.d_name);
- if (err < 0) {
- MSC_DBG_ERR("ms_strappend error : %d", err);
- continue;
- }
-
- if (_msc_get_contents(path, cid) != MS_MEDIA_ERR_NONE)
- break;
- else
- getdata = true;
- }
- }
- }
- closedir(dp);
-
- if (getdata == true) {
- break;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-msc_update_mmc_info(void)
-{
- int err;
- char cid[MMC_INFO_SIZE] = { 0 };
-
- err = _msc_get_mmc_info(cid);
-
- err = _msc_update_mmc_info(cid);
-
- /*Active flush */
- if (!malloc_trim(0))
- MSC_DBG_ERR("malloc_trim is failed");
-
- return err;
-}
-
-bool
-_msc_check_mmc_info(const char *cid)
-{
- char pre_mmc_info[MMC_INFO_SIZE] = { 0 };
- bool res = false;
-
- if (cid == NULL) {
- MSC_DBG_ERR("Parameters are invalid");
- return false;
- }
-
- res = msc_config_get_str(MS_MMC_INFO_KEY, pre_mmc_info);
- if (!res) {
- MSC_DBG_ERR("fail to get MS_MMC_INFO_KEY");
- return false;
- }
-
- MSC_DBG_INFO("Last MMC info = %s", pre_mmc_info);
- MSC_DBG_INFO("Current MMC info = %s", cid);
-
- if (strcmp(pre_mmc_info, cid) == 0) {
- return true;
- }
-
- return false;
-}
-
-
-ms_dir_scan_type_t
-msc_get_mmc_state(void)
-{
- char cid[MMC_INFO_SIZE] = { 0 };
- ms_dir_scan_type_t ret = MS_SCAN_ALL;
-
- /*get new info */
- _msc_get_mmc_info(cid);
-
- /*check it's same mmc */
- if (_msc_check_mmc_info(cid)) {
- ret = MS_SCAN_PART;
- }
-
- return ret;
-}
-
-void
-msc_mmc_vconf_cb(void *data)
-{
- int status = 0;
- ms_comm_msg_s *scan_msg;
- ms_dir_scan_type_t scan_type = MS_SCAN_PART;
-
- if (!msc_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status)) {
- MSC_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
- }
-
- MSC_DBG_INFO("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
-
- mmc_state = status;
-
- MS_MALLOC(scan_msg, sizeof(ms_comm_msg_s));
-
- if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
- mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
-
- if (!msc_drm_extract_ext_memory())
- MSC_DBG_ERR("ms_drm_extract_ext_memory failed");
-
- scan_type = MS_SCAN_INVALID;
- } else if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
-
- if (!msc_drm_insert_ext_memory())
- MSC_DBG_ERR("ms_drm_insert_ext_memory failed");
-
- scan_type = msc_get_mmc_state();
- }
-
- switch (scan_type) {
- case MS_SCAN_ALL:
- scan_msg->msg_type = MS_MSG_STORAGE_ALL;
- break;
- case MS_SCAN_PART:
- scan_msg->msg_type = MS_MSG_STORAGE_PARTIAL;
- break;
- case MS_SCAN_INVALID:
- scan_msg->msg_type = MS_MSG_STORAGE_INVALID;
- break;
- }
-
- scan_msg->pid = 0;
- scan_msg->msg_size = strlen(MEDIA_ROOT_PATH_SDCARD);
- msc_strcopy(scan_msg->msg, scan_msg->msg_size+1, "%s", MEDIA_ROOT_PATH_SDCARD);
-
- MSC_DBG_INFO("ms_get_mmc_state is %d", scan_msg->msg_type);
-
- g_async_queue_push(storage_queue, GINT_TO_POINTER(scan_msg));
-
- return;
-}
-
-/*CAUTION : Before using this function, Have to allocate static memory of ret_path*/
-/*And the array length does not over MS_FILE_PATH_LEN_MAX*/
-/*for example : char path[MS_FILE_PATH_LEN_MAX] = {0};*/
-int
-msc_get_full_path_from_node(ms_dir_scan_info * const node, char *ret_path, int depth)
-{
- int i = 0;
- int path_length = 0;
- int length = 0;
- ms_dir_scan_info *cur_node;
- char **path_array;
-
- if (depth < 0) {
- MSC_DBG_ERR("depth < 0");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- MS_MALLOC(path_array, sizeof(char*) * (depth + 1));
-
- cur_node = node;
-
- while (1) {
- path_array[i] = cur_node->name;
- if (cur_node->parent == NULL)
- break;
-
- cur_node = cur_node->parent;
- i++;
- }
-
- for(i = depth ; i >= 0 ; i --) {
- length = strlen(path_array[i]);
-
- if (path_length + length > MS_FILE_PATH_LEN_MAX) {
- MSC_DBG_ERR("This is invalid path, %s, %d", node->name, depth);
- MS_SAFE_FREE(path_array);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- strncpy(ret_path+path_length, path_array[i], length);
- path_length += length;
-
- ret_path[path_length] = '/';
- path_length ++;
- }
-
- ret_path[-- path_length] = '\0';
-
- MS_SAFE_FREE(path_array);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-ms_storage_type_t
-msc_get_storage_type_by_full(const char *path)
-{
- if (strncmp(path, MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL)) == 0) {
- return MS_STORAGE_INTERNAL;
- } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
- return MS_STORAGE_EXTERNAL;
- } else
- return MS_MEDIA_ERR_INVALID_PATH;
-}
-
-int
-msc_strappend(char *res, const int size, const char *pattern,
- const char *str1, const char *str2)
-{
- int len = 0;
- int real_size = size - 1;
-
- if (!res ||!pattern || !str1 ||!str2 )
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- if (real_size < (strlen(str1) + strlen(str2)))
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- len = snprintf(res, real_size, pattern, str1, str2);
- if (len < 0) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- res[len] = '\0';
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int
-msc_strcopy(char *res, const int size, const char *pattern, const char *str1)
-{
- int len = 0;
- int real_size = size;
-
- if (!res || !pattern || !str1)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- if (real_size < strlen(str1))
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- len = snprintf(res, real_size, pattern, str1);
- if (len < 0) {
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- res[len] = '\0';
-
- return MS_MEDIA_ERR_NONE;
-}
-
-bool
-msc_config_get_int(const char *key, int *value)
-{
- int err;
-
- if (!key || !value) {
- MSC_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- err = vconf_get_int(key, value);
- if (err == 0)
- return true;
- else if (err == -1)
- return false;
- else
- MSC_DBG_ERR("Unexpected error code: %d", err);
-
- return false;
-}
-
-bool
-msc_config_set_int(const char *key, int value)
-{
- int err;
-
- if (!key) {
- MSC_DBG_ERR("Arguments key is NULL");
- return false;
- }
-
- err = vconf_set_int(key, value);
- if (err == 0)
- return true;
- else if (err == -1)
- return false;
- else
- MSC_DBG_ERR("Unexpected error code: %d", err);
-
- return false;
-}
-
-bool
-msc_config_get_str(const char *key, char *value)
-{
- char *res;
- if (!key || !value) {
- MSC_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- res = vconf_get_str(key);
- if (res) {
- strncpy(value, res, strlen(res) + 1);
- return true;
- }
-
- return false;
-}
-
-bool
-msc_config_set_str(const char *key, const char *value)
-{
- int err;
-
- if (!key || !value) {
- MSC_DBG_ERR("Arguments key or value is NULL");
- return false;
- }
-
- err = vconf_set_str(key, value);
- if (err == 0)
- return true;
- else
- MSC_DBG_ERR("fail to vconf_set_str %d", err);
-
- return false;
-}
-
AC_CONFIG_MACRO_DIR([m4])
# Checks for programs.
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
AC_PROG_CC
+AM_PROG_CC_C_O
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
CPPFLAGS="${CPPFLAGS} -DRND_LINUX"
+#using UDS socket
+#CPPFLAGS="${CPPFLAGS} -D_USE_UDS_SOCKET_"
+
# FMS_DEBUG - File Manager Service debug options
# To open debug options:
# export FMS_DEBUG=1 or configure --enable-debug
#define MS_TIMEOUT_SEC_10 10 /**< Response from Server time out */
#define MS_TIMEOUT_SEC_20 20 /**< Response from Media server time out */
+#ifdef _USE_UDS_SOCKET_
+typedef enum{
+ MS_DB_BATCH_UPDATE_PORT = 0, /**< Media DB batch update */
+ MS_SCAN_DAEMON_PORT, /**< Port of communication between scanner and server */
+ MS_SCAN_COMM_PORT, /**< Port of communication between scanner and server */
+ MS_SCANNER_PORT, /**< Directory Scanner */
+ MS_DB_UPDATE_PORT, /**< Media DB Update */
+ MS_THUMB_CREATOR_PORT, /**< Create thumbnail */
+ MS_THUMB_COMM_PORT, /**< Port of communication between creator and server */
+ MS_THUMB_DAEMON_PORT, /**< Port of Thumbnail server */
+ MS_PORT_MAX,
+}ms_msg_port_type_e;
+#else
#define MS_SCANNER_PORT 1001 /**< Directory Scanner */
#define MS_DB_UPDATE_PORT 1002 /**< Media DB Update */
#define MS_THUMB_CREATOR_PORT 1003 /**< Create thumbnail */
#define MS_DB_BATCH_UPDATE_PORT 1006 /**< Media DB batch update */
#define MS_SCAN_DAEMON_PORT 1007 /**< Port of communication between scanner and server */
#define MS_SCAN_COMM_PORT 1008 /**< Port of communication between scanner and server */
+#endif
#define MAX_MSG_SIZE 4096
MS_MSG_DB_UPDATE_BATCH_END, /**< End of media DB update batch */
MS_MSG_DIRECTORY_SCANNING, /**< Non recursive Directory Scan and Media DB Update*/
MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE,/**< Recursive Directory Scan and Media DB Update*/
+ MS_MSG_BURSTSHOT_INSERT,
MS_MSG_BULK_INSERT, /**< Request bulk insert */
MS_MSG_STORAGE_ALL,
MS_MSG_STORAGE_PARTIAL,
#define MS_MEDIA_ERR_DBUS_ADD_FILTER -37 /**< DBUS add filter fails*/
#define MS_MEDIA_ERR_DBUS_GET -38 /**< DBUS get fails */
#define MS_MEDIA_ERR_DATA_TAINTED -39 /**< received data is tainted */
+#define MS_MEDIA_ERR_SEND_NOTI_FAIL -40 /**< sending notification is failed */
/* SERVER error*/
#define MS_MEDIA_ERR_NOW_REGISTER_FILE -41 /**< already inserting into DB */
#endif
#define MS_SAFE_FREE(src) { if(src) {free(src); src = NULL;} }
+#define MS_MALLOC(src, size) { if (size > SIZE_MAX || size <= 0) {src = NULL;} \
+ else { src = malloc(size); memset(src, 0x0, size);} }
#define MS_STRING_VALID(str) \
((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define MS_MEDIA_DBUS_NAME "ms_db_updated"
#define MS_MEDIA_DBUS_MATCH_RULE "type='signal',interface='com.mediaserver.dbus.Signal'"
-
-#define MS_SCAN_STATUS_DIRECTORY "file/private/mediaserver/scan_directory"
-enum{
- VCONF_SCAN_DOING = 0,
- VCONF_SCAN_DONE,
-};
-
int media_db_update_db(MediaDBHandle *handle, const char *query_str);
int media_db_update_db_batch_start(const char *query_str);
extern "C" {
#endif
+#ifdef _USE_UDS_SOCKET_
+#include <sys/un.h>
+#else
#include <sys/socket.h>
+#endif
#include <netinet/in.h>
#include <arpa/inet.h>
MS_PROTOCOL_TCP
} ms_protocol_e;
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port);
+#else
int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd);
+#endif
int ms_ipc_create_server_socket(ms_protocol_e protocol, int port, int *sock_fd);
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr);
+int ms_ipc_send_msg_to_client(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_un *client_addr);
+int ms_ipc_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *client_addr, unsigned int *size);
+int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *size);
+#else
int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr);
int ms_ipc_send_msg_to_client(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_in *client_addr);
int ms_ipc_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *client_addr, unsigned int *size);
int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *recv_addr, unsigned int *size);
+#endif
#ifdef __cplusplus
}
*/
-typedef void (*db_update_cb)(void);
-
-int media_db_update_subscribe(db_update_cb user_cb);
+typedef enum {
+ MS_MEDIA_ITEM_FILE = 0,
+ MS_MEDIA_ITEM_DIRECTORY = 1,
+}media_item_type_e;
+
+typedef enum {
+ MS_MEDIA_ITEM_INSERT = 0,
+ MS_MEDIA_ITEM_DELETE = 1,
+ MS_MEDIA_ITEM_UPDATE = 2,
+}media_item_update_type_e;
+
+typedef enum {
+ MS_MEDIA_UNKNOWN = -1, /**< Unknown Conntent*/
+ MS_MEDIA_IMAGE = 0, /**< Image Content*/
+ MS_MEDIA_VIDEO = 1, /**< Video Content*/
+ MS_MEDIA_SOUND = 2, /**< Sound Content like Ringtone*/
+ MS_MEDIA_MUSIC = 3, /**< Music Content like mp3*/
+ MS_MEDIA_OTHER = 4, /**< Invalid Content*/
+}media_type_e;
+
+typedef void (*db_update_cb)(int pid, /* mandatory */
+ media_item_type_e item, /* mandatory */
+ media_item_update_type_e update_type, /* mandatory */
+ char* path, /* mandatory */
+ char* uuid, /* optional */
+ media_type_e media_type, /* optional */
+ char *mime_type, /* optional */
+ void *user_data);
+
+int media_db_update_subscribe(db_update_cb user_cb, void *user_data);
+
+int media_db_update_unsubscribe(void);
+
+int media_db_update_send(int pid, /* mandatory */
+ media_item_type_e item, /* mandatory */
+ media_item_update_type_e update_type, /* mandatory */
+ char* path, /* mandatory */
+ char* uuid, /* optional */
+ media_type_e media_type, /* optional */
+ char *mime_type /* optional */
+ );
/**
* @}
extern "C" {
#endif
-/**
- * @fn int ms_media_file_register(const char *file_full_path);
- * @brief This function registers multimedia file to media DB
- * When you did some file operations such as Create, Copy, Move, Rename, and Delete in phone or mmc storage, media-server registers the result to database automatically by inotify mechanism.
- * However, automatic registration will have a little delay because the method is asynchronous.
- * If you want to register some files to database immediately, you should use this API.
- *
- * @param file_full_path [in] full path of file for register
- * @return This function returns zero(MEDIA_INFO_ERROR_NONE) on success, or negative value with error code.
- * Please refer 'media-info-error.h' to know the exact meaning of the error.
- * @see None.
- * @pre None.
- * @post None.
- * @remark The database name is "/opt/usr/dbspace/.media.db".
- * You have to use this API only for registering multimedia files. If you try to register no multimedia file, this API returns error.
- * @par example
- * @code
-
-#include <media-info.h>
-
-int main()
-{
- int result = -1;
-
- result = ms_media_file_register("/opt/usr/media/test.mp3");
- if( result < 0 )
- {
- printf("FAIL to mediainfo_register_file\n");
- return 0;
- }
- else
- {
- printf("SUCCESS to register file\n");
- }
-
- return 0;
-}
-
- * @endcode
- */
-int media_file_register(const char *file_full_path);
-
typedef enum
{
MEDIA_DIRECTORY_SCAN = 0,
typedef void (*scan_complete_cb)(media_request_result_s *, void *);
typedef void (*insert_complete_cb)(media_request_result_s *, void *);
-int media_directory_scanning_async(const char *directory_path, bool recusive_on, scan_complete_cb user_callback, void *user_data);
+int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data);
int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data);
+int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data);
+
/**
* @}
*/
int request_msg_size = 0;
int sockfd = -1;
int err = -1;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
unsigned int serv_addr_len = -1;
int port = MS_DB_UPDATE_PORT;
strncpy(send_msg.msg, request_msg, request_msg_size);
/*Create Socket*/
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_3, &sockfd);
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd, port);
+#else
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd);
+#endif
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
ret = ms_ipc_send_msg_to_server(sockfd, port, &send_msg, &serv_addr);
- MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
+ close(sockfd);
+ return ret;
+ }
+
/*Receive Response*/
ms_comm_msg_s recv_msg;
return g_tcp_client_sock;
}
+#ifdef _USE_UDS_SOCKET_
+extern char MEDIA_IPC_PATH[][50];
+#endif
static int __media_db_prepare_tcp_client_socket()
{
int ret = MS_MEDIA_ERR_NONE;
int sockfd = -1;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
int port = MS_DB_BATCH_UPDATE_PORT;
/*Create TCP Socket*/
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_3, &sockfd);
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd, 0);
+#else
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, MS_TIMEOUT_SEC_10, &sockfd);
+#endif
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
/*Set server Address*/
memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH[port]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[port]);
+#else
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(port);
+#endif
/* Connecting to the media db server */
if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
#include "media-util-dbg.h"
#include "media-util.h"
+#ifdef _USE_UDS_SOCKET_
+char MEDIA_IPC_PATH[][50] ={
+ {"/tmp/media_ipc_dbbatchupdate.dat"},
+ {"/tmp/media_ipc_scandaemon.dat"},
+ {"/tmp/media_ipc_scancomm.dat"},
+ {"/tmp/media_ipc_scanner.dat"},
+ {"/tmp/media_ipc_dbupdate.dat"},
+ {"/tmp/media_ipc_thumbcreator.dat"},
+ {"/tmp/media_ipc_thumbcomm.dat"},
+ {"/tmp/media_ipc_thumbdaemon.dat"},
+};
+
+char MEDIA_IPC_PATH_CLIENT[][50] ={
+ {"/tmp/media_ipc_dbbatchupdate_client.dat"},
+ {"/tmp/media_ipc_scandaemon_client.dat"},
+ {"/tmp/media_ipc_scancomm_client.dat"},
+ {"/tmp/media_ipc_scanner_client.dat"},
+ {"/tmp/media_ipc_dbupdate_client.dat"},
+ {"/tmp/media_ipc_thumbcreator_client.dat"},
+ {"/tmp/media_ipc_thumbcomm_client.dat"},
+ {"/tmp/media_ipc_thumbdaemon_client.dat"},
+};
+#endif
+
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd, int port)
+#else
int ms_ipc_create_client_socket(ms_protocol_e protocol, int timeout_sec, int *sock_fd)
+#endif
{
int sock = -1;
if(protocol == MS_PROTOCOL_UDP)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#endif
+
/* Create a datagram/UDP socket */
+#ifdef _USE_UDS_SOCKET_
+ if ((sock = socket(PF_FILE, SOCK_DGRAM, 0)) < 0) {
+#else
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
+
+#ifdef _USE_UDS_SOCKET_
+ memset(&serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH_CLIENT[port]);
+ unlink(MEDIA_IPC_PATH_CLIENT[port]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH_CLIENT[port]);
+
+ /* Bind to the local address */
+ if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
+ MSAPI_DBG_ERR("bind failed : %s", strerror(errno));
+ close(sock);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+#endif
}
else
{
/*Create TCP Socket*/
+#ifdef _USE_UDS_SOCKET_
+ if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
+#else
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
{
int sock = -1;
int n_reuse = 1;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
unsigned short serv_port;
serv_port = port;
if(protocol == MS_PROTOCOL_UDP)
{
/* Create a datagram/UDP socket */
+#ifdef _USE_UDS_SOCKET_
+ if ((sock = socket(PF_FILE, SOCK_DGRAM, 0)) < 0) {
+#else
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
else
{
/* Create a TCP socket */
+#ifdef _USE_UDS_SOCKET_
+ if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) {
+#else
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+#endif
MSAPI_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
}
-
+#ifdef _USE_UDS_SOCKET_
+#else
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
MSAPI_DBG_ERR("setsockopt failed: %s", strerror(errno));
close(sock);
return MS_MEDIA_ERR_SOCKET_INTERNAL;
}
-
+#endif
memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ MSAPI_DBG("%s", MEDIA_IPC_PATH[serv_port]);
+ unlink(MEDIA_IPC_PATH[serv_port]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port]);
+#else
serv_addr.sin_family = AF_INET;
// serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(serv_port);
+#endif
/* Bind to the local address */
if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
return MS_MEDIA_ERR_NONE;
}
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_un *serv_addr)
+#else
int ms_ipc_send_msg_to_server(int sockfd, int port, ms_comm_msg_s *send_msg, struct sockaddr_in *serv_addr)
+#endif
{
int res = MS_MEDIA_ERR_NONE;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un addr;
+#else
struct sockaddr_in addr;
+#endif
/* Set server Address */
memset(&addr, 0, sizeof(addr));
+#ifdef _USE_UDS_SOCKET_
+ addr.sun_family = AF_UNIX;
+ strcpy(addr.sun_path, MEDIA_IPC_PATH[port]);
+ MSAPI_DBG("%s", addr.sun_path);
+#else
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(SERVER_IP);
addr.sin_port = htons(port);
+#endif
if (sendto(sockfd, send_msg, sizeof(*(send_msg)), 0, (struct sockaddr *)&addr, sizeof(addr)) != sizeof(*(send_msg))) {
MSAPI_DBG_ERR("sendto failed [%s]", strerror(errno));
return res;
}
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_send_msg_to_client(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_un *client_addr)
+#else
int ms_ipc_send_msg_to_client(int sockfd, ms_comm_msg_s *send_msg, struct sockaddr_in *client_addr)
+#endif
{
int res = MS_MEDIA_ERR_NONE;
+#ifdef _USE_UDS_SOCKET_
+ MSAPI_DBG("the path of client address : %s", client_addr->sun_path);
+#endif
if (sendto(sockfd, send_msg, sizeof(*(send_msg)), 0, (struct sockaddr *)client_addr, sizeof(*(client_addr))) != sizeof(*(send_msg))) {
MSAPI_DBG_ERR("sendto failed [%s]", strerror(errno));
res = MS_MEDIA_ERR_SOCKET_SEND;
return MS_MEDIA_ERR_NONE;
}
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *addr_size)
+#else
int ms_ipc_receive_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *recv_addr, unsigned int *addr_size)
+#endif
{
int recv_msg_size;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un addr;
+#else
struct sockaddr_in addr;
+#endif
socklen_t addr_len;
if (!recv_msg)
return MS_MEDIA_ERR_INVALID_PARAMETER;
+#ifdef _USE_UDS_SOCKET_
+ addr_len = sizeof(addr);
+#else
addr_len = sizeof(struct sockaddr_in);
+#endif
if ((recv_msg_size = recvfrom(sockfd, recv_msg, msg_size, 0, (struct sockaddr *)&addr, &addr_len)) < 0) {
MSAPI_DBG_ERR("recvfrom failed [%s]", strerror(errno));
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
+#ifdef _USE_UDS_SOCKET_
+ MSAPI_DBG("the path of received client address : %s", addr.sun_path);
+#endif
+
if (recv_addr != NULL)
*recv_addr = addr;
if (addr_size != NULL)
return MS_MEDIA_ERR_NONE;
}
+#ifdef _USE_UDS_SOCKET_
+int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *addr_size)
+#else
int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_in *recv_addr, unsigned int *addr_size)
+#endif
{
int recv_msg_size;
socklen_t addr_len;
if (!recv_msg ||!recv_addr)
return MS_MEDIA_ERR_INVALID_PARAMETER;
+#ifdef _USE_UDS_SOCKET_
+ addr_len = sizeof(struct sockaddr_un);
+#else
addr_len = sizeof(struct sockaddr_in);
+#endif
if ((recv_msg_size = recvfrom(sockfd, recv_msg, msg_size, 0, (struct sockaddr *)recv_addr, &addr_len)) < 0) {
MSAPI_DBG_ERR("recvfrom failed [%s]", strerror(errno));
return MS_MEDIA_ERR_NONE;
}
-
#include "media-util-dbg.h"
#include "media-util.h"
+DBusConnection *g_bus;
+void *g_data_store;
+GMutex *noti_mutex = NULL;
+
+typedef struct noti_callback_data{
+ db_update_cb user_callback;
+ void *user_data;
+} noti_callback_data;
+
+static void
+__free_data_fuction(void *memory)
+{
+ MS_SAFE_FREE(memory);
+}
+
static DBusHandlerResult
__message_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
{
- db_update_cb user_cb = user_data;
+ db_update_cb user_cb = ((noti_callback_data*)user_data)->user_callback;
+ void *userdata = ((noti_callback_data*)user_data)->user_data;
+
+ if (noti_mutex != NULL) {
+ g_mutex_lock(noti_mutex);
+ } else {
+ MSAPI_DBG_ERR("subscribe function is already unreferenced");
+ }
/* A Ping signal on the com.burtonini.dbus.Signal interface */
if (dbus_message_is_signal (message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME)) {
+ int i = 0;
DBusError error;
- dbus_uint16_t noti_type;
+ DBusMessageIter read_iter;
+ DBusBasicValue value[7];
+
+ dbus_int32_t item = -1;
+ dbus_int32_t pid = 0;
+ dbus_int32_t update_type = MS_MEDIA_UNKNOWN;
+ dbus_int32_t content_type = -1;
+ char *update_path = NULL;
+ char *uuid = NULL;
+ char *mime_type = NULL;
dbus_error_init (&error);
- if (dbus_message_get_args (message, &error, DBUS_TYPE_UINT16, ¬i_type, DBUS_TYPE_INVALID)) {
- MSAPI_DBG("noti type: %d\n", noti_type);
- user_cb();
- } else {
- MSAPI_DBG("messgae received, but error getting message: %s\n", error.message);
- dbus_error_free (&error);
+ MSAPI_DBG("size [%d]", sizeof(value));
+ memset(value, 0x0, sizeof(value));
+
+ /* get data from dbus message */
+ dbus_message_iter_init (message, &read_iter);
+ while (dbus_message_iter_get_arg_type (&read_iter) != DBUS_TYPE_INVALID){
+ dbus_message_iter_get_basic (&read_iter, &value[i]);
+ dbus_message_iter_next (&read_iter);
+ i ++;
}
+
+ item = value[0].i32;
+ pid = value[1].i32;
+ update_type = value[2].i32;
+ update_path = strdup(value[3].str);
+ if (value[4].str != NULL) uuid = strdup(value[4].str);
+ content_type = value[5].i32;
+ if (value[6].str != NULL) mime_type = strdup(value[6].str);
+
+ /* getting data complete */
+ user_cb(pid,
+ item,
+ update_type,
+ update_path,
+ uuid,
+ content_type,
+ mime_type,
+ userdata);
+
+ g_mutex_unlock(noti_mutex);
+
return DBUS_HANDLER_RESULT_HANDLED;
}
+
+ g_mutex_unlock(noti_mutex);
+
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-int media_db_update_subscribe(db_update_cb user_cb)
+int media_db_update_subscribe(db_update_cb user_cb, void *user_data)
{
- DBusConnection *bus;
DBusError error;
+ noti_callback_data *callback_data = NULL;
- dbus_g_thread_init();
+ if (noti_mutex == NULL) {
+ noti_mutex = g_mutex_new();
+ }
- dbus_error_init (&error);
+ if (g_bus == NULL) {
+ dbus_g_thread_init();
+
+ dbus_error_init (&error);
+
+ g_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (!g_bus) {
+ MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message);
+ dbus_error_free (&error);
+ return MS_MEDIA_ERR_DBUS_GET;
+ }
+
+ dbus_connection_setup_with_g_main (g_bus, NULL);
+
+ callback_data = malloc(sizeof(noti_callback_data));
+ MS_MALLOC(callback_data, sizeof(noti_callback_data));
+ if (callback_data == NULL) {
+ MSAPI_DBG_ERR("MS_MALLOC failed");
+ return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
+ }
+ callback_data->user_callback = user_cb;
+ callback_data->user_data = user_data;
- bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ /* listening to messages from all objects as no path is specified */
+ dbus_bus_add_match (g_bus, MS_MEDIA_DBUS_MATCH_RULE, &error);
+ if( !dbus_connection_add_filter (g_bus, __message_filter, callback_data, __free_data_fuction)) {
+ MS_SAFE_FREE(callback_data);
+ return MS_MEDIA_ERR_DBUS_ADD_FILTER;
+ }
+ g_data_store = (void *)callback_data;
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_db_update_unsubscribe(void)
+{
+ g_mutex_lock(noti_mutex);
+
+ if (g_bus != NULL) {
+ dbus_connection_remove_filter(g_bus, __message_filter, g_data_store);
+
+ dbus_connection_unref(g_bus);
+
+ g_bus = NULL;
+ }
+
+ g_mutex_unlock(noti_mutex);
+
+ if (noti_mutex) g_mutex_free(noti_mutex);
+ noti_mutex = NULL;
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int media_db_update_send(int pid, /* mandatory */
+ media_item_type_e item, /* mandatory */
+ media_item_update_type_e update_type, /* mandatory */
+ char* path, /* mandatory */
+ char* uuid, /* optional */
+ media_type_e media_type, /* optional */
+ char *mime_type /* optional */
+ )
+{
+ DBusMessage *message;
+ DBusConnection *bus;
+ DBusError error;
+
+ /* Get a connection to the session bus */
+ dbus_error_init (&error);
+ bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if (!bus) {
MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free (&error);
return MS_MEDIA_ERR_DBUS_GET;
}
- dbus_connection_setup_with_g_main (bus, NULL);
+ /* Create a new signal on the "MS_DBUS_INTERFACE" interface,
+ * from the object "MS_DBUS_PATH". */
+ message = dbus_message_new_signal (MS_MEDIA_DBUS_PATH, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME);
+ if (message != NULL) {
+ if (item == MS_MEDIA_ITEM_FILE) {
+ MSAPI_DBG("FILE CHANGED");
+ if (uuid != NULL && mime_type != NULL) {
+ /* fill all datas */
+ dbus_message_append_args (message,
+ DBUS_TYPE_INT32, &item,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &update_type,
+ DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_INT32, &media_type,
+ DBUS_TYPE_STRING, &mime_type,
+ DBUS_TYPE_INVALID);
+ } else {
+ MSAPI_DBG_ERR("uuid or mime_type is NULL");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ } else if (item == MS_MEDIA_ITEM_DIRECTORY) {
+ MSAPI_DBG("DIRECTORY CHANGED");
+ /* fill all datas */
+ if(uuid != NULL) {
+ dbus_message_append_args (message,
+ DBUS_TYPE_INT32, &item,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &update_type,
+ DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_STRING, &uuid,
+ DBUS_TYPE_INVALID);
+ } else {
+ dbus_message_append_args (message,
+ DBUS_TYPE_INT32, &item,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &update_type,
+ DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
+ }
+ } else {
+ MSAPI_DBG("this request is wrong");
+ }
+
+ /* Send the signal */
+ dbus_connection_send (bus, message, NULL);
+
+ /* Free the signal now we have finished with it */
+ dbus_message_unref (message);
- /* listening to messages from all objects as no path is specified */
- dbus_bus_add_match (bus, MS_MEDIA_DBUS_MATCH_RULE, &error);
- if( !dbus_connection_add_filter (bus, __message_filter, user_cb, NULL))
- return MS_MEDIA_ERR_DBUS_ADD_FILTER;
+ MSAPI_DBG_ERR("success send notification");
+ } else {
+ MSAPI_DBG_ERR("dbus_message_new_signal failed");
+ }
+ /* Return TRUE to tell the event loop we want to be called again */
return MS_MEDIA_ERR_NONE;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#ifdef _USE_UDS_SOCKET_
+#include <sys/un.h>
+#else
#include <sys/socket.h>
+#endif
#include <sys/syscall.h>
#include <string.h>
#include <stdbool.h>
return MS_MEDIA_ERR_NONE;
}
-static int __media_db_request_update_sync(ms_msg_type_e msg_type, const char *request_msg)
-{
- int ret = MS_MEDIA_ERR_NONE;
- int request_msg_size = 0;
- int sockfd = -1;
- int err = -1;
- struct sockaddr_in serv_addr;
- unsigned int serv_addr_len = -1;
- int port = MS_SCANNER_PORT;
- ms_comm_msg_s send_msg;
-
- if(!MS_STRING_VALID(request_msg))
- {
- MSAPI_DBG_ERR("invalid query");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- request_msg_size = strlen(request_msg);
- if(request_msg_size >= MAX_MSG_SIZE)
- {
- MSAPI_DBG_ERR("Query is Too long. [%d] query size limit is [%d]", request_msg_size, MAX_MSG_SIZE);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- MSAPI_DBG("querysize[%d] query[%s]", request_msg_size, request_msg);
-
- memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s));
- send_msg.msg_type = msg_type;
- send_msg.pid = syscall(__NR_getpid);
- send_msg.msg_size= request_msg_size;
- strncpy(send_msg.msg, request_msg, request_msg_size);
-
- /*Create Socket*/
- ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd);
- MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
-
- ret = ms_ipc_send_msg_to_server(sockfd, port, &send_msg, &serv_addr);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret);
- close(sockfd);
- return ret;
- }
-
- /*Receive Response*/
- ms_comm_msg_s recv_msg;
- serv_addr_len = sizeof(serv_addr);
-
- memset(&recv_msg, 0x0, sizeof(ms_comm_msg_s));
- err = ms_ipc_wait_message(sockfd, &recv_msg, sizeof(recv_msg), &serv_addr, NULL);
- if (err != MS_MEDIA_ERR_NONE) {
- ret = err;
- } else {
- MSAPI_DBG("RECEIVE OK [%d]", recv_msg.result);
- ret = recv_msg.result;
- }
-
- close(sockfd);
-
- return ret;
-}
-
-
static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *request_msg, scan_complete_cb user_callback, void *user_data)
{
int ret = MS_MEDIA_ERR_NONE;
strncpy(send_msg.msg, request_msg, request_msg_size);
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, port);
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+#endif
MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
ret = ms_ipc_send_msg_to_server(sockfd, port, &send_msg, NULL);
}
-int media_directory_scanning_async(const char *directory_path, bool recusive_on, scan_complete_cb user_callback, void *user_data)
+int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data)
{
int ret;
if(ret != MS_MEDIA_ERR_NONE)
return ret;
- if (recusive_on == TRUE)
+ if (recursive_on == TRUE)
ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING, directory_path, user_callback, user_data);
else
ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, directory_path, user_callback, user_data);
return ret;
}
-static int _check_file_path(const char *file_path)
-{
- int exist;
- struct stat file_st;
-
- /* check location of file */
- /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
- if(!_is_valid_path(file_path)) {
- MSAPI_DBG("Invalid path : %s", file_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- /* check the file exits actually */
- exist = open(file_path, O_RDONLY);
- if(exist < 0) {
- MSAPI_DBG("Not exist path : %s", file_path);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- close(exist);
-
- /* check type of the path */
- /* It must be a regular file */
- memset(&file_st, 0, sizeof(struct stat));
- if(stat(file_path, &file_st) == 0) {
- if(!S_ISREG(file_st.st_mode)) {
- /* In this case, it is not a regula file */
- MSAPI_DBG("this path is not a file");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
- } else {
- MSAPI_DBG("stat failed [%s]", strerror(errno));
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int media_file_register(const char *file_full_path)
+int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data)
{
int ret;
- ret = _check_file_path(file_full_path);
- if(ret != MS_MEDIA_ERR_NONE)
- return ret;
-
- ret = __media_db_request_update_sync(MS_MSG_DB_UPDATE, file_full_path);
+ ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, list_path, user_callback, user_data);
MSAPI_DBG("client receive: %d", ret);
return ret;
}
-int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data)
+int media_burstshot_register(const char *list_path, insert_complete_cb user_callback, void *user_data)
{
int ret;
- ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, list_path, user_callback, user_data);
+ ret = __media_db_request_update_async(MS_MSG_BURSTSHOT_INSERT, list_path, user_callback, user_data);
MSAPI_DBG("client receive: %d", ret);
return ret;
+
}
<manifest>
<define>
- <domain name="media-server"/>
+ <domain name="media-server" policy="restricted" plist="media-thumbnail-server, media-data"/>
</define>
<request>
<domain name="_"/>
</request>
<assign>
- <filesystem path="/usr/bin/media-server" label="media-server" exec_label="media-server"/>
- <filesystem path="/usr/bin/media-scanner" label="media-server" exec_label="media-server" />
- <filesystem path="/usr/bin/mediadb-update" label="media-server" exec_label="media-server" />
- <filesystem path="/etc/rc.d/init.d/mediasvr" label="_" exec_label="none" />
- <filesystem path="/etc/rc.d/rc3.d/S99mediasvr" label="_" exec_label="none" />
- <filesystem path="/etc/rc.d/rc5.d/S99mediasvr" label="_" exec_label="none" />
+ <filesystem path="/usr/bin/media-server" label="media-server" exec_label="media-server" />
+ <filesystem path="/usr/bin/media-scanner" label="media-server" exec_label="media-server" />
+ <filesystem path="/usr/bin/mediadb-update" label="media-server" exec_label="media-server" />
+ <filesystem path="/etc/rc.d/init.d/mediasvr" label="_" exec_label="none" />
+ <filesystem path="/etc/rc.d/rc3.d/S99mediasvr" label="_" exec_label="none" />
+ <filesystem path="/etc/rc.d/rc5.d/S99mediasvr" label="_" exec_label="none" />
</assign>
</manifest>
[Unit]
Description=Media server
+After=vconf-setup.service
+Requires=vconf-setup.service
[Service]
Type=simple
Name: media-server
Summary: File manager service server.
-Version: 0.2.26
+Version: 0.2.34
Release: 1
Group: utils
License: Apache License, Version 2.0
%attr(755,-,-) %{_sysconfdir}/rc.d/init.d/mediasvr
/etc/rc.d/rc3.d/S99mediasvr
/etc/rc.d/rc5.d/S99mediasvr
-/usr/local/bin/reset_mediadb.sh
/usr/lib/systemd/system/media-server.service
/usr/lib/systemd/system/multi-user.target.wants/media-server.service
#License
%{_libdir}/pkgconfig/libmedia-utils.pc
%{_includedir}/media-utils/*.h
-%changelog
-* Mon Oct 15 2012 Hyunjun Ko <zzoon.ko@samsnug.com> - 0.1.97
-- Fix a bug in db thread
-
-* Wed Oct 10 2012 Hyunjun Ko <zzoon.ko@samsnug.com> - 0.1.96
-- Some apis are added : media_db_request_update_db_batch / start / end
-
-* Mon Sep 10 2012 Haejeong Kim <backto.kim@samsnug.com> - 0.1.86
-- Make new thread for DB write. Only Media server can update db
-
-* Mon Aug 06 2012 Yong Yeon Kim <yy9875.kim@samsnug.com> - 0.1.86
-- add notification subscribe function for application
-- fix bug : once validity checking time, call insert_item_batch two times.
-- add MS_SAFE_FREE Macro, modify check value after using snprintf by secure coding guide
-- change macro name MS_PHONE_ROOT_PATH, MS_MMC_ROOT_PATH
-- make reference directory list by each thread
-
-* Tue Jul 03 2012 Yong Yeon Kim <yy9875.kim@samsnug.com> - 0.1.80
-- manage db handle by plug-in
-
-* Wed Jun 27 2012 Yong Yeon Kim <yy9875.kim@samsnug.com> - 0.1.79
-- If item exists in media db, return directly
-
-* Tue Jun 26 2012 Yong Yeon Kim <yy9875.kim@samsnug.com> - 0.1.78
-- change modified file updating routine (delete & insert -> refresh)
-- modify return error type of media_file_register
-
+++ /dev/null
-#!/bin/sh
-
-if [ $# -ne 1 ]
-then
- echo 'Usage : reset_mediadb.sh [phone|sd|all]'
- exit
-fi
-
-if [ $1 = "phone" ]
-then
- vconftool set -f -t int db/filemanager/dbupdate "0"
- killall media-server
-fi
-
-if [ $1 = "sd" ]
-then
- vconftool set -f -t string db/private/mediaserver/mmc_info ""
- killall media-server
-fi
-
-if [ $1 = "all" ]
-then
- vconftool set -f -t int db/filemanager/dbupdate "0"
- vconftool set -f -t string db/private/mediaserver/mmc_info ""
- killall media-server
-fi
-
-
--- /dev/null
+/*
+ * Media Server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yong Yeon Kim <yy9875.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.
+ *
+ */
+
+/**
+ * This file defines api utilities of contents manager engines.
+ *
+ * @file media-server-dbg.h
+ * @author Yong Yeon Kim(yy9875.kim@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef _MEDIA_SERVER_DBG_H_
+#define _MEDIA_SERVER_DBG_H_
+
+#include <sys/syscall.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "MEDIA_COMMON"
+
+#define MS_DBG(fmt, args...) LOGD(fmt "\n", ##args);
+
+#define MS_DBG_INFO(fmt, args...) do{ if (true) { \
+ LOGE(fmt "\n" , ##args); \
+ }} while(false)
+
+#define MS_DBG_WARN(fmt, args...) do{ if (true) { \
+ LOGW(fmt "\n", ##args); \
+ }} while(false)
+
+#define MS_DBG_ERR(fmt, args...) do{ if (true) { \
+ LOGE(fmt "\n", ##args); \
+ }} while(false)
+
+#endif /*_MEDIA_SERVER_DBG_H_*/
#ifndef _MEDIA_SERVER_EXTERNAL_STORAGE_H_
#define _MEDIA_SERVER_EXTERNAL_STORAGE_H_
-#include "media-server-types.h"
+#include "media-common-types.h"
void
ms_make_default_path_mmc(void);
ms_mmc_removed_handler(void);
int
-ms_present_mmc_insert(void);
+ms_present_mmc_status(ms_sdcard_status_type_t status);
void
ms_mmc_vconf_cb(void *data);
/**
* This file defines api utilities of contents manager engines.
*
- * @file media-server-types.h
+ * @file media-common-types.h
* @author Yong Yeon Kim(yy9875.kim@samsung.com)
* @version 1.0
* @brief
#include <unistd.h>
#define FMS_PERF
-#define MS_INOTI_ENABLE 0
#define MS_VALIND 1
#define MS_INVALID 0
/*This macro is used to save and check information of inserted memory card*/
#define MS_MMC_INFO_KEY "db/private/mediaserver/mmc_info"
-/* store scanning status of each storage */
-#define MS_SCAN_STATUS_INTERNAL "file/private/mediaserver/scan_internal"
-#define MS_SCAN_STATUS_DIRECTORY "file/private/mediaserver/scan_directory"
-enum{
- P_VCONF_SCAN_DOING = 0,
- P_VCONF_SCAN_DONE,
-};
-
/*Use for Poweroff sequence*/
#define POWEROFF_NOTI_NAME "power_off_start" /*poeroff noti from system-server*/
#define POWEROFF_DIR_PATH "/opt/usr/media/_POWER_OFF" /*This path uses for stopping Inotify thread and Socket thread*/
} ms_storage_type_t;
typedef enum {
- MS_SCANNING_INTERNAL,
- MS_SCANNING_EXTERNAL,
- MS_SCANNING_DIRECTORY,
-} ms_scanning_location_t;
+ MS_SDCARD_INSERTED, /**< Stored only in phone */
+ MS_SDCARD_REMOVED, /**< Stored only in MMC */
+} ms_sdcard_status_type_t;
typedef enum {
MS_SCAN_INVALID,
/**
* This file defines api utilities of contents manager engines.
*
- * @file media-server-utils.h
+ * @file media-common-utils.h
* @author Yong Yeon Kim(yy9875.kim@samsung.com)
* @version 1.0
* @brief
#ifndef _MEDIA_SERVER_UTILS_H__
#define _MEDIA_SERVER_UTILS_H__
-#include "media-server-types.h"
-
-int
-ms_set_db_status(ms_db_status_type_t status);
+#include "media-common-types.h"
int
ms_db_init(bool need_db_create);
void
ms_end(void);
-int
-ms_get_full_path_from_node(ms_dir_scan_info * const node, char *ret_path, int depth);
-
ms_storage_type_t
ms_get_storage_type_by_full(const char *path);
int
+ms_get_mime(const char *path, char *mimetype);
+
+int
ms_strappend(char *res, const int size, const char *pattern,
const char *str1, const char *str2);
#include "media-util.h"
-#include "media-server-dbg.h"
-#include "media-server-types.h"
-#include "media-server-inotify.h"
-#include "media-server-drm.h"
+#include "media-common-dbg.h"
+#include "media-common-types.h"
+#include "media-common-drm.h"
bool
ms_is_drm_file(const char *path)
{
int ret;
drm_content_info_s contentInfo;
+ drm_file_type_e file_type = DRM_TYPE_UNDEFINED;
if (path == NULL || mime == NULL)
return MS_MEDIA_ERR_INVALID_PARAMETER;
- memset(&contentInfo,0x0,sizeof(drm_content_info_s));
- ret = drm_get_content_info(path, &contentInfo);
+ /* check drm type */
+ ret = drm_get_file_type(path, &file_type);
if (ret != DRM_RETURN_SUCCESS) {
- MS_DBG_ERR("drm_svc_get_content_info() fails. ");
+ MS_DBG_ERR("drm_get_file_type() failed");
+ MS_DBG_ERR("%s [%d]", path, ret);
return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
+ } else {
+ MS_DBG_ERR("DRM TYPE [%d]", file_type);
+ /* if a drm file is OMA drm, use DRM API for getting mime information */
+ if (file_type == DRM_TYPE_OMA_V1
+ || file_type == DRM_TYPE_OMA_V2
+ || file_type == DRM_TYPE_OMA_PD) {
+ MS_DBG_ERR("THIS IS OMA DRM");
+ memset(&contentInfo,0x0,sizeof(drm_content_info_s));
+ ret = drm_get_content_info(path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ MS_DBG_ERR("drm_svc_get_content_info() failed");
+ MS_DBG_ERR("%s [%d]", path, ret);
+ return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
+ }
+ strncpy(mime, contentInfo.mime_type, 100);
+ } else {
+ MS_DBG_ERR("THIS IS DRM BUT YOU SHOULD USE API OF AUL LIBRARY");
+ return MS_MEDIA_ERR_DRM_GET_INFO_FAIL;
+ }
}
- strncpy(mime, contentInfo.mime_type, 100);
- MS_DBG("DRM contentType : %s", contentInfo.mime_type);
- MS_DBG("DRM mime : %s", mime);
-
return MS_MEDIA_ERR_NONE;
}
MS_DBG("THIS IS DRM FILE");
int res = MS_MEDIA_ERR_NONE;
int ret;
-#if MS_INOTI_ENABLE
-// ms_inoti_add_ignore_file(path);
-#endif
+
ret = drm_process_request(DRM_REQUEST_TYPE_REGISTER_FILE, (void *)path, NULL);
if (ret != DRM_RETURN_SUCCESS) {
MS_DBG_ERR("drm_svc_register_file error : %d", ret);
ms_drm_unregister(const char* path)
{
int ret;
-#if MS_INOTI_ENABLE
- ms_ignore_file_info *ignore_file;
-#endif
+
ret = drm_process_request(DRM_REQUEST_TYPE_UNREGISTER_FILE, (void *)path, NULL);
if (ret != DRM_RETURN_SUCCESS)
MS_DBG_ERR("drm_process_request error : %d", ret);
-#if MS_INOTI_ENABLE
- ignore_file = ms_inoti_find_ignore_file(path);
- if (ignore_file != NULL)
- ms_inoti_delete_ignore_file(ignore_file);
-#endif
}
void
#include <notification.h>
#include "media-util.h"
-#include "media-server-dbg.h"
-#include "media-server-utils.h"
#include "media-server-ipc.h"
-#include "media-server-socket.h"
-#include "media-server-inotify.h"
-#include "media-server-db-svc.h"
-#include "media-server-scanner.h"
-#include "media-server-external-storage.h"
-#include "media-server-drm.h"
+#include "media-common-dbg.h"
+#include "media-common-utils.h"
+#include "media-common-drm.h"
+#include "media-common-external-storage.h"
#define MMC_INFO_SIZE 256
-int mmc_state = 0;
-
char default_path[][MS_FILE_NAME_LEN_MAX + 1] = {
{"/opt/storage/sdcard/Images"},
{"/opt/storage/sdcard/Videos"},
ret = mkdir(default_path[i], 0777);
if (ret < 0) {
MS_DBG("make fail");
- } else {
-#if MS_INOTI_ENABLE
- ms_inoti_add_watch(default_path[i]);
-#endif
- /*this fuction for emulator*/
- /*at the first time, the directroies are made permission 755*/
- chmod(default_path[i], 0777);
- chown(default_path[i], 5000, 5000);
}
} else {
closedir(dp);
void update_lang(void)
{
- char *lang;
- char *r;
+ char *lang = NULL;
+ char *r = NULL;
lang = vconf_get_str(VCONFKEY_LANGSET);
if (lang) {
}
int
-ms_present_mmc_insert(void)
+ms_present_mmc_status(ms_sdcard_status_type_t status)
{
- int ret;
+ int ret = NOTIFICATION_ERROR_NONE;
update_lang();
- ret = notification_status_message_post(_GETSYSTEMSTR("IDS_COM_BODY_PREPARING_SD_CARD"));
+ if (status == MS_SDCARD_INSERTED)
+ ret = notification_status_message_post(_GETSYSTEMSTR("IDS_COM_BODY_PREPARING_SD_CARD"));
+ else if (status == MS_SDCARD_REMOVED)
+ ret = notification_status_message_post(_GETSYSTEMSTR("IDS_COM_BODY_SD_CARD_REMOVED"));
+
if(ret != NOTIFICATION_ERROR_NONE)
return MS_MEDIA_ERR_INTERNAL;
return MS_MEDIA_ERR_NONE;
}
-void
-ms_mmc_vconf_cb(void *data)
-{
- int status = 0;
-
- if (!ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status)) {
- MS_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
- }
-
- MS_DBG("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
-
- mmc_state = status;
-
- /* If scanner is not working, media server executes media scanner and sends request. */
- /* If scanner is working, it detects changing status of SD card. */
- if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
- mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
-
- /*remove added watch descriptors */
-#if MS_INOTI_ENABLE
- ms_inoti_remove_watch_recursive(MEDIA_ROOT_PATH_SDCARD);
- ms_inoti_delete_mmc_ignore_file();
-#endif
- if (!ms_get_scanner_status()) {
- if (!ms_drm_extract_ext_memory())
- MS_DBG_ERR("ms_drm_extract_ext_memory failed");
-
- ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, MS_SCAN_INVALID);
- }
- } else if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
-
- ms_make_default_path_mmc();
-#if MS_INOTI_ENABLE
- ms_inoti_add_watch_all_directory(MS_STORAGE_EXTERNAL);
-#endif
- ms_present_mmc_insert();
-
- if (!ms_get_scanner_status()) {
- if (!ms_drm_insert_ext_memory())
- MS_DBG_ERR("ms_drm_insert_ext_memory failed");
-
- ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, ms_get_mmc_state());
- }
- }
-
- return;
-}
-
#include <errno.h>
#include <pmapi.h>
#include <vconf.h>
+#include <aul/aul.h>
#include "media-util.h"
-#include "media-server-dbg.h"
#include "media-server-ipc.h"
-#include "media-server-inotify.h"
-#include "media-server-utils.h"
-#include "media-server-drm.h"
-#include "media-server-dbus.h"
-#include "media-server-socket.h"
+#include "media-common-dbg.h"
+#include "media-common-drm.h"
+#include "media-common-utils.h"
#ifdef FMS_PERF
#include <sys/time.h>
#define MS_DRM_CONTENT_TYPE_LENGTH 100
-extern int mmc_state;
-
-static int
-_ms_set_power_mode(ms_db_status_type_t status)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err;
-
- switch (status) {
- case MS_DB_UPDATING:
- err = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- case MS_DB_UPDATED:
- err = pm_unlock_state(LCD_OFF, STAY_CUR_STATE);
- if (err != 0)
- res = MS_MEDIA_ERR_INTERNAL;
- break;
- default:
- MS_DBG_ERR("Unacceptable type : %d", status);
- break;
- }
-
- return res;
-}
-
-int
-ms_set_db_status(ms_db_status_type_t status)
-{
- int res = MS_MEDIA_ERR_NONE;
- int err = 0;
-
- if (status == MS_DB_UPDATING) {
- if (ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING))
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- } else if (status == MS_DB_UPDATED) {
- if(ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED))
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- /*notify to other application about db updated by DBUS*/
- ms_dbus_send_noti(MS_DBUS_DB_UPDATED);
- }
-
- err = _ms_set_power_mode(status);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("_ms_set_power_mode fail");
- res = err;
- }
-
- return res;
-}
-
#ifdef FMS_PERF
void
ms_check_start_time(struct timeval *start_time)
}
}
-/*CAUTION : Before using this function, Have to allocate static memory of ret_path*/
-/*And the array length does not over MS_FILE_PATH_LEN_MAX*/
-/*for example : char path[MS_FILE_PATH_LEN_MAX] = {0};*/
-int
-ms_get_full_path_from_node(ms_dir_scan_info * const node, char *ret_path, int depth)
-{
- int i = 0;
- int path_length = 0;
- int length = 0;
- ms_dir_scan_info *cur_node;
- char **path_array;
-
- if (depth < 0) {
- MS_DBG_ERR("depth < 0");
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- MS_MALLOC(path_array, sizeof(char*) * (depth + 1));
-
- cur_node = node;
-
- while (1) {
- path_array[i] = cur_node->name;
- if (cur_node->parent == NULL)
- break;
-
- cur_node = cur_node->parent;
- i++;
- }
-
- for(i = depth ; i >= 0 ; i --) {
- length = strlen(path_array[i]);
-
- if (path_length + length > MS_FILE_PATH_LEN_MAX) {
- MS_DBG_ERR("This is invalid path, %s, %d", node->name, depth);
- MS_SAFE_FREE(path_array);
- return MS_MEDIA_ERR_INVALID_PATH;
- }
-
- strncpy(ret_path+path_length, path_array[i], length);
- path_length += length;
-
- ret_path[path_length] = '/';
- path_length ++;
- }
-
- ret_path[-- path_length] = '\0';
-
- MS_SAFE_FREE(path_array);
-
- return MS_MEDIA_ERR_NONE;
-}
-
ms_storage_type_t
ms_get_storage_type_by_full(const char *path)
{
}
int
+ms_get_mime(const char *path, char *mimetype)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ if (path == NULL)
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+
+ /*get content type and mime type from file. */
+ /*in case of drm file. */
+ if (ms_is_drm_file(path)) {
+ if (ms_get_mime_in_drm_info(path, mimetype) != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("Fail to get mime from drm API");
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ MS_DBG_ERR("aul_get_mime_from_file fail");
+ ret = MS_MEDIA_ERR_MIME_GET_FAIL;
+ } else {
+ MS_DBG_ERR("aul_get_mime_from_file success");
+ ret = MS_MEDIA_ERR_NONE;
+ }
+ }
+ } else {
+ /*in case of normal files */
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ MS_DBG_ERR("aul_get_mime_from_file fail");
+ ret = MS_MEDIA_ERR_MIME_GET_FAIL;
+ }
+ }
+
+ return ret;
+}
+
+int
ms_strappend(char *res, const int size, const char *pattern,
const char *str1, const char *str2)
{
{
printf("=======================================================================================\n");
printf("\n");
- printf("mediadb-update [option] <directory path> \n");
+ printf("db-update [option] <directory path> \n");
printf("\n");
printf("[option]\n");
printf(" -r : [only directory] update all directory recursivly under <directory path>\n");
printf("\n");
- printf("mediadb-update --help for check this messages.\n");
+ printf("db-update --help for check this messages.\n");
printf("\n");
printf("A file or directory must exists under /opt/usr/media or /opt/storage/sdcard.\n");
printf("Using /opt/storage/sdcard is allowed SD card is mounted.\n");
printf("\n");
printf("=======================================================================================\n");
- exit(1);
}
int dir_scan_non_recursive(char *path)
} else {
closedir(dp);
}
- printf("[%d]invalid path\n", __LINE__);
print_help();
+ return NOT_OK;
}
} else {
- printf("stat error : %s\n", strerror(errno));
+ printf("stat error : %s", strerror(errno));
}
return NOT_OK;
char *argv1 = NULL;
char *argv2 = NULL;
- if (argc > 3 || argc < 2) {
+ if (argc > 3 ||argc < 2) {
print_help();
+ exit(1);
}
argv1 = strdup(argv[1]);
if (argc == 2) {
if (strcmp(argv1 , "--help") == 0) {
print_help();
+ exit(1);
}
if (check_path(argv1) == DIRECTORY_OK) {
exit(1);
}
} else {
+ printf("[%d]invalid path\n", __LINE__);
print_help();
+ exit(1);
}
} else if (argc == 3) {
argv2 = strdup(argv[2]);
exit(1);
}
} else {
+ printf("[%d]invalid path\n", __LINE__);
print_help();
+ exit(1);
}
} else {
printf("[%d] invalide option\n", __LINE__);
print_help();
+ exit(1);
}
}
#ifndef _MEDIA_SCANNER_DB_SVC_H_
#define _MEDIA_SCANNER_DB_SVC_H_
-#include "media-server-types.h"
+#include "media-common-types.h"
typedef int (*CHECK_ITEM)(const char*, const char*, char **);
typedef int (*CONNECT)(void**, char **);
typedef int (*DISCONNECT)(void*, char **);
typedef int (*CHECK_ITEM_EXIST)(void*, const char*, int, char **);
-typedef int (*INSERT_ITEM_BEGIN)(void*, int, char **);
+typedef int (*INSERT_ITEM_BEGIN)(void*, int, int, int, char **);
typedef int (*INSERT_ITEM_END)(void*, char **);
typedef int (*INSERT_ITEM)(void*, const char*, int, const char*, char **);
typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
typedef int (*UPDATE_END)(void);
typedef int (*SET_FOLDER_ITEM_VALIDITY)(void*, const char*, int, int, char**);
typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void*, const char*, char**);
+typedef int (*INSERT_BURST_ITEM)(void *, const char *, int , const char*, char **);
+typedef int (*SEND_DIR_UPDATE_NOTI)(void *, const char *, char **);
int
msc_load_functions(void);
msc_disconnect_db(void ***handle);
int
-msc_validate_item(void **handle, char *path);
+msc_validate_item(void **handle, const char *path);
int
msc_insert_item_batch(void **handle, const char *path);
+int
+msc_insert_burst_item(void **handle, const char *path);
+
bool
msc_delete_all_items(void **handle, ms_storage_type_t store_type);
int
msc_delete_invalid_items_in_folder(void **handle, const char*path);
+int
+msc_send_dir_update_noti(void **handle, const char*path);
+
/****************************************************************************************************
FOR BULK COMMIT
*****************************************************************************************************/
+typedef enum {
+ MS_NOTI_DISABLE = 0, /**< Stored only in phone */
+ MS_NOTI_ENABLE = 1, /**< Stored only in MMC */
+} ms_noti_status_e;
void
-msc_register_start(void **handle);
+msc_register_start(void **handle, ms_noti_status_e noti_status, int pid);
void
msc_register_end(void **handle);
#ifndef _MEDIA_SCANNER_SOCKET_H_
#define _MEDIA_SCANNER_SOCKET_H_
-#include "media-server-types.h"
+#include "media-common-types.h"
#include "media-server-ipc.h"
gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer data);
*/
#include <dlfcn.h>
-#include <aul/aul.h>
#include "media-util.h"
+#include "media-common-utils.h"
+#include "media-common-drm.h"
#include "media-scanner-dbg.h"
-#include "media-scanner-utils.h"
-#include "media-scanner-drm.h"
#include "media-scanner-db-svc.h"
#define CONFIG_PATH "/opt/usr/data/file-manager-service/plugin-config"
eUPDATE_END,
eSET_FOLDER_VALIDITY,
eDELETE_FOLDER,
+ eINSERT_BURST,
+ eSEND_DIR_UPDATE_NOTI,
eFUNC_MAX
};
-
-static int
-_msc_get_mime(const char *path, char *mimetype)
-{
- int ret = 0;
-
- if (path == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
-
- /*get content type and mime type from file. */
- /*in case of drm file. */
- if (msc_is_drm_file(path)) {
- ret = msc_get_mime_in_drm_info(path, mimetype);
- if (ret != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("Fail to get mime");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- } else {
- /*in case of normal files */
- if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
- MSC_DBG_ERR("aul_get_mime_from_file fail");
- return MS_MEDIA_ERR_MIME_GET_FAIL;
- }
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
static int
_msc_check_category(const char *path, const char *mimetype, int index)
{
"update_end",
"set_folder_item_validity",
"delete_all_invalid_items_in_folder",
+ "insert_burst_item",
+ "send_dir_update_noti",
};
/*init array for adding name of so*/
so_array = g_array_new(FALSE, FALSE, sizeof(char*));
}
int
-msc_validate_item(void **handle, char *path)
+msc_validate_item(void **handle, const char *path)
{
int lib_index;
int res = MS_MEDIA_ERR_NONE;
char mimetype[255] = {0};
ms_storage_type_t storage_type;
- ret = _msc_get_mime(path, mimetype);
+ ret = ms_get_mime(path, mimetype);
if (ret != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("err : _msc_get_mime [%d]", ret);
+ MSC_DBG_ERR("err : ms_get_mime [%d]", ret);
return ret;
}
- storage_type = msc_get_storage_type_by_full(path);
+ storage_type = ms_get_storage_type_by_full(path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_msc_check_category(path, mimetype, lib_index)) {
}
}
- if (msc_is_drm_file(path)) {
- ret = msc_drm_register(path);
+ if (ms_is_drm_file(path)) {
+ ret = ms_drm_register(path);
}
return res;
char *err_msg = NULL;
ms_storage_type_t storage_type;
- ret = _msc_get_mime(path, mimetype);
+ ret = ms_get_mime(path, mimetype);
if (ret != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("err : _msc_get_mime [%d]", ret);
+ MSC_DBG_ERR("err : ms_get_mime [%d]", ret);
return ret;
}
- storage_type = msc_get_storage_type_by_full(path);
+
+ storage_type = ms_get_storage_type_by_full(path);
for (lib_index = 0; lib_index < lib_num; lib_index++) {
if (!_msc_check_category(path, mimetype, lib_index)) {
}
}
- if (msc_is_drm_file(path)) {
- ret = msc_drm_register(path);
+ if (ms_is_drm_file(path)) {
+ ret = ms_drm_register(path);
+ res = ret;
+ }
+
+ return res;
+}
+
+int
+msc_insert_burst_item(void **handle, const char *path)
+{
+ int lib_index;
+ int res = MS_MEDIA_ERR_NONE;
+ int ret;
+ char mimetype[255] = {0};
+ char *err_msg = NULL;
+ ms_storage_type_t storage_type;
+
+ ret = ms_get_mime(path, mimetype);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MSC_DBG_ERR("err : ms_get_mime [%d]", ret);
+ return ret;
+ }
+
+ storage_type = ms_get_storage_type_by_full(path);
+
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ if (!_msc_check_category(path, mimetype, lib_index)) {
+ ret = ((INSERT_BURST_ITEM)func_array[lib_index][eINSERT_BURST])(handle[lib_index], path, storage_type, mimetype, &err_msg); /*dlopen*/
+ if (ret != 0) {
+ MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+ MSC_DBG_ERR("[%s] %s", mimetype, path);
+ MS_SAFE_FREE(err_msg);
+ res = MS_MEDIA_ERR_DB_INSERT_FAIL;
+ }
+ } else {
+ MSC_DBG_ERR("check category failed");
+ MSC_DBG_ERR("[%s] %s", mimetype, path);
+ }
+ }
+
+ if (ms_is_drm_file(path)) {
+ ret = ms_drm_register(path);
res = ret;
}
return MS_MEDIA_ERR_NONE;
}
+int
+msc_send_dir_update_noti(void **handle, const char*path)
+{
+ int lib_index;
+ int ret;
+ char *err_msg = NULL;
+
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ ret = ((SEND_DIR_UPDATE_NOTI)func_array[lib_index][eSEND_DIR_UPDATE_NOTI])(handle[lib_index], path, &err_msg); /*dlopen*/
+ if (ret != 0) {
+ MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+ MS_SAFE_FREE(err_msg);
+ return MS_MEDIA_ERR_SEND_NOTI_FAIL;
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
/****************************************************************************************************
FOR BULK COMMIT
*****************************************************************************************************/
void
-msc_register_start(void **handle)
+msc_register_start(void **handle, ms_noti_status_e noti_status, int pid)
{
int lib_index;
int ret = 0;
char *err_msg = NULL;
for (lib_index = 0; lib_index < lib_num; lib_index++) {
- ret = ((INSERT_ITEM_BEGIN)func_array[lib_index][eINSERT_BEGIN])(handle[lib_index], MSC_REGISTER_COUNT, &err_msg);/*dlopen*/
+ ret = ((INSERT_ITEM_BEGIN)func_array[lib_index][eINSERT_BEGIN])(handle[lib_index], MSC_REGISTER_COUNT, noti_status, pid, &err_msg);/*dlopen*/
if (ret != 0) {
MSC_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
MS_SAFE_FREE(err_msg);
#include "media-util.h"
#include "media-server-ipc.h"
+#include "media-common-utils.h"
+#include "media-common-external-storage.h"
#include "media-scanner-dbg.h"
-#include "media-scanner-utils.h"
#include "media-scanner-db-svc.h"
#include "media-scanner-socket.h"
#include "media-scanner-scan.h"
struct msc_scan_data *next;
} msc_scan_data;
-int mmc_state;
+int mmc_state = 0;
bool power_off;
GAsyncQueue * storage_queue;
GAsyncQueue *scan_queue;
}
static int
-_msc_set_db_status(ms_scanning_location_t location, ms_db_status_type_t status)
+_msc_set_db_status(ms_db_status_type_t status)
{
int res = MS_MEDIA_ERR_NONE;
int err = 0;
if (status == MS_DB_UPDATING) {
- if (location != MS_SCANNING_DIRECTORY) {
- if (!msc_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- }
- /* this is temporay code for tizen 2.0*/
- if(location == MS_SCANNING_EXTERNAL) {
- if (!msc_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- }
-
- /* Update private vconf key for media server*/
- if (location == MS_SCANNING_INTERNAL) {
- if (!msc_config_set_int(MS_SCAN_STATUS_INTERNAL, P_VCONF_SCAN_DOING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- } else if (location == MS_SCANNING_DIRECTORY) {
- if (!msc_config_set_int(MS_SCAN_STATUS_DIRECTORY, P_VCONF_SCAN_DOING)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
+ if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MSC_DBG_ERR("ms_config_set_int failed");
}
} else if (status == MS_DB_UPDATED) {
- if (location != MS_SCANNING_DIRECTORY) {
- if(!msc_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- }
-
- /* this is temporay code for tizen 2.0*/
- if(location == MS_SCANNING_EXTERNAL) {
- if (!msc_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- }
-
- /* Update private vconf key for media server*/
- if (location == MS_SCANNING_INTERNAL) {
- if (!msc_config_set_int(MS_SCAN_STATUS_INTERNAL, P_VCONF_SCAN_DONE)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
- } else if (location == MS_SCANNING_DIRECTORY) {
- if (!msc_config_set_int(MS_SCAN_STATUS_DIRECTORY, P_VCONF_SCAN_DONE)) {
- res = MS_MEDIA_ERR_VCONF_SET_FAIL;
- MSC_DBG_ERR("msc_config_set_int failed");
- }
+ if(!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
+ res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+ MSC_DBG_ERR("ms_config_set_int failed");
}
}
return res;
}
-static int _msc_scan_get_next_path_from_current_node(int find_folder,
- ms_dir_scan_info **current_root,
- ms_dir_scan_info **real_root, char **path, int *depth)
-{
- int err = MS_MEDIA_ERR_NONE;
- char get_path[FAT_FILEPATH_LEN_MAX] = { 0 };
-
- if (find_folder == 0) {
- if ((*current_root)->Rbrother != NULL) {
- *current_root = (*current_root)->Rbrother;
- } else {
- while (1) {
- if ((*current_root)->parent == *real_root
- || (*current_root)->parent == NULL) {
- *current_root = NULL;
- *depth = 0;
- return MS_MEDIA_ERR_NONE;
- } else if ((*current_root)->parent->Rbrother == NULL) {
- *current_root = (*current_root)->parent;
- (*depth) --;
- } else {
- *current_root = (*current_root)->parent->Rbrother;
- (*depth) --;
- break;
- }
- }
- }
- (*depth) --;
- }
-
- err = msc_get_full_path_from_node(*current_root, get_path, *depth);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INVALID_PATH;
-
- *path = strdup(get_path);
-
- return err;
-}
-
-static int _msc_scan_add_node(msc_scan_data **first_node, ms_dir_scan_info *const node, int depth)
-{
- int err;
- char full_path[MS_FILE_PATH_LEN_MAX] = { 0 };
- msc_scan_data *current_dir = NULL;
- msc_scan_data *prv_node = NULL;
- msc_scan_data *last_node = NULL;
-
- err = msc_get_full_path_from_node(node, full_path, depth);
- if (err != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INVALID_PATH;
-
- last_node = *first_node;
- while (last_node != NULL) {
- last_node = last_node->next;
- }
-
- /*find same folder */
- if (*first_node != NULL) {
- last_node = *first_node;
- while (last_node != NULL) {
- if (strcmp(full_path, last_node->name) == 0) {
- return MS_MEDIA_ERR_NONE;
- }
- prv_node = last_node;
- last_node = last_node->next;
- }
- }
-
- MS_MALLOC(current_dir, sizeof(msc_scan_data));
- current_dir->name = strdup(full_path);
- current_dir->next = NULL;
-
- if (*first_node == NULL) {
- *first_node = current_dir;
- } else {
- /*if next node of current node is NULL, it is the lastest node. */
- prv_node->next = current_dir;
- }
-
-// MSC_DBG_INFO("scan path : %s %x %p", full_path, first_node, first_node);
-
- return MS_MEDIA_ERR_NONE;
-}
-
static bool _msc_check_scan_ignore(char * path)
{
DIR *dp = NULL;
return ret;
}
-static void _msc_dir_check(msc_scan_data **first_node, const ms_comm_msg_s *scan_data)
+static void _msc_insert_array(GArray *garray, ms_comm_msg_s *insert_data)
{
- int err = 0;
- int depth = 0;
- int find_folder = 0;
- char get_path[MS_FILE_PATH_LEN_MAX] = { 0 };
- char *path = NULL;
- DIR *dp = NULL;
- struct dirent entry;
- struct dirent *result;
- ms_storage_type_t storage_type;
-
- ms_dir_scan_info *root = NULL;
- ms_dir_scan_info *tmp_root = NULL;
- ms_dir_scan_info *cur_node = NULL; /*current node*/
- ms_dir_scan_info *prv_node = NULL; /*previous node*/
- ms_dir_scan_info *next_node = NULL;
+ MSC_DBG_INFO("path : %s", insert_data->msg);
+ MSC_DBG_INFO("scan_type : %d", insert_data->msg_type);
- MS_MALLOC(root, sizeof(ms_dir_scan_info));
- if (root == NULL) {
- MSC_DBG_ERR("malloc fail");
- return;
+ if (insert_data->pid == POWEROFF) {
+ g_array_prepend_val(garray, insert_data);
+ } else {
+ g_array_append_val(garray, insert_data);
}
+}
- storage_type = msc_get_storage_type_by_full(scan_data->msg);
-
- root->name = strndup(scan_data->msg, scan_data->msg_size);
- if (root->name == NULL) {
- MSC_DBG_ERR("strdup fail");
- MS_SAFE_FREE(root);
- return;
- }
+void _msc_check_dir_path(char *dir_path)
+{
+ /* need implementation */
+ /* if dir_path is not NULL terminated, this function will occure crash */
+ int len = strlen(dir_path);
- root->parent = NULL;
- root->Rbrother = NULL;
- root->next = NULL;
- tmp_root = root;
- prv_node = root;
+ if (dir_path[len -1] == '/')
+ dir_path[len -1] = '\0';
+}
- MS_MALLOC(path, sizeof(char) * MS_FILE_PATH_LEN_MAX);
+static int _msc_dir_scan(void **handle, const char*start_path, ms_storage_type_t storage_type, int scan_type)
+{
+ DIR *dp = NULL;
+ GArray *dir_array = NULL;
+ struct dirent entry;
+ struct dirent *result = NULL;
+ int i;
+ int ret = MS_MEDIA_ERR_NONE;
+ char *new_path = NULL;
+ char *current_path = NULL;
+ char path[MS_FILE_PATH_LEN_MAX] = { 0 };
+ int (*scan_function)(void **, const char*) = NULL;
- err = msc_get_full_path_from_node(tmp_root, path, depth);
- if (err != MS_MEDIA_ERR_NONE) {
- MS_SAFE_FREE(path);
- MS_SAFE_FREE(root);
- return;
+ /* make new array for storing directory */
+ dir_array = g_array_new (FALSE, FALSE, sizeof (char*));
+ if (dir_array == NULL){
+ MSC_DBG_ERR("g_array_new failed");
+ return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
}
+ /* add first direcotiry to directory array */
+ g_array_append_val (dir_array, start_path);
- _msc_scan_add_node(first_node, root, depth);
+ if (scan_type == MS_MSG_STORAGE_ALL)
+ scan_function = msc_insert_item_batch;
+ else
+ scan_function = msc_validate_item;
- while (1) {
+ /*start db update. the number of element in the array , db update is complete.*/
+ while (dir_array->len != 0) {
/*check poweroff status*/
- err = _ms_check_stop_status(storage_type);
- if (err != MS_MEDIA_ERR_NONE) {
- goto FREE_RESOURCES;
- }
-
- depth ++;
- dp = opendir(path);
- if (dp == NULL) {
- MSC_DBG_ERR("%s folder opendir fails", path);
- goto NEXT_DIR;
+ ret = _ms_check_stop_status(storage_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ goto STOP_SCAN;
+ }
+ /* get the current path from directory array */
+ current_path = g_array_index(dir_array , char*, 0);
+ g_array_remove_index (dir_array, 0);
+ MSC_DBG_INFO("%d", dir_array->len);
+
+ if (_msc_check_scan_ignore(current_path)) {
+ MSC_DBG_ERR("%s is ignore", current_path);
+ MS_SAFE_FREE(current_path);
+ continue;
}
- while (!readdir_r(dp, &entry, &result)) {
- /*check poweroff status*/
- err = _ms_check_stop_status(storage_type);
- if (err != MS_MEDIA_ERR_NONE) {
- goto FREE_RESOURCES;
- }
-
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
- continue;
-
- if (entry.d_type & DT_DIR) {
- err = msc_strappend(get_path, sizeof(get_path), "%s/%s",path, entry.d_name);
- if (err != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("msc_strappend error");
- continue;
- }
-
- if (_msc_check_scan_ignore(get_path)) {
- MSC_DBG_ERR("%s is ignore", get_path);
- continue;
+ dp = opendir(current_path);
+ if (dp != NULL) {
+ while (!readdir_r(dp, &entry, &result)) {
+ /*check poweroff status*/
+ ret = _ms_check_stop_status(storage_type);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ goto STOP_SCAN;
}
- MS_MALLOC(cur_node, sizeof(ms_dir_scan_info));
- if (cur_node == NULL) {
- MSC_DBG_ERR("malloc fail");
+ if (result == NULL)
+ break;
- goto FREE_RESOURCES;
- }
+ if (entry.d_name[0] == '.')
+ continue;
- cur_node->name = strdup(entry.d_name);
- cur_node->Rbrother = NULL;
- cur_node->next = NULL;
-
- /*1. 1st folder */
- if (find_folder == 0) {
- cur_node->parent = tmp_root;
- tmp_root = cur_node;
- } else {
- cur_node->parent = tmp_root->parent;
- prv_node->Rbrother = cur_node;
+ if (entry.d_type & DT_REG) {
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+ MSC_DBG_ERR("ms_strappend failed");
+ continue;
+ }
+ /* insert into media DB */
+ if (scan_function(handle,path) != MS_MEDIA_ERR_NONE) {
+ MSC_DBG_ERR("failed to update db : %d\n", scan_type);
+ continue;
+ }
+ } else if (entry.d_type & DT_DIR) {
+ if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+ /* this request is recursive scanning */
+ if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+ MSC_DBG_ERR("ms_strappend failed");
+ continue;
+ }
+ /* add new directory to dir_array */
+ new_path = strdup(path);
+ g_array_append_val (dir_array, new_path);
+ } else {
+ /* this request is recursive scanning */
+ /* don't add new directory to dir_array */
+ }
}
- prv_node->next = cur_node;
-
- /*add watch */
- _msc_scan_add_node(first_node, cur_node, depth);
-
- /*change previous */
- prv_node = cur_node;
- find_folder++;
}
+ } else {
+ MSC_DBG_ERR("%s folder opendir fails", current_path);
}
-NEXT_DIR:
- MS_SAFE_FREE(path);
if (dp) closedir(dp);
dp = NULL;
+ MS_SAFE_FREE(current_path);
+ } /*db update while */
+STOP_SCAN:
+ if (dp) closedir(dp);
- err = _msc_scan_get_next_path_from_current_node(find_folder, &tmp_root, &root, &path, &depth);
- if (err != MS_MEDIA_ERR_NONE)
- break;
-
- if (tmp_root == NULL)
- break;
-
- find_folder = 0;
+ /*delete all node*/
+ if(dir_array != NULL) {
+ for (i =0; i < dir_array->len; i++) {
+ char *data = NULL;
+ data = g_array_index(dir_array , char*, 0);
+ g_array_remove_index (dir_array, 0);
+ MS_SAFE_FREE(data);
+ }
+ g_array_free (dir_array, TRUE);
+ dir_array = NULL;
}
-FREE_RESOURCES:
- /*free allocated memory */
- MS_SAFE_FREE(path);
- if (dp) closedir(dp);
- dp = NULL;
-
- cur_node = root;
- while (cur_node != NULL) {
- next_node = cur_node->next;
- MS_SAFE_FREE(cur_node->name);
- MS_SAFE_FREE(cur_node);
- cur_node = next_node;
- }
+ MSC_DBG_INFO("ret : %d", ret);
+
+ return ret;
}
-static int _msc_dir_scan(void **handle, msc_scan_data **first_node, const ms_comm_msg_s * scan_data)
+static int _msc_db_update(void **handle, const ms_comm_msg_s * scan_data)
{
- DIR *dp = NULL;
int scan_type;
- int ret = MS_MEDIA_ERR_NONE;
- int err = 0;
- char path[MS_FILE_PATH_LEN_MAX] = { 0 };
- msc_scan_data *node;
+ int err = MS_MEDIA_ERR_NONE;
+ char *start_path = NULL;
+ char *noti_path = NULL;
ms_storage_type_t storage_type;
- err = msc_strcopy(path, sizeof(path), "%s", scan_data->msg);
- if (err != MS_MEDIA_ERR_NONE) {
- MSC_DBG_ERR("error : %d", err );
- return err;
- }
-
- storage_type = msc_get_storage_type_by_full(scan_data->msg);
+ storage_type = ms_get_storage_type_by_full(scan_data->msg);
scan_type = scan_data->msg_type;
/*if scan type is not MS_SCAN_NONE, check data in db. */
if (scan_type != MS_MSG_STORAGE_INVALID) {
- struct dirent entry;
- struct dirent *result = NULL;
+ MSC_DBG_INFO("INSERT");
+ start_path = strndup(scan_data->msg, scan_data->msg_size);
+ scan_type = scan_data->msg_type;
- if (scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
- _msc_dir_check(first_node, scan_data);
+ err = _msc_dir_scan(handle, start_path, storage_type, scan_type);
+ if (err != MS_MEDIA_ERR_NONE) {
+ MSC_DBG_ERR("error : %d", err);
} else {
- msc_scan_data *scan_node;
-
- MS_MALLOC(scan_node, sizeof(msc_scan_data));
-
- scan_node->name = strdup(scan_data->msg);
- scan_node->next = NULL;
-
- *first_node = scan_node;
+ noti_path = strndup(scan_data->msg, scan_data->msg_size);
+ msc_send_dir_update_noti(handle, noti_path);
+ MS_SAFE_FREE(noti_path);
}
-
- node = *first_node;
-
- /*start db update. If node is null, db update is done.*/
- while (node != NULL) {
- /*check poweroff status*/
- ret = _ms_check_stop_status(storage_type);
- if (ret != MS_MEDIA_ERR_NONE) {
- goto STOP_SCAN;
- }
-
- dp = opendir(node->name);
- if (dp != NULL) {
- while (!readdir_r(dp, &entry, &result)) {
- /*check poweroff status*/
- ret = _ms_check_stop_status(storage_type);
- if (ret != MS_MEDIA_ERR_NONE) {
- goto STOP_SCAN;
- }
-
- if (result == NULL)
- break;
-
- if (entry.d_name[0] == '.')
- continue;
-
- if (entry.d_type & DT_REG) {
- err = msc_strappend(path, sizeof(path), "%s/%s", node->name, entry.d_name);
- if (err < 0) {
- MSC_DBG_ERR("error : %d", err);
- continue;
- }
-
- if (scan_type == MS_MSG_STORAGE_ALL)
- err = msc_insert_item_batch(handle, path);
- else
- err = msc_validate_item(handle,path);
- if (err < 0) {
- MSC_DBG_ERR("failed to update db : %d , %d\n", err, scan_type);
- continue;
- }
- }
- }
- } else {
- MSC_DBG_ERR("%s folder opendir fails", node->name);
- }
- if (dp) closedir(dp);
- dp = NULL;
-
- node = node->next;
- } /*db update while */
} else if ( scan_type == MS_MSG_STORAGE_INVALID) {
+ MSC_DBG_INFO("INVALID");
/*In this case, update just validation record*/
/*update just valid type*/
err = msc_invalidate_all_items(handle, storage_type);
- if (err != MS_MEDIA_ERR_NONE)
+ if (err != MS_MEDIA_ERR_NONE) {
MSC_DBG_ERR("error : %d", err);
- }
-STOP_SCAN:
- if (dp) closedir(dp);
-
- /*delete all node*/
- node = *first_node;
-
- while (node != NULL) {
- MS_SAFE_FREE(node->name);
- MS_SAFE_FREE(node);
- }
-
- *first_node = NULL;
-
- sync();
-
- MSC_DBG_INFO("ret : %d", ret);
-
- return ret;
-}
-
-
-static void _msc_insert_array(GArray *garray, ms_comm_msg_s *insert_data)
-{
- ms_scan_data_t *data;
- bool insert_ok = false;
- int len = garray->len;
- int i;
-
- MSC_DBG_INFO("the length of array : %d", len);
- MSC_DBG_INFO("path : %s", insert_data->msg);
- MSC_DBG_INFO("scan_type : %d", insert_data->msg_type);
-
- if (insert_data->pid == POWEROFF) {
- g_array_prepend_val(garray, insert_data);
- } else {
- for (i=0; i < len; i++) {
- data = g_array_index(garray, ms_scan_data_t*, i);
-/*
- if (data->pid != POWEROFF) {
- if (data->storage_type == insert_data->storage_type) {
- if(data->scan_type > insert_data->scan_type) {
- g_array_remove_index (garray, i);
- g_array_insert_val(garray, i, insert_data);
- insert_ok = true;
- }
- }
+ } else {
+ if (storage_type == MS_STORAGE_INTERNAL) {
+ msc_send_dir_update_noti(handle, MEDIA_ROOT_PATH_INTERNAL);
+ } else {
+ msc_send_dir_update_noti(handle, MEDIA_ROOT_PATH_SDCARD);
}
-*/
}
-
- if (insert_ok == false)
- g_array_append_val(garray, insert_data);
}
-}
-void _msc_check_dir_path(char *dir_path)
-{
- int len = strlen(dir_path);
+ sync();
- if (dir_path[len -1] == '/')
- dir_path[len -1] = '\0';
+ MSC_DBG_INFO("ret : %d", err);
+
+ return err;
}
gboolean msc_directory_scan_thread(void *data)
void **handle = NULL;
ms_storage_type_t storage_type;
int scan_type;
- msc_scan_data *first_node = NULL;
/*create array for processing overlay data*/
garray = g_array_new (FALSE, FALSE, sizeof (ms_comm_msg_s *));
if (err != MS_MEDIA_ERR_NONE)
continue;
- storage_type = msc_get_storage_type_by_full(scan_data->msg);
+ storage_type = ms_get_storage_type_by_full(scan_data->msg);
scan_type = scan_data->msg_type;
if (scan_type != MS_MSG_DIRECTORY_SCANNING
goto NEXT;
}
- /*start db updating */
-// _msc_set_db_status(MS_SCANNING_DIRECTORY, MS_DB_UPDATING);
-
_msc_check_dir_path(scan_data->msg);
/*change validity before scanning*/
MSC_DBG_ERR("error : %d", err);
/*call for bundle commit*/
- msc_register_start(handle);
+ msc_register_start(handle, MS_NOTI_DISABLE, 0);
msc_validate_start(handle);
/*insert data into media db */
- ret = _msc_dir_scan(handle, &first_node, scan_data);
+ ret = _msc_db_update(handle, scan_data);
/*call for bundle commit*/
msc_register_end(handle);
msc_delete_invalid_items_in_folder(handle, scan_data->msg);
}
- /*set vconf key mmc loading for indicator */
-// _msc_set_db_status(MS_SCANNING_DIRECTORY, MS_DB_UPDATED);
-
if (power_off) {
MSC_DBG_INFO("power off");
goto _POWEROFF;
msc_send_scan_result(ret, scan_data);
-// MS_SAFE_FREE(scan_data->msg);
MS_SAFE_FREE(scan_data);
MSC_DBG_INFO("DIRECTORY SCAN END");
} /*thread while*/
_POWEROFF:
-// MS_SAFE_FREE(scan_data->msg);
MS_SAFE_FREE(scan_data);
if (garray) g_array_free (garray, TRUE);
if (handle) msc_disconnect_db(&handle);
void **handle = NULL;
ms_storage_type_t storage_type;
int scan_type;
- msc_scan_data *first_node = NULL;
/*create array for processing overlay data*/
garray = g_array_new (FALSE, FALSE, sizeof (ms_comm_msg_s *));
goto NEXT;
}
- storage_type = msc_get_storage_type_by_full(scan_data->msg);
+ storage_type = ms_get_storage_type_by_full(scan_data->msg);
MSC_DBG_INFO("%d", storage_type);
/*connect to media db, if conneting is failed, db updating is stopped*/
continue;
/*start db updating */
- if (storage_type == MS_STORAGE_INTERNAL)
- _msc_set_db_status(MS_SCANNING_INTERNAL, MS_DB_UPDATING);
- else if (storage_type == MS_STORAGE_EXTERNAL)
- _msc_set_db_status(MS_SCANNING_EXTERNAL, MS_DB_UPDATING);
+ _msc_set_db_status(MS_DB_UPDATING);
/*Delete all data before full scanning*/
if (scan_type == MS_MSG_STORAGE_ALL) {
}
if (storage_type == MS_STORAGE_EXTERNAL && scan_type == MS_MSG_STORAGE_ALL) {
- msc_update_mmc_info();
+ ms_update_mmc_info();
}
#ifdef FMS_PERF
if (storage_type == MS_STORAGE_EXTERNAL) {
- msc_check_start_time(&g_mmc_start_time);
+ ms_check_start_time(&g_mmc_start_time);
}
#endif
/*call for bundle commit*/
- msc_register_start(handle);
+ msc_register_start(handle, MS_NOTI_DISABLE, 0);
if (scan_type == MS_MSG_STORAGE_PARTIAL) {
/*enable bundle commit*/
msc_validate_start(handle);
}
/*add inotify watch and insert data into media db */
- ret = _msc_dir_scan(handle, &first_node, scan_data);
+ ret = _msc_db_update(handle, scan_data);
/*call for bundle commit*/
msc_register_end(handle);
#ifdef FMS_PERF
if (storage_type == MS_STORAGE_EXTERNAL) {
- msc_check_end_time(&g_mmc_end_time);
- msc_check_time_diff(&g_mmc_start_time, &g_mmc_end_time);
+ ms_check_end_time(&g_mmc_end_time);
+ ms_check_time_diff(&g_mmc_start_time, &g_mmc_end_time);
}
#endif
/*set vconf key mmc loading for indicator */
- if (storage_type == MS_STORAGE_INTERNAL)
- _msc_set_db_status(MS_SCANNING_INTERNAL, MS_DB_UPDATED);
- else if (storage_type == MS_STORAGE_EXTERNAL)
- _msc_set_db_status(MS_SCANNING_EXTERNAL, MS_DB_UPDATED);
+ _msc_set_db_status(MS_DB_UPDATED);
if (power_off) {
MSC_DBG_INFO("power off");
msc_send_scan_result(ret, scan_data);
-// MS_SAFE_FREE(scan_data->msg);
MS_SAFE_FREE(scan_data);
MSC_DBG_INFO("STORAGE SCAN END");
} /*thread while*/
_POWEROFF:
-// MS_SAFE_FREE(scan_data->msg);
MS_SAFE_FREE(scan_data);
if (garray) g_array_free (garray, TRUE);
if (handle) msc_disconnect_db(&handle);
if (insert_data->pid == POWEROFF) {
g_array_prepend_val(register_array, insert_data);
+ } else if (insert_data->msg_type == MS_MSG_BURSTSHOT_INSERT) {
+ g_array_prepend_val(register_array, insert_data);
} else {
g_array_append_val(register_array, insert_data);
}
/* check the file exits actually */
exist = open(file_path, O_RDONLY);
if(exist < 0) {
- MSC_DBG_ERR("Not exist path : %s", file_path);
+ MSC_DBG_ERR("error [%s, %s]", file_path, strerror(errno));
return MS_MEDIA_ERR_INVALID_PATH;
}
close(exist);
int i;
int ret;
void **handle = NULL;
+ ms_msg_type_e current_msg = MS_MSG_MAX;
+ int (*insert_function)(void **, const char*) = NULL;
/*create array for processing overlay data*/
register_array = g_array_new (FALSE, FALSE, sizeof (ms_comm_msg_s *));
path_size = register_data->msg_size + 1;
}
- /* copy from received data */
- MS_MALLOC(file_path, path_size);
- if (file_path == NULL) {
- MSC_DBG_ERR("MS_MALLOC failed");
- goto FREE_RESOURCE;
- }
-
- ret = msc_strcopy(file_path, path_size, "%s", register_data->msg);
- if (ret != MS_MEDIA_ERR_NONE){
- MSC_DBG_ERR("msc_strcopy failed : %d", ret);
- goto FREE_RESOURCE;
- }
+ file_path = strndup(register_data->msg, register_data->msg_size);
/* load the file list from file */
- fp = fopen(register_data->msg, "rt");
+ fp = fopen(file_path, "rt");
if (fp == NULL) {
MSC_DBG_ERR("fopen failed [%s]", strerror(errno));
goto FREE_RESOURCE;
/* read registering file path from stored file */
while(fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
- length = strlen(buf);
- buf[length - 1] = '\0';
- path = strdup(buf);
+ length = strlen(buf); /*the return value of function, strlen(), includes "\n" */
+ path = strndup(buf, length - 1); /*copying except "\n" and strndup fuction adds "\0" at the end of the copying string */
MSC_DBG_INFO("insert path : %s [%d]", path, strlen(path));
/* insert getted path to the list */
if (g_array_append_val(path_array, path) == NULL) {
/*start db updating */
/*call for bundle commit*/
- msc_register_start(handle);
+ msc_register_start(handle, MS_NOTI_ENABLE, register_data->pid);
+
+ /* check current request */
+ current_msg = register_data->msg_type;
+ if (current_msg == MS_MSG_BULK_INSERT) {
+ insert_function = msc_insert_item_batch;
+ } else if (current_msg == MS_MSG_BURSTSHOT_INSERT) {
+ insert_function = msc_insert_burst_item;
+ } else {
+ MSC_DBG_ERR("wrong message type");
+ goto FREE_RESOURCE;
+ }
/* get the inserting file path from array and insert to db */
for (i = 0; i < path_array->len; i++) {
}
/* insert to db */
- err = msc_insert_item_batch(handle, insert_path);
+ err = insert_function(handle, insert_path);
if (power_off) {
MSC_DBG_INFO("power off");
/*Active flush */
malloc_trim(0);
+ /* If register_files operation is stopped, there is no necessrty for sending result. */
msc_send_register_result(MS_MEDIA_ERR_NONE, register_data);
FREE_RESOURCE:
if (path_array) {
if(fp) fclose(fp);
fp = NULL;
+
+ /* reset function pointer */
+ insert_function = NULL;
} /*thread while*/
_POWEROFF:
*/
#include <arpa/inet.h>
#include <sys/types.h>
+#ifdef _USE_UDS_SOCKET_
+#include <sys/un.h>
+#else
#include <sys/socket.h>
+#endif
#include <malloc.h>
#include <vconf.h>
#include "media-util.h"
-
#include "media-server-ipc.h"
-#include "media-server-types.h"
+#include "media-common-types.h"
+#include "media-common-utils.h"
#include "media-scanner-dbg.h"
#include "media-scanner-db-svc.h"
-#include "media-scanner-utils.h"
#include "media-scanner-socket.h"
extern GAsyncQueue *storage_queue;
pid = recv_msg->pid;
/* request bulk insert*/
- if (req_num == MS_MSG_BULK_INSERT) {
+ if (req_num == MS_MSG_BULK_INSERT ||req_num == MS_MSG_BURSTSHOT_INSERT) {
MSC_DBG_INFO("BULK INSERT");
g_async_queue_push(reg_queue, GINT_TO_POINTER(recv_msg));
} else if (req_num == MS_MSG_DIRECTORY_SCANNING ||req_num == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
ms_comm_msg_s send_msg;
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
ms_comm_msg_s send_msg;
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
ms_comm_msg_s send_msg;
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_COMM_PORT);
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
#include <dirent.h>
#include <vconf.h>
#include <heynoti.h>
+#include <errno.h>
+
+#include "media-common-utils.h"
+#include "media-common-drm.h"
+#include "media-common-external-storage.h"
#include "media-util.h"
#include "media-scanner-dbg.h"
-#include "media-scanner-utils.h"
#include "media-scanner-db-svc.h"
#include "media-scanner-scan.h"
#include "media-scanner-socket.h"
-#include "media-scanner-drm.h"
#define APP_NAME "media-scanner"
char buff[128];
char path[128];
- msc_strcopy(path, sizeof(path), "/proc/%s/status", pinfo.d_name);
+ ms_strcopy(path, sizeof(path), "/proc/%s/status", pinfo.d_name);
fp = fopen(path, "rt");
if (fp) {
if (fgets(buff, 128, fp) == NULL)
}
}
} else {
- MSC_DBG_ERR("Can't read file [%s]", path);
+ MSC_DBG_ERR("media-server: Looking for process of name: [%s]. Cannot find. Reason: %s", APP_NAME, strerror(errno));
}
}
if (g_main_loop_is_running(scanner_mainloop)) g_main_loop_quit(scanner_mainloop);
}
+void
+_msc_mmc_vconf_cb(void *data)
+{
+ int status = 0;
+ ms_comm_msg_s *scan_msg;
+ ms_dir_scan_type_t scan_type = MS_SCAN_PART;
+
+ if (!ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status)) {
+ MSC_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
+ }
+
+ MSC_DBG_INFO("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
+
+ mmc_state = status;
+/*
+ MS_MALLOC(scan_msg, sizeof(ms_comm_msg_s));
+
+ if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED ||
+ mmc_state == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
+ scan_type = MS_SCAN_INVALID;
+ } else if (mmc_state == VCONFKEY_SYSMAN_MMC_MOUNTED) {
+ scan_type = ms_get_mmc_state();
+ }
+
+ switch (scan_type) {
+ case MS_SCAN_ALL:
+ scan_msg->msg_type = MS_MSG_STORAGE_ALL;
+ break;
+ case MS_SCAN_PART:
+ scan_msg->msg_type = MS_MSG_STORAGE_PARTIAL;
+ break;
+ case MS_SCAN_INVALID:
+ scan_msg->msg_type = MS_MSG_STORAGE_INVALID;
+ break;
+ }
+
+ scan_msg->pid = 0;
+ scan_msg->msg_size = strlen(MEDIA_ROOT_PATH_SDCARD);
+ ms_strcopy(scan_msg->msg, scan_msg->msg_size+1, "%s", MEDIA_ROOT_PATH_SDCARD);
+
+ MSC_DBG_INFO("ms_get_mmc_state is %d", scan_msg->msg_type);
+
+ g_async_queue_push(storage_queue, GINT_TO_POINTER(scan_msg));
+*/
+ return;
+}
+
int main(int argc, char **argv)
{
GThread *storage_scan_thread = NULL;
register_thread = g_thread_new("register_thread", (GThreadFunc)msc_register_thread, NULL);
/*set vconf callback function*/
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) msc_mmc_vconf_cb, NULL);
+ err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) _msc_mmc_vconf_cb, NULL);
if (err == -1)
MSC_DBG_ERR("add call back function for event %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
- if (msc_is_mmc_inserted()) {
+ if (ms_is_mmc_inserted()) {
mmc_state = VCONFKEY_SYSMAN_MMC_MOUNTED;
}
/**
* This file defines api utilities of contents manager engines.
*
- * @file media-server-drm.h
+ * @file media-server-db-svc.h
* @author Yong Yeon Kim(yy9875.kim@samsung.com)
* @version 1.0
- * @brief This file implements main database operation.
+ * @brief
*/
-#ifndef _MEDIA_SCANNER_DRM_H_
-#define _MEDIA_SCANNER_DRM_H_
+#ifndef _MEDIA_SERVER_DB_SVC_H_
+#define _MEDIA_SERVER_DB_SVC_H_
-bool
-msc_is_drm_file(const char *path);
+#include "media-common-types.h"
-int
-msc_get_mime_in_drm_info(const char *path, char *mime);
+typedef int (*CONNECT)(void**, char **);
+typedef int (*DISCONNECT)(void*, char **);
+typedef int (*SET_ALL_STORAGE_ITEMS_VALIDITY)(void*, int, int, char **);
int
-msc_drm_register(const char* path);
+ms_load_functions(void);
void
-msc_drm_unregister(const char* path);
+ms_unload_functions(void);
-void
-msc_drm_unregister_all(void);
+int
+ms_connect_db(void ***handle);
-bool
-msc_drm_insert_ext_memory(void);
+int
+ms_disconnect_db(void ***handle);
-bool
-msc_drm_extract_ext_memory(void);
+int
+ms_invalidate_all_items(void **handle, ms_storage_type_t store_type);
-#endif /*_MEDIA_SCANNER_DRM_H_*/
\ No newline at end of file
+#endif /*_MEDIA_SERVER_DB_SVC_H_*/
#ifndef _MEDIA_SERVER_SOCKET_H_
#define _MEDIA_SERVER_SOCKET_H_
-#include "media-server-types.h"
+#include "media-common-types.h"
#include "media-server-ipc.h"
gboolean ms_read_socket(GIOChannel *src, GIOCondition condition, gpointer data);
*/
#include <glib.h>
+#ifdef _USE_UDS_SOCKET_
+#include <sys/un.h>
+#else
#include <sys/socket.h>
+#endif
#include <arpa/inet.h>
-#include "media-server-types.h"
+#include "media-common-types.h"
#include "media-server-ipc.h"
#ifndef _MEDIA_SERVER_THUMB_H_
#define _MEDIA_SERVER_THUMB_H_
+#define MAX_THUMB_REQUEST 100
+
GMainLoop *
ms_get_thumb_thread_mainloop(void);
int
_ms_thumb_recv_msg(int sock, int header_size, thumbMsg *msg);
+#ifdef _USE_UDS_SOCKET_
+int
+_ms_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_un *from_addr, unsigned int *from_size);
+#else
int
_ms_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size);
+#endif
int
_ms_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size);
--- /dev/null
+/*
+ * Media Server
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Yong Yeon Kim <yy9875.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.
+ *
+ */
+
+/**
+ * This file defines api utilities of contents manager engines.
+ *
+ * @file media-server-db-svc.c
+ * @author Yong Yeon Kim(yy9875.kim@samsung.com)
+ * @version 1.0
+ * @brief This file implements main database operation.
+ */
+
+#include <dlfcn.h>
+
+#include "media-util.h"
+
+#include "media-common-utils.h"
+#include "media-common-drm.h"
+#include "media-server-dbg.h"
+#include "media-server-db-svc.h"
+
+#define CONFIG_PATH "/opt/usr/data/file-manager-service/plugin-config"
+#define EXT ".so"
+#define EXT_LEN 3
+
+GArray *so_array;
+void ***func_array;
+int lib_num;
+
+void **func_handle = NULL; /*dlopen handle*/
+
+enum func_list {
+ eCONNECT,
+ eDISCONNECT,
+ eSET_ALL_VALIDITY,
+ eFUNC_MAX
+};
+
+static int
+_ms_token_data(char *buf, char **name)
+{
+ int len;
+ char* pos = NULL;
+
+ pos = strstr(buf, EXT);
+ if (pos == NULL) {
+ MS_DBG_ERR("This is not shared object library.");
+ name = NULL;
+ return -1;
+ } else {
+ len = pos - buf + EXT_LEN;
+ *name = strndup(buf, len);
+ MS_DBG("%s", *name);
+ }
+
+ return 0;
+}
+
+static bool
+_ms_load_config()
+{
+ int ret;
+ FILE *fp;
+ char *so_name = NULL;
+ char buf[256] = {0};
+
+ fp = fopen(CONFIG_PATH, "rt");
+ if (fp == NULL) {
+ MS_DBG_ERR("fp is NULL");
+ return MS_MEDIA_ERR_FILE_OPEN_FAIL;
+ }
+ while(1) {
+ if (fgets(buf, 256, fp) == NULL) {
+ MS_DBG_ERR("fgets failed");
+ break;
+ }
+
+ ret = _ms_token_data(buf, &so_name);
+ if (ret == 0) {
+ /*add to array*/
+ g_array_append_val(so_array, so_name);
+ so_name = NULL;
+ }
+ }
+
+ fclose(fp);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int
+ms_load_functions(void)
+{
+ int lib_index = 0, func_index;
+ char func_list[eFUNC_MAX][40] = {
+ "connect",
+ "disconnect",
+ "set_all_storage_items_validity",
+ };
+ /*init array for adding name of so*/
+ so_array = g_array_new(FALSE, FALSE, sizeof(char*));
+
+ /*load information of so*/
+ _ms_load_config();
+
+ if(so_array->len == 0) {
+ MS_DBG("There is no information for functions");
+ return MS_MEDIA_ERR_DYNAMIC_LINK;
+ }
+
+ /*the number of functions*/
+ lib_num = so_array->len;
+
+ MS_DBG("The number of information of so : %d", lib_num);
+ MS_MALLOC(func_handle, sizeof(void*) * lib_num);
+ if (func_handle == NULL) {
+ MS_DBG_ERR("malloc failed");
+ return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
+ }
+
+ while(lib_index < lib_num) {
+ /*get handle*/
+ MS_DBG("[name of so : %s]", g_array_index(so_array, char*, lib_index));
+ func_handle[lib_index] = dlopen(g_array_index(so_array, char*, lib_index), RTLD_LAZY);
+ if (!func_handle[lib_index]) {
+ MS_DBG_ERR("%s", dlerror());
+ MS_SAFE_FREE(func_handle);
+ return MS_MEDIA_ERR_DYNAMIC_LINK;
+ }
+ lib_index++;
+ }
+
+ dlerror(); /* Clear any existing error */
+
+ /*allocate for array of functions*/
+ MS_MALLOC(func_array, sizeof(void*) * lib_num);
+ if (func_array == NULL) {
+ MS_DBG_ERR("malloc failed");
+ MS_SAFE_FREE(func_handle);
+ return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
+ }
+
+ for(lib_index = 0 ; lib_index < lib_num; lib_index ++) {
+ MS_MALLOC(func_array[lib_index], sizeof(void*) * eFUNC_MAX);
+ if (func_array[lib_index] == NULL) {
+ int index;
+
+ for (index = 0; index < lib_index; index ++) {
+ MS_SAFE_FREE(func_array[index]);
+ }
+ MS_SAFE_FREE(func_array);
+ MS_SAFE_FREE(func_handle);
+
+ MS_DBG_ERR("malloc failed");
+ return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
+ }
+ }
+
+ /*add functions to array */
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ for (func_index = 0; func_index < eFUNC_MAX ; func_index++) {
+ func_array[lib_index][func_index] = dlsym(func_handle[lib_index], func_list[func_index]);
+ if (func_array[lib_index][func_index] == NULL) {
+ int index;
+
+ for (index = 0; index < lib_index; index ++) {
+ MS_SAFE_FREE(func_array[index]);
+ }
+ MS_SAFE_FREE(func_array);
+ MS_SAFE_FREE(func_handle);
+
+ MS_DBG_ERR("dlsym failed");
+ return MS_MEDIA_ERR_DYNAMIC_LINK;
+ }
+ }
+ }
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+void
+ms_unload_functions(void)
+{
+ int lib_index;
+
+ for (lib_index = 0; lib_index < lib_num; lib_index ++)
+ dlclose(func_handle[lib_index]);
+
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ if (func_array[lib_index]) {
+ MS_SAFE_FREE(func_array[lib_index]);
+ }
+ }
+
+ MS_SAFE_FREE (func_array);
+ MS_SAFE_FREE (func_handle);
+ if (so_array) g_array_free(so_array, TRUE);
+}
+
+int
+ms_connect_db(void ***handle)
+{
+ int lib_index;
+ int ret;
+ char * err_msg = NULL;
+
+ MS_MALLOC(*handle, sizeof (void*) * lib_num);
+
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ ret = ((CONNECT)func_array[lib_index][eCONNECT])(&((*handle)[lib_index]), &err_msg); /*dlopen*/
+ if (ret != 0) {
+ MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+ MS_SAFE_FREE(err_msg);
+ return MS_MEDIA_ERR_DB_CONNECT_FAIL;
+ }
+ }
+
+ MS_DBG("connect Media DB");
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int
+ms_disconnect_db(void ***handle)
+{
+ int lib_index;
+ int ret;
+ char * err_msg = NULL;
+
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ ret = ((DISCONNECT)func_array[lib_index][eDISCONNECT])((*handle)[lib_index], &err_msg); /*dlopen*/
+ if (ret != 0) {
+ MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+ MS_SAFE_FREE(err_msg);
+ return MS_MEDIA_ERR_DB_DISCONNECT_FAIL;
+ }
+ }
+
+ MS_SAFE_FREE(*handle);
+
+ MS_DBG("Disconnect Media DB");
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+int
+ms_invalidate_all_items(void **handle, ms_storage_type_t store_type)
+{
+ int lib_index;
+ int res = MS_MEDIA_ERR_NONE;
+ int ret;
+ char *err_msg = NULL;
+ MS_DBG("");
+ for (lib_index = 0; lib_index < lib_num; lib_index++) {
+ ret = ((SET_ALL_STORAGE_ITEMS_VALIDITY)func_array[lib_index][eSET_ALL_VALIDITY])(handle[lib_index], store_type, false, &err_msg); /*dlopen*/
+ if (ret != 0) {
+ MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+ MS_SAFE_FREE(err_msg);
+ res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
+ }
+ }
+ MS_DBG("");
+ return res;
+}
+
#include <unistd.h>
#include "media-util.h"
+#include "media-server-ipc.h"
+#include "media-common-types.h"
#include "media-server-dbg.h"
-#include "media-server-db.h"
-#include "media-server-types.h"
#include "media-server-socket.h"
#include "media-server-db.h"
-#include "media-server-ipc.h"
static GMainLoop *g_db_mainloop = NULL;
static bool db_thread_ready = FALSE;
if(ret != MS_MEDIA_ERR_NONE) {
/* Disconnect DB*/
media_db_disconnect(db_handle);
-
+ close(sockfd);
MS_DBG_ERR("Failed to create socket\n");
return FALSE;
}
/*close socket*/
close(sockfd);
+ close(tcp_sockfd);
g_main_loop_unref(g_db_mainloop);
#include <heynoti.h>
#include "media-util.h"
+#include "media-common-utils.h"
+#include "media-common-drm.h"
+#include "media-common-external-storage.h"
#include "media-server-dbg.h"
-#include "media-server-utils.h"
-#include "media-server-external-storage.h"
#include "media-server-db-svc.h"
-#include "media-server-inotify.h"
#include "media-server-socket.h"
#include "media-server-db.h"
-#include "media-server-drm.h"
-#include "media-server-dbus.h"
#include "media-server-thumb.h"
#include "media-server-scanner.h"
#define APP_NAME "media-server"
extern GMutex *scanner_mutex;
-extern GMutex *db_mutex;
-extern int mmc_state;
-
-#if MS_INOTI_ENABLE
-extern GAsyncQueue* ret_queue;
-extern GMutex *list_mutex;
-extern GMutex *queue_mutex;
-extern GArray *reg_list;
-extern bool power_off; /*If this is TRUE, poweroff notification received*/
-#endif
+
GMainLoop *mainloop = NULL;
bool check_process()
}
}
} else {
- MS_DBG_ERR("Can't read file [%s]", path);
+ MS_DBG_ERR("media-server: Looking for process of name: [%s]. Cannot find. Reason: %s", APP_NAME, strerror(errno));
}
}
MS_DBG("++++++++++++++++++++++++++++++++++++++");
MS_DBG("POWER OFF");
MS_DBG("++++++++++++++++++++++++++++++++++++++");
-#if MS_INOTI_ENABLE
- power_off = true;
-#endif
+
/*Quit Thumbnail Thread*/
GMainLoop *thumb_mainloop = ms_get_thumb_thread_mainloop();
if (thumb_mainloop && g_main_is_running(thumb_mainloop)) {
return;
}
-static bool _db_clear(void** handle)
+static void _db_clear(void)
{
- int err;
- int db_status;
- bool need_db_create = false;
-
- /*update just valid type*/
- err = ms_invalidate_all_items(handle, MS_STORAGE_EXTERNAL);
- if (err != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("ms_change_valid_type fail");
+ int err = MS_MEDIA_ERR_NONE;
+ void **handle = NULL;
- ms_config_get_int(MS_SCAN_STATUS_INTERNAL, &db_status);
- MS_DBG("finish_phone_init_data db = %d", db_status);
+ /*load functions from plusin(s)*/
+ err = ms_load_functions();
+ if (err != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("function load failed");
+ exit(0);
+ }
- if (db_status == P_VCONF_SCAN_DOING) {
- need_db_create = true;
+ /*connect to media db, if conneting is failed, db updating is stopped*/
+ ms_connect_db(&handle);
- err = ms_invalidate_all_items(handle, MS_STORAGE_INTERNAL);
- if (err != MS_MEDIA_ERR_NONE)
- MS_DBG_ERR("ms_change_valid_type fail");
- }
+ /*update just valid type*/
+ if (ms_invalidate_all_items(handle, MS_STORAGE_EXTERNAL) != MS_MEDIA_ERR_NONE)
+ MS_DBG_ERR("ms_change_valid_type fail");
-// ms_set_db_status(MS_DB_UPDATED);
+ /*disconnect form media db*/
+ if (handle) ms_disconnect_db(&handle);
- return need_db_create;
+ /*unload functions*/
+ ms_unload_functions();
}
void _ms_signal_handler(int n)
static void _ms_new_global_variable(void)
{
-#if MS_INOTI_ENABLE
- /*Init for register file*/
- if (!list_mutex) list_mutex = g_mutex_new();
- if (!queue_mutex) queue_mutex = g_mutex_new();
- if (!reg_list) reg_list = g_array_new(TRUE, TRUE, sizeof(char*));
- /*These are a communicator for thread*/
- if (!ret_queue) ret_queue = g_async_queue_new();
-#endif
/*Init mutex variable*/
- if (!db_mutex) db_mutex = g_mutex_new();
-
/*media scanner stop/start mutex*/
if (!scanner_mutex) scanner_mutex = g_mutex_new();
}
static void _ms_free_global_variable(void)
{
-#if MS_INOTI_ENABLE
- if (list_mutex) g_mutex_free(list_mutex);
- if (queue_mutex)g_mutex_free(queue_mutex);
- if (reg_list) g_array_free(reg_list, true);
- if (ret_queue) g_async_queue_unref(ret_queue);
-#endif
/*Clear mutex variable*/
- if (db_mutex) g_mutex_free (db_mutex);
-
if (scanner_mutex) g_mutex_free(scanner_mutex);
}
+
+void
+_ms_mmc_vconf_cb(void *data)
+{
+ int status = 0;
+
+ if (!ms_config_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &status)) {
+ MS_DBG_ERR("Get VCONFKEY_SYSMAN_MMC_STATUS failed.");
+ }
+
+ MS_DBG("VCONFKEY_SYSMAN_MMC_STATUS :%d", status);
+
+ /* If scanner is not working, media server executes media scanner and sends request. */
+ /* If scanner is working, it detects changing status of SD card. */
+ if (status == VCONFKEY_SYSMAN_MMC_REMOVED ||
+ status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED) {
+
+ /*remove added watch descriptors */
+ ms_present_mmc_status(MS_SDCARD_REMOVED);
+
+ if (!ms_drm_extract_ext_memory())
+ MS_DBG_ERR("ms_drm_extract_ext_memory failed");
+
+ ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, MS_SCAN_INVALID);
+ } else if (status == VCONFKEY_SYSMAN_MMC_MOUNTED) {
+
+ ms_make_default_path_mmc();
+
+ ms_present_mmc_status(MS_SDCARD_INSERTED);
+
+ if (!ms_drm_insert_ext_memory())
+ MS_DBG_ERR("ms_drm_insert_ext_memory failed");
+
+ ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, ms_get_mmc_state());
+ }
+
+ return;
+}
+
+
int main(int argc, char **argv)
{
-#if MS_INOTI_ENABLE
- GThread *inoti_thread = NULL;
-#endif
GThread *db_thread = NULL;
GThread *thumb_thread = NULL;
GSource *source = NULL;
int err;
int heynoti_id;
bool check_result = false;
- bool need_db_create;
- void **handle = NULL;
struct sigaction sigset;
check_result = check_process();
/*Init main loop*/
mainloop = g_main_loop_new(NULL, FALSE);
-#if MS_INOTI_ENABLE
- /*inotify setup */
- ms_inoti_init();
-#endif
+
/*heynoti for power off*/
if ((heynoti_id = heynoti_init()) <0) {
MS_DBG("heynoti_init failed");
MS_DBG("heynoti_attach_handler failed");
}
- /*load functions from plusin(s)*/
- err = ms_load_functions();
- if (err != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("function load failed");
- exit(0);
- }
-
_ms_new_global_variable();
- /*connect to media db, if conneting is failed, db updating is stopped*/
- ms_connect_db(&handle);
-
- ms_dbus_init();
-#if MS_INOTI_ENABLE
- ms_inoti_add_watch_all_directory(MS_STORAGE_INTERNAL);
-#endif
/*prepare socket*/
/* Create and bind new UDP socket */
if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCANNER_PORT, &sockfd)
source = g_io_create_watch(channel, G_IO_IN);
/* Set callback to be called when socket is readable */
- g_source_set_callback(source, (GSourceFunc)ms_read_socket, handle, NULL);
+ g_source_set_callback(source, (GSourceFunc)ms_read_socket, NULL, NULL);
g_source_attach(source, context);
g_source_unref(source);
}
/*create each threads*/
-#if MS_INOTI_ENABLE
- inoti_thread = g_thread_new("inotify_thread", (GThreadFunc)ms_inoti_thread, NULL);
-#endif
db_thread = g_thread_new("db_thread", (GThreadFunc)ms_db_thread, NULL);
thumb_thread = g_thread_new("thumb_agent_thread", (GThreadFunc)ms_thumb_agent_start_thread, NULL);
/*set vconf callback function*/
- err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) ms_mmc_vconf_cb, NULL);
+ err = vconf_notify_key_changed(VCONFKEY_SYSMAN_MMC_STATUS, (vconf_callback_fn) _ms_mmc_vconf_cb, NULL);
if (err == -1)
MS_DBG_ERR("add call back function for event %s fails", VCONFKEY_SYSMAN_MMC_STATUS);
MS_DBG("*********************************************************");
/* Add signal handler */
+ sigemptyset(&sigset.sa_mask);
+ sigaddset(&sigset.sa_mask, SIGCHLD);
+ sigset.sa_flags = 0;
sigset.sa_handler = _ms_signal_handler;
+
if (sigaction(SIGCHLD, &sigset, NULL) < 0) {
MS_DBG_ERR("sigaction failed [%s]", strerror(errno));
} else {
sleep(1);
}
- need_db_create = _db_clear(handle);
- if (need_db_create) {
- /*insert records*/
- ms_send_storage_scan_request(MS_STORAGE_INTERNAL, MS_SCAN_ALL);
- } else {
- ms_send_storage_scan_request(MS_STORAGE_INTERNAL, MS_SCAN_PART);
- }
+ _db_clear();
- if (ms_is_mmc_inserted()) {
- mmc_state = VCONFKEY_SYSMAN_MMC_MOUNTED;
+ ms_send_storage_scan_request(MS_STORAGE_INTERNAL, MS_SCAN_PART);
+ if (ms_is_mmc_inserted()) {
if (!ms_drm_insert_ext_memory())
MS_DBG_ERR("ms_drm_insert_ext_memory failed");
ms_make_default_path_mmc();
-#if MS_INOTI_ENABLE
- ms_inoti_add_watch_all_directory(MS_STORAGE_EXTERNAL);
-#endif
- ms_present_mmc_insert();
+ ms_present_mmc_status(MS_SDCARD_INSERTED);
ms_send_storage_scan_request(MS_STORAGE_EXTERNAL, ms_get_mmc_state());
}
MS_DBG("*****************************************");
g_main_loop_run(mainloop);
-#if MS_INOTI_ENABLE
- g_thread_join(inoti_thread);
-#endif
g_thread_join(db_thread);
g_thread_join(thumb_thread);
**remove call back functions
************/
vconf_ignore_key_changed(VCONFKEY_SYSMAN_MMC_STATUS,
- (vconf_callback_fn) ms_mmc_vconf_cb);
+ (vconf_callback_fn) _ms_mmc_vconf_cb);
_ms_free_global_variable();
- /*disconnect form media db*/
- if (handle) ms_disconnect_db(&handle);
-
/*close socket*/
close(sockfd);
- /*unload functions*/
- ms_unload_functions();
-
exit(0);
}
#include <vconf.h>
#include "media-util.h"
-#include "media-server-types.h"
+#include "media-server-ipc.h"
+#include "media-common-types.h"
+#include "media-common-utils.h"
#include "media-server-dbg.h"
-#include "media-server-utils.h"
#include "media-server-socket.h"
#include "media-server-scanner.h"
int sockfd = -1;
int err = -1;
int n_reuse = 1;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
unsigned int serv_addr_len = -1;
int port = MS_SCAN_COMM_PORT;
ms_comm_msg_s recv_msg;
GMainContext *res_context = NULL;
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_server_socket(MS_PROTOCOL_UDP, MS_SCAN_COMM_PORT, &sockfd);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ MS_DBG_ERR("ms_ipc_create_server_socket failed [%d]",ret);
+ g_mutex_unlock(scanner_mutex);
+ return MS_MEDIA_ERR_SOCKET_CONN;
+ }
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sockfd);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_ipc_create_client_socket failed [%d]",ret);
g_mutex_unlock(scanner_mutex);
return MS_MEDIA_ERR_SOCKET_CONN;
}
-
/* set socket re-use */
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n_reuse, sizeof(n_reuse)) == -1) {
MS_DBG_ERR("setsockopt failed: %s", strerror(errno));
g_mutex_unlock(scanner_mutex);
return MS_MEDIA_ERR_SOCKET_INTERNAL;
}
-
/*Set server Address*/
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
serv_addr.sin_port = htons(port);
-
/* Bind to the local address */
if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
MS_DBG_ERR("bind failed [%s]", strerror(errno));
g_mutex_unlock(scanner_mutex);
return MS_MEDIA_ERR_SOCKET_BIND;
}
+#endif
/*Receive Response*/
serv_addr_len = sizeof(serv_addr);
child_pid = 0;
scanner_ready = false;
- /* scanning is done */
- if (!ms_config_set_int(MS_SCAN_STATUS_DIRECTORY, P_VCONF_SCAN_DONE)) {
- MS_DBG_ERR("ms_config_set_int failed");
- }
-
g_mutex_unlock(scanner_mutex);
}
*/
#include <arpa/inet.h>
#include <sys/types.h>
+#ifdef _USE_UDS_SOCKET_
+#include <sys/un.h>
+#else
#include <sys/socket.h>
+#endif
#include <errno.h>
#include <malloc.h>
#include <vconf.h>
#include "media-util.h"
#include "media-util-internal.h"
-#include "media-server-dbg.h"
#include "media-server-ipc.h"
+#include "media-common-utils.h"
+#include "media-server-dbg.h"
#include "media-server-db-svc.h"
-#include "media-server-utils.h"
#include "media-server-scanner.h"
#include "media-server-socket.h"
#include "media-server-db.h"
typedef struct ms_req_owner_data
{
int pid;
+ int index;
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un *client_addr;
+#else
struct sockaddr_in *client_addr;
+#endif
}ms_req_owner_data;
int _ms_add_owner(ms_req_owner_data *owner_data)
// MS_DBG("pid : %d", owner_data->pid);
// MS_DBG("client_addr : %p", owner_data->client_addr);
+ owner_data->index = -1;
g_array_append_val(owner_list, owner_data);
return MS_MEDIA_ERR_NONE;
{
int i;
int len = owner_list->len;
- bool find_flag = false;
ms_req_owner_data *data = NULL;
+ *owner_data = NULL;
+
MS_DBG("length list : %d", len);
for (i=0; i < len; i++) {
data = g_array_index(owner_list, ms_req_owner_data*, i);
MS_DBG("%d %d", data->pid, pid);
if (data->pid == pid) {
- find_flag = true;
+ data->index = i;
+ *owner_data = data;
+ MS_DBG("FIND OWNER");
break;
}
}
- if (find_flag == true) {
- *owner_data = data;
- MS_DBG("FIND OWNER");
- } else {
- *owner_data = NULL;
- MS_DBG("DO NOT FIND OWNER");
- }
-
return MS_MEDIA_ERR_NONE;
}
int _ms_delete_owner(ms_req_owner_data *owner_data)
{
- int i;
- int len = owner_list->len;
- ms_req_owner_data *data = NULL;
-
- for (i=0; i < len; i++) {
- data = g_array_index(owner_list, ms_req_owner_data*, i);
- if (data->pid == owner_data->pid) {
- if (data->client_addr == owner_data->client_addr) {
- g_array_remove_index(owner_list, i);
- MS_SAFE_FREE(owner_data->client_addr);
- MS_SAFE_FREE(owner_data);
- }
- break;
- }
+ if (owner_data->index != -1) {
+ g_array_remove_index(owner_list, owner_data->index);
+ MS_SAFE_FREE(owner_data->client_addr);
+ MS_SAFE_FREE(owner_data);
+ MS_DBG("DELETE OWNER");
}
return MS_MEDIA_ERR_NONE;
gboolean ms_read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un *client_addr = NULL;
+#else
struct sockaddr_in *client_addr = NULL;
+#endif
socklen_t client_addr_len;
ms_comm_msg_s recv_msg;
- ms_comm_msg_s result_msg;
ms_comm_msg_s scan_msg;
int msg_size;
int sockfd = MS_SOCK_NOT_ALLOCATE;
int pid;
int req_num;
int path_size;
- void **handle = data;
- char *path = NULL;
g_mutex_lock(scanner_mutex);
}
/* Socket is readable */
+#ifdef _USE_UDS_SOCKET_
+ MS_MALLOC(client_addr, sizeof(struct sockaddr_un));
+#else
MS_MALLOC(client_addr, sizeof(struct sockaddr_in));
+#endif
if (client_addr == NULL) {
MS_DBG_ERR("malloc failed");
g_mutex_unlock(scanner_mutex);
return TRUE;
}
-
+#ifdef _USE_UDS_SOCKET_
+ client_addr_len = sizeof(struct sockaddr_un);
+#else
client_addr_len = sizeof(struct sockaddr_in);
+#endif
ret = ms_ipc_receive_message(sockfd, &recv_msg, sizeof(recv_msg), client_addr, NULL);
if (ret != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("ms_ipc_receive_message failed");
/* register file request
* media server inserts the meta data of one file into media db */
- if (req_num == MS_MSG_DB_UPDATE) {
- MS_MALLOC(path, path_size);
- if (path != NULL) {
- ret = ms_strcopy(path, path_size, "%s", recv_msg.msg);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_SAFE_FREE(path);
- MS_SAFE_FREE(client_addr);
- g_mutex_unlock(scanner_mutex);
- return TRUE;
- }
-
- MS_DBG("REQUEST FILE REGISTER");
-#if MS_INOTI_ENABLE
- ret = ms_register_file(handle, path, ret_queue);
- if (ret == MS_MEDIA_ERR_NOW_REGISTER_FILE) {
- ret= GPOINTER_TO_INT(g_async_queue_pop(ret_queue)) - MS_MEDIA_ERR_MAX;
- }
-#else
- ret = ms_register_file(handle, path);
-#endif
- MS_DBG_INFO("register result : %d", ret);
- /* the result of inserting to db */
- result_msg.result = ret;
- } else {
- MS_DBG_ERR("malloc failed");
- result_msg.result = MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL;
- }
-
- ms_ipc_send_msg_to_client(sockfd, &result_msg, client_addr);
-
- MS_SAFE_FREE(path);
- MS_SAFE_FREE(client_addr);
-
- g_mutex_unlock(scanner_mutex);
- } else if (req_num == MS_MSG_DIRECTORY_SCANNING
+ if (req_num == MS_MSG_DIRECTORY_SCANNING
||req_num == MS_MSG_BULK_INSERT
- ||req_num == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+ ||req_num == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE
+ || req_num == MS_MSG_BURSTSHOT_INSERT) {
/* this request process in media scanner */
ms_req_owner_data *owner_data = NULL;
scan_msg.msg_size = msg_size;
ms_strcopy(scan_msg.msg, path_size, "%s", recv_msg.msg);
- /* change the status of media scanner for directory scanning */
- if (req_num == MS_MSG_DIRECTORY_SCANNING
- || req_num == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
- MS_DBG("DIRECTORY SCANNING IS START");
- if (!ms_config_set_int(MS_SCAN_STATUS_DIRECTORY, P_VCONF_SCAN_DOING)) {
- MS_DBG_ERR("ms_config_set_int failed");
- }
- }
-
g_mutex_unlock(scanner_mutex);
if (ms_get_scanner_status()) {
_ms_find_owner(recv_msg.pid, &owner_data);
if (owner_data != NULL) {
MS_DBG("PID : %d", owner_data->pid);
- ms_comm_msg_s *result_msg;
if (msg_type == MS_MSG_SCANNER_RESULT) {
MS_DBG("DIRECTORY SCANNING IS DONE");
- if (!ms_config_set_int(MS_SCAN_STATUS_DIRECTORY, P_VCONF_SCAN_DONE)) {
- MS_DBG_ERR("ms_config_set_int failed");
- }
}
- MS_MALLOC(result_msg, sizeof(ms_comm_msg_s));
/* owner data exists */
/* send result to the owner of request */
ms_ipc_send_msg_to_client(sockfd, &recv_msg, owner_data->client_addr);
/* free owner data*/
_ms_delete_owner(owner_data);
-
- MS_SAFE_FREE(result_msg);
}
} else {
/* owner data does not exist*/
int sockfd = -1;
/*Create Socket*/
+#ifdef _USE_UDS_SOCKET_
+ ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd, MS_SCAN_DAEMON_PORT);
+#else
ret = ms_ipc_create_client_socket(MS_PROTOCOL_UDP, 0, &sockfd);
+#endif
if (ret != MS_MEDIA_ERR_NONE)
return MS_MEDIA_ERR_SOCKET_CONN;
gboolean ms_read_db_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
struct sockaddr_in client_addr;
+#endif
ms_comm_msg_s recv_msg;
int send_msg = MS_MEDIA_ERR_NONE;
MediaDBHandle *db_handle = (MediaDBHandle *)data;
ms_comm_msg_s msg;
char * sql_query = NULL;
- size_t sql_query_size = 0;
memset(&recv_msg, 0, sizeof(recv_msg));
return TRUE;
}
- sql_query_size = recv_msg.msg_size + 1;
- MS_MALLOC(sql_query, sql_query_size);
+ sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
if (sql_query != NULL) {
- ret = ms_strcopy(sql_query, sql_query_size, "%s", recv_msg.msg);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strcopy failed");
- MS_SAFE_FREE(sql_query);
- return TRUE;
- }
-
ret = media_db_update_db(db_handle, sql_query);
if (ret != MS_MEDIA_ERR_NONE)
MS_DBG_ERR("media_db_update_db error : %d", ret);
gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
struct sockaddr_in client_addr;
+#endif
unsigned int client_addr_len;
ms_comm_msg_s recv_msg;
int recv_msg_size = -1;
int ret = MS_MEDIA_ERR_NONE;
char * sql_query = NULL;
- size_t sql_query_size = 0;
MediaDBHandle *db_handle = (MediaDBHandle *)data;
sock = g_io_channel_unix_get_fd(src);
return TRUE;
}
- sql_query_size = recv_msg.msg_size + 1;
- MS_MALLOC(sql_query, sql_query_size);
+ sql_query = strndup(recv_msg.msg, recv_msg.msg_size);
if (sql_query != NULL) {
- ret = ms_strcopy(sql_query, sql_query_size, "%s", recv_msg.msg);
- if (ret != MS_MEDIA_ERR_NONE) {
- MS_DBG_ERR("ms_strcopy failed");
- MS_SAFE_FREE(sql_query);
- close(client_sock);
- return TRUE;
- }
-
if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_START) {
ret = media_db_update_db_batch_start(sql_query);
} else if(recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END) {
close(client_sock);
return TRUE;
}
-
}
close(client_sock);
#include <errno.h>
#include "media-util.h"
+#include "media-common-utils.h"
#include "media-server-dbg.h"
#include "media-server-thumb.h"
-#include "media-server-utils.h"
#ifdef LOG_TAG
#undef LOG_TAG
thumbMsg *recv_msg;
} thumbRequest;
+#ifdef _USE_UDS_SOCKET_
+extern char MEDIA_IPC_PATH[][50];
+#endif
+
gboolean _ms_thumb_agent_start_jobs(gpointer data)
{
MS_DBG("");
break;
}
} else {
- MS_DBG_ERR("Can't read file [%s]", path);
+ MS_DBG_ERR("media-server: Looking for process of name: [%s]. Cannot find. Reason: %s",
+ THUMB_SERVER_NAME, strerror(errno));
}
}
{
int sock_fd = 0;
+#ifdef _USE_UDS_SOCKET_
+ if ((sock_fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+#else
if ((sock_fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+#endif
MS_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
{
int sock_fd = 0;
+#ifdef _USE_UDS_SOCKET_
+ if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
+#else
if ((sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+#endif
MS_DBG_ERR("socket failed: %s", strerror(errno));
return MS_MEDIA_ERR_SOCKET_CONN;
}
int
+#ifdef _USE_UDS_SOCKET_
+_ms_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_un *from_addr, unsigned int *from_size)
+#else
_ms_thumb_recv_udp_msg(int sock, int header_size, thumbMsg *msg, struct sockaddr_in *from_addr, unsigned int *from_size)
+#endif
{
int recv_msg_len = 0;
+#ifdef _USE_UDS_SOCKET_
+ unsigned int from_addr_size = sizeof(struct sockaddr_un);
+#else
unsigned int from_addr_size = sizeof(struct sockaddr_in);
+#endif
unsigned char *buf = NULL;
buf = (unsigned char*)malloc(sizeof(thumbMsg));
{
int sock;
const char *serv_ip = "127.0.0.1";
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
int send_str_len = strlen(recv_msg->org_path);
return FALSE;
}
#endif
+#ifdef _USE_UDS_SOCKET_
+ if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock, MS_THUMB_DAEMON_PORT) < 0) {
+#else
if (ms_ipc_create_client_socket(MS_PROTOCOL_UDP, MS_TIMEOUT_SEC_10, &sock) < 0) {
+#endif
MS_DBG_ERR("ms_ipc_create_client_socket failed");
return FALSE;
}
memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ MS_DBG("%s", MEDIA_IPC_PATH[MS_THUMB_DAEMON_PORT]);
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[MS_THUMB_DAEMON_PORT]);
+#else
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(serv_ip);
serv_addr.sin_port = htons(MS_THUMB_DAEMON_PORT);
+#endif
int buf_size = 0;
int header_size = 0;
MS_SAFE_FREE(buf);
MS_DBG("Sending msg to thumbnail server is successful");
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
struct sockaddr_in client_addr;
+#endif
unsigned int client_addr_len;
header_size = sizeof(thumbMsg) - MAX_MSG_SIZE*2;
GIOCondition condition,
gpointer data)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
struct sockaddr_in client_addr;
+#endif
unsigned int client_addr_len;
thumbMsg recv_msg;
if (send(client_sock, buf, buf_size, 0) != buf_size) {
MS_DBG_ERR("sendto failed : %s", strerror(errno));
} else {
- MS_DBG("Sent %s(%d) \n", res_msg.dst_path, strlen(res_msg.dst_path));
+ MS_DBG("Sent %s(%d) from %s \n", res_msg.dst_path, strlen(res_msg.dst_path), res_msg.org_path);
}
close(client_sock);
GIOCondition condition,
gpointer data)
{
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un client_addr;
+#else
struct sockaddr_in client_addr;
+#endif
unsigned int client_addr_len;
thumbMsg *recv_msg = NULL;
if ((client_sock = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len)) < 0) {
MS_DBG_ERR("accept failed : %s", strerror(errno));
+ close(client_sock);
return TRUE;
}
g_request_queue = g_queue_new();
}
+ if (g_queue_get_length(g_request_queue) >= MAX_THUMB_REQUEST) {
+ MS_DBG_WARN("Request Queue is full");
+ thumbMsg res_msg;
+ memset((void *)&res_msg, 0, sizeof(res_msg));
+
+ res_msg.msg_type = 6; // THUMB_RESPONSE
+ res_msg.status = 1; //THUMB_FAIL
+ res_msg.org_path[0] = '\0';
+ res_msg.origin_path_size = 0;
+ res_msg.dst_path[0] = '\0';
+ res_msg.dest_path_size = 0;
+
+ int buf_size = 0;
+ unsigned char *buf = NULL;
+ _ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
+
+ if (send(client_sock, buf, buf_size, 0) != buf_size) {
+ MS_DBG_ERR("sendto failed : %s", strerror(errno));
+ } else {
+ MS_DBG("Sent Refuse msg from %s \n", recv_msg->org_path);
+ }
+
+ close(client_sock);
+ MS_SAFE_FREE(buf);
+ MS_SAFE_FREE(thumb_req->recv_msg);
+ MS_SAFE_FREE(thumb_req);
+
+ return TRUE;
+ }
+
MS_DBG("%s is queued", recv_msg->org_path);
g_queue_push_tail(g_request_queue, (gpointer)thumb_req);
serv_port = MS_THUMB_CREATOR_PORT;
#if 0
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
/* Create a TCP socket */
if (_ms_thumb_create_socket(SERVER_SOCKET, &sock) < 0) {
}
memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port]);
+#else
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(serv_port);
+#endif
/* Bind to the local address */
if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
serv_port = MS_THUMB_COMM_PORT;
if (ms_ipc_create_server_socket(MS_PROTOCOL_UDP, serv_port, &sock) < 0) {
- MS_DBG_ERR("ms_ipc_create_client_socket failed");
+ MS_DBG_ERR("ms_ipc_create_server_socket failed");
return FALSE;
}
#if 0
+#ifdef _USE_UDS_SOCKET_
+ struct sockaddr_un serv_addr;
+#else
struct sockaddr_in serv_addr;
+#endif
/* Creaete a UDP socket */
if (_ms_thumb_create_udp_socket(&sock) < 0) {
}
memset(&serv_addr, 0, sizeof(serv_addr));
+#ifdef _USE_UDS_SOCKET_
+ serv_addr.sun_family = AF_UNIX;
+ strcpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port]);
+#else
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(serv_port);
+#endif
/* Bind to the local address */
if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {