Add WatchMirror class
authorhyunho <hhstark.kang@samsung.com>
Wed, 5 Feb 2020 04:11:00 +0000 (13:11 +0900)
committerhyunho <hhstark.kang@samsung.com>
Wed, 5 Feb 2020 04:11:00 +0000 (13:11 +0900)
Signed-off-by: hyunho <hhstark.kang@samsung.com>
watch-holder/CMakeLists.txt
watch-holder/src/common.hh
watch-holder/src/sharable_watch_interface.hh [new file with mode: 0644]
watch-holder/src/watch.cc
watch-holder/src/watch.hh
watch-holder/src/watch_mirror.cc [new file with mode: 0644]
watch-holder/src/watch_mirror.hh [new file with mode: 0644]

index f6d7566..c21437e 100644 (file)
@@ -20,6 +20,7 @@ pkg_check_modules(watch-holder REQUIRED
        evas
        screen_connector_remote_surface_evas
        appsvc
+       vconf
 )
 
 AUX_SOURCE_DIRECTORY(src BUILD_SOURCE)
@@ -45,9 +46,16 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/watch.h DESTINATION include/${PROJECT_NAME})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/api/watch_holder.h DESTINATION include/${PROJECT_NAME})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/watch_holder.hh DESTINATION include/${PROJECT_NAME})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/watch.hh DESTINATION include/${PROJECT_NAME})
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING
+       PATTERN "*.hh"
+       PATTERN "*.h"
+       PATTERN "*_implementation.h" EXCLUDE
+       )
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING
+       PATTERN "*.hh"
+       PATTERN "*.h"
+       PATTERN "*_implementation.h" EXCLUDE
+       )
 
 
index 3d70a68..e1fccc3 100644 (file)
@@ -23,6 +23,7 @@
 #define EXPORT_API __attribute__((visibility("default")))
 
 #define NOTIFY_CHANGED_EVENT_END_POINT "watch_holder,changed"
-#define NOTIFY_CHANGED_EVENT_APPID "watch_holder,changed,appid"
+#define NOTIFY_CHANGED_EVENT_APPID_KEY "__NOTIFY_CHANGED_EVENT_APPID_KEY__"
+#define NOTIFY_CHANGED_EVENT_RID_KEY "__NOTIFY_CHANGED_EVENT_RID_KEY__"
 
 #endif  // __WATCH_HOLDER_COMMON_HH__
diff --git a/watch-holder/src/sharable_watch_interface.hh b/watch-holder/src/sharable_watch_interface.hh
new file mode 100644 (file)
index 0000000..9327b08
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __WATCH_HOLDER_SHARABLE_WATCH_INTERFACE_HH__
+#define __WATCH_HOLDER_SHARABLE_WATCH_INTERFACE_HH__
+
+#include <Evas.h>
+#include <bundle_cpp.h>
+
+#include <string>
+
+namespace watch_holder {
+
+class ISharableWatch {
+ public:
+  virtual void Resume() = 0;
+  virtual void Pause() = 0;
+  virtual Evas_Object* GetCurrentImage() const = 0;
+  virtual bool IsBound() = 0;
+  virtual std::string GetAppId() const = 0;
+  virtual int GetPid() const = 0;
+  virtual tizen_base::Bundle GetExtra() = 0;
+  virtual bool IsFaulted() = 0;
+};
+
+}  // namespace watch_holder
+
+#endif  // __WATCH_HOLDER_SHARABLE_WATCH_INTERFACE_HH__
\ No newline at end of file
index 2a6da1c..32cd225 100644 (file)
@@ -17,6 +17,7 @@
 #include <aul.h>
 #include <dlog.h>
 #include <aul_app_com.h>
+#include <vconf.h>
 
 #include "watch.hh"
 
@@ -27,6 +28,7 @@
 #define LOG_TAG "WATCH_HOLDER"
 
 using namespace std;
+using namespace tizen_base;
 using namespace screen_connector;
 namespace watch_holder {
 
@@ -37,6 +39,13 @@ Watch::Watch(string appid, Evas_Object* viewer_win, Watch::IEvent* listener)
     RemoteSurfaceEvas::SetAutoVisibility(false);
 }
 
+Watch::Watch(int rid, string id, string appid, Evas_Object* viewer_win, Watch::IEvent* listener)
+    : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH,
+        make_shared<screen_connector::EvasObject>(viewer_win, false)),
+        appid_(appid), listener_(listener) {
+    RemoteSurfaceEvas::SetAutoVisibility(false);
+}
+
 void Watch::Resume() {
   RemoteSurfaceEvas::NoRenderPush(200);
   RemoteSurfaceEvas::SendVisibility(true);
@@ -72,6 +81,23 @@ int Watch::GetPid() const {
   return pid_;
 }
 
+bool Watch::IsBound() {
+  return false;
+}
+
+string Watch::GetAppId() const {
+  return appid_;
+}
+
+Bundle Watch::GetExtra() {
+  Bundle b;
+  return b;
+}
+
+bool Watch::IsFaulted() {
+  return false;
+}
+
 void Watch::Bind(Evas_Object* win) {
   bind_win_ = win;
   elm_win_aux_hint_add(win, "wm.policy.win.msg.use", "1");
@@ -106,10 +132,12 @@ void Watch::OnEvasChanged(const std::string& appId, const std::string& instId,
   listener_->OnUpdated(*this);
 }
 
-int Watch::NotifyChangedEvent() {
+int Watch::NotifyChangedEvent() const {
   tizen_base::Bundle b;
-  b.Add(NOTIFY_CHANGED_EVENT_APPID, appid_);
-  int ret = aul_app_com_send(NOTIFY_CHANGED_EVENT_END_POINT, b.GetHandle());
+  b.Add(NOTIFY_CHANGED_EVENT_APPID_KEY, appid_);
+  b.Add(NOTIFY_CHANGED_EVENT_RID_KEY, to_string(GetRid()));
+  int ret = vconf_set_str(
+      VCONFKEY_WATCH_CURRENT_WATCH_INFO, (const char*)b.ToRaw().first.get());
   if (ret != 0) {
     LOGE("Fail to send noti (%d)", ret);
     return -1;
index 53aa4ae..ffd04bb 100644 (file)
 #include <screen_connector_remote_surface_evas/remote_surface_evas.h>
 
 #include "common.hh"
+#include "sharable_watch_interface.hh"
 
 namespace watch_holder {
 
-class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas {
+class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas,
+    public ISharableWatch {
  public:
   class IEvent {
    public:
@@ -37,19 +39,22 @@ class EXPORT_API Watch : private screen_connector::RemoteSurfaceEvas {
     virtual void OnRemoved(const Watch& watch) = 0;
   };
   Watch(std::string appid, Evas_Object* viewer_win, IEvent* listener);
-  void Resume();
-  void Pause();
+  Watch(int rid, std::string id, std::string appid,
+      Evas_Object* viewer_win, Watch::IEvent* listener);
+  void Resume() override;
+  void Pause() override;
   void Terminate();
   void Bind(Evas_Object* win);
   void Unbind();
-  Evas_Object* GetCurrentImage() const ;
-  int NotifyChangedEvent();
-  bool IsBound();
-  std::string GetAppId();
-  int GetPid() const ;
+  Evas_Object* GetCurrentImage() const override;
+  int NotifyChangedEvent() const;
+  bool IsBound() override;
+  std::string GetAppId() const;
+  int GetPid() const override;
   int GetRid() const ;
-  tizen_base::Bundle GetExtra();
-  bool IsFaulted();
+  tizen_base::Bundle GetExtra() override;
+  bool IsFaulted() override;
+
  private:
   void OnEvasAdded(const std::string& appId, const std::string& instId,
     int pid, const screen_connector::EvasObject& image) override;
diff --git a/watch-holder/src/watch_mirror.cc b/watch-holder/src/watch_mirror.cc
new file mode 100644 (file)
index 0000000..416a92a
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+#include <aul.h>
+#include <dlog.h>
+#include <app_control_internal.h>
+#include <appsvc.h>
+#include <uuid/uuid.h>
+
+#include "watch_mirror.hh"
+#include "bundle_cpp.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "WATCH_HOLDER"
+
+using namespace tizen_base;
+using namespace std;
+namespace watch_holder {
+
+WatchMirror::WatchMirror(Evas_Object* win) : win_(win) {
+}
+
+string WatchMirror::GetUUID(string rid) {
+  char uuid[37];
+  uuid_t u;
+
+  uuid_generate(u);
+  uuid_unparse(u, uuid);
+  return string(uuid) + rid;
+}
+
+void WatchMirror::OnChangedSignal(keynode_t *node, void *user_data) {
+  WatchMirror* mirror = (WatchMirror*)user_data;
+  const char* raw = vconf_get_str(VCONFKEY_WATCH_CURRENT_WATCH_INFO);
+  if (raw == nullptr || strlen(raw) == 0)
+    return;
+  try {
+    Bundle data(raw);
+    string appid = data.GetString(NOTIFY_CHANGED_EVENT_APPID_KEY);
+    string rid = data.GetString(NOTIFY_CHANGED_EVENT_RID_KEY);
+    mirror->stack_.push_back(make_shared<Watch>(
+      stoi(rid), mirror->GetUUID(rid), appid, mirror->win_, mirror));
+    mirror->OnChanged(*mirror->stack_.back());
+  } catch (const std::exception& e) {
+    LOGE("Exception occurred : %s", e.what());
+    return;
+  }
+}
+
+int WatchMirror::Listen() {
+  if (vconf_notify_key_changed(
+      VCONFKEY_WATCH_CURRENT_WATCH_INFO, OnChangedSignal, this) != 0) {
+    LOGE("failed to listen on changed signal");
+    return -1;
+  }
+  OnChangedSignal(nullptr, this);
+  return 0;
+}
+
+ISharableWatch& WatchMirror::GetCurrent() {
+  return *stack_.back();
+}
+
+void WatchMirror::OnChanged(const ISharableWatch& watch) {
+}
+
+void WatchMirror::OnAdded(const ISharableWatch& watch) {
+}
+
+void WatchMirror::OnUpdated(const ISharableWatch& watch) {
+}
+
+void WatchMirror::OnRemoved(const ISharableWatch& watch) {
+}
+
+void WatchMirror::OnAdded(const Watch& watch) {
+  OnAdded((const ISharableWatch&)watch);
+}
+
+void WatchMirror::OnUpdated(const Watch& watch) {
+  OnUpdated((const ISharableWatch&)watch);
+}
+
+void WatchMirror::OnRemoved(const Watch& watch) {
+  OnRemoved((const ISharableWatch&)watch);
+}
+
+void WatchMirror::OnBound(const Watch& watch) {
+}
+
+}
\ No newline at end of file
diff --git a/watch-holder/src/watch_mirror.hh b/watch-holder/src/watch_mirror.hh
new file mode 100644 (file)
index 0000000..4e6c31a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef __WATCH_HOLDER_WATCH_MIRROR_HH__
+#define __WATCH_HOLDER_WATCH_MIRROR_HH__
+
+#include <string>
+#include <list>
+#include <memory>
+
+#include <Evas.h>
+#include <bundle.h>
+#include <app_control.h>
+#include <aul_app_com.h>
+#include <vconf.h>
+
+#include "common.hh"
+#include "watch.hh"
+
+namespace watch_holder {
+
+class EXPORT_API WatchMirror : public Watch::IEvent {
+ public:
+  WatchMirror(Evas_Object* win);
+  int Listen();
+  ISharableWatch& GetCurrent();
+  virtual void OnChanged(const ISharableWatch& watch);
+  virtual void OnAdded(const ISharableWatch& watch);
+  virtual void OnUpdated(const ISharableWatch& watch);
+  virtual void OnRemoved(const ISharableWatch& watch);
+
+ private:
+  std::string GetUUID(std::string rid);
+  void OnAdded(const Watch& watch) override final;
+  void OnUpdated(const Watch& watch) override final;
+  void OnRemoved(const Watch& watch) override final;
+  void OnBound(const Watch& watch) override final;
+  static void OnChangedSignal(keynode_t *node, void *user_data);
+
+ private:
+  std::string appid_;
+  Evas_Object* win_;
+  aul_app_com_connection_h watch_changed_conn_;
+  std::list<std::shared_ptr<Watch>> stack_;
+};
+
+}  // namespace watch_holder
+
+#endif  // __WATCH_HOLDER_WATCH_MIRROR_HH__
+