Implement WatchSurface 39/226339/11
authorhyunho <hhstark.kang@samsung.com>
Mon, 2 Mar 2020 01:56:09 +0000 (10:56 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 3 Mar 2020 01:54:02 +0000 (01:54 +0000)
Change-Id: I455f499b049586a8ac2b8f6f9da39e713c0f9705
Signed-off-by: hyunho <hhstark.kang@samsung.com>
16 files changed:
ambient-viewer/CMakeLists.txt
ambient-viewer/src/ambient-viewer.cc
ambient-viewer/src/ambient-viewer.hh [moved from ambient-viewer/src/ambient-viewer.h with 86% similarity]
ambient-viewer/src/iambient-viewer.hh [moved from ambient-viewer/src/iambient-viewer.h with 98% similarity]
ambient-viewer/src/internal.cc
ambient-viewer/src/internal.hh [moved from ambient-viewer/src/internal.h with 93% similarity]
ambient-viewer/src/isurface.hh [moved from ambient-viewer/src/isurface.h with 92% similarity]
ambient-viewer/src/stub.cc
ambient-viewer/src/top-app-surface.cc
ambient-viewer/src/top-app-surface.hh [moved from ambient-viewer/src/top-app-surface.h with 89% similarity]
ambient-viewer/src/watch-surface.cc
ambient-viewer/src/watch-surface.hh [moved from ambient-viewer/src/watch-surface.h with 82% similarity]
packaging/libwidget_viewer.spec
unittest/src/test_ambient_viewer.cc
watch-holder/src/watch_holder.hh
watch-holder/src/watch_mirror.hh

index d3fe774..c8ce3e7 100644 (file)
@@ -42,9 +42,7 @@ 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}/include/ambient_viewer.h DESTINATION include/${PROJECT_NAME})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/ambient_viewer_surface.h DESTINATION include/${PROJECT_NAME})
-#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include DESTINATION include/${PROJECT_NAME}
-#      FILES_MATCHING PATTERN "*.h")
-#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src DESTINATION include/${PROJECT_NAME}
-#      FILES_MATCHING PATTERN "*.h")
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING
+       PATTERN "*.h")
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION include/${PROJECT_NAME} FILES_MATCHING
+       PATTERN "*.hh")
\ No newline at end of file
index 5f57076..1d99bfe 100644 (file)
 
 #include <aul.h>
 #include <bundle.h>
+#include <bundle_cpp.h>
 #include <dlog.h>
 #include <aul_app_com.h>
+#include <uuid/uuid.h>
 
-#include "ambient-viewer.h"
-#include "top-app-surface.h"
-#include "watch-surface.h"
+#include "ambient-viewer.hh"
+#include "top-app-surface.hh"
+#include "watch-surface.hh"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 
 #define LOG_TAG "AMBIENT_VIEWER"
 
+#define NOTIFY_CHANGED_EVENT_APPID_KEY "__NOTIFY_CHANGED_EVENT_APPID_KEY__"
+#define NOTIFY_CHANGED_EVENT_RID_KEY "__NOTIFY_CHANGED_EVENT_RID_KEY__"
+
+using namespace std;
 using namespace tizen_base;
 namespace ambient_viewer {
 
-AmbientViewer::AmbientViewer(std::shared_ptr<screen_connector::EvasObject> win)
+AmbientViewer::AmbientViewer(Evas_Object* win)
     : win_(win) {
   char appid_buf[512] = {0, };
   if (aul_app_get_appid_bypid(
@@ -53,13 +59,41 @@ AmbientViewer::AmbientViewer(std::shared_ptr<screen_connector::EvasObject> win)
 
 AmbientViewer::~AmbientViewer() = default;
 
-void AmbientViewer::Monitor() {
-  char appid[512] = {0, };
-  if (aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)) != AUL_R_OK)
-    LOGE("Failed to get appid (%d)", getpid());
+string AmbientViewer::GetUUID(string rid) const {
+  char uuid[37];
+  uuid_t u;
 
-  top_app_surface_ = std::make_shared<TopAppSurface>(win_, this);
-  watch_surface_ = std::make_shared<WatchSurface>(appid, win_, this);
+  uuid_generate(u);
+  uuid_unparse(u, uuid);
+  return string(uuid) + rid;
+}
+
+void AmbientViewer::OnChangedSignal(keynode_t *node, void *user_data) {
+  AmbientViewer* viewer = (AmbientViewer*)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);
+    viewer->watch_surface_ = make_shared<WatchSurface>(
+      stoi(rid), viewer->GetUUID(rid), appid, viewer->win_, viewer);
+  } catch (const std::exception& e) {
+    LOGE("Exception occurred : %s", e.what());
+    return;
+  }
+}
+
+void AmbientViewer::Monitor() {
+  top_app_surface_ = std::make_shared<TopAppSurface>(
+      make_shared<screen_connector::EvasObject>(win_, false), this);
+  if (vconf_notify_key_changed(
+      VCONFKEY_WATCH_CURRENT_WATCH_INFO, OnChangedSignal, this) != 0) {
+    LOGE("failed to listen on changed signal");
+    return;
+  }
+  OnChangedSignal(nullptr, this);
 }
 
 void AmbientViewer::Unmonitor() {
@@ -67,6 +101,10 @@ void AmbientViewer::Unmonitor() {
   watch_surface_.reset();
 }
 
+void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender,
+    Bundle extra) {
+}
+
 int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir,
     Bundle extra) {
   bundle* b;
similarity index 86%
rename from ambient-viewer/src/ambient-viewer.h
rename to ambient-viewer/src/ambient-viewer.hh
index d500e57..6d7f5f8 100644 (file)
 #ifndef __AMBIENT_VIEWER_AMBIENT_VIEWER_H__
 #define __AMBIENT_VIEWER_AMBIENT_VIEWER_H__
 
-#include <aul.h>
 #include <aul_app_com.h>
 #include <bundle.h>
 #include <bundle_cpp.h>
+#include <vconf.h>
 
 #include <string>
 #include <memory>
 
-#include "iambient-viewer.h"
-#include "isurface.h"
+#include "iambient-viewer.hh"
+#include "isurface.hh"
 
 #ifndef EXPORT_API
 #define EXPORT_API __attribute__((visibility("default")))
@@ -49,25 +49,24 @@ class EXPORT_API AmbientViewer : public IAmbientViewer {
   };
 
  public:
-  AmbientViewer(std::shared_ptr<screen_connector::EvasObject> win);
-
+  AmbientViewer(Evas_Object* win);
   virtual ~AmbientViewer();
-  virtual void OnReceived(EventType ev, std::string sender, tizen_base::Bundle extra) = 0;
-
   void Monitor();
   void Unmonitor();
+  virtual void OnReceived(EventType ev, std::string sender, tizen_base::Bundle extra) = 0;
   int NotifyAmbientEvent(bool enter, Direction dir, tizen_base::Bundle extra);
   const ISurface& GetWatchSurface() const;
   const ISurface& GetTopAppSurface() const;
 
  private:
+  std::string GetUUID(std::string rid) const;
+  static void OnChangedSignal(keynode_t *node, void *user_data);
   static int OnReceiveSignal(const char *endpoint, aul_app_com_result_e e,
       bundle *envelope, void *user_data);
-
-  std::shared_ptr<screen_connector::EvasObject> win_;
+  Evas_Object* win_;
   std::shared_ptr<ISurface> watch_surface_;
   std::shared_ptr<ISurface> top_app_surface_;
-  aul_app_com_connection_h receive_signal_conn_;
+  aul_app_com_connection_h receive_signal_conn_ = nullptr;
 };
 
 }  // namespace ambient_viewer
similarity index 98%
rename from ambient-viewer/src/iambient-viewer.h
rename to ambient-viewer/src/iambient-viewer.hh
index 04c3e79..165b2b0 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <string>
 
-#include "isurface.h"
+#include "isurface.hh"
 
 namespace ambient_viewer {
 
index a986620..c3fd82d 100644 (file)
 
 #include <system_info.h>
 
-#include "internal.h"
+#include "internal.hh"
 
 #define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
 
 namespace ambient_viewer::internal {
 
-float _GetOpr(void* source_data, int width, int height) {
+float GetOpr(void* source_data, int width, int height) {
   int *source;
   int x;
   int y;
similarity index 93%
rename from ambient-viewer/src/internal.h
rename to ambient-viewer/src/internal.hh
index a0c2259..0457719 100644 (file)
@@ -19,7 +19,7 @@
 
 namespace ambient_viewer::internal {
 
-  float _GetOpr(void* source_data, int width, int height);
+  float GetOpr(void* source_data, int width, int height);
 
 }  // namespace ambient_viewer::internal
 
similarity index 92%
rename from ambient-viewer/src/isurface.h
rename to ambient-viewer/src/isurface.hh
index 5d940f2..768e8a1 100644 (file)
@@ -21,7 +21,7 @@
 #define EXPORT_API __attribute__((visibility("default")))
 #endif
 
-#include <evas_object.h>
+#include <Elementary.h>
 
 #include <string>
 
@@ -30,7 +30,7 @@ namespace ambient_viewer {
 class EXPORT_API ISurface {
  public:
   virtual ~ISurface() = default;
-  virtual screen_connector::EvasObject& GetCurrentImage() const = 0;
+  virtual Evas_Object* GetCurrentImage() const = 0;
   virtual bool IsWatch() const = 0;
   virtual std::string GetAppId() const = 0;
   virtual std::string GetInstId() const = 0;
index cfbb737..8f618d7 100644 (file)
  */
 
 #include <dlog.h>
-#include <remote_surface_watcher.h>
+#include <bundle_cpp.h>
 
 #include "ambient_viewer.h"
 #include "ambient_viewer_surface.h"
 #include "ambient_viewer_common.h"
 
-#include "ambient-viewer.h"
-#include "isurface.h"
+#include "ambient-viewer.hh"
+#include "isurface.hh"
 
 using namespace std;
 using namespace tizen_base;
 using namespace ambient_viewer;
-using namespace screen_connector;
 
 class MonitorCallbackInfo {
  public:
@@ -79,7 +78,7 @@ class ReceiveCallbackInfo {
 
 class AmbientViewerStub : public AmbientViewer {
  public:
-  AmbientViewerStub(std::shared_ptr<EvasObject> win)
+  AmbientViewerStub(Evas_Object* win)
     : AmbientViewer(win) {
   }
 
@@ -132,8 +131,7 @@ extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win,
     return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
   }
 
-  AmbientViewerStub* h = new (nothrow) AmbientViewerStub(
-    shared_ptr<EvasObject>(new EvasObject(win, false)));
+  AmbientViewerStub* h = new (nothrow) AmbientViewerStub(win);
   if (h == nullptr) {
     LOGE("out of memory");
     return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY;
@@ -285,7 +283,7 @@ extern "C" EXPORT_API int ambient_viewer_surface_get_cur_image(
   }
 
   const ISurface* surface = static_cast<const ISurface*>(handle);
-  *image = surface->GetCurrentImage().GetRaw();
+  *image = surface->GetCurrentImage();
 
   return AMBIENT_VIEWER_ERROR_NONE;
 }
index daedd95..76aecc9 100644 (file)
  * limitations under the License.
  */
 
+#include <dlog.h>
 
-#include "top-app-surface.h"
-#include "internal.h"
+#include "top-app-surface.hh"
+#include "internal.hh"
 
-using namespace ambient_viewer::internal;
-using namespace screen_connector;
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "AMBIENT_VIEWER"
 
 namespace ambient_viewer {
 
 TopAppSurface::TopAppSurface(
-    std::shared_ptr<EvasObject> surface, IAmbientViewer* listener)
-    : RemoteSurfaceWatcher(RemoteSurface::UI, surface), listener_(listener) {
+    std::shared_ptr<screen_connector::EvasObject> surface, IAmbientViewer* listener)
+    : screen_connector::RemoteSurfaceWatcher(
+          screen_connector::RemoteSurface::UI, surface), listener_(listener) {
 }
 
 TopAppSurface::~TopAppSurface() = default;
 
-EvasObject& TopAppSurface::GetCurrentImage() const {
-  return *image_;
+Evas_Object* TopAppSurface::GetCurrentImage() const {
+  return image_;
 }
 
 bool TopAppSurface::IsWatch() const {
@@ -60,9 +65,9 @@ float TopAppSurface::GetOpr() const {
   if (image_ == nullptr)
     return 0;
 
-  evas_object_geometry_get(image_->GetRaw(), nullptr, nullptr, &width, &height);
+  evas_object_geometry_get(image_, nullptr, nullptr, &width, &height);
 
-  ns = evas_object_image_native_surface_get(image_->GetRaw());
+  ns = evas_object_image_native_surface_get(image_);
   if (ns == nullptr) {
     return 0;
   }
@@ -84,7 +89,7 @@ float TopAppSurface::GetOpr() const {
     return 0;
   }
 
-  opr = _GetOpr(source_data, width, height);
+  opr = ambient_viewer::internal::GetOpr(source_data, width, height);
 
   tbm_surface_unmap(surface);
 
@@ -95,15 +100,17 @@ void TopAppSurface::OnWatcherAdded(const std::string& appId,
                             const std::string& instId, const int pid) {
   app_id_ = appId;
   inst_id_ = instId;
-
-  listener_->OnAdded(*this);
 }
 
 void TopAppSurface::OnWatcherChanged(const std::string& appId,
                             const std::string& instId, const int pid,
-                            const EvasObject& image) {
-  *image_ = image;
-  listener_->OnUpdated(*this);
+                            const screen_connector::EvasObject& image) {
+  bool added = (image_ == nullptr);
+  image_ = image.GetRaw();
+  if (added)
+    listener_->OnAdded(*this);
+  else
+    listener_->OnUpdated(*this);
 }
 
 void TopAppSurface::OnWatcherRemoved(const std::string& appId,
similarity index 89%
rename from ambient-viewer/src/top-app-surface.h
rename to ambient-viewer/src/top-app-surface.hh
index c044d75..0a539c2 100644 (file)
 #include <string>
 #include <memory>
 
-#include "iambient-viewer.h"
-#include "isurface.h"
-#include "ambient-viewer.h"
+#include "iambient-viewer.hh"
+#include "isurface.hh"
+#include "ambient-viewer.hh"
 
 namespace ambient_viewer {
 
 class TopAppSurface : public screen_connector::RemoteSurfaceWatcher,
     public ISurface {
  public:
-  screen_connector::EvasObject& GetCurrentImage() const override;
+  Evas_Object* GetCurrentImage() const override;
   bool IsWatch() const override;
   std::string GetAppId() const override;
   std::string GetInstId() const override;
@@ -51,7 +51,7 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher,
                     const int pid) override;
 
  private:
-  std::shared_ptr<screen_connector::EvasObject> image_;
+  Evas_Object* image_ = nullptr;
   std::string app_id_;
   std::string inst_id_;
 
index 7b516f9..7f455d9 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include <dlog.h>
 
-#include "watch-surface.h"
-#include "internal.h"
+#include "watch-surface.hh"
+#include "internal.hh"
 
-using namespace std;
-using namespace ambient_viewer::internal;
-using namespace screen_connector;
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "AMBIENT_VIEWER"
 
 namespace ambient_viewer {
 
-WatchSurface::WatchSurface(string appid,
-    shared_ptr<EvasObject> surface, IAmbientViewer* listener)
-    : RemoteSurfaceEvas(appid, RemoteSurface::WATCH, surface),
-      listener_(listener) {
+WatchSurface::WatchSurface(
+    int rid, std::string id, std::string appid,
+    Evas_Object* viewer_win, IAmbientViewer* listener)
+    : RemoteSurfaceEvas(rid, id, RemoteSurface::WATCH,
+        std::make_shared<screen_connector::EvasObject>(viewer_win, false)),
+        appid_(appid), listener_(listener) {
+  LOGI("WatchSurface created (%s)", appid.c_str());
 }
 
 WatchSurface::~WatchSurface() = default;
 
-EvasObject& WatchSurface::GetCurrentImage() const {
-  return *image_;
+Evas_Object* WatchSurface::GetCurrentImage() const {
+  return image_;
 }
 
 bool WatchSurface::IsWatch() const {
@@ -40,7 +46,7 @@ bool WatchSurface::IsWatch() const {
 }
 
 std::string WatchSurface::GetAppId() const {
-  return app_id_;
+  return appid_;
 }
 
 std::string WatchSurface::GetInstId() const {
@@ -61,9 +67,9 @@ float WatchSurface::GetOpr() const {
   if (image_ == nullptr)
     return 0;
 
-  evas_object_geometry_get(image_->GetRaw(), nullptr, nullptr, &width, &height);
+  evas_object_geometry_get(image_, nullptr, nullptr, &width, &height);
 
-  ns = evas_object_image_native_surface_get(image_->GetRaw());
+  ns = evas_object_image_native_surface_get(image_);
   if (ns == nullptr) {
     return 0;
   }
@@ -85,8 +91,7 @@ float WatchSurface::GetOpr() const {
     return 0;
   }
 
-  opr = _GetOpr(source_data, width, height);
-
+  opr = ambient_viewer::internal::GetOpr(source_data, width, height);
   tbm_surface_unmap(surface);
 
   return opr;
@@ -94,25 +99,24 @@ float WatchSurface::GetOpr() const {
 
 void WatchSurface::OnEvasAdded(const std::string& appId,
                             const std::string& instId, int pid,
-                            const EvasObject& image) {
-  app_id_ = appId;
+                            const screen_connector::EvasObject& image) {
   inst_id_ = instId;
-  *image_ = image;
+  image_ = image.GetRaw();
 
   listener_->OnAdded(*this);
 }
 
 void WatchSurface::OnEvasRemoved(const std::string& appId,
                             const std::string& instId, int pid,
-                            const EvasObject& image) {
+                            const screen_connector::EvasObject& image) {
   image_ = nullptr;
   listener_->OnRemoved(*this);
 }
 
 void WatchSurface::OnEvasChanged(const std::string& appId,
                             const std::string& instId, int pid,
-                            const EvasObject& image) {
-  *image_ = image;
+                            const screen_connector::EvasObject& image) {
+  image_ = image.GetRaw();
   listener_->OnUpdated(*this);
 }
 
similarity index 82%
rename from ambient-viewer/src/watch-surface.h
rename to ambient-viewer/src/watch-surface.hh
index 33fe89e..2b3f1b4 100644 (file)
 #include <string>
 #include <memory>
 
-#include "iambient-viewer.h"
-#include "isurface.h"
-#include "ambient-viewer.h"
+#include "iambient-viewer.hh"
+#include "isurface.hh"
+#include "ambient-viewer.hh"
 
 namespace ambient_viewer {
 
 class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface {
  public:
-  screen_connector::EvasObject& GetCurrentImage() const override;
+  Evas_Object* GetCurrentImage() const override;
   bool IsWatch() const override;
   std::string GetAppId() const override;
   std::string GetInstId() const override;
   float GetOpr() const override;
-
-  WatchSurface(std::string appid,
-    std::shared_ptr<screen_connector::EvasObject> surface,
-    IAmbientViewer* listener);
+  WatchSurface(int rid, std::string id, std::string appid,
+      Evas_Object* viewer_win, IAmbientViewer* listener);
   virtual ~WatchSurface();
 
  private:
@@ -50,8 +48,8 @@ class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface
                     int pid, const screen_connector::EvasObject& image) override;
 
  private:
-  std::shared_ptr<screen_connector::EvasObject> image_;
-  std::string app_id_;
+  Evas_Object* image_ = nullptr;
+  std::string appid_;
   std::string inst_id_;
 
   IAmbientViewer* listener_;
index 61090b1..1170a46 100644 (file)
@@ -353,6 +353,7 @@ Header & package configuration of ambient-viewer
 
 %files -n ambient-viewer-devel
 %{_includedir}/ambient-viewer/*.h
+%{_includedir}/ambient-viewer/*.hh
 %{_libdir}/pkgconfig/ambient-viewer.pc
 %{_libdir}/libambient-viewer.so
 # End of a file
index 5dc8517..87227d8 100644 (file)
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 
-#include <ambient-viewer.h>
+#include <ambient-viewer.hh>
 
 using namespace std;
 using namespace ambient_viewer;
-using namespace screen_connector;
 using namespace tizen_base;
 
 class AmbientViewerStub : public AmbientViewer {
  public:
-  AmbientViewerStub(std::shared_ptr<EvasObject> win)
+  AmbientViewerStub(Evas_Object* win)
     : AmbientViewer(win) {
   }
   void OnAdded(const ISurface& surface) override {}
@@ -42,7 +41,7 @@ class AmbientViewerTest : public ::testing::Test {
 
   virtual void SetUp() {
     Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
-    stub = new AmbientViewerStub(shared_ptr<EvasObject>(new EvasObject(win, false)));
+    stub = new AmbientViewerStub(win);
   }
   virtual void TearDown() {
     delete stub;
index 5ab3bef..cdf92a5 100644 (file)
@@ -54,9 +54,9 @@ class EXPORT_API WatchHolder : public Watch::IEvent, public AmbientListener {
   std::string appid_;
   Evas_Object* win_;
   std::list<std::shared_ptr<Watch>> stack_;
-  aul_app_com_connection_h launch_signal_conn_;
-  aul_app_com_connection_h dead_signal_conn_;
-  aul_app_com_connection_h ambient_changed_signal_conn_;
+  aul_app_com_connection_h launch_signal_conn_ = nullptr;
+  aul_app_com_connection_h dead_signal_conn_ = nullptr;
+  aul_app_com_connection_h ambient_changed_signal_conn_ = nullptr;
 };
 
 }  // namespace watch_holder
index f786306..adbd12b 100644 (file)
@@ -56,6 +56,7 @@ class EXPORT_API WatchMirror : public Watch::IEvent, public AmbientListener {
  private:
   std::string appid_;
   Evas_Object* win_;
+  aul_app_com_connection_h watch_changed_conn_ = nullptr;
   std::list<std::shared_ptr<Watch>> stack_;
 };