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