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