Relocate ability initialization from library to daemon 80/215380/6 accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix accepted/tizen/5.5/unified/20191031.031433 accepted/tizen/5.5/unified/mobile/hotfix/20201027.065838 accepted/tizen/unified/20191018.060328 submit/tizen/20191016.081926 submit/tizen_5.5/20191031.000002 submit/tizen_5.5_mobile_hotfix/20201026.185102 tizen_5.5.m2_release
authorjiyong.min <jiyong.min@samsung.com>
Mon, 7 Oct 2019 08:04:09 +0000 (17:04 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 15 Oct 2019 06:48:43 +0000 (15:48 +0900)
 - To reduce socket communication

Change-Id: Ice9a2d6212eeb63dfd3f6e7b7b5cb9a34151ffa9

include/media_controller_client.h
include/media_controller_db.h
include/media_controller_server.h
src/media_controller_db.c
src/media_controller_server.c
svc/media_controller_db_util.c

index 164bd2c..4bd5432 100644 (file)
@@ -1839,7 +1839,8 @@ int mc_client_get_server_display_rotation(mc_client_h client, const char *server
  * @privlevel public
  * @privilege %http://tizen.org/privilege/mediacontroller.client
  *
- * @remarks The @a ability should be released using @c mc_playback_ability_destroy().
+ * @remarks The @a ability should be released using @c mc_playback_ability_destroy().\n
+ *              If the media controller server is deactivated, this function will return #MC_ABILITY_SUPPORTED_UNDECIDED.\n
  *
  * @param[in] client The handle of the media controller client
  * @param[in] server_name    The app_id of the media controller server
@@ -1933,7 +1934,8 @@ int mc_client_get_server_repeat_ability_support(mc_client_h client, const char *
  * @privilege %http://tizen.org/privilege/mediacontroller.client
  *
  * @remarks If the server's ability support is not set, the result value is #MC_ABILITY_SUPPORTED_UNDECIDED. \n
- *              It means you can send the corresponding command to the server, but it's not guaranteed that the server can handle it.
+ *              It means you can send the corresponding command to the server, but it's not guaranteed that the server can handle it. \n
+ *              If the media controller server is deactivated, this function will return #MC_ABILITY_SUPPORTED_UNDECIDED.
  *
  * @param[in] client The handle of the media controller client
  * @param[in] server_name    The app_id of the media controller server
@@ -1967,6 +1969,7 @@ int mc_client_get_server_ability_support(mc_client_h client, const char *server_
  * @privilege %http://tizen.org/privilege/mediacontroller.client
  *
  * @remarks If a display mode is not present in the @a supported_modes, then the server's support for this mode is #MC_ABILITY_SUPPORTED_NO and you can't send the corresponding command to the server. \n
+ *              If the media controller server is deactivated, this function will return #MC_ABILITY_SUPPORTED_NO.
  *
  * @param[in] client The handle of the media controller client
  * @param[in] server_name    The app_id of the media controller server
@@ -1999,6 +2002,7 @@ int mc_client_get_server_display_mode_ability(mc_client_h client, const char *se
  * @privilege %http://tizen.org/privilege/mediacontroller.client
  *
  * @remarks If a display rotation is not present in the @a supported_rotations, then the server's support for this mode is #MC_ABILITY_SUPPORTED_NO and you can't send the corresponding command to the server. \n
+ *              If the media controller server is deactivated, this function will return #MC_ABILITY_SUPPORTED_NO.
  *
  * @param[in] client The handle of the media controller client
  * @param[in] server_name    The app_id of the media controller server
index 0d8c835..5616084 100644 (file)
@@ -60,5 +60,6 @@ int _mc_db_get_subtitles_enabled(sqlite3 *handle, const char *server_name, bool
 int _mc_db_get_360_mode_enabled(sqlite3 *handle, const char *server_name, bool *enabled);
 int _mc_db_get_display_mode(sqlite3 *handle, const char *server_name, mc_display_mode_e *mode);
 int _mc_db_get_display_rotation(sqlite3 *handle, const char *server_name, mc_display_rotation_e *rotation);
+int _mc_db_get_ability(sqlite3 *handle, const char *server_name, unsigned long long *decided, unsigned long long *supported);
 
 #endif /*__TIZEN_MULTIMEDIA_MEDIA_CONTROLLER_DB_H__*/
index 03f56e0..2dcc69c 100755 (executable)
@@ -1453,6 +1453,9 @@ int mc_server_unset_search_cmd_received_cb(mc_server_h server);
 /**
  * @brief Destroys media controller server.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
+ *
+ * @remarks After the server is destroyed, all its abilities will be initialized to the default automatically.
+ *
  * @param[in] server The handle to media controller server
  * @return @c 0 on success,
  *         otherwise a negative error value
index 6450f3e..6b3a802 100644 (file)
@@ -1049,3 +1049,8 @@ int _mc_db_get_display_rotation(sqlite3 *handle, const char *server_name, mc_dis
 
        return MEDIA_CONTROLLER_ERROR_NONE;
 }
+
+int _mc_db_get_ability(sqlite3 *handle, const char *server_name, unsigned long long *decided, unsigned long long *supported)
+{
+       return __mc_db_get_ability(handle, server_name, decided, supported);
+}
index a262657..5e6a806 100644 (file)
@@ -1497,33 +1497,6 @@ int mc_server_set_display_rotation_ability(mc_server_h server, mc_display_rotati
        return MEDIA_CONTROLLER_ERROR_NONE;
 }
 
-static void __set_default_ability_support(mc_server_h server)
-{
-       int ret = MEDIA_CONTROLLER_ERROR_NONE;
-
-       ret = __mc_server_update_ability(server, MC_ABILITY_SUBTITLES, MC_ABILITY_SUPPORTED_NO, TRUE);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set subtitles ability [%d]", ret);
-
-       ret = __mc_server_update_ability(server, MC_ABILITY_360_MODE, MC_ABILITY_SUPPORTED_NO, TRUE);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set 360 mode ability [%d]", ret);
-
-       ret = __mc_server_update_ability(server, (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_LETTER_BOX), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_ORIGIN_SIZE), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_FULL_SCREEN), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_CROPPED_FULL), MC_ABILITY_SUPPORTED_NO, TRUE);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set display mode ability [%d]", ret);
-
-       ret = __mc_server_update_ability(server, (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_NONE), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_90), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_180), MC_ABILITY_SUPPORTED_NO, FALSE);
-       ret = __mc_server_update_ability(server, (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_270), MC_ABILITY_SUPPORTED_NO, TRUE);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set display rotation ability [%d]", ret);
-}
-
 int mc_server_create(mc_server_h *server)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
@@ -1544,16 +1517,10 @@ int mc_server_create(mc_server_h *server)
                return ret;
        }
 
-       __set_default_ability_support(mc_server);
-
-       /* Set default value of display*/
-       ret = _mc_db_update_server_attribute(mc_server->server_name, MC_DB_CMD_UPDATE_DISPLAY_MODE, MC_DISPLAY_MODE_FULL_SCREEN);
-       if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set display mode [%d]", ret);
-
-       ret = _mc_db_update_server_attribute(mc_server->server_name, MC_DB_CMD_UPDATE_DISPLAY_ROTATION, MC_DISPLAY_ROTATION_NONE);
+       /* Get default abilities from database */
+       ret = _mc_db_get_ability(mc_server->db_handle, mc_server->server_name, &mc_server->basic_ability.decided, &mc_server->basic_ability.supported);
        if (ret != MEDIA_CONTROLLER_ERROR_NONE)
-               mc_error("fail to set display rotation [%d]", ret);
+               mc_error("fail to get ability [%d]", ret);
 
        ret = __mc_server_send_message(mc_server, MC_DBUS_UPDATE_INTERFACE, MC_DBUS_SIGNAL_NAME_SERVER_STATE, MC_SERVER_STATE_ACTIVATE, 0, NULL);
        if (ret != MEDIA_CONTROLLER_ERROR_NONE)
index 8bf1894..54b04b6 100644 (file)
@@ -114,6 +114,41 @@ static gboolean __mc_db_is_latest(sqlite3 *handle, const char *server_name)
        return is_latest;
 }
 
+static void __mc_db_set_default_ability(unsigned long long *ability_decided, unsigned long long *ability_supported)
+{
+       unsigned long long val = 1;
+
+       /*
+        * Please set the default ability in this function.
+        *
+        * If 'ability_decieded' is set to 1, the default is #MC_ABILITY_SUPPORTED_NO.
+        * Ohterwise, the default is #MC_ABILITY_SUPPORTED_UNDECIDED.
+        * If both 'ability_decieded' and 'ability_supported' are set to 1,
+        * the default is #MC_ABILITY_SUPPORTED_YES.
+        */
+
+       /* Set default to MC_ABILITY_SUPPORTED_UNDECIDED for all abilities */
+       *ability_decided = 0;
+       *ability_supported = 0;
+
+       /* Change default to MC_ABILITY_SUPPORTED_NO */
+       *ability_decided |= (val << MC_ABILITY_SUBTITLES);
+       *ability_decided |= (val << MC_ABILITY_360_MODE);
+
+       *ability_decided |= (val << (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_LETTER_BOX));
+       *ability_decided |= (val << (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_ORIGIN_SIZE));
+       *ability_decided |= (val << (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_FULL_SCREEN));
+       *ability_decided |= (val << (DISPLAY_MODE_ABILITY + MC_DISPLAY_MODE_CROPPED_FULL));
+
+       *ability_decided |= (val << (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_NONE));
+       *ability_decided |= (val << (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_90));
+       *ability_decided |= (val << (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_180));
+       *ability_decided |= (val << (DISPLAY_ROTATION_ABILITY + MC_DISPLAY_ROTATION_270));
+
+       /* Change default to MC_ABILITY_SUPPORTED_YES */
+       /* ex) *ability_supported |= (val << MC_ABILITY_SUBTITLES); */
+}
+
 static int __mc_update_latest_server_state_to_vconf(mc_server_state_e server_state, mc_playback_states_e playback_state)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
@@ -133,12 +168,23 @@ static int __mc_update_latest_server_info_to_db(sqlite3 *handle, mc_server_state
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        char *sql_str = NULL;
+       unsigned long long ability_decided = 0, ability_supported = 0;
 
        mc_retvm_if(!handle, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "invalid handle");
 
        /* Update DB */
-       sql_str = sqlite3_mprintf("UPDATE %q SET server_state=%d, playback_state=%d WHERE name IN (SELECT name FROM %q)",
-               MC_DB_TABLE_SERVER_INFO, server_state, playback_state, MC_DB_TABLE_LATEST_SERVER);
+       if (server_state == MC_SERVER_STATE_DEACTIVATE) {
+               __mc_db_set_default_ability(&ability_decided, &ability_supported);
+               sql_str = sqlite3_mprintf("UPDATE %q SET server_state=%d, playback_state=%d, \
+                       display_mode=%d, display_rotation=%d, ability_decided=%llu, ability_supported=%llu \
+                       WHERE name IN (SELECT name FROM %q)",
+                       MC_DB_TABLE_SERVER_INFO, server_state, playback_state,
+                       MC_DISPLAY_MODE_FULL_SCREEN, MC_DISPLAY_ROTATION_NONE, ability_decided, ability_supported,
+                       MC_DB_TABLE_LATEST_SERVER);
+       } else {
+               sql_str = sqlite3_mprintf("UPDATE %q SET server_state=%d, playback_state=%d WHERE name IN (SELECT name FROM %q)",
+                       MC_DB_TABLE_SERVER_INFO, server_state, playback_state, MC_DB_TABLE_LATEST_SERVER);
+       }
 
        ret = mc_db_util_update_db(handle, sql_str);
        SQLITE3_SAFE_FREE(sql_str);
@@ -396,6 +442,7 @@ int mc_db_util_create_tables(sqlite3 *handle)
 {
        int ret = MEDIA_CONTROLLER_ERROR_NONE;
        char *sql_str = NULL;
+       unsigned long long ability_decided = 0, ability_supported = 0;
 
        mc_retvm_if(handle == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Handle is NULL");
 
@@ -410,24 +457,36 @@ int mc_db_util_create_tables(sqlite3 *handle)
        SQLITE3_SAFE_FREE(sql_str);
        mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "create app_list table failed [%d]", ret);
 
+       __mc_db_set_default_ability(&ability_decided, &ability_supported);
+
        sql_str = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s( \
                name TEXT PRIMARY KEY, \
-               server_state INTEGER DEFAULT 1, \
-               playback_state INTEGER DEFAULT 0, \
+               server_state INTEGER DEFAULT %d, \
+               playback_state INTEGER DEFAULT %d, \
                playback_position INTEGER DEFAULT 0, \
                playlist_name TEXT, playlist_index TEXT, \
-               playback_content_type INTEGER DEFAULT 4, \
-               age_rating INTEGER DEFAULT 0, \
-               shuffle_mode INTEGER DEFAULT 1, \
-               repeat_mode INTEGER DEFAULT 1, \
+               playback_content_type INTEGER DEFAULT %d, \
+               age_rating INTEGER DEFAULT %d, \
+               shuffle_mode INTEGER DEFAULT %d, \
+               repeat_mode INTEGER DEFAULT %d, \
                icon_uri TEXT, \
                subtitles_mode INTEGER DEFAULT 0, \
-               display_mode INTEGER DEFAULT 0, \
-               display_rotation INTEGER DEFAULT 0, \
+               display_mode INTEGER DEFAULT %d, \
+               display_rotation INTEGER DEFAULT %d, \
                spherical_mode INTEGER DEFAULT 0, \
-               ability_decided INTEGER DEFAULT 0, \
-               ability_supported INTEGER DEFAULT 0)",
-               MC_DB_TABLE_SERVER_INFO);
+               ability_decided INTEGER DEFAULT %llu, \
+               ability_supported INTEGER DEFAULT %llu)",
+               MC_DB_TABLE_SERVER_INFO,
+               MC_SERVER_STATE_ACTIVATE,
+               MC_PLAYBACK_STATE_NONE,
+               MC_CONTENT_TYPE_UNDECIDED,
+               MC_CONTENT_RATING_ALL,
+               MC_SHUFFLE_MODE_OFF,
+               MC_REPEAT_MODE_OFF,
+               MC_DISPLAY_MODE_FULL_SCREEN,
+               MC_DISPLAY_ROTATION_NONE,
+               ability_decided,
+               ability_supported);
 
        ret = mc_db_util_update_db(handle, sql_str);
        SQLITE3_SAFE_FREE(sql_str);
@@ -1013,4 +1072,4 @@ int mc_db_util_migration(sqlite3 *handle, const char *table_name)
        mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "mc_db_util_drop_table failed [%d]", ret);
 
        return ret;
-}
\ No newline at end of file
+}