Add watch-holder C API
authorDaehyeon Jung <darrenh.jung@samsung.com>
Fri, 7 Feb 2020 05:51:02 +0000 (14:51 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Fri, 7 Feb 2020 06:52:47 +0000 (15:52 +0900)
Change-Id: I468592d026e21e5b6773befcdbe2b46bd7d4d6fb

watch-holder/api/watch.cc [new file with mode: 0644]
watch-holder/api/watch.h
watch-holder/api/watch_holder.cc [new file with mode: 0644]
watch-holder/api/watch_holder.h
watch-holder/api/watch_holder_error.h [new file with mode: 0644]
watch-holder/src/watch_holder.cc
watch-holder/src/watch_holder.hh

diff --git a/watch-holder/api/watch.cc b/watch-holder/api/watch.cc
new file mode 100644 (file)
index 0000000..13363aa
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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 "watch.h"
+#include "../src/watch.hh"
+
+#ifndef C_EXPORT
+#define C_EXPORT extern "C" __attribute__((visibility("default")))
+#endif
+
+using namespace watch_holder;
+
+struct watch_s : public Watch {};
+
+C_EXPORT int watch_resume(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  w->Resume();
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_pause(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  w->Pause();
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_terminate(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  w->Terminate();
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_bind(watch_h watch, Evas_Object *win) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  w->Bind(win);
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_unbind(watch_h watch) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  w->Unbind();
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_appid(watch_h watch, const char **appid) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  char* id = strdup(w->GetAppId().c_str());
+  if (id == nullptr)
+      return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
+
+  *appid = id;
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_pid(watch_h watch, int *pid) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+  if (w == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *pid = w->GetPid();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_opr(watch_h watch, float *opr) {
+  // TODO
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_get_current_image(watch_h watch, Evas_Object **image) {
+  Watch* w = reinterpret_cast<Watch*>(watch);
+
+  if (w == nullptr || image == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *image = w->GetCurrentImage();
+
+  if (*image == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_OPERATION;
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
index 80fba35..61b7431 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __WATCH_H__
 #define __WATCH_H__
 
-#include <tizen_type.h>
+#include "watch_holder_error.h"
 #include <Evas.h>
 
 #ifdef __cplusplus
@@ -42,7 +42,7 @@ int watch_get_pid(watch_h watch, int *pid);
 
 int watch_get_opr(watch_h watch, float *opr);
 
-int watch_get_current_image(watch_h watch, Evas_Object *image);
+int watch_get_current_image(watch_h watch, Evas_Object **image);
 
 #ifdef __cplusplus
 }
diff --git a/watch-holder/api/watch_holder.cc b/watch-holder/api/watch_holder.cc
new file mode 100644 (file)
index 0000000..37b1fb6
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * 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 "watch_holder.h"
+#include "../src/watch_holder.hh"
+
+#ifndef C_EXPORT
+#define C_EXPORT extern "C" __attribute__((visibility("default")))
+#endif
+
+using namespace watch_holder;
+
+struct watch_holder_s : public WatchHolder {
+ public:
+  watch_holder_s(Evas_Object* win) : WatchHolder(win), cb_init_(false) {}
+
+  void OnLaunched(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+      cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
+    }
+  }
+
+  void OnDead(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+      cb_.watch_holder_lifecycle_dead_cb(reinterpret_cast<watch_h>(&w), false, cb_data_);
+    }
+  }
+
+  void OnBound(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+      cb_.watch_holder_lifecycle_bound_cb(reinterpret_cast<watch_h>(&w), cb_data_);
+    }
+  }
+
+  void OnAdded(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+      cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
+    }
+  }
+
+  void OnUpdated(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+        cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast<watch_h>(&w), watch.GetCurrentImage(), cb_data_);
+    }
+  }
+
+  void OnRemoved(const Watch& watch) override {
+    if (cb_init_) {
+      Watch& w = const_cast<Watch&>(watch);
+      cb_.watch_holder_lifecycle_removed_cb(reinterpret_cast<watch_h>(&w), cb_data_);
+    }
+  }
+
+  bool cb_init_;
+  watch_lifecycle_st cb_;
+  void* cb_data_;
+};
+
+C_EXPORT int watch_holder_create(Evas_Object *viewer_win,
+    watch_holder_h *handle) {
+  if (viewer_win == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  struct watch_holder_s *h = new struct watch_holder_s(viewer_win);
+
+  if (h == nullptr)
+    return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
+
+  *handle = h;
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_destroy(watch_holder_h handle) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  delete handle;
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_launch(watch_holder_h handle, bool background, app_control_h control) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  return handle->Launch(control, background, nullptr);
+}
+
+C_EXPORT int watch_holder_enable_rendering(watch_holder_h handle) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  handle->EnableRendering();
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_disable_rendering(watch_holder_h handle, int timeout) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  handle->DisableRendering(timeout);
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_get_current(watch_holder_h handle, watch_h *watch) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  *watch = reinterpret_cast<watch_h>(&(handle->GetCurrent()));
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_monitor(watch_holder_h handle, watch_lifecycle_st lifecycle, void *user_data) {
+  if (handle == nullptr)
+    return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
+
+  handle->cb_init_ = true;
+  handle->cb_ = lifecycle;
+  handle->cb_data_ = user_data;
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
+
+C_EXPORT int watch_holder_unmonitor(watch_holder_h handle) {
+
+  handle->cb_init_ = false;
+  handle->cb_data_ = nullptr;
+
+  return WATCH_HOLDER_ERROR_NONE;
+}
index cc3b2ea..850e929 100644 (file)
@@ -26,6 +26,8 @@
 extern "C" {
 #endif
 
+typedef struct watch_holder_s *watch_holder_h;
+
 typedef struct {
        void (*watch_holder_lifecycle_launched_cb)(watch_h watch, void *data);
        void (*watch_holder_lifecycle_dead_cb)(watch_h watch, bool is_faulted, void *data);
diff --git a/watch-holder/api/watch_holder_error.h b/watch-holder/api/watch_holder_error.h
new file mode 100644 (file)
index 0000000..c4f92e9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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_API_ERROR_H_
+#define WATCH_HOLDER_API_ERROR_H_
+
+#include <tizen.h>
+
+typedef enum _watch_holder_error {
+       WATCH_HOLDER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Success */
+       WATCH_HOLDER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+       WATCH_HOLDER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+       WATCH_HOLDER_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+       WATCH_HOLDER_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+       WATCH_HOLDER_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */
+} watch_holder_error_e;
+
+#endif /* WATCH_HOLDER_API_ERROR_H_ */
+
index 6cfdde1..e2dfc77 100644 (file)
@@ -84,21 +84,6 @@ Watch& WatchHolder::GetCurrent() {
   return *stack_.back();
 }
 
-void WatchHolder::OnDead(const Watch& watch) {
-}
-
-void WatchHolder::OnBound(const Watch& watch) {
-}
-
-void WatchHolder::OnAdded(const Watch& watch) {
-}
-
-void WatchHolder::OnUpdated(const Watch& watch) {
-}
-
-void WatchHolder::OnRemoved(const Watch& watch) {
-}
-
 int WatchHolder::OnDeadSignal(const char *endpoint, aul_app_com_result_e e,
                bundle *envelope, void *user_data) {
   return 0;
index 27a9ae2..244f9ce 100644 (file)
@@ -34,16 +34,18 @@ namespace watch_holder {
 class EXPORT_API WatchHolder : public Watch::IEvent {
  public:
   WatchHolder(Evas_Object* win);
+  virtual ~WatchHolder() = 0;
   int Launch(app_control_h control, bool background, bundle* extra);
   void EnableRendering();
   void DisableRendering(int timeout);
   const std::list<std::shared_ptr<Watch>>& GetStack();
   Watch& GetCurrent();
-  void OnDead(const Watch& watch);
-  void OnBound(const Watch& watch);
-  void OnAdded(const Watch& watch) override;
-  void OnUpdated(const Watch& watch) override;
-  void OnRemoved(const Watch& watch) override;
+  virtual void OnLaunched(const Watch& watch) = 0;
+  virtual void OnDead(const Watch& watch) = 0;
+  virtual void OnBound(const Watch& watch) = 0;
+  virtual void OnAdded(const Watch& watch) = 0;
+  virtual void OnUpdated(const Watch& watch) = 0;
+  virtual void OnRemoved(const Watch& watch) = 0;
 
  private:
   static int OnDeadSignal(const char *endpoint, aul_app_com_result_e e,