Implements WatchBase
[platform/core/appfw/widget-viewer.git] / watch-holder / src / watch_mirror.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #include <dlog.h>
17 #include <screen_connector_remote_surface_evas/util.h>
18
19 #include <utility>
20
21 #include "watch_mirror.hh"
22 #include "watch.hh"
23 #include "util.hh"
24
25 #ifdef LOG_TAG
26 #undef LOG_TAG
27 #endif
28
29 #define LOG_TAG "WATCH_HOLDER"
30
31 using namespace tizen_base;
32 using namespace std;
33 namespace watch_holder {
34
35 WatchMirror::~WatchMirror() = default;
36 WatchMirror::WatchMirror(Evas_Object* win)
37   : WatchMirrorBase(screen_connector::util::GetWlSurface(win)),
38       viewer_win_(win) {
39 }
40
41 void WatchMirror::OnChanged(const ISharableWatchBase& watch) {
42 }
43
44 void WatchMirror::OnChanged(int rid, std::string inst_id, std::string appid) {
45   WatchMirrorBase::AddWatch(make_shared<Watch>(
46           rid, inst_id, appid, viewer_win_, nullptr, this));
47   shared_ptr<ISharableWatchBase> cur = WatchMirrorBase::GetCurrent();
48   OnChanged(*cur.get());
49 }
50
51 shared_ptr<ISharableWatch> WatchMirror::Cast(
52     shared_ptr<ISharableWatchBase> watch) {
53   shared_ptr<Watch> wa = dynamic_pointer_cast<Watch>(watch);
54   return static_pointer_cast<ISharableWatch>(wa);
55 }
56
57 const ISharableWatch& WatchMirror::Cast(const ISharableWatchBase& watch) {
58   const Watch& wa = dynamic_cast<const Watch&>(watch);
59   return (ISharableWatch&)wa;
60 }
61
62 std::shared_ptr<WatchBase> WatchMirror::CreateWatch(int rid, std::string id,
63     std::string appid, bool mock) {
64   return make_shared<Watch>(rid, std::move(id), std::move(appid),
65       viewer_win_, this, mock);
66 }
67
68 std::shared_ptr<WatchBase> WatchMirror::CreateWatch(int rid, std::string id,
69     std::string appid, tizen_base::Bundle extra, bool mock) {
70   return make_shared<Watch>(rid, std::move(id), std::move(appid),
71       viewer_win_, std::move(extra), this, mock);
72 }
73
74 }  // namespace watch_holder