Add ChangeVolumeActivity template, and fix AppControlActivity 42/160142/14
authorPawel Kurowski <p.kurowski2@samsung.com>
Tue, 14 Nov 2017 14:03:09 +0000 (15:03 +0100)
committerPawel Kurowski <p.kurowski2@samsung.com>
Thu, 16 Nov 2017 12:30:47 +0000 (13:30 +0100)
remove static_cast to DerivedType in AppControlActivity template

Using template allows to delete RETURN_DEFAULT_SOUND_TYPE_ON_ERROR macro

Change-Id: Icc4b8b184345da9c4dbbd271cb6f303be55f062e

src/AppControlActivity.cpp
src/VolumeControlActivity.cpp

index f9cf3ae..8936d92 100644 (file)
@@ -44,14 +44,15 @@ public:
                markAsCompleted();
        }
 
+       static int addExtraDataToCall(app_control_h handle)
+       {
+               return APP_CONTROL_ERROR_NONE;
+       }
+
 protected:
        app_control_h appControlHandle;
 
 private:
-       int addExtraDataToCall()
-       {
-               return APP_CONTROL_ERROR_NONE;
-       }
 
        void launch()
        {
@@ -64,7 +65,7 @@ private:
                status = app_control_set_app_id(appControlHandle, DerivedType::appToLaunch);
                RETURN_IF(status != APP_CONTROL_ERROR_NONE);
 
-               status = static_cast<DerivedType *>(this)->addExtraDataToCall();
+               status = DerivedType::addExtraDataToCall(appControlHandle);
                RETURN_IF(status != APP_CONTROL_ERROR_NONE);
 
                status = app_control_send_launch_request(appControlHandle, NULL, NULL);
@@ -96,14 +97,11 @@ public:
 class StartSettingsActivity : public AppControlActivity<StartSettingsActivity, false>
 {
 public:
-       friend AppControlActivity<StartSettingsActivity, false>;
-
        static constexpr const char *activityType = "START_SETTINGS";
        static constexpr const char *appToLaunch = "org.tizen.setting-accessibility";
 
-protected:
-       int addExtraDataToCall()
+       static int addExtraDataToCall(app_control_h handle)
        {
-               return app_control_add_extra_data(appControlHandle, "SHOW_US_SETTINGS", "1");
+               return app_control_add_extra_data(handle, "SHOW_US_SETTINGS", "1");
        }
 };
index a6fdb79..3c5e8a1 100644 (file)
 
 #include <sound_manager.h>
 
-#define RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(status) do {                                                                \
-               if (status != SOUND_MANAGER_ERROR_NONE) {                                                                       \
-                       if (status == SOUND_MANAGER_ERROR_NO_PLAYING_SOUND)                                             \
-                               DEBUG("Sound isn't playing on any channel");                                            \
-                       else                                                                                                                                    \
-                               ERROR("sound_manager_get_current_sound_type error: %d", status);        \
-                       return soundType;                                                                                                               \
-               }                                                                                                                                                       \
-       } while (false)
-
 template <typename DerivedType, bool bindable>
 class VolumeControlActivity : public Activity, private RegisterActivity<DerivedType, bindable>
 {
@@ -46,7 +36,7 @@ public:
                markAsCompleted();
        }
 
-       virtual sound_type_e getSoundType() const
+       static sound_type_e getSoundType()
        {
                return DerivedType::soundType;
        }
@@ -57,7 +47,7 @@ private:
                auto volume = 0;
                auto maxVolume = 0;
                auto minVolume = 0;
-               auto soundType = getSoundType();
+               auto soundType = DerivedType::getSoundType();
 
                auto status = sound_manager_get_max_volume(soundType, &maxVolume);
                RETURN_IF(status != SOUND_MANAGER_ERROR_NONE);
@@ -121,32 +111,37 @@ public:
        static constexpr const sound_type_e soundType = SOUND_TYPE_NOTIFICATION;
 };
 
-class IncreaseVolumeActivity : public VolumeControlActivity<IncreaseVolumeActivity, true>
+template <typename DerivedType, bool bindable>
+class ChangeVolumeActivity : public VolumeControlActivity<DerivedType, bindable>
 {
 public:
-       sound_type_e getSoundType() const override
+       static sound_type_e getSoundType()
        {
                sound_type_e type;
-               RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
+               auto status = sound_manager_get_current_sound_type(&type);
+               if (status != SOUND_MANAGER_ERROR_NONE) {
+                       if (status == SOUND_MANAGER_ERROR_NO_PLAYING_SOUND)
+                               DEBUG("Sound isn't playing on any channel");
+                       else
+                               ERROR("sound_manager_get_current_sound_type error: %d", status);
+
+                       type = SOUND_TYPE_RINGTONE;
+               }
+
                return type;
        }
+};
 
+class IncreaseVolumeActivity : public ChangeVolumeActivity<IncreaseVolumeActivity, true>
+{
+public:
        static constexpr const char *activityType = "INCREASE_VOLUME";
        static constexpr const int step = 1;
-       static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
 };
 
-class DecreaseVolumeActivity : public VolumeControlActivity<DecreaseVolumeActivity, true>
+class DecreaseVolumeActivity : public ChangeVolumeActivity<DecreaseVolumeActivity, true>
 {
 public:
-       sound_type_e getSoundType() const override
-       {
-               sound_type_e type;
-               RETURN_DEFAULT_SOUND_TYPE_ON_ERROR(sound_manager_get_current_sound_type(&type));
-               return type;
-       }
-
        static constexpr const char *activityType = "DECREASE_VOLUME";
        static constexpr const int step = -1;
-       static constexpr const sound_type_e soundType = SOUND_TYPE_RINGTONE;
 };