2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "watch_holder.h"
21 #include "../src/watch_holder.hh"
24 #define C_EXPORT extern "C" __attribute__((visibility("default")))
27 using namespace watch_holder;
29 struct watch_holder_s : public WatchHolder {
31 watch_holder_s(Evas_Object* win, watch_holder_lifecycle_st cb, void* cb_data)
32 : WatchHolder(win), cb_(cb), cb_data_(cb_data) {}
34 void OnLaunched(const WatchBase& watch) override {
35 WatchBase& w = const_cast<WatchBase&>(watch);
36 cb_.watch_holder_lifecycle_launched_cb(reinterpret_cast<watch_h>(&w), cb_data_);
39 void OnDead(const WatchBase& watch) override {
40 WatchBase& w = const_cast<WatchBase&>(watch);
41 cb_.watch_holder_lifecycle_dead_cb(reinterpret_cast<watch_h>(&w), false, cb_data_);
44 void OnBound(const WatchBase& watch) override {
45 WatchBase& w = const_cast<WatchBase&>(watch);
46 cb_.watch_holder_lifecycle_bound_cb(reinterpret_cast<watch_h>(&w), cb_data_);
49 void OnAdded(const WatchBase& watch) override {
50 WatchBase& w = const_cast<WatchBase&>(watch);
51 cb_.watch_holder_lifecycle_added_cb(reinterpret_cast<watch_h>(&w), cb_data_);
54 void OnUpdated(const WatchBase& watch) override {
55 WatchBase& w = const_cast<WatchBase&>(watch);
56 cb_.watch_holder_lifecycle_updated_cb(reinterpret_cast<watch_h>(&w),
57 ((const Watch&)watch).GetCurrentImageEvas(), cb_data_);
60 void OnRemoved(const WatchBase& watch) override {
61 WatchBase& w = const_cast<WatchBase&>(watch);
62 cb_.watch_holder_lifecycle_removed_cb(reinterpret_cast<watch_h>(&w), cb_data_);
65 void OnAmbientChanged(bool enter, const tizen_base::Bundle& extra) override {
66 cb_.watch_holder_lifecycle_ambient_changed_cb(enter, extra.GetHandle(), cb_data_);
69 void OnAmbientEvent(EventType ev, std::string sender, tizen_base::Bundle extra) override {
70 cb_.watch_holder_lifecycle_ambient_event_cb(
71 (watch_holder_ambient_event_e)ev, sender.c_str(), extra.GetHandle(), cb_data_);
74 watch_holder_lifecycle_st cb_;
78 C_EXPORT int watch_holder_create(Evas_Object *viewer_win,
79 watch_holder_lifecycle_st lifecycle, void *user_data, watch_holder_h *handle) {
81 if (viewer_win == nullptr)
82 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
84 struct watch_holder_s *h = new struct watch_holder_s(viewer_win, lifecycle,
88 return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
91 return WATCH_HOLDER_ERROR_NONE;
94 C_EXPORT int watch_holder_destroy(watch_holder_h handle) {
95 if (handle == nullptr)
96 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
99 return WATCH_HOLDER_ERROR_NONE;
102 C_EXPORT int watch_holder_launch(watch_holder_h handle, bool background, const char *appid, bundle *extra) {
103 if (handle == nullptr || appid == nullptr)
104 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
106 return handle->Launch(std::string(appid), background, extra);
109 C_EXPORT int watch_holder_get_current(watch_holder_h handle, watch_h *watch) {
110 if (handle == nullptr)
111 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
113 if (handle->GetCurrent() == nullptr)
114 return WATCH_HOLDER_ERROR_INVALID_OPERATION;
116 *watch = reinterpret_cast<watch_h>(handle->GetCurrent().get());
118 return WATCH_HOLDER_ERROR_NONE;
121 C_EXPORT int watch_holder_foreach_watch(watch_holder_h handle, watch_holder_foreach_cb callback, void *user_data) {
122 if (handle == nullptr || callback == nullptr)
123 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
125 std::list<std::shared_ptr<WatchBase>> list = handle->GetStack();
126 for (std::shared_ptr<WatchBase> wptr : list) {
127 callback(reinterpret_cast<watch_h>(wptr.get()), user_data);
130 return WATCH_HOLDER_ERROR_NONE;