Redesign theme event callback 01/237001/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 24 Jun 2020 04:28:35 +0000 (13:28 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 24 Jun 2020 05:48:00 +0000 (14:48 +0900)
Remove unloaded callback, rename loaded callback to changed callback.
When current theme changed, the changed callback will be invoked.

Change-Id: Ib528b63bdcae7a161e6bb9ef36130fe9f5d22605
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/api/theme_loader.cc
src/api/theme_loader.h
src/theme/dbus/command.h
src/theme/loader/theme_event.h
src/theme/loader/theme_info_loader.cc
src/theme/loader/theme_info_loader.h
test/unit_tests/test_request_broker.cc
test/unit_tests/test_theme_info_loader.cc

index e2c4837..f0d2c64 100644 (file)
@@ -43,23 +43,17 @@ namespace {
 
 class ThemeEventHandler : public IThemeEvent {
  public:
-  explicit ThemeEventHandler(theme_loader_loaded_cb loaded_cb,
-      theme_loader_unloaded_cb unloaded_cb, void* user_data)
-    : loaded_cb_(loaded_cb), unloaded_cb_(unloaded_cb), userdata_(user_data) {}
+  explicit ThemeEventHandler(theme_loader_changed_cb changed_cb,
+      void* user_data) : changed_cb_(changed_cb), userdata_(user_data) {}
   virtual ~ThemeEventHandler() = default;
-  void OnThemeLoaded(const ThemeInfo* theme,
+  void OnThemeChanged(const ThemeInfo* theme,
       const tizen_base::Bundle& args) override {
     std::shared_ptr<ThemeInfo> shared_info(new ThemeInfo(*theme));
-    loaded_cb_(static_cast<theme_h>(&shared_info), userdata_);
-  }
-
-  void OnThemeUnloaded(const std::string& id) override {
-    unloaded_cb_(id.c_str(), userdata_);
+    changed_cb_(static_cast<theme_h>(&shared_info), userdata_);
   }
 
  private:
-  theme_loader_loaded_cb loaded_cb_;
-  theme_loader_unloaded_cb unloaded_cb_;
+  theme_loader_changed_cb changed_cb_;
   void* userdata_;
 };
 
@@ -164,16 +158,15 @@ extern "C" EXPORT_API int theme_loader_query_id(theme_loader_h handle,
 }
 
 extern "C" EXPORT_API int theme_loader_add_event(theme_loader_h handle,
-    theme_loader_loaded_cb loaded, theme_loader_unloaded_cb unloaded,
-    void* user_data, theme_loader_event_h* event_h) {
-  if (handle == nullptr || loaded == nullptr ||
-      unloaded == nullptr || event_h == nullptr) {
+    theme_loader_changed_cb changed, void* user_data,
+    theme_loader_event_h* event_h) {
+  if (handle == nullptr || changed == nullptr || event_h == nullptr) {
     LOG(ERROR) << "Invalid parameter";
     return THEME_MANAGER_ERROR_INVALID_PARAMETER;
   }
 
   std::shared_ptr<IThemeEvent> event_handler(new ThemeEventHandler(
-      loaded, unloaded, user_data));
+      changed, user_data));
   if (event_handler.get() == nullptr) {
     LOG(ERROR) << "Out of memory";
     return THEME_MANAGER_ERROR_OUT_OF_MEMORY;
index dd9fdc1..68f6007 100644 (file)
@@ -33,32 +33,19 @@ extern "C" {
  */
 
 /**
- * @brief Called to get the loaded theme information.
+ * @brief Called to get the changed theme information.
  * @since_tizen 6.0
  * @remarks The @a handle should not be released
  * @remarks @handle is valid only inside this function. If you want to keep it,
- *         please use theme_clone().
- * @param[in] handle    The loaded theme information.
+ *          please use theme_clone().
+ * @param[in] handle    The changed theme information.
  * @param[in] user_data The user data passed from add event function.
  * @return @c 0 on success,
  *         otherwise a negative value.
  * @pre theme_loader_add_event() will invoke this callback.
  * @see theme_loader_add_event()
  */
-typedef int (*theme_loader_loaded_cb) (theme_h handle, void *user_data);
-
-/**
- * @brief Called to get the unloaded theme ID.
- * @since_tizen 6.0
- * @remarks The @a id can be used only in the callback. To use outside, make a copy.
- * @param[in] id        The ID of unloaded theme.
- * @param[in] user_data The user data passed from add event function.
- * @return @c 0 on success,
- *         otherwise a negative value.
- * @pre theme_loader_add_event() will invoke this callback.
- * @see theme_loader_add_event()
- */
-typedef int (*theme_loader_unloaded_cb) (const char *id, void *user_data);
+typedef int (*theme_loader_changed_cb) (theme_h handle, void *user_data);
 
 /**
  * @brief The theme loader handle.
@@ -99,11 +86,10 @@ int theme_loader_create(theme_loader_h *handle);
 int theme_loader_destroy(theme_loader_h handle);
 
 /**
- * @brief Registers a callback function to be invoked when the theme is being loaded or unloaded.
+ * @brief Registers a callback function to be invoked when the theme is being changed.
  * @since_tizen 6.0
  * @param[in] handle    The theme loader handle
- * @param[in] loaded    The callback function to be registered for theme load event
- * @param[in] unloaded  The callback function to be registered for theme unload event
+ * @param[in] changed   The callback function to be registered for theme changed event
  * @param[in] user_data The user data to be passed to the callback function
  * @param[out] event_h  The theme event handle
  * @return @c 0 on success,
@@ -114,8 +100,8 @@ int theme_loader_destroy(theme_loader_h handle);
  * @see theme_loader_remove_event()
 */
 int theme_loader_add_event(theme_loader_h handle,
-    theme_loader_loaded_cb loaded, theme_loader_unloaded_cb unloaded,
-    void *user_data, theme_loader_event_h* event_h);
+    theme_loader_changed_cb changed, void *user_data,
+    theme_loader_event_h* event_h);
 
 /**
  * @brief Unregisters a callback function.
index 3e79b70..8192669 100644 (file)
@@ -29,7 +29,6 @@ enum class Command : int {
   UPDATE,
   REMOVE,
   CHANGED,
-  REMOVED
 };
 
 extern const char kCmdDataKey[];
index f1f37ce..c0dbbb3 100644 (file)
@@ -28,9 +28,8 @@ namespace loader {
 class IThemeEvent {
  public:
   virtual ~IThemeEvent() = default;
-  virtual void OnThemeLoaded(const ThemeInfo* info,
+  virtual void OnThemeChanged(const ThemeInfo* info,
       const tizen_base::Bundle& args) = 0;
-  virtual void OnThemeUnloaded(const std::string& id) = 0;
 };
 
 }  // namespace loader
index 502318e..dc1bc3b 100644 (file)
@@ -34,19 +34,11 @@ tizen_base::Bundle ThemeInfoLoader::OnRequest(dbus::Command cmd,
       const ThemeInfo* info = new ThemeInfo(b);
       for (auto& listener : listeners_) {
         std::shared_ptr<IThemeEvent> ev = listener.second;
-        ev->OnThemeLoaded(info, args);
+        ev->OnThemeChanged(info, args);
       }
       delete info;
       break;
     }
-    case dbus::Command::REMOVED: {
-      std::string id = args.GetString(dbus::kCmdDataKey);
-      for (auto& listener : listeners_) {
-        std::shared_ptr<IThemeEvent> ev = listener.second;
-        ev->OnThemeUnloaded(id);
-      }
-      break;
-    }
     default: {
       LOG(ERROR) << "Invalid command type";
       break;
@@ -66,13 +58,6 @@ std::string ThemeInfoLoader::AddEvent(std::shared_ptr<IThemeEvent> ev) {
       dbus::RequestBroker::GetInst().RegisterRequestFilter(*changed_filter_);
   }
 
-  if (removed_filter_ == nullptr) {
-    removed_filter_ =
-        std::make_unique<dbus::RequestFilter>(dbus::Command::REMOVED,
-            shared_from_this(), false);
-    dbus::RequestBroker::GetInst().RegisterRequestFilter(*removed_filter_);
-  }
-
   std::size_t hash = std::hash<std::shared_ptr<IThemeEvent>>{}(ev);
   std::string key(std::to_string(hash));
   listeners_.insert(std::make_pair(key, std::move(ev)));
index 6049cc4..92a3d02 100644 (file)
@@ -49,7 +49,6 @@ class ThemeInfoLoader : public dbus::IRequestHandler,
 
   std::shared_ptr<ThemeInfo> cache_;
   std::unique_ptr<dbus::RequestFilter> changed_filter_;
-  std::unique_ptr<dbus::RequestFilter> removed_filter_;
   std::map<std::string, std::shared_ptr<IThemeEvent>> listeners_;
 };
 
index 45e525f..a7d4f07 100644 (file)
@@ -53,7 +53,7 @@ static guint __g_dbus_connection_signal_subscribe_fake(
     gpointer user_data, GDestroyNotify noti) {
   tizen_base::Bundle b;
   GVariant* param = g_variant_new("(is)",
-      static_cast<int>(ttm::dbus::Command::REMOVED),
+      static_cast<int>(ttm::dbus::Command::CHANGED),
       reinterpret_cast<char*>(b.ToRaw().first.get()));
   callback(nullptr, nullptr, nullptr, nullptr, nullptr, param, user_data);
   return 1;
index 5c8d5e1..ed49a02 100644 (file)
@@ -36,12 +36,9 @@ using ::testing::StrEq;
 
 class ThemeEvent : public IThemeEvent {
  public:
-  void OnThemeLoaded(const ThemeInfo* theme,
+  void OnThemeChanged(const ThemeInfo* theme,
       const tizen_base::Bundle& args) override {
   }
-
-  void OnThemeUnloaded(const std::string& id) override {
-  }
 };
 
 class Mocks : public ::testing::NiceMock<GioMock> {};