Implements WatchBase
[platform/core/appfw/widget-viewer.git] / watch-holder-base / src / watch_mirror_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_MIRROR_BASE_HH_
18 #define WATCH_HOLDER_BASE_SRC_WATCH_MIRROR_BASE_HH_
19
20 #include <string>
21 #include <list>
22 #include <memory>
23
24 #include <bundle.h>
25 #include <app_control.h>
26 #include <aul_app_com.h>
27 #include <vconf.h>
28 #include <screen_connector_remote_surface/handle.h>
29
30 #include "common.hh"
31 #include "watch_base.hh"
32 #include "ambient_listener.hh"
33
34 namespace watch_holder {
35
36 class EXPORT_API WatchMirrorBase : public WatchBase::IEvent, public AmbientListener {
37  public:
38   WatchMirrorBase(std::shared_ptr<screen_connector::WlSurface> surface);
39   virtual ~WatchMirrorBase() = 0;
40   int Listen();
41   std::shared_ptr<ISharableWatchBase> GetCurrent() const;
42   virtual void OnChanged(const ISharableWatchBase& watch);
43   virtual void OnAdded(const ISharableWatchBase& watch);
44   virtual void OnUpdated(const ISharableWatchBase& watch);
45   virtual void OnRemoved(const ISharableWatchBase& watch);
46   void OnAmbientChanged(bool enter,
47       const tizen_base::Bundle& extra) override;
48   void OnAmbientEvent(EventType ev, std::string sender,
49       tizen_base::Bundle extra) override;
50   void AddWatch(std::shared_ptr<WatchBase> watch);
51
52  private:
53   std::string GetUUID(std::string rid) const;
54   void OnAdded(const WatchBase& watch) final;
55   void OnUpdated(const WatchBase& watch) final;
56   void OnRemoved(const WatchBase& watch) final;
57   void OnBound(const WatchBase& watch) final;
58   virtual void OnChanged(int, std::string inst_id, std::string appid);
59   static void OnChangedSignal(keynode_t *node, void *user_data);
60
61  protected:
62   virtual std::shared_ptr<WatchBase> CreateWatch(int rid, std::string id,
63     std::string appid, bool mock = false) = 0;
64   virtual std::shared_ptr<WatchBase> CreateWatch(int rid, std::string id,
65     std::string appid, tizen_base::Bundle extra, bool mock = false) = 0;
66
67  private:
68   std::string appid_;
69   aul_app_com_connection_h watch_changed_conn_ = nullptr;
70   std::list<std::shared_ptr<WatchBase>> stack_;
71 };
72
73 }  // namespace watch_holder
74
75 #endif  // WATCH_HOLDER_BASE_SRC_WATCH_MIRROR_BASE_HH_