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.
17 #include "watch_mirror.h"
18 #include "../src/watch_mirror.hh"
24 #define C_EXPORT extern "C" __attribute__((visibility("default")))
27 using namespace watch_holder;
29 struct watch_mirror_s : public WatchMirror {
31 watch_mirror_s(Evas_Object* win, watch_mirror_lifecycle_st cb, void* cb_data)
32 : WatchMirror(win), cb_(cb), cb_data_(cb_data) {}
33 void OnAdded(const ISharableWatch& watch) override {
34 ISharableWatch& w = const_cast<ISharableWatch&>(watch);
35 cb_.watch_mirror_lifecycle_added_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
38 void OnUpdated(const ISharableWatch& watch) override {
39 ISharableWatch& w = const_cast<ISharableWatch&>(watch);
40 cb_.watch_mirror_lifecycle_updated_cb(reinterpret_cast<sharable_watch_h>(&w), watch.GetCurrentImage(), cb_data_);
43 void OnRemoved(const ISharableWatch& watch) override {
44 ISharableWatch& w = const_cast<ISharableWatch&>(watch);
45 cb_.watch_mirror_lifecycle_removed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
48 void OnChanged(const ISharableWatch& watch) override {
49 ISharableWatch& w = const_cast<ISharableWatch&>(watch);
50 cb_.watch_mirror_lifecycle_changed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
53 void OnAmbientChanged(bool enter, tizen_base::Bundle& extra) override {
54 cb_.watch_mirror_lifecycle_ambient_changed_cb(enter, extra.GetHandle(), cb_data_);
57 void OnAmbientEvent(EventType ev, std::string sender,
58 tizen_base::Bundle extra) override {
59 cb_.watch_mirror_lifecycle_ambient_event_cb(
60 (watch_mirror_ambient_event_e)ev, sender.c_str(), extra.GetHandle(), cb_data_);
63 watch_mirror_lifecycle_st cb_;
67 C_EXPORT int watch_mirror_create(Evas_Object *viewer_win,
68 watch_mirror_lifecycle_st lifecycle, void *user_data, watch_mirror_h *handle) {
70 if (viewer_win == nullptr)
71 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
73 struct watch_mirror_s *h = new (std::nothrow) struct watch_mirror_s(
74 viewer_win, lifecycle, user_data);
77 return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
80 return WATCH_HOLDER_ERROR_NONE;
83 C_EXPORT int watch_mirror_destroy(watch_mirror_h handle) {
84 if (handle == nullptr)
85 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
88 return WATCH_HOLDER_ERROR_NONE;
91 C_EXPORT int watch_mirror_listen(watch_mirror_h handle) {
92 if (handle == nullptr)
93 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
95 if (handle->Listen() < 0)
96 return WATCH_HOLDER_ERROR_INVALID_OPERATION;
98 return WATCH_HOLDER_ERROR_NONE;
101 C_EXPORT int watch_mirror_get_current(watch_mirror_h handle, sharable_watch_h *watch) {
102 if (handle == nullptr)
103 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
105 if (handle->GetCurrent() == nullptr)
106 return WATCH_HOLDER_ERROR_INVALID_OPERATION;
108 *watch = reinterpret_cast<sharable_watch_h>(handle->GetCurrent().get());
110 return WATCH_HOLDER_ERROR_NONE;