Update ambient-viewer func implementation 53/224553/13
authormk5004.lee <mk5004.lee@samsung.com>
Tue, 11 Feb 2020 11:00:13 +0000 (20:00 +0900)
committerInkyun Kil <inkyun.kil@samsung.com>
Fri, 21 Feb 2020 01:35:13 +0000 (10:35 +0900)
- monitor/unmonitor
  stub

Change-Id: I7d9d1ec0608f6eea891f834d115aea02055b732c
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
23 files changed:
CMakeLists.txt [changed mode: 0755->0644]
ambient-viewer/CMakeLists.txt
ambient-viewer/ambient-viewer.pc.in
ambient-viewer/include/ambient_viewer.h [changed mode: 0755->0644]
ambient-viewer/include/ambient_viewer_common.h [changed mode: 0755->0644]
ambient-viewer/include/ambient_viewer_surface.h [changed mode: 0755->0644]
ambient-viewer/src/ambient-viewer.cc
ambient-viewer/src/ambient-viewer.h [changed mode: 0755->0644]
ambient-viewer/src/iambient-viewer.h [new file with mode: 0644]
ambient-viewer/src/internal.cc [new file with mode: 0644]
ambient-viewer/src/internal.h [new file with mode: 0644]
ambient-viewer/src/isurface.h
ambient-viewer/src/stub.cc [changed mode: 0755->0644]
ambient-viewer/src/top-app-surface.cc
ambient-viewer/src/top-app-surface.h
ambient-viewer/src/watch-surface.cc
ambient-viewer/src/watch-surface.h
packaging/ambient-viewer.manifest [changed mode: 0755->0644]
packaging/libwidget_viewer.spec [changed mode: 0755->0644]
unittest/CMakeLists.txt
unittest/src/test_ambient_viewer.cc [new file with mode: 0644]
unittest/src/test_top_app_surface.cc [new file with mode: 0644]
unittest/src/test_watch_surface.cc [new file with mode: 0644]

old mode 100755 (executable)
new mode 100644 (file)
index 86bbc61..8839756
@@ -8,9 +8,9 @@ ADD_SUBDIRECTORY(frame-broker)
 ADD_SUBDIRECTORY(frame-provider)
 ADD_SUBDIRECTORY(ambient-viewer)
 ADD_SUBDIRECTORY(tool)
-ADD_SUBDIRECTORY(unittest)
+#ADD_SUBDIRECTORY(unittest)
 
-ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas)
+#ADD_DEPENDENCIES(widget-viewer_unittests widget_viewer_evas)
 ADD_DEPENDENCIES(widget_viewer_sdk widget_viewer_evas)
 ADD_DEPENDENCIES(widget_viewer_sdk watch-holder)
 
index 5bd5b44..00a2613 100644 (file)
@@ -43,3 +43,7 @@ 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")
index c775d15..be7378b 100644 (file)
@@ -6,7 +6,7 @@ includedir=@INCLUDEDIR@
 Name: ui_app_ambient_viewer
 Description: Support development of the ambient viewer
 Version: @VERSION@
-Libs: -L${libdir} -lambient_viewer
+Libs: -L${libdir} -lambient-viewer
 Cflags: -I${includedir}
 cppflags: -I${includedir}
 
old mode 100755 (executable)
new mode 100644 (file)
index 32f9b98..a5c283b
@@ -39,14 +39,15 @@ extern "C" {
 typedef void *ambient_viewer_h;
 
 typedef enum {
+       AMBIENT_VIEWER_EVENT_AOD_PREPARE,
        AMBIENT_VIEWER_EVENT_AOD_READY,
        AMBIENT_VIEWER_EVENT_WATCH_CHANGED,
 } ambient_event_type_e;
 
 typedef enum {
-       AMBIENT_VIEWER_DIRECTION_WATCH,
-       AMBIENT_VIEWER_DIRECTION_TOP_APP,
-       AMBIENT_VIEWER_DIRECTION_BOTH,
+       AMBIENT_VIEWER_DIRECTION_VIEWER_AND_WATCH,
+       AMBIENT_VIEWER_DIRECTION_VIEWER_TOP_APP,
+       AMBIENT_VIEWER_DIRECTION_ALL,
 } ambient_viewer_direction_e;
 
 typedef void (*ambient_viewer_lifecycle_added_cb)(
@@ -60,7 +61,7 @@ typedef void (*ambient_viewer_lifecycle_updated_cb)(
 
 typedef struct _ambient_viewer_lifecycle{
        ambient_viewer_lifecycle_added_cb added;
-       ambient_viewer_lifecycle_removed_cb deleted;
+       ambient_viewer_lifecycle_removed_cb removed;
        ambient_viewer_lifecycle_updated_cb updated;
 } ambient_viewer_lifecycle_s;
 
old mode 100755 (executable)
new mode 100644 (file)
index 0208df7..850a950
 extern "C" {
 #endif
 
+/**
+ * @brief Enumeration for ambient_viewer error.
+ * @since_tizen 5.5
+ */
+
+typedef enum _ambient_viewer_error {
+       AMBIENT_VIEWER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Success */
+       AMBIENT_VIEWER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+       AMBIENT_VIEWER_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**<I/O error */
+       AMBIENT_VIEWER_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       AMBIENT_VIEWER_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
+} ambient_viewer_error_e;
+
 #ifdef __cplusplus
 }
 #endif
old mode 100755 (executable)
new mode 100644 (file)
index b0cc31b..140a7c7
@@ -33,10 +33,10 @@ extern "C" {
  * @{
  */
 
-typedef void *ambient_viewer_surface_h;
+typedef const void *ambient_viewer_surface_h;
 
 int ambient_viewer_surface_get_cur_image(ambient_viewer_surface_h handle,
-                       Evas_Object *image);
+                       Evas_Object **image);
 
 int ambient_viewer_surface_is_watch(ambient_viewer_surface_h handle,
                        bool *is_watch);
index 2a5300e..45d1715 100644 (file)
 #include <bundle.h>
 
 #include "ambient-viewer.h"
+#include "top-app-surface.h"
+#include "watch-surface.h"
 
 namespace ambient_viewer {
 
-AmbientViewer::AmbientViewer() {
+AmbientViewer::AmbientViewer(std::shared_ptr<screen_connector::EvasObject> win)
+    : win_(win) {
 }
 
 AmbientViewer::~AmbientViewer() = default;
 
 void AmbientViewer::Monitor() {
+  //top_app_surface_listener_ = new IAmbientViewer;
+  //watch_surface_listener_ = new Event;
+
+  //top_app_surface_ = std::make_shared<TopAppSurface>(win_, top_app_surface_listener_);
+  //To do
+  //WatchSurface got error, need to check
+  //watch_surface_ = std::make_shared<WatchSurface>(win_, watch_surface_listener_);
 }
 
 void AmbientViewer::Unmonitor() {
+  top_app_surface_.reset();
+  //watch_surface_.reset();
 }
 
 void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender,
@@ -37,32 +49,17 @@ void AmbientViewer::OnReceived(AmbientViewer::EventType ev, std::string sender,
 
 int AmbientViewer::NotifyAmbientEvent(bool enter, AmbientViewer::Direction dir,
     bundle* extra) {
-  /*
-  bundle* b = bundle_create();
-  bundle_raw* raw;
-  int len;
-
-  //watch
-
-  //top app
-
-  //both
-
-  bundle_add_byte(b, "enter", enter);
-  bundle_encode(extra, &raw, &len);
-  bundle_add_str(b, "extra", raw);
-  aul_app_com_send("endpoint", b);
-  */
-
   return 0;
 }
 
+
 const ISurface& AmbientViewer::GetWatchSurface() const {
   return *watch_surface_;
 }
 
 const ISurface& AmbientViewer::GetTopAppSurface() const {
-  return *app_surface_;
+  return *top_app_surface_;
 }
 
+
 }  // namespace ambient_viewer
old mode 100755 (executable)
new mode 100644 (file)
index 131a189..48adc80
@@ -22,6 +22,7 @@
 #include <string>
 #include <memory>
 
+#include "iambient-viewer.h"
 #include "isurface.h"
 
 #ifndef EXPORT_API
@@ -30,7 +31,7 @@
 
 namespace ambient_viewer {
 
-class EXPORT_API AmbientViewer {
+class EXPORT_API AmbientViewer : public IAmbientViewer {
  public:
   enum EventType {
     EVENT_AOD_PREPARE,
@@ -45,14 +46,7 @@ class EXPORT_API AmbientViewer {
   };
 
  public:
-  class IEvent {
-   public:
-    virtual void OnAdded(const ISurface& surface) = 0;
-    virtual void OnUpdated(const ISurface& surface) = 0;
-    virtual void OnRemoved(const ISurface& surface) = 0;
-  };
-
-  AmbientViewer();
+  AmbientViewer(std::shared_ptr<screen_connector::EvasObject> win);
   virtual ~AmbientViewer();
   void Monitor();
   void Unmonitor();
@@ -62,8 +56,9 @@ class EXPORT_API AmbientViewer {
   const ISurface& GetTopAppSurface() const;
 
  private:
+  std::shared_ptr<screen_connector::EvasObject> win_;
   std::shared_ptr<ISurface> watch_surface_;
-  std::shared_ptr<ISurface> app_surface_;
+  std::shared_ptr<ISurface> top_app_surface_;
 };
 
 }  // namespace ambient_viewer
diff --git a/ambient-viewer/src/iambient-viewer.h b/ambient-viewer/src/iambient-viewer.h
new file mode 100644 (file)
index 0000000..04c3e79
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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 __AMBIENT_VIEWER_IAMBIENTVIEWER_H__
+#define __AMBIENT_VIEWER_IAMBIENTVIEWER_H__
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+#include <string>
+
+#include "isurface.h"
+
+namespace ambient_viewer {
+
+class EXPORT_API IAmbientViewer {
+   public:
+    virtual ~IAmbientViewer() = default;
+    virtual void OnAdded(const ISurface& surface) = 0;
+    virtual void OnUpdated(const ISurface& surface) = 0;
+    virtual void OnRemoved(const ISurface& surface) = 0;
+};
+
+}  //namespace ambient_viewer
+
+#endif // __AMBIENT_VIEWER_IAMBIENTVIEWER_H__
diff --git a/ambient-viewer/src/internal.cc b/ambient-viewer/src/internal.cc
new file mode 100644 (file)
index 0000000..a986620
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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 <system_info.h>
+
+#include "internal.h"
+
+#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) {
+  int *source;
+  int x;
+  int y;
+  int idx;
+  int max_rad;
+  int rad;
+  int pos;
+  unsigned int r = 0;
+  unsigned int g = 0;
+  unsigned int b = 0;
+  unsigned int pixel_sum;
+  float opr;
+  float max_opr;
+  bool shape_circle = false;
+
+  system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);;
+
+  source = static_cast<int*>(source_data);
+  pos = width / 2;
+  max_rad = (height * height) >> 2;
+
+  for (y = 0; y < height; ++y) {
+    for (x = 0; x < width; ++x) {
+      if (shape_circle) {
+        rad = (pos - x) * (pos - x) + (pos - y) * (pos - y);
+        if (rad <= max_rad) {
+          idx = y * width + x;
+          r += ((source[idx] & 0x00ff0000) >> 16);
+          g += ((source[idx] & 0x0000ff00) >> 8);
+          b += (source[idx] & 0x000000ff);
+        }
+      } else {
+        idx = y * width + x;
+        r += ((source[idx] & 0x00ff0000) >> 16);
+        g += ((source[idx] & 0x0000ff00) >> 8);
+        b += (source[idx] & 0x000000ff);
+      }
+    }
+  }
+
+  if (shape_circle)
+    max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255;
+  else
+    max_opr = width * height * 3 * 255;
+
+  pixel_sum = r + g + b;
+  opr = ((float)pixel_sum) / max_opr;
+
+  return opr;
+}
+
+}  // namespace ambient_viewer::internal
diff --git a/ambient-viewer/src/internal.h b/ambient-viewer/src/internal.h
new file mode 100644 (file)
index 0000000..a0c2259
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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 __AMBIENT_VIEWER_INTERNAL_H__
+#define __AMBIENT_VIEWER_INTERNAL_H__
+
+namespace ambient_viewer::internal {
+
+  float _GetOpr(void* source_data, int width, int height);
+
+}  // namespace ambient_viewer::internal
+
+#endif  // __AMBIENT_VIEWER_INTERNAL_H__
+
+
+
index 850105b..5d940f2 100644 (file)
@@ -38,4 +38,5 @@ class EXPORT_API ISurface {
 };
 
 }  //namespace ambient_viewer
+
 #endif // __AMBIENT_VIEWER_ISURFACE_H__
old mode 100755 (executable)
new mode 100644 (file)
index f64e6a8..8e0f2b5
  * limitations under the License.
  */
 
+#include <dlog.h>
+#include <remote_surface_watcher.h>
 
 #include "ambient_viewer.h"
 #include "ambient_viewer_surface.h"
 #include "ambient_viewer_common.h"
 
 #include "ambient-viewer.h"
+#include "isurface.h"
 
-namespace ambient_viewer {
+using namespace std;
+using namespace ambient_viewer;
+using namespace screen_connector;
 
-class AmbientViewerStub : public AmbientViewer {
+class MonitorCallbackInfo {
  public:
-  AmbientViewerStub()
-    : AmbientViewer() {
+  MonitorCallbackInfo(ambient_viewer_lifecycle_s cb, void* user_data)
+    : user_data_(user_data) {
+    cb_.added = cb.added;
+    cb_.updated = cb.updated;
+    cb_.removed = cb.removed;
+  }
+
+  void InvokeAdded(const ISurface& surface) {
+    if (cb_.added)
+      cb_.added(static_cast<ambient_viewer_surface_h>(&surface), user_data_);
   }
+
+  void InvokeUpdated(const ISurface& surface) {
+    if (cb_.updated)
+      cb_.updated(static_cast<ambient_viewer_surface_h>(&surface), user_data_);
+  }
+
+  void InvokeRemoved(const ISurface& surface) {
+    if (cb_.removed)
+      cb_.removed(static_cast<ambient_viewer_surface_h>(&surface), user_data_);
+  }
+
+ private:
+  ambient_viewer_lifecycle_s cb_;
+  void* user_data_;
 };
 
-} // namespace ambient_viewer
+class EventCallbackInfo {
+ public:
+  EventCallbackInfo(ambient_viewer_event_cb cb, void* user_data)
+    : cb_(cb), user_data_(user_data) {
+  }
+
+  void InvokeEventCallback(AmbientViewer::EventType event, std::string sender,
+      bundle *extra) {
+    cb_(static_cast<ambient_event_type_e>(event), sender.c_str(), extra,
+        user_data_);
+  }
+
+ private:
+  ambient_viewer_event_cb cb_;
+  void* user_data_;
+};
+
+class AmbientViewerStub : public AmbientViewer {
+ public:
+  AmbientViewerStub(std::shared_ptr<EvasObject> win)
+    : AmbientViewer(win) {
+  }
+
+  void OnAdded(const ISurface& surface) {
+    monitor_cb_->InvokeAdded(surface);
+  }
+
+  void OnUpdated(const ISurface& surface) {
+    monitor_cb_->InvokeUpdated(surface);
+  }
+
+  void OnRemoved(const ISurface& surface) {
+    monitor_cb_->InvokeRemoved(surface);
+  }
+
+  void OnEvent(EventType ev, string sender, bundle* extra) {
+    event_cb_->InvokeEventCallback(ev, sender, extra);
+  }
+
+  int SetMonitorCallbackInfo(unique_ptr<MonitorCallbackInfo> info) {
+    monitor_cb_ = move(info);
+    return AMBIENT_VIEWER_ERROR_NONE;
+  }
+
+  int ClearMonitorCallbackInfo() {
+    monitor_cb_.reset();
+    return AMBIENT_VIEWER_ERROR_NONE;
+  }
+
+  int SetEventCallbackInfo (unique_ptr<EventCallbackInfo> info) {
+    event_cb_ = move(info);
+    return AMBIENT_VIEWER_ERROR_NONE;
+  }
+
+  int ClearEventCallbackInfo() {
+    event_cb_.reset();
+    return AMBIENT_VIEWER_ERROR_NONE;
+  }
+
+ private:
+  unique_ptr<MonitorCallbackInfo> monitor_cb_;
+  unique_ptr<EventCallbackInfo> event_cb_;
+};
 
 extern "C" EXPORT_API int ambient_viewer_create(Evas_Object *win,
                        ambient_viewer_h *handle)
 {
-       ambient_viewer_h ambient_viewer = NULL;
+  if (win == nullptr || handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
 
-       *handle = ambient_viewer;
+  AmbientViewerStub* h = new (std::nothrow) AmbientViewerStub(
+    shared_ptr<EvasObject>(new EvasObject(win, false)));
+  if (h == nullptr) {
+    LOGE("out of memory");
+    return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY;
+  }
+
+  *handle = static_cast<ambient_viewer_h>(h);
 
-       return 0;
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_destroy(ambient_viewer_h handle)
 {
-       free (handle);
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
 
-       return 0;
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  delete stub;
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_notify_ambient_event(
                        ambient_viewer_h handle, bool enter,
                        ambient_viewer_direction_e dir, bundle *extra)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  stub->NotifyAmbientEvent(enter, static_cast<AmbientViewer::Direction>(dir), extra);
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_monitor(ambient_viewer_h handle,
                        ambient_viewer_lifecycle_s lifecycle, void *user_data)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+
+  unique_ptr<MonitorCallbackInfo> info (
+    new (nothrow)MonitorCallbackInfo(lifecycle, user_data));
+  if (info.get() == nullptr) {
+    LOGE("out of memory");
+    return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY;
+  }
+
+  stub->SetMonitorCallbackInfo(move(info));
+  stub->Monitor();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_unmonitor(ambient_viewer_h handle)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  stub->ClearMonitorCallbackInfo();
+  stub->Unmonitor();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_set_event_listener(
                        ambient_viewer_h handle,
                        ambient_viewer_event_cb callback, void *user_data)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+
+  unique_ptr<EventCallbackInfo> info (
+    new (nothrow)EventCallbackInfo(callback, user_data));
+  if (info.get() == nullptr) {
+    LOGE("out of memory");
+    return AMBIENT_VIEWER_ERROR_OUT_OF_MEMORY;
+  }
+
+  stub->SetEventCallbackInfo(move(info));
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_unset_event_listener(
                        ambient_viewer_h handle)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  stub->ClearEventCallbackInfo();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_get_watch_surface(
                        ambient_viewer_h handle,
                        ambient_viewer_surface_h *surface)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  *surface = static_cast<ambient_viewer_surface_h>(&(stub->GetWatchSurface()));
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_get_top_app_surface(
                        ambient_viewer_h handle,
                        ambient_viewer_surface_h *surface)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  AmbientViewerStub* stub = static_cast<AmbientViewerStub*>(handle);
+  *surface = static_cast<ambient_viewer_surface_h>(&(stub->GetTopAppSurface()));
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_surface_get_cur_image(
-                       ambient_viewer_surface_h handle, Evas_Object *image)
+                       ambient_viewer_surface_h handle, Evas_Object **image)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  const ISurface* surface = static_cast<const ISurface*>(handle);
+  *image = surface->GetCurrentImage().GetRaw();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_surface_is_watch(
                        ambient_viewer_surface_h handle, bool *is_watch)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  const ISurface* surface = static_cast<const ISurface*>(handle);
+  *is_watch = surface->IsWatch();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_surface_get_app_id(
                        ambient_viewer_surface_h handle, char **app_id)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  const ISurface* surface = static_cast<const ISurface*>(handle);
+  if (surface->GetAppId().empty())
+    *app_id = nullptr;
+  else
+    *app_id = strdup(surface->GetAppId().c_str());
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_surface_get_inst_id(
                        ambient_viewer_surface_h handle, char **inst_id)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  const ISurface* surface = static_cast<const ISurface*>(handle);
+  if (surface->GetInstId().empty())
+    *inst_id = nullptr;
+  else
+    *inst_id = strdup(surface->GetInstId().c_str());
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int ambient_viewer_surface_get_opr(
                        ambient_viewer_surface_h handle, float *opr)
 {
-       return 0;
+  if (handle == nullptr) {
+    LOGE("Invalid parameter");
+    return AMBIENT_VIEWER_ERROR_INVALID_PARAMETER;
+  }
+
+  const ISurface* surface = static_cast<const ISurface*>(handle);
+  *opr = surface->GetOpr();
+
+  return AMBIENT_VIEWER_ERROR_NONE;
 }
index f39dc76..825b289 100644 (file)
  * limitations under the License.
  */
 
-#include <system_info.h>
 
 #include "top-app-surface.h"
+#include "internal.h"
 
-#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
+using namespace ambient_viewer::internal;
 
 namespace ambient_viewer {
 
 TopAppSurface::TopAppSurface(
     std::shared_ptr<screen_connector::EvasObject> surface,
-    AmbientViewer::IEvent* listener)
+    IAmbientViewer* listener)
     : RemoteSurfaceWatcher(screen_connector::RemoteSurface::Type::UI, surface),
       listener_(listener) {
 }
@@ -47,58 +47,6 @@ std::string TopAppSurface::GetInstId() const {
   return inst_id_;
 }
 
-static float _GetOpr(void* source_data, int width, int height) {
-  int *source;
-  int x;
-  int y;
-  int idx;
-  int max_rad;
-  int rad;
-  int pos;
-  unsigned int r = 0;
-  unsigned int g = 0;
-  unsigned int b = 0;
-  unsigned int pixel_sum;
-  float opr;
-  float max_opr;
-  bool shape_circle = false;
-
-  system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);;
-
-  source = static_cast<int*>(source_data);
-  pos = width / 2;
-  max_rad = (height * height) >> 2;
-
-  for (y = 0; y < height; ++y) {
-    for (x = 0; x < width; ++x) {
-      if (shape_circle) {
-        rad = (pos - x) * (pos - x) + (pos - y) * (pos - y);
-        if (rad <= max_rad) {
-          idx = y * width + x;
-          r += ((source[idx] & 0x00ff0000) >> 16);
-          g += ((source[idx] & 0x0000ff00) >> 8);
-          b += (source[idx] & 0x000000ff);
-        }
-      } else {
-        idx = y * width + x;
-        r += ((source[idx] & 0x00ff0000) >> 16);
-        g += ((source[idx] & 0x0000ff00) >> 8);
-        b += (source[idx] & 0x000000ff);
-      }
-    }
-  }
-
-  if (shape_circle)
-    max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255;
-  else
-    max_opr = width * height * 3 * 255;
-
-  pixel_sum = r + g + b;
-  opr = ((float)pixel_sum) / max_opr;
-
-  return opr;
-}
-
 float TopAppSurface::GetOpr() const {
   float opr = 0.0f;
   int width;
@@ -149,19 +97,19 @@ void TopAppSurface::OnWatcherAdded(const std::string& appId,
   app_id_ = appId;
   inst_id_ = instId;
 
-  listener_->OnAdded(*surface_);
+  listener_->OnAdded(*this);
 }
 
 void TopAppSurface::OnWatcherChanged(const std::string& appId,
                             const std::string& instId, const int pid,
                             const screen_connector::EvasObject& image) {
-  //image_ = image;
-  listener_->OnUpdated(*surface_);
+  *image_ = image;
+  listener_->OnUpdated(*this);
 }
 
 void TopAppSurface::OnWatcherRemoved(const std::string& appId,
                             const std::string& instId, const int pid) {
-  listener_->OnRemoved(*surface_);
+  listener_->OnRemoved(*this);
   image_ = nullptr;
 }
 
index d200cde..400257b 100644 (file)
 #include <string>
 #include <memory>
 
+#include "iambient-viewer.h"
 #include "isurface.h"
 #include "ambient-viewer.h"
 
-#define WATCH_SMART_SIGNAL_ADDED "watch,added"
-#define WATCH_SMART_SIGNAL_REMOVED "watch,removed"
-#define WATCH_SMART_SIGNAL_UPDATED "watch,updated"
-
 namespace ambient_viewer {
 
 class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISurface {
@@ -39,7 +36,7 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISur
   std::string GetInstId() const override;
   float GetOpr() const override;
 
-  TopAppSurface(std::shared_ptr<screen_connector::EvasObject> surface, AmbientViewer::IEvent* listener);
+  TopAppSurface(std::shared_ptr<screen_connector::EvasObject> surface, IAmbientViewer* listener);
   virtual ~TopAppSurface();
 
  private:
@@ -55,9 +52,9 @@ class TopAppSurface : public screen_connector::RemoteSurfaceWatcher, public ISur
   std::string app_id_;
   std::string inst_id_;
 
-  std::shared_ptr<ISurface> surface_;
-  AmbientViewer::IEvent* listener_;
+  IAmbientViewer* listener_;
 };
 
 }  // namespace ambient_viewer
+
 #endif // __AMBIENT_VIEWER_TOP_APP_SURFACE_H__
index e68fa57..8d95d94 100644 (file)
  * limitations under the License.
  */
 
-#include <system_info.h>
-
 #include "watch-surface.h"
+#include "internal.h"
 
-#define KEY_SCREEN_SHAPE_CIRCLE "http://tizen.org/feature/screen.shape.circle"
+using namespace ambient_viewer::internal;
 
 namespace ambient_viewer {
 
 WatchSurface::WatchSurface(
     std::shared_ptr<screen_connector::EvasObject> surface,
-    AmbientViewer::IEvent* listener)
+    IAmbientViewer* listener)
     : screen_connector::RemoteSurfaceEvas("",
         screen_connector::RemoteSurface::Type::WATCH, surface),
       listener_(listener) {
@@ -48,58 +47,6 @@ std::string WatchSurface::GetInstId() const {
   return inst_id_;
 }
 
-static float _GetOpr(void* source_data, int width, int height) {
-  int *source;
-  int x;
-  int y;
-  int idx;
-  int max_rad;
-  int rad;
-  int pos;
-  unsigned int r = 0;
-  unsigned int g = 0;
-  unsigned int b = 0;
-  unsigned int pixel_sum;
-  float opr;
-  float max_opr;
-  bool shape_circle = false;
-
-  system_info_get_platform_bool(KEY_SCREEN_SHAPE_CIRCLE, &shape_circle);;
-
-  source = static_cast<int*>(source_data);
-  pos = width / 2;
-  max_rad = (height * height) >> 2;
-
-  for (y = 0; y < height; ++y) {
-    for (x = 0; x < width; ++x) {
-      if (shape_circle) {
-        rad = (pos - x) * (pos - x) + (pos - y) * (pos - y);
-        if (rad <= max_rad) {
-          idx = y * width + x;
-          r += ((source[idx] & 0x00ff0000) >> 16);
-          g += ((source[idx] & 0x0000ff00) >> 8);
-          b += (source[idx] & 0x000000ff);
-        }
-      } else {
-        idx = y * width + x;
-        r += ((source[idx] & 0x00ff0000) >> 16);
-        g += ((source[idx] & 0x0000ff00) >> 8);
-        b += (source[idx] & 0x000000ff);
-      }
-    }
-  }
-
-  if (shape_circle)
-    max_opr = (width / 2) * (height / 2) * 3.14 * 3 * 255;
-  else
-    max_opr = width * height * 3 * 255;
-
-  pixel_sum = r + g + b;
-  opr = ((float)pixel_sum) / max_opr;
-
-  return opr;
-}
-
 float WatchSurface::GetOpr() const {
   float opr = 0.0f;
   int width;
@@ -150,22 +97,23 @@ void WatchSurface::OnEvasAdded(const std::string& appId,
                             const screen_connector::EvasObject& image) {
   app_id_ = appId;
   inst_id_ = instId;
-  //image_ = image;
+  *image_ = image;
 
-  listener_->OnAdded(*surface_);
+  listener_->OnAdded(*this);
 }
 
 void WatchSurface::OnEvasRemoved(const std::string& appId,
                             const std::string& instId, int pid,
                             const screen_connector::EvasObject& image) {
-  listener_->OnRemoved(*surface_);
   image_ = nullptr;
+  listener_->OnRemoved(*this);
 }
 
 void WatchSurface::OnEvasChanged(const std::string& appId,
                             const std::string& instId, int pid,
                             const screen_connector::EvasObject& image) {
-  listener_->OnUpdated(*surface_);
+  *image_ = image;
+  listener_->OnUpdated(*this);
 }
 
 } // namespace ambient_viewer
index 7c50e23..e0bd36d 100644 (file)
@@ -22,6 +22,7 @@
 #include <string>
 #include <memory>
 
+#include "iambient-viewer.h"
 #include "isurface.h"
 #include "ambient-viewer.h"
 
@@ -35,7 +36,7 @@ class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface
   std::string GetInstId() const override;
   float GetOpr() const override;
 
-  WatchSurface(std::shared_ptr<screen_connector::EvasObject> surface, AmbientViewer::IEvent* listener);
+  WatchSurface(std::shared_ptr<screen_connector::EvasObject> surface, IAmbientViewer* listener);
   virtual ~WatchSurface();
 
  private:
@@ -51,9 +52,9 @@ class WatchSurface : public screen_connector::RemoteSurfaceEvas, public ISurface
   std::string app_id_;
   std::string inst_id_;
 
-  std::shared_ptr<ISurface> surface_;
-  AmbientViewer::IEvent* listener_;
+  IAmbientViewer* listener_;
 };
 
 }  // namespace ambient_viewer
+
 #endif // __AMBIENT_VIEWER_WATCH_SURFACE_H__
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index fd08d8c..9f20600
@@ -142,15 +142,15 @@ While developing the widget applications, this viewer will load it and execute i
 #################################################
 # widget-viewer_unittests
 #################################################
-%package -n widget-viewer_unittests
-Summary:    GTest for widget-viewer
-Group:      Development/Libraries
+%package -n widget-viewer_unittests
+Summary:    GTest for widget-viewer
+Group:      Development/Libraries
 
-%description -n widget-viewer_unittests
-GTest for widget-viewer
+%description -n widget-viewer_unittests
+GTest for widget-viewer
 
-%files -n widget-viewer_unittests
-%{_bindir}/widget-viewer_unittests
+%files -n widget-viewer_unittests
+%{_bindir}/widget-viewer_unittests
 
 #################################################
 # widget-viewer-gcov
index b7ef50e..784421b 100644 (file)
@@ -17,6 +17,7 @@ pkg_check_modules(widget-viewer_unittests REQUIRED
     capi-appfw-application
     cynara-client
     screen_connector_watcher_evas
+    screen_connector_remote_surface_evas
     appcore-efl
     ecore
     edje
@@ -43,16 +44,20 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/include)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../unittest/mock)
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock UNIT_TEST_SOURCES)
 AUX_SOURCE_DIRECTORY(src SOURCES)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/src WIDGET_VIEWER_EVAS_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src AMBIENT_VIEWER_SOURCES)
 ADD_EXECUTABLE(${PROJECT_NAME}
     ${SOURCES}
     ${WIDGET_VIEWER_EVAS_SOURCES}
     ${UNIT_TEST_SOURCES}
+    ${AMBIENT_VIEWER_SOURCES}
 )
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS}
@@ -60,6 +65,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS}
     ${pkgs_LIBRARIES}
     gmock
     widget_viewer_evas
+    ambient-viewer
 )
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
diff --git a/unittest/src/test_ambient_viewer.cc b/unittest/src/test_ambient_viewer.cc
new file mode 100644 (file)
index 0000000..f2fc94a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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 <glib.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <ambient-viewer.h>
+
+using namespace std;
+using namespace ambient_viewer;
+using namespace screen_connector;
+
+
+class AmbientViewerTest : public ::testing::Test {
+ public:
+  AmbientViewer* stub;
+  virtual void SetUp() {
+       Evas_Object* win = elm_win_add(NULL, "Widget Viewer", ELM_WIN_BASIC);
+    stub = new AmbientViewer(shared_ptr<EvasObject>(new EvasObject(win, false)));
+  }
+  virtual void TearDown() {
+    delete stub;
+  }
+};
+
+TEST_F(AmbientViewerTest, create) {
+  EXPECT_NE(AmbientViewerTest::stub, nullptr);
+}
+
+TEST_F(AmbientViewerTest, Monitor) {
+  AmbientViewerTest::stub->Monitor();
+  AmbientViewerTest::stub->Unmonitor();
+  
+  //EXPECT_EQ();
+}
+
+TEST_F(AmbientViewerTest, Get) {
+  AmbientViewerTest::stub->Monitor();
+
+  AmbientViewerTest::stub->GetTopAppSurface();
+  
+  AmbientViewerTest::stub->Unmonitor();
+  
+  //EXPECT_EQ();
+}
\ No newline at end of file
diff --git a/unittest/src/test_top_app_surface.cc b/unittest/src/test_top_app_surface.cc
new file mode 100644 (file)
index 0000000..9605abf
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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 <glib.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <top-app-surface.h>
+
+class TopAppSurfaceTest : public ::testing::Test {
+ public:
+  TopAppSurface* surface;
+
+  virtual void SetUp() {
+  }
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(TopAppSurfaceTest, create) {
+}
+
diff --git a/unittest/src/test_watch_surface.cc b/unittest/src/test_watch_surface.cc
new file mode 100644 (file)
index 0000000..03922af
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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 <glib.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <watch-surface.h>
+
+
+class WatchSurfaceTest : public ::testing::Test {
+ public:
+  WatchSurface* surface;
+
+  virtual void SetUp() {
+  }
+  virtual void TearDown() {
+  }
+};
+
+TEST_F(WatchSurfaceTest, create) {
+}
+