• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FRAMEWORKS_WM_INCLUDE_WAYLAND_SERVICE_H
17 #define FRAMEWORKS_WM_INCLUDE_WAYLAND_SERVICE_H
18 
19 #include <functional>
20 #include <string>
21 #include <vector>
22 
23 #include <refbase.h>
24 #include <wayland-client-protocol.h>
25 #include <window_manager_type.h>
26 
27 #include "singleton_delegator.h"
28 
29 namespace OHOS {
30 using GetServiceFunc = std::function<void *(const struct wl_interface *interface, uint32_t ver)>;
31 using AppearListenFunc = std::function<void(
32     const GetServiceFunc get, const std::string &iname, uint32_t ver)>;
33 using RemoveListenFunc = std::function<void(uint32_t name)>;
34 
35 class WaylandService : public RefBase {
36 public:
37     static sptr<WaylandService> GetInstance();
38 
39     // client
40     MOCKABLE void OnAppear(const AppearListenFunc &func);
41     MOCKABLE void OnRemove(const RemoveListenFunc &func);
42 
43     // server
44     MOCKABLE GSError Start();
45     MOCKABLE void Stop();
46 
47 private:
48     WaylandService() = default;
49     MOCKABLE ~WaylandService() = default;
50     static inline sptr<WaylandService> instance = nullptr;
51     static inline SingletonDelegator<WaylandService> delegator;
52 
53     void Appear(uint32_t id, const std::string iname, uint32_t ver) const;
54     void Remove(uint32_t name) const;
55 
56     struct wl_registry *registry = nullptr;
57     std::vector<AppearListenFunc> appearListenFuncs;
58     std::vector<RemoveListenFunc> removeListenFuncs;
59 };
60 } // namespace OHOS
61 
62 #endif // FRAMEWORKS_WM_INCLUDE_WAYLAND_SERVICE_H
63