• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2023 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 NAP_PROCESS_H
17 #define NAP_PROCESS_H
18 
19 #include "uds_server.h"
20 
21 namespace OHOS {
22 namespace MMI {
23 class NapProcess final {
24 public:
25 
26     virtual ~NapProcess() = default;
27 
28     static NapProcess *GetInstance();
29 
30     struct NapStatusData {
31         int32_t pid;
32         int32_t uid;
33         std::string bundleName;
34         bool operator==(const NapStatusData b) const
35         {
36             return pid == b.pid && uid == b.uid && bundleName == b.bundleName;
37         }
38         bool operator<(const NapStatusData b) const
39         {
40             if (pid != b.pid) return pid < b.pid;
41             if (uid != b.uid) return uid < b.uid;
42             return bundleName < b.bundleName;
43         }
44     };
45 
46 public:
47     int32_t NotifyBundleName(NapStatusData napData, int32_t syncState);
48     int32_t SetNapStatus(int32_t pid, int32_t uid, const std::string &bundleName, int32_t napState);
49     int32_t NotifyNapOnline();
50     int32_t GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas);
51     int32_t RemoveInputEventObserver();
52     int32_t AddMmiSubscribedEventData(const NapStatusData& napData, int32_t syncState);
53     int32_t RemoveMmiSubscribedEventData(const NapStatusData& napData);
54     int32_t GetNapClientPid();
55     bool IsNeedNotify(const NapStatusData& napData);
56     void Init(UDSServer& udsServer);
57     int32_t napClientPid_ { -1 };
58 
59 private:
60     UDSServer* udsServer_ { nullptr };
61     NapProcess() = default;
62     DISALLOW_COPY_AND_MOVE(NapProcess);
63     static NapProcess *instance_;
64     std::map<NapStatusData, int32_t> napMap_;
65     std::mutex mapMtx_;
66 };
67 } // namespace MMI
68 } // namespace OHOS
69 #endif // NAP_PROCESS_H
70