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.
19 #include <aul_app_com.h>
22 #include "watch_base.hh"
28 #define LOG_TAG "WATCH_HOLDER"
31 using namespace tizen_base;
32 using namespace screen_connector;
33 namespace watch_holder {
35 WatchBase::WatchBase(std::string appid,
36 std::shared_ptr<WlSurface> surface,
37 tizen_base::Bundle extra, IEvent* listener, bool mock)
38 : RemoteSurface(appid, RemoteSurface::WATCH, surface, mock),
39 appid_(appid), listener_(listener), extra_data_(extra) {
42 WatchBase::WatchBase(int rid, std::string id, std::string appid,
43 std::shared_ptr<WlSurface> surface,
44 tizen_base::Bundle extra, IEvent* listener, bool mock)
45 : RemoteSurface(rid, id, RemoteSurface::WATCH, surface, mock),
46 appid_(appid), listener_(listener), extra_data_(extra) {
49 WatchBase::WatchBase(std::string appid,
50 std::shared_ptr<screen_connector::WlSurface> surface,
51 IEvent* listener, bool mock)
52 : RemoteSurface(appid, RemoteSurface::WATCH, surface, mock),
53 appid_(appid), listener_(listener) {
56 WatchBase::WatchBase(int rid, std::string id, std::string appid,
57 std::shared_ptr<screen_connector::WlSurface> surface,
58 IEvent* listener, bool mock)
59 : RemoteSurface(rid, id, RemoteSurface::WATCH, surface, mock),
60 appid_(appid), listener_(listener) {
63 WatchBase::~WatchBase() = default;
64 void WatchBase::Resume() {
65 RemoteSurface::SendVisibility(true);
68 void WatchBase::Pause() {
69 RemoteSurface::SendVisibility(false);
72 int WatchBase::Terminate() {
73 LOGW("Terminate (%d)", pid_);
74 return aul_terminate_pid(pid_);
77 void WatchBase::BlockUpdate(bool enable) {
78 RemoteSurface::SetBlock(enable);
82 void WatchBase::CancelTouch() {
83 RemoteSurface::SendTouchCancel();
86 int WatchBase::GetRid() const {
87 return RemoteSurface::GetRid();
90 int WatchBase::GetPid() const {
94 bool WatchBase::IsBound() const {
98 string WatchBase::GetAppId() const {
102 bool WatchBase::IsFaulted() const {
106 void WatchBase::Bind(std::shared_ptr<WlSurface> surface) {
107 RemoteSurface::Bind(surface);
111 void WatchBase::Unbind() {
112 RemoteSurface::Unbind();
116 std::shared_ptr<WlBuffer> WatchBase::GetCurrentImage() const {
117 return current_buffer_;
120 tizen_base::Bundle WatchBase::GetExtra() const {
124 void WatchBase::SetFaulted(bool faulted) {
125 is_faulted_ = faulted;
128 void WatchBase::OnBufferAdded(const std::string& appId,
129 const std::string& instId, int pid) {
133 void WatchBase::OnBufferRemoved(const std::string& appId,
134 const std::string& instId, int pid) {
135 if (current_buffer_ == nullptr)
138 OnRemoved(appId, instId, pid, current_buffer_);
139 current_buffer_ = nullptr;
142 void WatchBase::OnBufferChanged(int type,
143 std::shared_ptr<screen_connector::WlBuffer> tbm,
144 int fd, uint32_t size, uint32_t time) {
145 if (type != TIZEN_REMOTE_SURFACE_BUFFER_TYPE_TBM)
148 if (tbm.get() == nullptr || tbm->GetRaw() == nullptr) {
153 if (GetType() == RemoteSurface::WATCH && RemoteSurface::IsBound())
156 if (current_buffer_ == nullptr) {
157 LOGD("first added !!!! %d %s", type, GetAppId().c_str());
158 OnAdded(GetAppId(), GetInstId(), GetPid(), tbm);
160 OnChanged(GetAppId(), GetInstId(), GetPid(), tbm);
162 current_buffer_ = tbm;
165 void WatchBase::OnAdded(const std::string& appId, const std::string& instId,
166 int pid, std::shared_ptr<screen_connector::WlBuffer> tbm) {
168 listener_->OnAdded(*this);
171 void WatchBase::OnRemoved(const std::string& appId, const std::string& instId,
172 int pid, std::shared_ptr<screen_connector::WlBuffer> tbm) {
173 listener_->OnRemoved(*this);
176 void WatchBase::OnChanged(const std::string& appId, const std::string& instId,
177 int pid, std::shared_ptr<screen_connector::WlBuffer> tbm) {
178 listener_->OnUpdated(*this);
181 int WatchBase::NotifyChangedEvent() const {
182 tizen_base::Bundle b;
183 b.Add(NOTIFY_CHANGED_EVENT_APPID_KEY, appid_);
184 b.Add(NOTIFY_CHANGED_EVENT_RID_KEY, to_string(GetRid()));
185 int ret = vconf_set_str(
186 VCONFKEY_WATCH_CURRENT_WATCH_INFO, (const char*)b.ToRaw().first.get());
188 LOGE("Fail to send noti (%d)", ret);
194 WatchBase::IEvent* WatchBase::GetListener() {
198 } // namespace watch_holder