From 7e25312ddc7beac68128663089618216e11f5a2e Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sat, 24 Oct 2015 16:54:46 +0900 Subject: [PATCH] tizen 2.4 release --- LICENSE.APLv2.0 | 5 - Makefile.am | 182 ++- NOTICE | 3 + configure.ac | 14 + lib/include/media-server-ipc.h | 21 +- lib/include/media-util-db.h | 14 +- lib/include/media-util-dbg.h | 8 - lib/include/media-util-err.h | 103 +- lib/include/media-util-internal.h | 11 +- lib/include/media-util-ipc.h | 11 +- lib/include/media-util-noti-common.h | 10 +- lib/include/media-util-noti-internal.h | 95 ++ lib/include/media-util-noti.h | 10 +- lib/include/media-util-register.h | 14 +- lib/include/media-util.h | 7 +- lib/media-util-db.c | 65 +- lib/media-util-ipc.c | 81 +- lib/media-util-noti-internal.c | 373 +++++ lib/media-util-noti.c | 412 ++--- lib/media-util-register.c | 217 ++- media-server.manifest | 19 +- media_content_config.ini | 12 + packaging/media-scanner.service.wearable | 10 - ...-server.service.mobile => media-server.service} | 5 +- packaging/media-server.service.wearable | 14 - packaging/media-server.spec | 29 +- src/common/include/media-common-db-svc.h | 166 ++ src/common/include/media-common-dbg.h | 35 +- src/common/include/media-common-external-storage.h | 20 +- src/common/include/media-common-security.h | 29 + src/common/include/media-common-system.h | 60 + src/common/include/media-common-types.h | 53 +- src/common/include/media-common-utils.h | 79 +- src/common/media-common-db-svc.c | 1385 ++++++++++++++++ src/common/media-common-external-storage.c | 268 ++- src/common/media-common-security.c | 209 +++ src/common/media-common-system.c | 487 ++++++ src/common/media-common-utils.c | 185 +-- src/mediadb-update.c | 120 +- src/scanner-v2/include/media-scanner-common-v2.h | 33 + src/scanner-v2/include/media-scanner-dbg-v2.h | 37 + .../include/media-scanner-device-block-v2.h | 29 + src/scanner-v2/include/media-scanner-extract-v2.h | 46 + src/scanner-v2/include/media-scanner-scan-v2.h | 53 + .../include/media-scanner-socket-v2.h} | 38 +- src/scanner-v2/media-scanner-common-v2.c | 56 + src/scanner-v2/media-scanner-device-block-v2.c | 116 ++ src/scanner-v2/media-scanner-extract-v2.c | 762 +++++++++ src/scanner-v2/media-scanner-scan-v2.c | 1719 ++++++++++++++++++++ src/scanner-v2/media-scanner-socket-v2.c | 244 +++ src/scanner-v2/media-scanner-v2.c | 181 +++ src/scanner/include/media-scanner-db-svc.h | 148 -- src/scanner/include/media-scanner-dbg.h | 42 +- src/scanner/include/media-scanner-device-block.h | 29 + src/scanner/include/media-scanner-scan.h | 32 +- src/scanner/include/media-scanner-socket.h | 8 - src/scanner/media-scanner-db-svc.c | 769 --------- src/scanner/media-scanner-device-block.c | 69 + src/scanner/media-scanner-scan.c | 1005 +++++++++--- src/scanner/media-scanner-socket.c | 47 +- src/scanner/media-scanner.c | 258 +-- src/server/include/media-server-dbg.h | 39 +- src/server/include/media-server-device-block.h | 32 + src/server/include/media-server-scanner.h | 9 +- src/server/include/media-server-socket.h | 17 +- src/server/include/media-server-thumb.h | 17 +- src/server/media-server-db-svc.c | 304 ---- src/server/media-server-db.c | 11 +- src/server/media-server-device-block.c | 358 ++++ src/server/media-server-main.c | 348 ++-- src/server/media-server-scanner.c | 100 +- src/server/media-server-socket.c | 237 ++- src/server/media-server-thumb.c | 422 +++-- 73 files changed, 9231 insertions(+), 3225 deletions(-) create mode 100755 NOTICE create mode 100755 lib/include/media-util-noti-internal.h create mode 100755 lib/media-util-noti-internal.c create mode 100644 media_content_config.ini delete mode 100644 packaging/media-scanner.service.wearable rename packaging/{media-server.service.mobile => media-server.service} (71%) delete mode 100644 packaging/media-server.service.wearable create mode 100755 src/common/include/media-common-db-svc.h create mode 100644 src/common/include/media-common-security.h create mode 100755 src/common/include/media-common-system.h create mode 100755 src/common/media-common-db-svc.c create mode 100644 src/common/media-common-security.c create mode 100755 src/common/media-common-system.c mode change 100644 => 100755 src/mediadb-update.c create mode 100644 src/scanner-v2/include/media-scanner-common-v2.h create mode 100755 src/scanner-v2/include/media-scanner-dbg-v2.h create mode 100755 src/scanner-v2/include/media-scanner-device-block-v2.h create mode 100755 src/scanner-v2/include/media-scanner-extract-v2.h create mode 100755 src/scanner-v2/include/media-scanner-scan-v2.h rename src/{server/include/media-server-db-svc.h => scanner-v2/include/media-scanner-socket-v2.h} (50%) create mode 100644 src/scanner-v2/media-scanner-common-v2.c create mode 100755 src/scanner-v2/media-scanner-device-block-v2.c create mode 100755 src/scanner-v2/media-scanner-extract-v2.c create mode 100755 src/scanner-v2/media-scanner-scan-v2.c create mode 100755 src/scanner-v2/media-scanner-socket-v2.c create mode 100755 src/scanner-v2/media-scanner-v2.c delete mode 100755 src/scanner/include/media-scanner-db-svc.h create mode 100755 src/scanner/include/media-scanner-device-block.h delete mode 100755 src/scanner/media-scanner-db-svc.c create mode 100755 src/scanner/media-scanner-device-block.c create mode 100755 src/server/include/media-server-device-block.h delete mode 100755 src/server/media-server-db-svc.c create mode 100755 src/server/media-server-device-block.c diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0 index f94008a..261eeb9 100644 --- a/LICENSE.APLv2.0 +++ b/LICENSE.APLv2.0 @@ -1,5 +1,3 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -201,6 +199,3 @@ Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. 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. - - - diff --git a/Makefile.am b/Makefile.am index 4cbb428..7dce0f2 100755 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 +AUTOMAKE_OPTIONS = subdir-objects SUBDIRS = . @@ -6,13 +7,52 @@ AM_CPPFLAGS = $(FMS_DEBUG_FLAGS) AM_LDFLAGS=-Wl,--as-needed -Wl,--hash-style=both -### pkgconfig ### + +###################################################### +#common flags for binary +###################################################### +COMMON_CFLAGS = -I${srcdir}/lib/include \ + -I${srcdir}/src/common/include \ + $(GLIB_CFLAGS) \ + $(GTHREAD_CFLAGS) \ + $(DLOG_CFLAGS) \ + $(INIPARSER_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(LIBPMCONTROL_CFLAGS) \ + $(SECURITY_CFLAGS) \ + $(SMACK_CFLAGS) + +if USE_NOTIFICATION +COMMON_CFLAGS += $(STATUS_CFLAGS) +endif + +COMMON_LDADD = libmedia-utils.la \ + $(GLIB_LIBS) \ + $(GTHREAD_LIBS) \ + $(DLOG_LIBS) \ + $(INIPARSER_LIBS) \ + $(DBUS_LIBS) \ + $(LIBPMCONTROL_LIBS) \ + $(SECURITY_LIBS) \ + $(SMACK_LIBS) \ + -ldl + +if USE_NOTIFICATION +COMMON_LDADD += $(STATUS_LIBS) +endif + +###################################################### +#pkgconfig +###################################################### pkgconfigdir = $(libdir)/pkgconfig dist_pkgconfig_DATA = libmedia-utils.pc -### libmedia-utils.la ### +###################################################### +#libmedia utils +###################################################### lib_LTLIBRARIES = libmedia-utils.la -libmedia_utils_la_SOURCES = lib/media-util-noti.c \ +libmedia_utils_la_SOURCES = lib/media-util-noti-internal.c \ + lib/media-util-noti.c \ lib/media-util-ipc.c \ lib/media-util-db.c \ lib/media-util-register.c @@ -20,109 +60,99 @@ libmedia_utils_la_SOURCES = lib/media-util-noti.c \ libmedia_utils_la_CFLAGS = -I${srcdir}/lib/include \ $(GLIB_CFLAGS) \ $(DLOG_CFLAGS) \ - $(DBUS_CFLAGS) \ + $(GIO_CFLAGS) \ $(SQLITE3_CFLAGS) \ $(DB_UTIL_CFLAGS) \ - $(PHONESTATUS_CFLAGS) + $(PHONESTATUS_CFLAGS) \ + $(DBUS_CFLAGS) libmedia_utils_la_LIBADD = $(GLIB_LIBS) \ $(DLOG_LIBS) \ - $(DBUS_LIBS) \ + $(GIO_LIBS) \ $(SQLITE3_LIBS) \ $(DB_UTIL_LIBS) \ - $(PHONESTATUS_LIBS) - + $(PHONESTATUS_LIBS) \ + $(DBUS_LIBS) -### file-manager-server ### bin_PROGRAMS = media-server \ media-scanner \ + media-scanner-v2 \ mediadb-update - +###################################################### +#media server +###################################################### media_server_SOURCES = src/common/media-common-utils.c \ - src/common/media-common-external-storage.c \ - src/server/media-server-db-svc.c \ + src/common/media-common-system.c \ + src/common/media-common-external-storage.c \ + src/common/media-common-db-svc.c \ + src/common/media-common-security.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) \ - $(DLOG_CFLAGS) \ - $(PHONESTATUS_CFLAGS) \ - $(DBUS_CFLAGS) -if USE_NOTIFICATION -media_server_CFLAGS += $(STATUS_CFLAGS) -endif + src/server/media-server-device-block.c \ + src/server/media-server-main.c -media_server_CFLAGS += $(LIBPMCONTROL_CFLAGS) - -media_server_CFLAGS += $(SECURITY_CFLAGS) +media_server_CFLAGS = -I${srcdir}/src/server/include \ + $(COMMON_CFLAGS) \ + $(PHONESTATUS_CFLAGS) media_server_CFLAGS += -fPIE media_server_LDFLAGS = -pie -media_server_LDADD = libmedia-utils.la \ - $(GLIB_LIBS) \ - $(GTHREAD_LIBS) \ - $(PHONESTATUS_LIBS) \ - $(DLOG_LIBS) \ - $(AUL_LIBS) \ - $(DBUS_LIBS) \ - -ldl -if USE_NOTIFICATION -media_server_LDADD += $(STATUS_LIBS) -endif +media_server_LDADD = $(COMMON_LDADD) \ + $(PHONESTATUS_LIBS) -media_server_LDADD += $(LIBPMCONTROL_LIBS) +###################################################### +#media scanner v1 +###################################################### +media_scanner_SOURCES = src/common/media-common-utils.c \ + src/common/media-common-system.c \ + src/common/media-common-external-storage.c \ + src/common/media-common-db-svc.c \ + src/common/media-common-security.c \ + src/scanner/media-scanner-device-block.c \ + src/scanner/media-scanner-scan.c \ + src/scanner/media-scanner-socket.c \ + src/scanner/media-scanner.c + +media_scanner_CFLAGS = -I${srcdir}/src/scanner/include \ + $(COMMON_CFLAGS) -media_server_LDADD += $(SECURITY_LIBS) +media_scanner_CFLAGS += -fPIE +media_scanner_LDFLAGS = -pie +media_scanner_LDADD = $(COMMON_LDADD) -media_scanner_SOURCES = src/common/media-common-utils.c \ - src/common/media-common-external-storage.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) \ - $(DLOG_CFLAGS) \ - $(DBUS_CFLAGS) -if USE_NOTIFICATION -media_scanner_CFLAGS += $(STATUS_CFLAGS) -endif +###################################################### +#media scanner v2 +###################################################### +media_scanner_v2_SOURCES = src/common/media-common-utils.c \ + src/common/media-common-system.c \ + src/common/media-common-external-storage.c \ + src/common/media-common-db-svc.c \ + src/common/media-common-security.c \ + src/scanner-v2/media-scanner-common-v2.c \ + src/scanner-v2/media-scanner-device-block-v2.c\ + src/scanner-v2/media-scanner-scan-v2.c \ + src/scanner-v2/media-scanner-socket-v2.c \ + src/scanner-v2/media-scanner-extract-v2.c \ + src/scanner-v2/media-scanner-v2.c -media_scanner_CFLAGS += $(LIBPMCONTROL_CFLAGS) +media_scanner_v2_CFLAGS = -I${srcdir}/src/scanner-v2/include \ + $(COMMON_CFLAGS) -media_scanner_CFLAGS += -fPIE +media_scanner_v2_CFLAGS += -fPIE -media_scanner_LDFLAGS = -pie +media_scanner_v2_LDFLAGS = -pie -media_scanner_LDADD = libmedia-utils.la \ - $(GLIB_LIBS) \ - $(GTHREAD_LIBS) \ - $(PHONESTATUS_LIBS) \ - $(DLOG_LIBS) \ - $(DBUS_LIBS) \ - -ldl -if USE_NOTIFICATION -media_scanner_LDADD += $(STATUS_LIBS) -endif - -media_scanner_LDADD += $(LIBPMCONTROL_LIBS) +media_scanner_v2_LDADD = $(COMMON_LDADD) +###################################################### +#mediadb_udpate +###################################################### mediadb_update_SOURCES = src/mediadb-update.c mediadb_update_CFLAGS = -I${srcdir}/lib/include \ @@ -135,11 +165,13 @@ mediadb_update_LDFLAGS = -pie mediadb_update_LDADD = libmedia-utils.la \ $(GLIB_LIBS) \ - $(GTHREAD_LIBS) + $(GTHREAD_LIBS) \ + -ldl ### includeheaders ### includeheadersdir = $(includedir)/media-utils includeheaders_HEADERS = lib/include/media-util-noti-common.h \ + lib/include/media-util-noti-internal.h \ lib/include/media-util-noti.h \ lib/include/media-util-register.h \ lib/include/media-util-err.h \ diff --git a/NOTICE b/NOTICE new file mode 100755 index 0000000..ccdad52 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE file for Apache License terms and conditions. diff --git a/configure.ac b/configure.ac index edcd8bf..3e07d86 100755 --- a/configure.ac +++ b/configure.ac @@ -38,6 +38,8 @@ CPPFLAGS="${CPPFLAGS} -DRND_LINUX" #For supporting Large file CPPFLAGS="${CPPFLAGS} -D_FILE_OFFSET_BITS=64" +#CPPFLAGS="${CPPFLAGS} -D_USE_TV_PROFILE" + # FMS_DEBUG - File Manager Service debug options # To open debug options: # export FMS_DEBUG=1 or configure --enable-debug @@ -77,6 +79,10 @@ PKG_CHECK_MODULES(DBUS, dbus-glib-1) AC_SUBST(DBUS_CFLAGS) AC_SUBST(DBUS_LIBS) +PKG_CHECK_MODULES(GIO, gio-2.0) +AC_SUBST(GIO_CFLAGS) +AC_SUBST(GIO_LIBS) + PKG_CHECK_MODULES(SQLITE, sqlite3) AC_SUBST(SQLITE3_CFLAGS) AC_SUBST(SQLITE3_LIBS) @@ -85,6 +91,14 @@ PKG_CHECK_MODULES(DB_UTIL, db-util) AC_SUBST(DB_UTIL_CFLAGS) AC_SUBST(DB_UTIL_LIBS) +PKG_CHECK_MODULES(INIPARSER, iniparser) +AC_SUBST(INIPARSER_CFLAGS) +AC_SUBST(INIPARSER_LIBS) + +PKG_CHECK_MODULES(SMACK, libsmack) +AC_SUBST(SMACK_CFLAGS) +AC_SUBST(SMACK_LIBS) + dnl use notification -------------------------------------------------------------------------- AC_ARG_ENABLE(notification, AC_HELP_STRING([--enable-notification], [using notification]), [ diff --git a/lib/include/media-server-ipc.h b/lib/include/media-server-ipc.h index 36f667f..9d7a893 100755 --- a/lib/include/media-server-ipc.h +++ b/lib/include/media-server-ipc.h @@ -19,14 +19,6 @@ * */ -/** - * This file defines IPC protocol - * - * @file media-server-ipc.h - * @author Haejeong Kim(backto.kim@samsung.com) - * @version 1.0 - * @brief - */ #ifndef _MEDIA_SERVER_IPC_H_ #define _MEDIA_SERVER_IPC_H_ @@ -66,6 +58,9 @@ typedef enum{ MS_MSG_SCANNER_RESULT, /**< Result of directory scanning */ MS_MSG_SCANNER_BULK_RESULT, /**< Request bulk insert */ MS_MSG_STORAGE_META, /**< Request updating meta data */ + MS_MSG_DIRECTORY_SCANNING_CANCEL, /**< Request cancel directory scan*/ + MS_MSG_STORAGE_SCANNER_COMPLETE, /**< Storage Scanner complete */ + MS_MSG_DIRECTORY_SCANNER_COMPLETE, /**< Directory Scanner complete */ MS_MSG_MAX /**< Invalid msg type */ }ms_msg_type_e; @@ -79,12 +74,15 @@ typedef struct char *sock_path; }ms_sock_info_s; +#define MS_UUID_SIZE 37 /* size of uuid + NULL */ + typedef struct { ms_msg_type_e msg_type; int pid; int result; size_t msg_size; /*this is size of message below and this does not include the terminationg null byte ('\0'). */ + char storage_id[MS_UUID_SIZE]; char msg[MAX_MSG_SIZE]; }ms_comm_msg_s; @@ -104,7 +102,7 @@ typedef struct { typedef struct _thumbMsg{ int msg_type; - int thumb_type; + int request_id; int status; int pid; int thumb_size; @@ -114,9 +112,14 @@ typedef struct _thumbMsg{ int origin_height; int origin_path_size; int dest_path_size; + unsigned char *thumb_data; char org_path[MAX_FILEPATH_LEN]; char dst_path[MAX_FILEPATH_LEN]; } thumbMsg; +typedef struct _thumbRawAddMsg{ + int thumb_size; + unsigned char *thumb_data; +} thumbRawAddMsg; #endif /*_MEDIA_SERVER_IPC_H_*/ diff --git a/lib/include/media-util-db.h b/lib/include/media-util-db.h index efbea0f..183fd2e 100755 --- a/lib/include/media-util-db.h +++ b/lib/include/media-util-db.h @@ -19,24 +19,18 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-noti.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_DB_H_ +#ifndef _MEDIA_UTIL_DB_H_ #define _MEDIA_UTIL_DB_H_ #ifdef __cplusplus extern "C" { #endif +#include + typedef void MediaDBHandle; /**< Handle */ -int media_db_connect(MediaDBHandle **handle); +int media_db_connect(pid_t pid, MediaDBHandle **handle, bool need_write); int media_db_disconnect(MediaDBHandle *handle); diff --git a/lib/include/media-util-dbg.h b/lib/include/media-util-dbg.h index d5e06a3..13e19b8 100755 --- a/lib/include/media-util-dbg.h +++ b/lib/include/media-util-dbg.h @@ -19,14 +19,6 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-dbg.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ #ifndef _MEDIA_UTIL_DBG_H_ #define _MEDIA_UTIL_DBG_H_ diff --git a/lib/include/media-util-err.h b/lib/include/media-util-err.h index c39e7c4..fcb6c37 100755 --- a/lib/include/media-util-err.h +++ b/lib/include/media-util-err.h @@ -19,75 +19,72 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-err.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ #ifndef _MEDIA_UTIL_ERR_H_ #define _MEDIA_UTIL_ERR_H_ -#define MS_MEDIA_ERR_NONE 0 +#define MS_MEDIA_ERR_NONE 0 -/* internal operation error*/ -#define MS_MEDIA_ERR_INTERNAL -1 -#define MS_MEDIA_ERR_INVALID_PARAMETER -2 /* invalid parameter(s) */ -#define MS_MEDIA_ERR_INVALID_PATH -3 /* Invalid path */ -#define MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL -4 /* exception of memory allocation */ -#define MS_MEDIA_ERR_NOT_ENOUGH_SPACE -5 /* not enough space in storage */ +/* Internal operation error*/ +#define MS_MEDIA_ERR_INTERNAL -1 +#define MS_MEDIA_ERR_INVALID_PARAMETER -2 /* Invalid parameter(s) */ +#define MS_MEDIA_ERR_INVALID_PATH -3 /* Invalid path */ +#define MS_MEDIA_ERR_OUT_OF_MEMORY -4 /* Out of memory */ /* DB operation error*/ -#define MS_MEDIA_ERR_DB_CONNECT_FAIL -11 /* connecting database fails */ -#define MS_MEDIA_ERR_DB_DISCONNECT_FAIL -12 /* disconnecting database fails */ -#define MS_MEDIA_ERR_DB_INSERT_FAIL -13 /* inserting record fails */ -#define MS_MEDIA_ERR_DB_DELETE_FAIL -14 /* deleting record fails */ -#define MS_MEDIA_ERR_DB_UPDATE_FAIL -15 /* updating record fails */ -#define MS_MEDIA_ERR_DB_BUSY_FAIL -16 /* DB Busy */ -#define MS_MEDIA_ERR_DB_CONSTRAINT_FAIL -17 /* DB CONSTRAINT fails - In case of insert, the record already exists */ -#define MS_MEDIA_ERR_DB_BATCH_UPDATE_BUSY -18 /* Batch update thread is full */ +#define MS_MEDIA_ERR_DB_CONNECT_FAIL -101 /* connecting database fails */ +#define MS_MEDIA_ERR_DB_DISCONNECT_FAIL -102 /* disconnecting database fails */ +#define MS_MEDIA_ERR_DB_INSERT_FAIL -103 /* inserting record fails */ +#define MS_MEDIA_ERR_DB_DELETE_FAIL -104 /* deleting record fails */ +#define MS_MEDIA_ERR_DB_UPDATE_FAIL -105 /* updating record fails */ +#define MS_MEDIA_ERR_DB_BUSY_FAIL -106 /* DB Busy */ +#define MS_MEDIA_ERR_DB_SERVER_BUSY_FAIL -107 /* DB Server Busy */ +#define MS_MEDIA_ERR_DB_CONSTRAINT_FAIL -108 /* DB CONSTRAINT fails - In case of insert, the record already exists */ +#define MS_MEDIA_ERR_DB_BATCH_UPDATE_BUSY -109 /* Batch update thread is full */ +#define MS_MEDIA_ERR_DB_NO_RECORD -110 /* Item not found in DB */ +#define MS_MEDIA_ERR_DB_CORRUPT -112 /* DB corrut error */ +#define MS_MEDIA_ERR_DB_PERMISSION -113 /* DB permission error */ +#define MS_MEDIA_ERR_DB_FULL_FAIL -114 /* DB storage full error */ +#define MS_MEDIA_ERR_DB_INTERNAL -150 /* DB internal error */ /* IPC operation error*/ -#define MS_MEDIA_ERR_SOCKET_INTERNAL -21 /* receive error from socket API */ -#define MS_MEDIA_ERR_SOCKET_CONN -22 /* socket connect error */ -#define MS_MEDIA_ERR_SOCKET_BIND -23 /* socket binding fails */ -#define MS_MEDIA_ERR_SOCKET_SEND -24 /* socket sending fails */ -#define MS_MEDIA_ERR_SOCKET_RECEIVE -25 /* socket receiving fails */ -#define MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT -26 /* socket receive timeout error */ -#define MS_MEDIA_ERR_SOCKET_ACCEPT -27 /* socket accept fails */ - -#define MS_MEDIA_ERR_DBUS_ADD_FILTER -31 /* DBUS add filter fails*/ -#define MS_MEDIA_ERR_DBUS_GET -32 /* DBUS get fails */ - -#define MS_MEDIA_ERR_FIFO_MAKE_FAIL -41 /* FIFO making fails */ +#define MS_MEDIA_ERR_SOCKET_CONN -201 /* socket connect error */ +#define MS_MEDIA_ERR_SOCKET_BIND -202 /* socket binding fails */ +#define MS_MEDIA_ERR_SOCKET_SEND -203 /* socket sending fails */ +#define MS_MEDIA_ERR_SOCKET_RECEIVE -204 /* socket receiving fails */ +#define MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT -205 /* socket receive timeout error */ +#define MS_MEDIA_ERR_SOCKET_ACCEPT -206 /* socket accept fails */ +#define MS_MEDIA_ERR_SOCKET_INTERNAL -250 /* receive error from socket API */ /* DIRECTORY error*/ -#define MS_MEDIA_ERR_DIR_OPEN_FAIL -51 /* direcotry opennig fails */ -#define MS_MEDIA_ERR_DIR_CLOSE_FAIL -53 /* directory closing fails */ -#define MS_MEDIA_ERR_DIR_READ_FAIL -52 /* directory reading fails */ +#define MS_MEDIA_ERR_DIR_OPEN_FAIL -501 /* direcotry opennig fails */ +#define MS_MEDIA_ERR_DIR_CLOSE_FAIL -502 /* directory closing fails */ +#define MS_MEDIA_ERR_DIR_READ_FAIL -503 /* directory reading fails */ /* FILE error*/ -#define MS_MEDIA_ERR_FILE_OPEN_FAIL -61 /* file opennig fails */ -#define MS_MEDIA_ERR_FILE_CLOSE_FAIL -62 /* file closing fails */ -#define MS_MEDIA_ERR_FILE_READ_FAIL -63 /* file reading fails */ -#define MS_MEDIA_ERR_FILE_WRITE_FAIL -64 /* file writing fails */ +#define MS_MEDIA_ERR_FILE_OPEN_FAIL -601 /* file opennig fails */ +#define MS_MEDIA_ERR_FILE_CLOSE_FAIL -602 /* file closing fails */ +#define MS_MEDIA_ERR_FILE_READ_FAIL -603 /* file reading fails */ +#define MS_MEDIA_ERR_FILE_WRITE_FAIL -604 /* file writing fails */ +#define MS_MEDIA_ERR_FILE_NOT_EXIST -605 /* file does not exist */ /* MEDIA SERVER error*/ -#define MS_MEDIA_ERR_DB_SERVER_BUSY_FAIL -101 /* DB server busy */ -#define MS_MEDIA_ERR_SCANNER_FORCE_STOP -102 /* scanning is stopped forcely */ -#define MS_MEDIA_ERR_PERMISSION_DENIED -103 /* Do have permission of request */ +#define MS_MEDIA_ERR_SCANNER_FORCE_STOP -701 /* scanning is stopped forcely */ +#define MS_MEDIA_ERR_PERMISSION_DENIED -702 /* Do have permission of request */ + +/* Thumbnail error*/ +#define MS_MEDIA_ERR_THUMB_TOO_BIG -801 /* Original is too big to make thumb */ +#define MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST -802 /* Duplicated request of same path */ /*ETC*/ -#define MS_MEDIA_ERR_VCONF_SET_FAIL -201 /* vconf setting fails*/ -#define MS_MEDIA_ERR_VCONF_GET_FAIL -202 /* vconf getting fails*/ -#define MS_MEDIA_ERR_SCANNER_NOT_READY -203 /* scanner is not ready */ -#define MS_MEDIA_ERR_DYNAMIC_LINK -204 /* fail to dynamic link */ -#define MS_MEDIA_ERR_INVALID_IPC_MESSAGE -205 /* received message is not valid */ -#define MS_MEDIA_ERR_DATA_TAINTED -206 /* received data is tainted */ -#define MS_MEDIA_ERR_SEND_NOTI_FAIL -207 /* sending notification is failed */ +#define MS_MEDIA_ERR_VCONF_SET_FAIL -901 /* vconf setting fails*/ +#define MS_MEDIA_ERR_VCONF_GET_FAIL -902 /* vconf getting fails*/ +#define MS_MEDIA_ERR_SCANNER_NOT_READY -903 /* scanner is not ready */ +#define MS_MEDIA_ERR_DYNAMIC_LINK -904 /* fail to dynamic link */ +#define MS_MEDIA_ERR_INVALID_IPC_MESSAGE -905 /* received message is not valid */ +#define MS_MEDIA_ERR_DATA_TAINTED -906 /* received data is tainted */ +#define MS_MEDIA_ERR_SEND_NOTI_FAIL -907 /* sending notification is failed */ +#define MS_MEDIA_ERR_USB_UNMOUNTED -908 /* USB unmounted */ -#define MS_MEDIA_ERR_MAX -999 +#define MS_MEDIA_ERR_MAX -999 #endif /*_MEDIA_UTIL_ERR_H_*/ diff --git a/lib/include/media-util-internal.h b/lib/include/media-util-internal.h index 7cf8396..3fa1b0d 100755 --- a/lib/include/media-util-internal.h +++ b/lib/include/media-util-internal.h @@ -19,15 +19,6 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-internal.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_INTERNAL_H_ #define _MEDIA_UTIL_INTERNAL_H_ @@ -42,7 +33,7 @@ #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);} } + else { src = malloc(size); if(src) memset(src, 0x0, size);} } #define MS_STRING_VALID(str) \ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) diff --git a/lib/include/media-util-ipc.h b/lib/include/media-util-ipc.h index aa4d8c5..d34d178 100755 --- a/lib/include/media-util-ipc.h +++ b/lib/include/media-util-ipc.h @@ -19,15 +19,7 @@ * */ -/** - * This file defines api utilities of IPC. - * - * @file media-util-ipc.h - * @author Haejeong Kim(backto.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_IPC_H_ +#ifndef _MEDIA_UTIL_IPC_H_ #define _MEDIA_UTIL_IPC_H_ #ifdef __cplusplus @@ -56,6 +48,7 @@ int ms_ipc_send_msg_to_client_tcp(int sockfd, ms_comm_msg_s *send_msg, struct so 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_receive_message_tcp(int client_sock, ms_comm_msg_s *recv_msg); int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *size); +int ms_ipc_wait_block_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *size); int ms_ipc_delete_client_socket(ms_sock_info_s* sock_info); int ms_ipc_accept_client_tcp(int serv_sock, int* client_sock); diff --git a/lib/include/media-util-noti-common.h b/lib/include/media-util-noti-common.h index 60e8cf4..c259b40 100755 --- a/lib/include/media-util-noti-common.h +++ b/lib/include/media-util-noti-common.h @@ -19,15 +19,7 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-not-commoni.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_NOTI_COMMON_H_ +#ifndef _MEDIA_UTIL_NOTI_COMMON_H_ #define _MEDIA_UTIL_NOTI_COMMON_H_ #ifdef __cplusplus diff --git a/lib/include/media-util-noti-internal.h b/lib/include/media-util-noti-internal.h new file mode 100755 index 0000000..3e58f4a --- /dev/null +++ b/lib/include/media-util-noti-internal.h @@ -0,0 +1,95 @@ +/* + * Media Utility + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Yong Yeon Kim + * + * 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-util-noti.h + * @author Yong Yeon Kim(yy9875.kim@samsung.com) + * @version 1.0 + * @brief + */ + #ifndef _MEDIA_UTIL_NOTI_INTERNAL_H_ +#define _MEDIA_UTIL_NOTI_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "media-util-noti-common.h" + +/** +* @fn int media_db_update_subscribe(void); +* @brief This function announce media database is updated to other applications.
+* @return This function returns 0 on success, and -1 on failure. +* @param[in] none +* @remark This function is recommandation for other application being aware of database updating.
+* @par example +* @code + +#include +#include +#include + +void callback() +{ + printf("listen dbus from media-server\n"); +} + +int +main (int argc, char **argv) +{ + GMainLoop *loop; + + loop = g_main_loop_new (NULL, FALSE); + + media_db_update_subscribe(callback); + + g_main_loop_run (loop); + + return 0; +} + +*/ + +int media_db_update_send_internal(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 */ + ); + +int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data); + +int media_db_update_unsubscribe_internal(MediaNotiHandle handle, clear_user_data_cb clear_cb); + + +/** +* @} +*/ + +#ifdef __cplusplus +} +#endif + +#endif /*_MEDIA_UTIL_NOTI_INTERNAL_H_*/ diff --git a/lib/include/media-util-noti.h b/lib/include/media-util-noti.h index c7e8b28..155b48f 100755 --- a/lib/include/media-util-noti.h +++ b/lib/include/media-util-noti.h @@ -19,15 +19,7 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-noti.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_NOTI_H_ +#ifndef _MEDIA_UTIL_NOTI_H_ #define _MEDIA_UTIL_NOTI_H_ #ifdef __cplusplus diff --git a/lib/include/media-util-register.h b/lib/include/media-util-register.h index cc6e16e..0147440 100755 --- a/lib/include/media-util-register.h +++ b/lib/include/media-util-register.h @@ -19,15 +19,7 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-register.h - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #ifndef _MEDIA_UTIL_REGISTER_H_ +#ifndef _MEDIA_UTIL_REGISTER_H_ #define _MEDIA_UTIL_REGISTER_H_ #include @@ -54,7 +46,9 @@ typedef struct 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 recursive_on, scan_complete_cb user_callback, void *user_data); +int media_directory_scanning_async(const char *directory_path, const char *storage_id, bool recursive_on, scan_complete_cb user_callback, void *user_data); + +int media_directory_scanning_cancel(const char *directory_path); int media_files_register(const char *list_path, insert_complete_cb user_callback, void *user_data); diff --git a/lib/include/media-util.h b/lib/include/media-util.h index f7e6948..c07cc9c 100755 --- a/lib/include/media-util.h +++ b/lib/include/media-util.h @@ -26,16 +26,19 @@ #include #include #include +#include #include #define MOUNT_PATH "/opt/usr" #define STORAGE_PATH "/opt/storage" #define MEDIA_ROOT_PATH_INTERNAL MOUNT_PATH"/media" +#define MEDIA_ROOT_PATH_EXTERNAL STORAGE_PATH #define MEDIA_ROOT_PATH_SDCARD STORAGE_PATH"/sdcard" - +#define MEDIA_ROOT_PATH_USB STORAGE_PATH +#define MEDIA_ROOT_PATH_CLOUD STORAGE_PATH"/tnfs/cloud" #define MEDIA_THUMB_ROOT_PATH MOUNT_PATH"/share/media" #define MEDIA_DB_NAME MOUNT_PATH"/dbspace/.media.db" /**< media db name*/ -#define MEDIA_DATA_PATH MOUNT_PATH"/data/file-manager-service" +#define MEDIA_DATA_PATH MOUNT_PATH"/apps/media-server/data" #endif /*_MEDIA_UTIL_H_*/ diff --git a/lib/media-util-db.c b/lib/media-util-db.c index a094eee..95bc281 100755 --- a/lib/media-util-db.c +++ b/lib/media-util-db.c @@ -19,15 +19,6 @@ * */ -/** - * This file defines api utilities of Media DB. - * - * @file media-util-db.c - * @author Haejeong Kim(backto.kim@samsung.com) - * @version 1.0 - * @brief - */ - #include #include #include @@ -41,7 +32,7 @@ static __thread char **sql_list = NULL; static __thread int g_list_idx = 0; static int __media_db_busy_handler(void *pData, int count); -static int __media_db_connect_db_with_handle(sqlite3 **db_handle); +static int __media_db_connect_db_with_handle(pid_t pid, sqlite3 **db_handle, bool need_write); static int __media_db_disconnect_db_with_handle(sqlite3 *db_handle); static void __media_db_destroy_sql_list() @@ -62,16 +53,23 @@ static int __media_db_busy_handler(void *pData, int count) MSAPI_DBG("media_db_busy_handler called : %d", count); - return 100 - count; + return 200 - count; } -static int __media_db_connect_db_with_handle(sqlite3 **db_handle) +static int __media_db_connect_db_with_handle(pid_t pid, sqlite3 **db_handle, bool need_write) { - int ret = MS_MEDIA_ERR_NONE; + int ret = SQLITE_OK; + char db_path[256] = {0, }; + memset(db_path, 0, sizeof(db_path)); - /*Connect DB*/ - ret = db_util_open(MEDIA_DB_NAME, db_handle, DB_UTIL_REGISTER_HOOK_METHOD); + snprintf(db_path, sizeof(db_path), "%s", MEDIA_DB_NAME); + /*Connect DB*/ + if (need_write) { + ret = db_util_open_with_options(db_path, db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); + } else { + ret = db_util_open_with_options(db_path, db_handle, SQLITE_OPEN_READONLY, NULL); + } if (SQLITE_OK != ret) { MSAPI_DBG_ERR("error when db open"); @@ -335,24 +333,39 @@ static int __media_db_request_batch_update(ms_msg_type_e msg_type, const char *r return ret; } +#define RETRY_CNT 9 +#define SLEEP_TIME 1000 * 1000 static int _media_db_update_directly(sqlite3 *db_handle, const char *sql_str) { int ret = MS_MEDIA_ERR_NONE; char *zErrMsg = NULL; + int retry_count = 0; // MSAPI_DBG_SLOG("SQL = [%s]", sql_str); +EXEC_RETRY: ret = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg); if (SQLITE_OK != ret) { MSAPI_DBG_ERR("DB Update Fail SQL:%s", sql_str); MSAPI_DBG_ERR("ERROR [%s]", zErrMsg); - if (ret == SQLITE_BUSY) + if (ret == SQLITE_BUSY) { ret = MS_MEDIA_ERR_DB_BUSY_FAIL; - else if (ret == SQLITE_CONSTRAINT) + } else if (ret == SQLITE_CONSTRAINT) { ret = MS_MEDIA_ERR_DB_CONSTRAINT_FAIL; - else + } else if (ret == SQLITE_FULL) { + ret = MS_MEDIA_ERR_DB_FULL_FAIL; + } else if (ret == SQLITE_LOCKED) { + if (retry_count < RETRY_CNT) { + MSAPI_DBG_ERR("Locked retry[%d]", retry_count); + retry_count++; + usleep(SLEEP_TIME); + goto EXEC_RETRY; + } ret = MS_MEDIA_ERR_DB_UPDATE_FAIL; + } else { + ret = MS_MEDIA_ERR_DB_UPDATE_FAIL; + } } if (zErrMsg) @@ -361,14 +374,14 @@ static int _media_db_update_directly(sqlite3 *db_handle, const char *sql_str) return ret; } -int media_db_connect(MediaDBHandle **handle) +int media_db_connect(pid_t pid, MediaDBHandle **handle, bool need_write) { int ret = MS_MEDIA_ERR_NONE; sqlite3 * db_handle = NULL; MSAPI_DBG_FUNC(); - ret = __media_db_connect_db_with_handle(&db_handle); + ret = __media_db_connect_db_with_handle(pid, &db_handle, need_write); MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); *handle = db_handle; @@ -484,9 +497,9 @@ int media_db_update_db_batch_start(const char *query_str) ret = MS_MEDIA_ERR_DB_SERVER_BUSY_FAIL; } else { sql_list = (char**)malloc(sizeof(char*)); - MSAPI_RETVM_IF(sql_list == NULL, MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL, "Out of memory"); + MSAPI_RETVM_IF(sql_list == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); sql_list[g_list_idx++] = strdup(query_str); - MSAPI_RETVM_IF(sql_list[g_list_idx - 1] == NULL, MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL, "Out of memory"); + MSAPI_RETVM_IF(sql_list[g_list_idx - 1] == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); } return ret; @@ -499,10 +512,10 @@ int media_db_update_db_batch(const char *query_str) MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); sql_list = (char**)realloc(sql_list, (g_list_idx + 1) * sizeof(char*)); - MSAPI_RETVM_IF(sql_list == NULL, MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL, "Out of memory"); + MSAPI_RETVM_IF(sql_list == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); sql_list[g_list_idx++] = strdup(query_str); - MSAPI_RETVM_IF(sql_list[g_list_idx - 1] == NULL, MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL, "Out of memory"); + MSAPI_RETVM_IF(sql_list[g_list_idx - 1] == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); return ret; } @@ -522,14 +535,14 @@ int media_db_update_db_batch_end(MediaDBHandle *handle, const char *query_str) if (sql_list == NULL) { __media_db_destroy_sql_list(); MSAPI_DBG_ERR("Out of memory"); - return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL; + return MS_MEDIA_ERR_OUT_OF_MEMORY; } sql_list[g_list_idx++] = strdup(query_str); if (sql_list[g_list_idx - 1] == NULL) { __media_db_destroy_sql_list(); MSAPI_DBG_ERR("Out of memory"); - return MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL; + return MS_MEDIA_ERR_OUT_OF_MEMORY; } int i = 0; diff --git a/lib/media-util-ipc.c b/lib/media-util-ipc.c index e1c67c0..8d6e212 100755 --- a/lib/media-util-ipc.c +++ b/lib/media-util-ipc.c @@ -19,15 +19,6 @@ * */ -/** - * This file defines api utilities of IPC. - * - * @file media-util-ipc.c - * @author Haejeong Kim(backto.kim@samsung.com) - * @version 1.0 - * @brief - */ - #include #include #include @@ -35,6 +26,7 @@ #include "media-util-dbg.h" #include "media-util.h" +#include "media-util-internal.h" char MEDIA_IPC_PATH[][50] ={ {"/tmp/.media_ipc_dbbatchupdate"}, @@ -49,6 +41,7 @@ char MEDIA_IPC_PATH[][50] ={ #define MS_SOCK_PATH_PRFX "/tmp/.media_ipc_client" #define MS_SOCK_PATH_TEMPLATE "XXXXXX" #define MS_SOCK_PATH MS_SOCK_PATH_PRFX MS_SOCK_PATH_TEMPLATE +#define MS_SOCK_UDP_BLOCK_SIZE 512 static const char abc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; @@ -208,7 +201,7 @@ int ms_ipc_create_server_socket(ms_protocol_e protocol, ms_msg_port_type_e port, strncpy(serv_addr.sun_path, MEDIA_IPC_PATH[serv_port], strlen(MEDIA_IPC_PATH[serv_port])); /* Bind to the local address */ - for (i = 0; i < 20; i ++) { + for (i = 0; i < 100; i ++) { if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) { bind_success = true; break; @@ -237,13 +230,11 @@ int ms_ipc_create_server_socket(ms_protocol_e protocol, ms_msg_port_type_e port, } /*change permission of sock file*/ - if (chmod(MEDIA_IPC_PATH[serv_port], 0660) < 0) { + if (chmod(MEDIA_IPC_PATH[serv_port], 0660) < 0) MSAPI_DBG_STRERROR("chmod failed"); - } - - if (chown(MEDIA_IPC_PATH[serv_port], 0, 5000) < 0) { + if (chown(MEDIA_IPC_PATH[serv_port], 200, 5000) < 0) MSAPI_DBG_STRERROR("chown failed"); - } + *sock_fd = sock; return MS_MEDIA_ERR_NONE; @@ -267,7 +258,7 @@ int ms_ipc_send_msg_to_server(int sockfd, ms_msg_port_type_e port, ms_comm_msg_s MSAPI_DBG("sent result [%d]", send_msg->result); MSAPI_DBG_SLOG("result message [%s]", send_msg->msg); if (serv_addr != NULL) - *serv_addr = addr; + *serv_addr = addr; } return res; @@ -289,7 +280,13 @@ int ms_ipc_send_msg_to_server_tcp(int sockfd, ms_msg_port_type_e port, ms_comm_m if (connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { MSAPI_DBG_STRERROR("connect error"); close(sockfd); - return MS_MEDIA_ERR_SOCKET_CONN; + + res = MS_MEDIA_ERR_SOCKET_CONN; + + if (errno == EACCES || errno == EPERM) + res = MS_MEDIA_ERR_PERMISSION_DENIED; + + return res; } if (write(sockfd, send_msg, sizeof(*(send_msg))) != sizeof(*(send_msg))) { @@ -386,6 +383,56 @@ int ms_ipc_wait_message(int sockfd, void *recv_msg, unsigned int msg_size, struc return MS_MEDIA_ERR_NONE; } +int ms_ipc_wait_block_message(int sockfd, void *recv_msg, unsigned int msg_size, struct sockaddr_un *recv_addr, unsigned int *addr_size) +{ + int recv_msg_size; + socklen_t addr_len; + unsigned char *block_buf; + int block_size = 0; + int recv_size = 0; + unsigned int remain_size = msg_size; + + if (!recv_msg ||!recv_addr) + return MS_MEDIA_ERR_INVALID_PARAMETER; + + addr_len = sizeof(struct sockaddr_un); + block_size = MS_SOCK_UDP_BLOCK_SIZE; + block_buf = malloc(block_size * sizeof(unsigned char)); + if(block_buf == NULL) { + MSAPI_DBG_ERR("malloc failed."); + return MS_MEDIA_ERR_OUT_OF_MEMORY; + } + memset(block_buf, 0, block_size * sizeof(unsigned char)); + + while(remain_size > 0) { + if(remain_size < MS_SOCK_UDP_BLOCK_SIZE) { + block_size = remain_size; + } + if ((recv_msg_size = recvfrom(sockfd, block_buf, block_size, 0, (struct sockaddr *)recv_addr, &addr_len)) < 0) { + MSAPI_DBG_STRERROR("recvfrom failed"); + if (errno == EWOULDBLOCK) { + MSAPI_DBG_ERR("recvfrom Timeout."); + MS_SAFE_FREE(block_buf); + return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT; + } else { + MSAPI_DBG_STRERROR("recvfrom error"); + MS_SAFE_FREE(block_buf); + return MS_MEDIA_ERR_SOCKET_RECEIVE; + } + } + + memcpy(recv_msg+recv_size, block_buf, block_size); + recv_size += block_size; + remain_size -= block_size; + } + if (addr_size != NULL) + *addr_size = addr_len; + + MS_SAFE_FREE(block_buf); + + return MS_MEDIA_ERR_NONE; +} + int ms_ipc_accept_client_tcp(int serv_sock, int* client_sock) { int sockfd = -1; diff --git a/lib/media-util-noti-internal.c b/lib/media-util-noti-internal.c new file mode 100755 index 0000000..4ce1932 --- /dev/null +++ b/lib/media-util-noti-internal.c @@ -0,0 +1,373 @@ +/* + * Media Utility + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Yong Yeon Kim + * + * 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-util-noti.c + * @author Yong Yeon Kim(yy9875.kim@samsung.com) + * @version 1.0 + * @brief + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "media-util-internal.h" +#include "media-util-dbg.h" +#include "media-util.h" +#include "media-util-noti-internal.h" + +GArray *handle_list_internal; +static GMutex mutex_internal; +int ref_count; + +#define MS_MEDIA_DBUS_NAME_INTERNAL "ms_db_updated_internal" + +typedef struct internal_noti_cb_data{ + DBusConnection *dbus; + db_update_cb user_callback; + void *user_data; +} internal_noti_cb_data; + +int media_db_update_send_internal(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 = NULL; + DBusConnection *bus = NULL; + DBusError error; + unsigned char *path_array = NULL; + int path_length = strlen(path) + 1; + + /* 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_INTERNAL; + } + + message = dbus_message_new_signal (MS_MEDIA_DBUS_PATH, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME_INTERNAL); + if (message != NULL) { + path_array = malloc(sizeof(unsigned char) * path_length); + memcpy(path_array, path, path_length); + + 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, + 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"); + MS_SAFE_FREE(path_array); + dbus_message_unref (message); + 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, + 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, + DBUS_TYPE_INVALID); + } + } else { + MSAPI_DBG("this request is wrong"); + } + + MS_SAFE_FREE(path_array); + + /* Send the signal */ + dbus_connection_send (bus, message, NULL); + + /* Free the signal now we have finished with it */ + dbus_message_unref (message); + + MSAPI_DBG_ERR("success send notification"); + } else { + MSAPI_DBG_ERR("dbus_message_new_signal failed"); + } + + dbus_connection_unref(bus); + + /* Return TRUE to tell the event loop we want to be called again */ + return MS_MEDIA_ERR_NONE; +} + + +DBusHandlerResult +__get_message_internal(DBusMessage *message, db_update_cb user_cb, void *userdata) +{ + /* A Ping signal on the com.burtonini.dbus.Signal interface */ + if (dbus_message_is_signal (message, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME_INTERNAL)) { + int i = 0; + int current_type = DBUS_TYPE_INVALID; + DBusError error; + DBusMessageIter read_iter; + DBusBasicValue value[6]; + + 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; + void *recevie_path = NULL; + int path_len = 0; + + dbus_error_init (&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 ((current_type = dbus_message_iter_get_arg_type (&read_iter)) != DBUS_TYPE_INVALID){ + if (current_type == DBUS_TYPE_ARRAY) { + DBusMessageIter sub; + dbus_message_iter_recurse(&read_iter, &sub); + dbus_message_iter_get_fixed_array(&sub, &recevie_path, &path_len); + } else { + dbus_message_iter_get_basic (&read_iter, &value[i]); + i ++; + } + dbus_message_iter_next (&read_iter); + } + + item = value[0].i32; + pid = value[1].i32; + update_type = value[2].i32; + update_path = strndup(recevie_path, path_len); + if (value[3].str != NULL) uuid = strdup(value[3].str); + content_type = value[4].i32; + if (value[5].str != NULL) mime_type = strdup(value[5].str); + + if (item == MS_MEDIA_ITEM_DIRECTORY) + content_type = MS_MEDIA_UNKNOWN; + + /* getting data complete */ + MSAPI_DBG("update type[%d]", update_type); + user_cb(pid, + item, + update_type, + update_path, + uuid, + content_type, + mime_type, + userdata); + + MS_SAFE_FREE(update_path); + MS_SAFE_FREE(uuid); + MS_SAFE_FREE(mime_type); + + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +DBusHandlerResult +__message_filter_internal(DBusConnection *connection, DBusMessage *message, void *user_data) +{ + db_update_cb user_cb = ((internal_noti_cb_data*)user_data)->user_callback; + void *userdata = ((internal_noti_cb_data*)user_data)->user_data; + DBusHandlerResult ret; + + ret = __get_message_internal(message, user_cb, userdata); + + return ret; +} + +int media_db_update_subscribe_internal(MediaNotiHandle *handle, db_update_cb user_cb, void *user_data) +{ + int ret = MS_MEDIA_ERR_NONE; + internal_noti_cb_data *noti_data = NULL; + DBusError error; + DBusConnection *dbus; + + dbus_g_thread_init(); + + dbus_error_init (&error); + + dbus = dbus_bus_get_private (DBUS_BUS_SYSTEM, &error); + if (!dbus) { + MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message); + dbus_error_free (&error); + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; + } + + dbus_connection_setup_with_g_main (dbus, NULL); + + MS_MALLOC(noti_data, sizeof(internal_noti_cb_data)); + if (noti_data == NULL) { + MSAPI_DBG_ERR("MS_MALLOC failed"); + ret = MS_MEDIA_ERR_OUT_OF_MEMORY; + goto ERROR; + } + noti_data->user_callback = user_cb; + noti_data->user_data = user_data; + + /* listening to messages from all objects as no path is specified */ + dbus_bus_add_match (dbus, MS_MEDIA_DBUS_MATCH_RULE, &error); + if( !dbus_connection_add_filter (dbus, __message_filter_internal, noti_data, NULL)) { + dbus_bus_remove_match (dbus, MS_MEDIA_DBUS_MATCH_RULE, NULL); + ret = MS_MEDIA_ERR_INTERNAL; + goto ERROR; + } + + noti_data->dbus = dbus; + *handle = noti_data; + + g_mutex_lock(&mutex_internal); + + if (handle_list_internal == NULL) { + handle_list_internal = g_array_new(FALSE, FALSE, sizeof(MediaNotiHandle)); + if (handle_list_internal == NULL) { + g_mutex_unlock(&mutex_internal); + ret = MS_MEDIA_ERR_OUT_OF_MEMORY; + goto ERROR; + } + } + + g_array_append_val(handle_list_internal, *handle); + + g_mutex_unlock(&mutex_internal); + + return MS_MEDIA_ERR_NONE; + +ERROR: + + if (dbus != NULL) { + dbus_connection_close(dbus); + dbus_connection_unref(dbus); + dbus = NULL; + } + + MS_SAFE_FREE(noti_data); + + return ret; +} + +static int _find_handle(MediaNotiHandle handle, int *idx) +{ + unsigned int i; + int ret = MS_MEDIA_ERR_NONE; + bool find_flag = false; + MediaNotiHandle data; + + /*delete all node*/ + if(handle_list_internal != NULL) { + for (i =0; i < handle_list_internal->len; i++) { + data = g_array_index(handle_list_internal , MediaNotiHandle, i); + MSAPI_DBG_ERR("%x %x", handle, data); + if (data == handle) { + MSAPI_DBG("FIND HANDLE"); + *idx = i; + find_flag = true; + break; + } + } + } else { + ret = MS_MEDIA_ERR_INVALID_PARAMETER; + } + + if (find_flag == false) + ret = MS_MEDIA_ERR_INVALID_PARAMETER; + + return ret; +} + +int media_db_update_unsubscribe_internal(MediaNotiHandle handle, clear_user_data_cb clear_cb) +{ + int idx = -1; + int ret = MS_MEDIA_ERR_NONE; + int err; + + if (handle == NULL) { + MSAPI_DBG_ERR("INVALID PARAMETER"); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + g_mutex_lock(&mutex_internal); + + err = _find_handle(handle, &idx); + if(err == MS_MEDIA_ERR_NONE) { + DBusConnection *dbus = ((internal_noti_cb_data*)handle)->dbus; + + dbus_connection_remove_filter(dbus, __message_filter_internal, (internal_noti_cb_data*)handle); + dbus_bus_remove_match (dbus, MS_MEDIA_DBUS_MATCH_RULE, NULL); + dbus_connection_close(dbus); + dbus_connection_unref(dbus); + g_array_remove_index(handle_list_internal, idx); + + if (clear_cb != NULL) + clear_cb(((internal_noti_cb_data*)handle)->user_data); + + MS_SAFE_FREE(handle); + + if ((handle_list_internal != NULL) && (handle_list_internal->len == 0)) { + g_array_free(handle_list_internal, FALSE); + handle_list_internal = NULL; + } + } else { + MSAPI_DBG_ERR("PARAMETER DOES NOT FIND"); + ret = MS_MEDIA_ERR_INVALID_PARAMETER; + } + + g_mutex_unlock(&mutex_internal); + + return ret; +} + + diff --git a/lib/media-util-noti.c b/lib/media-util-noti.c index 46cddf1..938a974 100755 --- a/lib/media-util-noti.c +++ b/lib/media-util-noti.c @@ -19,34 +19,24 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-noti.c - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ - #include #include #include #include #include -#include -#include -#include +#include +#include #include "media-util-internal.h" #include "media-util-dbg.h" #include "media-util.h" #include "media-util-noti.h" -DBusConnection *g_bus; -void *g_data_store; -GArray *handle_list; -static GStaticMutex noti_mutex = G_STATIC_MUTEX_INIT; -int ref_count; +static GDBusConnection *g_bus = NULL; +static guint g_handler = 0; +static void *g_data_store = NULL; +static GMutex noti_mutex; +static int ref_count = 0; #define MS_MEDIA_DBUS_NAME "ms_db_updated" @@ -55,153 +45,123 @@ typedef struct noti_callback_data{ void *user_data; } noti_callback_data; -static void -__free_data_fuction(void *memory) +static bool __gdbus_message_is_signal(const char *iface, const char *signal) { - MS_SAFE_FREE(memory); - g_data_store = NULL; + if ((strcmp(iface, MS_MEDIA_DBUS_INTERFACE) == 0) && (strcmp(signal, MS_MEDIA_DBUS_NAME) == 0)) + return TRUE; + + return FALSE; } -DBusHandlerResult -__get_message(DBusMessage *message, db_update_cb user_cb, void *userdata) +static void __get_message(GVariant *message, db_update_cb user_cb, void *userdata) { - /* 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; - int current_type = DBUS_TYPE_INVALID; - DBusError error; - DBusMessageIter read_iter; - DBusBasicValue value[6]; - - 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; - void *recevie_path = NULL; - int path_len = 0; - - dbus_error_init (&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 ((current_type = dbus_message_iter_get_arg_type (&read_iter)) != DBUS_TYPE_INVALID){ - if (current_type == DBUS_TYPE_ARRAY) { - DBusMessageIter sub; - dbus_message_iter_recurse(&read_iter, &sub); - dbus_message_iter_get_fixed_array(&sub, &recevie_path, &path_len); - } else { - dbus_message_iter_get_basic (&read_iter, &value[i]); - i ++; - } - dbus_message_iter_next (&read_iter); - } - - item = value[0].i32; - pid = value[1].i32; - update_type = value[2].i32; - update_path = strndup(recevie_path, path_len); - if (value[3].str != NULL) uuid = strdup(value[3].str); - content_type = value[4].i32; - if (value[5].str != NULL) mime_type = strdup(value[5].str); - - if (item == MS_MEDIA_ITEM_DIRECTORY) - content_type = MS_MEDIA_UNKNOWN; - - /* getting data complete */ - user_cb(pid, - item, - update_type, - update_path, - uuid, - content_type, - mime_type, - userdata); - - MS_SAFE_FREE(update_path); - MS_SAFE_FREE(uuid); - MS_SAFE_FREE(mime_type); - - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + gint32 item = -1; + gint32 pid = 0; + gint32 update_type = MS_MEDIA_UNKNOWN; + gint32 content_type = -1; + char *update_path = NULL; + char *uuid = NULL; + char *mime_type = NULL; + + int item_number = g_variant_n_children(message); + + if (item_number == 7) + g_variant_get(message, "(iiissis)", &item, &pid, &update_type, &update_path, &uuid, &content_type, &mime_type); + else if (item_number == 5) + g_variant_get(message, "(iiiss)", &item, &pid, &update_type, &update_path, &uuid); + else if (item_number == 4) + g_variant_get(message, "(iiis)", &item, &pid, &update_type, &update_path); + + if (item == MS_MEDIA_ITEM_DIRECTORY) + content_type = MS_MEDIA_UNKNOWN; + + /* getting data complete */ + user_cb(pid, + item, + update_type, + update_path, + uuid, + content_type, + mime_type, + userdata); + + MS_SAFE_FREE(update_path); + MS_SAFE_FREE(uuid); + MS_SAFE_FREE(mime_type); } -static DBusHandlerResult -__message_filter (DBusConnection *connection, DBusMessage *message, void *user_data) +static void __message_filter(GDBusConnection* connection, + const gchar* sender_name, + const gchar* object_path, + const gchar* interface_name, + const gchar* signal_name, + GVariant* parameters, + gpointer user_data) { - db_update_cb user_cb = ((noti_callback_data*)user_data)->user_callback; - void *userdata = ((noti_callback_data*)user_data)->user_data; - DBusHandlerResult ret; - - ret = __get_message(message, user_cb, userdata); + if (__gdbus_message_is_signal(interface_name, signal_name)) { + db_update_cb user_cb = ((noti_callback_data*)user_data)->user_callback; + void *userdata = ((noti_callback_data*)user_data)->user_data; - return ret; + __get_message(parameters, user_cb, userdata); + } } - int media_db_update_subscribe(db_update_cb user_cb, void *user_data) { int ret = MS_MEDIA_ERR_NONE; - DBusError error; + GError *error = NULL; noti_callback_data *callback_data = NULL; - g_static_mutex_lock(¬i_mutex); + g_mutex_lock(¬i_mutex); if (g_bus == NULL) { - dbus_g_thread_init(); - - dbus_error_init (&error); - - g_bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); + g_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (!g_bus) { - MSAPI_DBG ("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free (&error); - ret = MS_MEDIA_ERR_DBUS_GET; + MSAPI_DBG ("Failed to connect to the g D-BUS daemon: %s", error->message); + g_error_free (error); + ret = MS_MEDIA_ERR_INTERNAL; goto ERROR; } - dbus_connection_setup_with_g_main (g_bus, NULL); - MS_MALLOC(callback_data, sizeof(noti_callback_data)); if (callback_data == NULL) { MSAPI_DBG_ERR("MS_MALLOC failed"); - ret = MS_MEDIA_ERR_ALLOCATE_MEMORY_FAIL; + ret = MS_MEDIA_ERR_OUT_OF_MEMORY; goto ERROR; } callback_data->user_callback = user_cb; callback_data->user_data = user_data; /* 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)) { - dbus_bus_remove_match (g_bus, MS_MEDIA_DBUS_MATCH_RULE, NULL); - ret = MS_MEDIA_ERR_DBUS_ADD_FILTER; - goto ERROR; - } + g_handler = g_dbus_connection_signal_subscribe( + g_bus, + NULL, + MS_MEDIA_DBUS_INTERFACE, + MS_MEDIA_DBUS_NAME, + MS_MEDIA_DBUS_PATH, + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + __message_filter, + callback_data, + NULL); g_data_store = (void *)callback_data; } ref_count ++; - g_static_mutex_unlock(¬i_mutex); + g_mutex_unlock(¬i_mutex); return MS_MEDIA_ERR_NONE; ERROR: if (g_bus != NULL) { - dbus_connection_unref(g_bus); + g_object_unref(g_bus); g_bus = NULL; } MS_SAFE_FREE(callback_data); - g_static_mutex_unlock(¬i_mutex); + g_mutex_unlock(¬i_mutex); return ret; } @@ -212,19 +172,21 @@ int media_db_update_unsubscribe(void) return MS_MEDIA_ERR_NONE; } - g_static_mutex_lock(¬i_mutex); + g_mutex_lock(¬i_mutex); if (ref_count == 1) { - dbus_connection_remove_filter(g_bus, __message_filter, g_data_store); - dbus_bus_remove_match (g_bus, MS_MEDIA_DBUS_MATCH_RULE, NULL); - dbus_connection_unref(g_bus); - + g_dbus_connection_signal_unsubscribe(g_bus, g_handler); + g_object_unref(g_bus); g_bus = NULL; + + /*Release Callback*/ + MS_SAFE_FREE(g_data_store); + g_data_store = NULL; } ref_count --; - g_static_mutex_unlock(¬i_mutex); + g_mutex_unlock(¬i_mutex); return MS_MEDIA_ERR_NONE; } @@ -238,82 +200,156 @@ int media_db_update_send(int pid, /* mandatory */ char *mime_type /* optional */ ) { - DBusMessage *message = NULL; - DBusConnection *bus = NULL; - DBusError error; - unsigned char *path_array = NULL; - int path_length = strlen(path) + 1; - - /* Get a connection to the session bus */ - dbus_error_init (&error); - bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); + GVariant *message = NULL; + GDBusConnection *bus = NULL; + GError *error = NULL; + + bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &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; + MSAPI_DBG ("Failed to get gdbus connection: %s", error->message); + g_error_free (error); + return MS_MEDIA_ERR_INTERNAL; } - message = dbus_message_new_signal (MS_MEDIA_DBUS_PATH, MS_MEDIA_DBUS_INTERFACE, MS_MEDIA_DBUS_NAME); - if (message != NULL) { - path_array = malloc(sizeof(unsigned char) * path_length); - memcpy(path_array, path, path_length); - - if (item == MS_MEDIA_ITEM_FILE) { - MSAPI_DBG("FILE CHANGED"); - if (uuid != NULL && mime_type != 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, - 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"); - MS_SAFE_FREE(path_array); - dbus_message_unref (message); - 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, - 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_ARRAY, DBUS_TYPE_BYTE, &path_array, path_length, - DBUS_TYPE_INVALID); - } + message = g_variant_new("(iiissis)", item, pid, update_type, path, uuid, media_type, mime_type); + } 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) { + message = g_variant_new("(iiiss)", item, pid, update_type, path, uuid); } else { - MSAPI_DBG("this request is wrong"); + message = g_variant_new("(iiis)", item, pid, update_type, path); } + } else { + MSAPI_DBG("this request is wrong"); + } - MS_SAFE_FREE(path_array); + gboolean emmiting = g_dbus_connection_emit_signal( + bus, + NULL, + MS_MEDIA_DBUS_PATH, + MS_MEDIA_DBUS_INTERFACE, + MS_MEDIA_DBUS_NAME, + message, + &error); + if (!emmiting) + { + MSAPI_DBG_ERR("g_dbus_connection_emit_signal failed : %s", error?error->message:"none"); + if (error) + { + MSAPI_DBG_ERR("Error in g_dbus_connection_emit_signal"); + g_object_unref(bus); + g_error_free(error); + } + return MS_MEDIA_ERR_INTERNAL; + } + MSAPI_DBG("success send notification"); + + gboolean flush = FALSE; + flush = g_dbus_connection_flush_sync(bus, NULL, &error); + if (!flush) + { + MSAPI_DBG_ERR("g_dbus_connection_flush_sync failed"); + if (error) + { + MSAPI_DBG_ERR("error : [%s]", error->message); + g_object_unref(bus); + g_error_free(error); + return MS_MEDIA_ERR_INTERNAL; + } + } - /* Send the signal */ - dbus_connection_send (bus, message, NULL); + g_object_unref(bus); - /* 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 MS_MEDIA_ERR_NONE; +} + +int media_db_update_send_v2(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 */ + ) +{ + GVariant *message = NULL; + GDBusConnection *bus = NULL; + GError *error = NULL; - MSAPI_DBG("success send notification"); + bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (!bus) { + MSAPI_DBG ("Failed to get gdbus connection: %s", error->message); + g_error_free (error); + return MS_MEDIA_ERR_INTERNAL; + } + + if (item == MS_MEDIA_ITEM_FILE) { + MSAPI_DBG("FILE CHANGED"); + if (uuid != NULL && mime_type != NULL) { + /* fill all datas */ + message = g_variant_new("(iiissis)", item, pid, update_type, path, uuid, media_type, mime_type); + } 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) { + message = g_variant_new("(iiiss)", item, pid, update_type, path, uuid); + } else { + message = g_variant_new("(iiis)", item, pid, update_type, path); + } } else { - MSAPI_DBG_ERR("dbus_message_new_signal failed"); + MSAPI_DBG("this request is wrong"); + } + + gboolean emmiting = g_dbus_connection_emit_signal( + bus, + NULL, + MS_MEDIA_DBUS_PATH, + MS_MEDIA_DBUS_INTERFACE, + MS_MEDIA_DBUS_NAME, + message, + &error); + if (!emmiting) + { + MSAPI_DBG_ERR("g_dbus_connection_emit_signal failed : %s", error?error->message:"none"); + if (error) + { + MSAPI_DBG_ERR("Error in g_dbus_connection_emit_signal"); + g_object_unref(bus); + g_error_free(error); + } + return MS_MEDIA_ERR_INTERNAL; + } + MSAPI_DBG("success send notification"); + + gboolean flush = FALSE; + flush = g_dbus_connection_flush_sync(bus, NULL, &error); + if (!flush) + { + MSAPI_DBG_ERR("g_dbus_connection_flush_sync failed"); + if (error) + { + MSAPI_DBG_ERR("error : [%s]", error->message); + g_object_unref(bus); + g_error_free(error); + return MS_MEDIA_ERR_INTERNAL; + } } - dbus_connection_unref(bus); + g_object_unref(bus); /* Return TRUE to tell the event loop we want to be called again */ return MS_MEDIA_ERR_NONE; diff --git a/lib/media-util-register.c b/lib/media-util-register.c index 9254209..0b287c7 100755 --- a/lib/media-util-register.c +++ b/lib/media-util-register.c @@ -19,14 +19,6 @@ * */ -/** - * This file defines api utilities of contents manager engines. - * - * @file media-util-register.c - * @author Yong Yeon Kim(yy9875.kim@samsung.com) - * @version 1.0 - * @brief - */ #include #include #include @@ -52,6 +44,15 @@ typedef struct media_callback_data{ char *sock_path; } media_callback_data; +typedef struct media_scan_data{ + GIOChannel *src; + media_callback_data *cb_data; + int pid; + char *req_path; +} media_scan_data; + +GArray *req_list; + static bool _is_valid_path(const char *path) { if (path == NULL) @@ -61,10 +62,10 @@ static bool _is_valid_path(const char *path) return true; } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) { return true; + } else if (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) { + return true; } else return false; - - return true; } static int _check_dir_path(const char *dir_path) @@ -134,11 +135,11 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data) req_result.pid = recv_msg.pid; req_result.result = recv_msg.result; if (recv_msg.msg_type ==MS_MSG_SCANNER_RESULT) { - req_result.complete_path = strndup(recv_msg.msg, MAX_FILEPATH_LEN); + req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size); req_result.request_type = MEDIA_DIRECTORY_SCAN; MSAPI_DBG("complete_path :%d", req_result.complete_path); } else if (recv_msg.msg_type == MS_MSG_SCANNER_BULK_RESULT) { - req_result.complete_path = strndup(recv_msg.msg, MAX_FILEPATH_LEN); + req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size); req_result.request_type = MEDIA_FILES_REGISTER; } @@ -173,13 +174,118 @@ ERROR: return TRUE; } -static int _attach_callback(int *sockfd, char* sock_path, scan_complete_cb user_callback, void *user_data) +static int _add_request(const char * req_path, media_callback_data *cb_data, GIOChannel *channel) +{ + media_scan_data *req_data = NULL; + + if (req_list == NULL) { + req_list = g_array_new(FALSE, FALSE, sizeof(media_scan_data*)); + } + + if (req_list == NULL) { + MSAPI_DBG_ERR("g_array_new falied"); + return MS_MEDIA_ERR_OUT_OF_MEMORY; + } + + req_data = malloc(sizeof(media_scan_data)); + if (req_data == NULL) { + MSAPI_DBG_ERR("malloc falied"); + return MS_MEDIA_ERR_OUT_OF_MEMORY; + } + + req_data->cb_data = cb_data; + req_data->req_path = strdup(req_path); + req_data->src = channel; + + g_array_append_val(req_list, req_data); + + return MS_MEDIA_ERR_NONE; + +} + +static int _remove_request(const char * req_path) +{ + media_scan_data *req_data = NULL; + media_callback_data *cb_data = NULL; + char *sock_path = NULL; + int i = 0; + int list_len = 0; + bool flag = false; + scan_complete_cb user_callback; + void *user_data = NULL; + GSource *source = NULL; + GIOChannel *src = NULL; + media_request_result_s req_result; + + if (req_list == NULL) { + MSAPI_DBG_ERR("The request list is NULL. This is invalid operation."); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + list_len = req_list->len; + + for (i = 0; i < list_len; i++) { + req_data = g_array_index(req_list, media_scan_data*, i); + if (strcmp(req_data->req_path, req_path) == 0) { + flag = true; + g_array_remove_index (req_list, i); + } + } + + if (flag == false) { + MSAPI_DBG("Not in scan queue :%s", req_path); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + req_result.pid = -1; + req_result.result = MS_MEDIA_ERR_NONE; + req_result.complete_path = strndup(req_path, strlen(req_path)); + req_result.request_type = MEDIA_FILES_REGISTER; + + src = req_data->src; + cb_data = req_data->cb_data; + source = ((media_callback_data *)cb_data)->source; + sock_path = ((media_callback_data *)cb_data)->sock_path; + user_callback = ((media_callback_data *)cb_data)->user_callback; + user_data = ((media_callback_data *)cb_data)->user_data; + + /*call user define function*/ + user_callback(&req_result, user_data); + + + /*close an IO channel*/ + g_io_channel_shutdown(src, FALSE, NULL); + g_io_channel_unref(src); + + g_source_destroy(source); + + if (sock_path != NULL) { + MSAPI_DBG("delete path :%s", sock_path); + unlink(sock_path); + MS_SAFE_FREE(sock_path); + } + + MS_SAFE_FREE(req_data->req_path); + MS_SAFE_FREE(req_data); + + return MS_MEDIA_ERR_NONE; + +} + +static int _attach_callback(const char *req_path, int *sockfd, char* sock_path, scan_complete_cb user_callback, void *user_data) { GIOChannel *channel = NULL; GMainContext *context = NULL; GSource *source = NULL; media_callback_data *cb_data; + cb_data = malloc(sizeof(media_callback_data)); + if (cb_data == NULL) { + MSAPI_DBG_ERR("Malloc failed"); + return MS_MEDIA_ERR_OUT_OF_MEMORY; + } + memset(cb_data, 0, sizeof(media_callback_data)); + /*get the global default main context*/ context = g_main_context_default(); @@ -187,7 +293,6 @@ static int _attach_callback(int *sockfd, char* sock_path, scan_complete_cb user_ channel = g_io_channel_unix_new(*sockfd); source = g_io_create_watch(channel, G_IO_IN); - cb_data = malloc(sizeof(media_callback_data)); cb_data->source = source; cb_data->user_callback = user_callback; cb_data->user_data = user_data; @@ -198,10 +303,12 @@ static int _attach_callback(int *sockfd, char* sock_path, scan_complete_cb user_ g_source_attach(source, context); g_source_unref(source); + _add_request(req_path, cb_data, channel); + return MS_MEDIA_ERR_NONE; } -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) +static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *storage_id, const char *request_msg, scan_complete_cb user_callback, void *user_data) { int ret = MS_MEDIA_ERR_NONE; int request_msg_size = 0; @@ -217,7 +324,7 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *r return MS_MEDIA_ERR_INVALID_PARAMETER; } - MSAPI_DBG("REQUEST DIRECTORY SCANNING"); + MSAPI_DBG("REQUEST DIRECTORY SCANNING[%s]", request_msg); request_msg_size = strlen(request_msg); if(request_msg_size >= MAX_MSG_SIZE) @@ -233,6 +340,9 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *r send_msg.pid = syscall(__NR_getpid); send_msg.msg_size = request_msg_size; strncpy(send_msg.msg, request_msg, request_msg_size); + if (storage_id != NULL) { + strncpy(send_msg.storage_id, storage_id, MS_UUID_SIZE -1); + } /*Create Socket*/ ret = ms_ipc_create_client_socket(MS_PROTOCOL_TCP, 0, &sock_info); @@ -249,15 +359,64 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *r return ret; } - ret = _attach_callback(&sockfd, sock_path, user_callback ,user_data); + ret = _attach_callback(request_msg, &sockfd, sock_path, user_callback ,user_data); if(ret != MS_MEDIA_ERR_NONE) return ret; return ret; } +static int __media_db_request_update_cancel(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 port = MS_SCANNER_PORT; + ms_comm_msg_s send_msg; + ms_sock_info_s sock_info; + + if(!MS_STRING_VALID(request_msg)) + { + MSAPI_DBG_ERR("invalid query"); + return MS_MEDIA_ERR_INVALID_PARAMETER; + } + + MSAPI_DBG("REQUEST CANCEL DIRECTORY SCANNING[%s]", request_msg); + + 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; + } + + 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_TCP, 0, &sock_info); + sockfd = sock_info.sock_fd; + + MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); + + ret = ms_ipc_send_msg_to_server_tcp(sockfd, port, &send_msg, NULL); + ms_ipc_delete_client_socket(&sock_info); + if (ret != MS_MEDIA_ERR_NONE) { + MSAPI_DBG_ERR("ms_ipc_send_msg_to_server failed : %d", ret); + return ret; + } + + ret = _remove_request(request_msg); + if(ret != MS_MEDIA_ERR_NONE) + return ret; -int media_directory_scanning_async(const char *directory_path, bool recursive_on, scan_complete_cb user_callback, void *user_data) + return ret; +} + +int media_directory_scanning_async(const char *directory_path, const char *storage_id, bool recursive_on, scan_complete_cb user_callback, void *user_data) { int ret = MS_MEDIA_ERR_NONE; @@ -266,9 +425,22 @@ int media_directory_scanning_async(const char *directory_path, bool recursive_on return ret; if (recursive_on == TRUE) - ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING, directory_path, user_callback, user_data); + ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING, storage_id, 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); + ret = __media_db_request_update_async(MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, storage_id, directory_path, user_callback, user_data); + + return ret; +} + +int media_directory_scanning_cancel(const char *directory_path) +{ + int ret = MS_MEDIA_ERR_NONE; + + ret = _check_dir_path(directory_path); + if(ret != MS_MEDIA_ERR_NONE) + return ret; + + ret = __media_db_request_update_cancel(MS_MSG_DIRECTORY_SCANNING_CANCEL, directory_path); return ret; } @@ -277,7 +449,7 @@ int media_files_register(const char *list_path, insert_complete_cb user_callback { int ret = MS_MEDIA_ERR_NONE; - ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, list_path, user_callback, user_data); + ret = __media_db_request_update_async(MS_MSG_BULK_INSERT, NULL, list_path, user_callback, user_data); MSAPI_DBG("client receive: %d", ret); @@ -288,11 +460,10 @@ int media_burstshot_register(const char *list_path, insert_complete_cb user_call { int ret = MS_MEDIA_ERR_NONE; - ret = __media_db_request_update_async(MS_MSG_BURSTSHOT_INSERT, list_path, user_callback, user_data); + ret = __media_db_request_update_async(MS_MSG_BURSTSHOT_INSERT, NULL, list_path, user_callback, user_data); MSAPI_DBG("client receive: %d", ret); return ret; - } diff --git a/media-server.manifest b/media-server.manifest index f447e3b..1066c9f 100644 --- a/media-server.manifest +++ b/media-server.manifest @@ -5,16 +5,28 @@