Add WatchMirror CAPI 73/225673/4
authorDaehyeon Jung <darrenh.jung@samsung.com>
Mon, 24 Feb 2020 01:53:59 +0000 (10:53 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Tue, 25 Feb 2020 01:33:15 +0000 (10:33 +0900)
Change-Id: Idcfef24d7ce8adc0b158535c24658ce321f9fd1a
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
watch-holder/api/sharable_watch.cc [new file with mode: 0644]
watch-holder/api/sharable_watch.h [new file with mode: 0644]
watch-holder/api/watch.cc
watch-holder/api/watch.h
watch-holder/api/watch_mirror.cc [new file with mode: 0644]
watch-holder/api/watch_mirror.h [new file with mode: 0644]
watch-holder/src/watch_mirror.cc
watch-holder/src/watch_mirror.hh
widget_viewer_sdk/src/main.c

diff --git a/watch-holder/api/sharable_watch.cc b/watch-holder/api/sharable_watch.cc
new file mode 100644 (file)
index 0000000..430c630
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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 "../src/watch.hh"
+
+#include "watch.h"
+#include "sharable_watch.h"
+
+#ifndef C_EXPORT
+#define C_EXPORT extern "C" __attribute__((visibility("default")))
+#endif
+
+using namespace watch_holder;
+
+struct sharable_watch_s : public Watch {};
+
+C_EXPORT int sharable_watch_resume(sharable_watch_h watch) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_resume(w);
+}
+
+C_EXPORT int sharable_watch_pause(sharable_watch_h watch) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_pause(w);
+}
+
+C_EXPORT int sharable_watch_get_appid(sharable_watch_h watch, char **appid) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_get_appid(w, appid);
+}
+
+C_EXPORT int sharable_watch_get_pid(sharable_watch_h watch, int *pid) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_get_pid(w, pid);
+}
+
+C_EXPORT int sharable_watch_get_extra(sharable_watch_h watch, bundle **extra) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_get_extra(w, extra);
+}
+
+C_EXPORT int sharable_watch_get_current_image(sharable_watch_h watch, Evas_Object **image) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_get_current_image(w, image);
+}
+
+C_EXPORT int sharable_watch_is_bound(sharable_watch_h watch, bool *bound) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_is_bound(w, bound);
+}
+
+C_EXPORT int sharable_watch_is_faulted(sharable_watch_h watch, bool *faulted) {
+  watch_h w = reinterpret_cast<watch_h>(watch);
+  return watch_is_faulted(w, faulted);
+}
diff --git a/watch-holder/api/sharable_watch.h b/watch-holder/api/sharable_watch.h
new file mode 100644 (file)
index 0000000..a1599da
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 __SHARABLE_WATCH_H__
+#define __SHARABLE_WATCH_H__
+
+#include <Evas.h>
+#include <bundle.h>
+
+#include "watch_holder_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct sharable_watch_s *sharable_watch_h;
+
+int sharable_watch_resume(sharable_watch_h watch);
+
+int sharable_watch_pause(sharable_watch_h watch);
+
+int sharable_watch_get_appid(sharable_watch_h watch, char **appid);
+
+int sharable_watch_get_pid(sharable_watch_h watch, int *pid);
+
+int sharable_watch_get_extra(sharable_watch_h watch, bundle **extra);
+
+int sharable_watch_get_current_image(sharable_watch_h watch, Evas_Object **image);
+
+int sharable_watch_is_bound(sharable_watch_h watch, bool *bound);
+
+int sharable_watch_is_faulted(sharable_watch_h watch, bool *faulted);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 13363aa..06d8fea 100644 (file)
@@ -67,7 +67,7 @@ C_EXPORT int watch_unbind(watch_h watch) {
   return WATCH_HOLDER_ERROR_NONE;
 }
 
-C_EXPORT int watch_get_appid(watch_h watch, const char **appid) {
+C_EXPORT int watch_get_appid(watch_h watch, char **appid) {
   Watch* w = reinterpret_cast<Watch*>(watch);
   char* id = strdup(w->GetAppId().c_str());
   if (id == nullptr)
@@ -106,3 +106,65 @@ C_EXPORT int watch_get_current_image(watch_h watch, Evas_Object **image) {
 
   return WATCH_HOLDER_ERROR_NONE;
 }
+
+C_EXPORT int watch_notify_changed_event(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  if (w->NotifyChangedEvent() < 0) {
+    return WATCH_HOLDER_ERROR_IO_ERROR;
+  }
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_rid(watch_h watch, int *rid) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr || rid == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *rid = w->GetRid();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_is_faulted(watch_h watch, bool *faulted) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr || faulted == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *faulted = w->IsFaulted();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_is_bound(watch_h watch, bool *bound) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr || bound == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *bound = w->IsBound();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_cancel_touch(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  w->CancelTouch();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_extra(watch_h watch, bundle **extra) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr || extra == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *extra = w->GetExtra().GetHandle(); // should copy? or reference?
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
index 61b7431..1147824 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "watch_holder_error.h"
 #include <Evas.h>
+#include <bundle.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -36,14 +37,27 @@ int watch_bind(watch_h watch, Evas_Object *win);
 
 int watch_unbind(watch_h watch);
 
-int watch_get_appid(watch_h watch, const char **appid);
+int watch_notify_changed_event(watch_h watch);
+
+int watch_get_appid(watch_h watch, char **appid);
 
 int watch_get_pid(watch_h watch, int *pid);
 
+int watch_get_rid(watch_h watch, int *rid);
+
 int watch_get_opr(watch_h watch, float *opr);
 
 int watch_get_current_image(watch_h watch, Evas_Object **image);
 
+int watch_get_extra(watch_h watch, bundle **extra);
+
+int watch_is_faulted(watch_h watch, bool *faulted);
+
+int watch_is_bound(watch_h watch, bool *bound);
+
+int watch_cancel_touch(watch_h watch);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/watch-holder/api/watch_mirror.cc b/watch-holder/api/watch_mirror.cc
new file mode 100644 (file)
index 0000000..1c55a49
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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 <cstring>
+#include <list>
+
+#include "watch_mirror.h"
+#include "../src/watch_mirror.hh"
+
+#ifndef C_EXPORT
+#define C_EXPORT extern "C" __attribute__((visibility("default")))
+#endif
+
+using namespace watch_holder;
+
+struct watch_mirror_s : public WatchMirror {
+ public:
+  watch_mirror_s(Evas_Object* win, watch_mirror_lifecycle_st cb, void* cb_data)
+    : WatchMirror(win), cb_(cb), cb_data_(cb_data) {}
+  void OnAdded(const ISharableWatch& watch) override {
+    ISharableWatch& w = const_cast<ISharableWatch&>(watch);
+    cb_.watch_mirror_lifecycle_added_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
+  }
+
+  void OnUpdated(const ISharableWatch& watch) override {
+    ISharableWatch& w = const_cast<ISharableWatch&>(watch);
+    cb_.watch_mirror_lifecycle_updated_cb(reinterpret_cast<sharable_watch_h>(&w), watch.GetCurrentImage(), cb_data_);
+  }
+
+  void OnRemoved(const ISharableWatch& watch) override {
+    ISharableWatch& w = const_cast<ISharableWatch&>(watch);
+    cb_.watch_mirror_lifecycle_removed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
+  }
+
+  void OnChanged(const ISharableWatch& watch) override {
+    ISharableWatch& w = const_cast<ISharableWatch&>(watch);
+    cb_.watch_mirror_lifecycle_removed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
+  }
+
+  watch_mirror_lifecycle_st cb_;
+  void* cb_data_;
+};
+
+C_EXPORT int watch_mirror_create(Evas_Object *viewer_win,
+    watch_mirror_lifecycle_st lifecycle, void *user_data, watch_mirror_h *handle) {
+
+  if (viewer_win == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  struct watch_mirror_s *h = new (std::nothrow) struct watch_mirror_s(
+                                            viewer_win, lifecycle, user_data);
+
+  if (h == nullptr)
+    return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
+
+  *handle = h;
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_mirror_destroy(watch_mirror_h handle) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  delete handle;
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_mirror_listen(watch_mirror_h handle) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  if (handle->Listen() < 0)
+    return WATCH_HOLDER_ERROR_INVALID_OPERATION;
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_mirror_get_current(watch_mirror_h handle, sharable_watch_h *watch) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *watch = reinterpret_cast<sharable_watch_h>(handle->GetCurrent().get());
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
diff --git a/watch-holder/api/watch_mirror.h b/watch-holder/api/watch_mirror.h
new file mode 100644 (file)
index 0000000..18f36b9
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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_H__
+#define __WATCH_HOLDER_H__
+
+#include <Evas.h>
+#include <bundle.h>
+
+#include "sharable_watch.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct watch_mirror_s *watch_mirror_h;
+
+typedef struct {
+       void (*watch_mirror_lifecycle_added_cb)(sharable_watch_h watch, void *data);
+       void (*watch_mirror_lifecycle_removed_cb)(sharable_watch_h watch, void *data);
+       void (*watch_mirror_lifecycle_updated_cb)(sharable_watch_h watch, Evas_Object *image, void *data);
+       void (*watch_mirror_lifecycle_changed_cb)(sharable_watch_h watch, void *data);
+       void (*watch_mirror_lifecycle_ambient_changed_cb)(bool enter, bundle *extra, void *data);
+} watch_mirror_lifecycle_st;
+
+/**
+ * @brief
+ * @details
+ * @since_tizen 5.5
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int watch_mirror_create(Evas_Object *viewer_win, watch_mirror_lifecycle_st lifecycle, void *user_data, watch_mirror_h *handle);
+
+int watch_mirror_destroy(watch_mirror_h handle);
+
+int watch_mirror_listen(watch_mirror_h handle);
+
+int watch_mirror_get_current(watch_mirror_h handle, sharable_watch_h *watch);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 0631a0a..d092be5 100644 (file)
@@ -32,6 +32,7 @@ using namespace tizen_base;
 using namespace std;
 namespace watch_holder {
 
+WatchMirror::~WatchMirror() = default;
 WatchMirror::WatchMirror(Evas_Object* win) : win_(win) {
 }
 
index 4b74a04..52874a6 100644 (file)
@@ -35,6 +35,7 @@ namespace watch_holder {
 class EXPORT_API WatchMirror : public Watch::IEvent {
  public:
   WatchMirror(Evas_Object* win);
+  virtual ~WatchMirror() = 0;
   int Listen();
   std::shared_ptr<ISharableWatch> GetCurrent() const;
   virtual void OnChanged(const ISharableWatch& watch);
@@ -53,7 +54,6 @@ class EXPORT_API WatchMirror : public Watch::IEvent {
  private:
   std::string appid_;
   Evas_Object* win_;
-  aul_app_com_connection_h watch_changed_conn_;
   std::list<std::shared_ptr<Watch>> stack_;
 };
 
index b1567a1..8b409f7 100644 (file)
@@ -783,7 +783,7 @@ static void __watch_added_cb(watch_h watch, void *data) {
                return;
        }
 
-       const char* appid = NULL;
+       char* appid = NULL;
        watch_get_appid(watch, &appid);
        DbgPrint("watch added : %s", appid);
        if (appid)