Implements WatchBase
[platform/core/appfw/widget-viewer.git] / watch-holder-base / src / watch_base.hh
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
17 #ifndef WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_
18 #define WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_
19
20 #include <bundle_cpp.h>
21
22 #include <string>
23 #include <memory>
24 #include <screen_connector_remote_surface/remote_surface.h>
25
26 #include "common.hh"
27 #include "sharable_watch_base_interface.hh"
28
29 namespace watch_holder {
30
31 class EXPORT_API WatchBase : public screen_connector::RemoteSurface,
32     public virtual ISharableWatchBase {
33  public:
34   class IEvent {
35    public:
36     virtual void OnBound(const WatchBase& watch) = 0;
37     virtual void OnAdded(const WatchBase& watch) = 0;
38     virtual void OnUpdated(const WatchBase& watch) = 0;
39     virtual void OnRemoved(const WatchBase& watch) = 0;
40   };
41
42   WatchBase(std::string appid,
43       std::shared_ptr<screen_connector::WlSurface> surface,
44       tizen_base::Bundle extra,
45       IEvent* listener, bool mock = false);
46   WatchBase(int rid, std::string id, std::string appid,
47       std::shared_ptr<screen_connector::WlSurface> surface,
48       tizen_base::Bundle extra,
49       IEvent* listener, bool mock = false);
50   WatchBase(std::string appid,
51       std::shared_ptr<screen_connector::WlSurface> surface,
52       IEvent* listener, bool mock = false);
53   WatchBase(int rid, std::string id, std::string appid,
54       std::shared_ptr<screen_connector::WlSurface> surface,
55       IEvent* listener, bool mock = false);
56   virtual ~WatchBase();
57
58   void Resume() override;
59   void Pause() override;
60
61   int Terminate();
62   void Bind(std::shared_ptr<screen_connector::WlSurface> surface);
63   void Unbind();
64   void CancelTouch();
65   std::shared_ptr<screen_connector::WlBuffer> GetCurrentImage() const override;
66   int NotifyChangedEvent() const;
67   bool IsBound() const override;
68   std::string GetAppId() const;
69   int GetPid() const override;
70   int GetRid() const;
71   tizen_base::Bundle GetExtra() const override;
72   bool IsFaulted() const override;
73   void BlockUpdate(bool enable) override;
74   IEvent* GetListener();
75   virtual void OnAdded(const std::string& appId, const std::string& instId,
76       int pid, std::shared_ptr<screen_connector::WlBuffer> tbm);
77   virtual void OnRemoved(const std::string& appId, const std::string& instId,
78       int pid, std::shared_ptr<screen_connector::WlBuffer> tbm);
79   virtual void OnChanged(const std::string& appId, const std::string& instId,
80       int pid, std::shared_ptr<screen_connector::WlBuffer> tbm);
81
82  protected:
83   friend class WatchHolderBase;
84   void OnBufferAdded(const std::string& appId,
85       const std::string& instId, int pid) override;
86   void OnBufferRemoved(const std::string& appId,
87       const std::string& instId, int pid) override;
88   void OnBufferChanged(int type,
89       std::shared_ptr<screen_connector::WlBuffer> tbm,
90       int fd, uint32_t size, uint32_t time) override;
91   void SetFaulted(bool is_faulted);
92
93  private:
94   int pid_ = 0;
95   std::string appid_;
96   IEvent* listener_;
97   std::shared_ptr<screen_connector::WlBuffer> current_buffer_ = nullptr;
98   tizen_base::Bundle extra_data_;
99   bool is_faulted_ = false;
100   bool is_bound_ = false;
101 };
102
103 }  // namespace watch_holder
104
105 #endif  // WATCH_HOLDER_BASE_SRC_WATCH_BASE_HH_