Modify shift operation to use 64-bit operand 96/207696/2
authorjiyong.min <jiyong.min@samsung.com>
Tue, 11 Jun 2019 07:44:33 +0000 (16:44 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 14 Jun 2019 04:09:39 +0000 (13:09 +0900)
Change-Id: Ie5efa19b8c59a9ca8d79f0ac7332eef7da3b3c7b

include/media_controller_private.h
src/media_controller_db.c
src/media_controller_metadata.c [changed mode: 0755->0644]
src/media_controller_server.c
src/media_controller_util.c

index 9c68c8b..e32ca57 100644 (file)
@@ -256,18 +256,7 @@ extern "C" {
 
 #define MC_BIT64_UNSET         0x0000000000000000
 #define MC_BIT64_SET           0x0000000000000001
-#define MC_BIT64_IS_OK(x)      ((x < 64) ? TRUE : FALSE)
-#define MC_BIT64_IS_TRUE(a, b) (((a >> b) & MC_BIT64_SET) ? TRUE : FALSE)
-#define MC_BIT64_SET_BIT(a, b) \
-       do { \
-               if (MC_BIT64_IS_OK(b)) \
-                       (a |= ((MC_BIT64_SET << b))); \
-       } while (0)
-#define MC_BIT64_UNSET_BIT(a, b) \
-       do { \
-               if (MC_BIT64_IS_OK(b)) \
-                       (a &= ~((MC_BIT64_SET << b))); \
-       } while (0)
+#define MC_SHIFT_IS_OK(x)      ((x < 32) ? TRUE : FALSE)
 
 typedef struct {
        void *callback;
@@ -333,7 +322,7 @@ typedef enum {
        MC_SERVER_EVENT_MAX,
 } mc_server_receive_event_e;
 
-#define PLAYBACK_ACTION_ABILITY        MC_SERVER_EVENT_PLAYBACK_ACTION + 20
+#define PLAYBACK_ACTION_ABILITY        MC_SERVER_EVENT_PLAYBACK_ACTION + 30
 
 typedef struct {
        char *server_name;
@@ -413,6 +402,8 @@ char *mc_util_generate_uuid(void);
 int mc_util_bundle_to_string(bundle *bundle_data, char **str_data);
 gboolean _mc_util_is_valid_playback_action(mc_playback_action_e action);
 gboolean _mc_util_is_valid_subscription_type(const mc_subscription_type_e subscription_type);
+void _mc_util_set_bit(int bit_num, gboolean set, unsigned long long *value);
+gboolean _mc_util_is_true_bit(unsigned long long value, int bit_num);
 
 /* for d-bus IPC */
 int mc_ipc_get_dbus_connection(GDBusConnection **conn, int *dref_count);
index ddddba3..e6d3bc8 100644 (file)
@@ -485,11 +485,11 @@ int mc_db_get_ability_supported(sqlite3 *handle, const char *server_name, mc_ser
        ret = __mc_db_get_ability(handle, server_name, &_decided, &_supported);
        mc_retvm_if(ret != MEDIA_CONTROLLER_ERROR_NONE, ret, "__mc_db_get_ability failed");
 
-       mc_secure_debug("IsDecided: %d", MC_BIT64_IS_TRUE(_decided, ability));
-       mc_secure_debug("IsSupported: %d", MC_BIT64_IS_TRUE(_supported, ability));
+       mc_secure_debug("IsDecided: %d", _mc_util_is_true_bit(_decided, ability));
+       mc_secure_debug("IsSupported: %d", _mc_util_is_true_bit(_supported, ability));
 
-       if (MC_BIT64_IS_TRUE(_decided, ability)) {
-               if (MC_BIT64_IS_TRUE(_supported, ability))
+       if (_mc_util_is_true_bit(_decided, ability)) {
+               if (_mc_util_is_true_bit(_supported, ability))
                        *supported = MC_ABILITY_SUPPORTED_YES;
                else
                        *supported = MC_ABILITY_SUPPORTED_NO;
old mode 100755 (executable)
new mode 100644 (file)
index 474ec3e..9cbb894
@@ -289,11 +289,11 @@ int mc_playback_action_is_supported(mc_playback_ability_h ability, mc_playback_a
        mc_retvm_if(!_mc_util_is_valid_playback_action(action), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "Invalid action");
        mc_retvm_if(supported == NULL, MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "supported is NULL");
 
-       mc_secure_debug("IsDecided: %d", MC_BIT64_IS_TRUE(mc_ability->decided, (PLAYBACK_ACTION_ABILITY + action)));
-       mc_secure_debug("IsSupported: %d", MC_BIT64_IS_TRUE(mc_ability->supported, (PLAYBACK_ACTION_ABILITY + action)));
+       mc_secure_debug("IsDecided: %d", _mc_util_is_true_bit(mc_ability->decided, (PLAYBACK_ACTION_ABILITY + action)));
+       mc_secure_debug("IsSupported: %d", _mc_util_is_true_bit(mc_ability->supported, (PLAYBACK_ACTION_ABILITY + action)));
 
-       if (MC_BIT64_IS_TRUE(mc_ability->decided, (PLAYBACK_ACTION_ABILITY + action))) {
-               if (MC_BIT64_IS_TRUE(mc_ability->supported, (PLAYBACK_ACTION_ABILITY + action)))
+       if (_mc_util_is_true_bit(mc_ability->decided, (PLAYBACK_ACTION_ABILITY + action))) {
+               if (_mc_util_is_true_bit(mc_ability->supported, (PLAYBACK_ACTION_ABILITY + action)))
                        *supported = MC_ABILITY_SUPPORTED_YES;
                else
                        *supported = MC_ABILITY_SUPPORTED_NO;
index f1b3a38..10f5d40 100644 (file)
@@ -1113,13 +1113,13 @@ static int __mc_server_update_ability(mc_server_h server, int support_item, mc_a
        mc_retvm_if(((support != MC_ABILITY_SUPPORTED_YES) && (support != MC_ABILITY_SUPPORTED_NO)), MEDIA_CONTROLLER_ERROR_INVALID_PARAMETER, "support is invalid [%d]", support);
 
        /* Change decided bit to 1(set) */
-       MC_BIT64_SET_BIT(mc_server->basic_ability.decided, support_item);
+       _mc_util_set_bit(support_item, TRUE, &mc_server->basic_ability.decided);
 
        /* if support is supported_yes, change supported bit to 1(set), otherwise change supported bit to 0(unset) */
        if (support == MC_ABILITY_SUPPORTED_YES)
-               MC_BIT64_SET_BIT(mc_server->basic_ability.supported, support_item);
+               _mc_util_set_bit(support_item, TRUE, &mc_server->basic_ability.supported);
        else
-               MC_BIT64_UNSET_BIT(mc_server->basic_ability.supported, support_item);
+               _mc_util_set_bit(support_item, FALSE, &mc_server->basic_ability.supported);
 
        if (immediate_update)
                return mc_db_update_ability_supported(mc_server->server_name, mc_server->basic_ability);
index a440397..5d4c489 100644 (file)
@@ -240,3 +240,41 @@ gboolean _mc_util_is_valid_subscription_type(const mc_subscription_type_e subscr
 
        return TRUE;
 }
+
+void _mc_util_set_bit(int bit_num, gboolean set, unsigned long long *value)
+{
+       int i = 0;
+       unsigned long long lshift = MC_BIT64_SET;
+
+       mc_retm_if(!value, "Invalid value");
+       mc_retm_if((bit_num < 0 || bit_num >= 64), "Invalid bit [%d]", bit_num);
+
+       if (MC_SHIFT_IS_OK(bit_num)) {
+               lshift = (lshift << bit_num);
+       } else {
+               for (i = 0; i < bit_num; i++)
+                       lshift = (lshift << 1);
+       }
+
+       if (set)
+               *value |= lshift;
+       else
+               *value &= ~lshift;
+}
+
+gboolean _mc_util_is_true_bit(unsigned long long value, int bit_num)
+{
+       int i = 0;
+       unsigned long long rshift = value;
+
+       mc_retvm_if((bit_num < 0 || bit_num >= 64), FALSE, "Invalid bit [%d]", bit_num);
+
+       if  (MC_SHIFT_IS_OK(bit_num)) {
+               rshift = (rshift >> bit_num);
+       } else {
+               for (i = 0; i < bit_num; i++)
+                       rshift = (rshift >> 1);
+       }
+
+       return ((rshift & MC_BIT64_SET) ? TRUE : FALSE);
+}