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 ISharableWatchBase& watch) override {
34 ISharableWatchBase& w = const_cast<ISharableWatchBase&>(watch);
35 cb_.watch_mirror_lifecycle_added_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
38 void OnUpdated(const ISharableWatchBase& watch) override {
39 ISharableWatchBase& w = const_cast<ISharableWatchBase&>(watch);
40 const Watch& wa = dynamic_cast<const Watch&>(watch);
41 cb_.watch_mirror_lifecycle_updated_cb(reinterpret_cast<sharable_watch_h>(&w), wa.GetCurrentImageEvas(), cb_data_);
44 void OnRemoved(const ISharableWatchBase& watch) override {
45 ISharableWatchBase& w = const_cast<ISharableWatchBase&>(watch);
46 cb_.watch_mirror_lifecycle_removed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
49 void OnChanged(const ISharableWatchBase& watch) override {
50 ISharableWatchBase& w = const_cast<ISharableWatchBase&>(watch);
51 cb_.watch_mirror_lifecycle_changed_cb(reinterpret_cast<sharable_watch_h>(&w), cb_data_);
54 void OnAmbientChanged(bool enter, const tizen_base::Bundle& extra) override {
55 cb_.watch_mirror_lifecycle_ambient_changed_cb(enter, extra.GetHandle(), cb_data_);
58 void OnAmbientEvent(EventType ev, std::string sender,
59 tizen_base::Bundle extra) override {
60 cb_.watch_mirror_lifecycle_ambient_event_cb(
61 (watch_mirror_ambient_event_e)ev, sender.c_str(), extra.GetHandle(), cb_data_);
64 watch_mirror_lifecycle_st cb_;
68 C_EXPORT int watch_mirror_create(Evas_Object *viewer_win,
69 watch_mirror_lifecycle_st lifecycle, void *user_data, watch_mirror_h *handle) {
71 if (viewer_win == nullptr)
72 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
74 struct watch_mirror_s *h = new (std::nothrow) struct watch_mirror_s(
75 viewer_win, lifecycle, user_data);
78 return WATCH_HOLDER_ERROR_OUT_OF_MEMORY;
81 return WATCH_HOLDER_ERROR_NONE;
84 C_EXPORT int watch_mirror_destroy(watch_mirror_h handle) {
85 if (handle == nullptr)
86 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
89 return WATCH_HOLDER_ERROR_NONE;
92 C_EXPORT int watch_mirror_listen(watch_mirror_h handle) {
93 if (handle == nullptr)
94 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
96 if (handle->Listen() < 0)
97 return WATCH_HOLDER_ERROR_INVALID_OPERATION;
99 return WATCH_HOLDER_ERROR_NONE;
102 C_EXPORT int watch_mirror_get_current(watch_mirror_h handle, sharable_watch_h *watch) {
103 if (handle == nullptr)
104 return WATCH_HOLDER_ERROR_INVALID_PARAMETER;
106 if (handle->GetCurrent() == nullptr)
107 return WATCH_HOLDER_ERROR_INVALID_OPERATION;
109 *watch = reinterpret_cast<sharable_watch_h>(handle->GetCurrent().get());
111 return WATCH_HOLDER_ERROR_NONE;