1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#ifndef NAP_PROCESS_H 17c29fa5a6Sopenharmony_ci#define NAP_PROCESS_H 18c29fa5a6Sopenharmony_ci 19c29fa5a6Sopenharmony_ci#include <map> 20c29fa5a6Sopenharmony_ci#include <memory> 21c29fa5a6Sopenharmony_ci#include <mutex> 22c29fa5a6Sopenharmony_ci 23c29fa5a6Sopenharmony_ci#include "nocopyable.h" 24c29fa5a6Sopenharmony_ci#include "singleton.h" 25c29fa5a6Sopenharmony_ci 26c29fa5a6Sopenharmony_ci#include "define_multimodal.h" 27c29fa5a6Sopenharmony_ci#include "uds_server.h" 28c29fa5a6Sopenharmony_ci 29c29fa5a6Sopenharmony_cinamespace OHOS { 30c29fa5a6Sopenharmony_cinamespace MMI { 31c29fa5a6Sopenharmony_ciclass NapProcess final { 32c29fa5a6Sopenharmony_cipublic: 33c29fa5a6Sopenharmony_ci 34c29fa5a6Sopenharmony_ci virtual ~NapProcess() = default; 35c29fa5a6Sopenharmony_ci 36c29fa5a6Sopenharmony_ci static NapProcess *GetInstance(); 37c29fa5a6Sopenharmony_ci 38c29fa5a6Sopenharmony_cistruct NapStatusData { 39c29fa5a6Sopenharmony_ci int32_t pid; 40c29fa5a6Sopenharmony_ci int32_t uid; 41c29fa5a6Sopenharmony_ci std::string bundleName; 42c29fa5a6Sopenharmony_ci bool operator==(const NapStatusData b) const 43c29fa5a6Sopenharmony_ci { 44c29fa5a6Sopenharmony_ci return pid == b.pid && uid == b.uid && bundleName == b.bundleName; 45c29fa5a6Sopenharmony_ci } 46c29fa5a6Sopenharmony_ci bool operator<(const NapStatusData b) const 47c29fa5a6Sopenharmony_ci { 48c29fa5a6Sopenharmony_ci if (pid != b.pid) return pid < b.pid; 49c29fa5a6Sopenharmony_ci if (uid != b.uid) return uid < b.uid; 50c29fa5a6Sopenharmony_ci return bundleName < b.bundleName; 51c29fa5a6Sopenharmony_ci } 52c29fa5a6Sopenharmony_ci}; 53c29fa5a6Sopenharmony_ci std::map<NapStatusData, int32_t> napMap_; 54c29fa5a6Sopenharmony_ci int32_t NotifyBundleName(NapStatusData napData, int32_t syncState); 55c29fa5a6Sopenharmony_ci int32_t SetNapStatus(int32_t pid, int32_t uid, std::string bundleName, int32_t napState); 56c29fa5a6Sopenharmony_ci int32_t NotifyNapOnline(); 57c29fa5a6Sopenharmony_ci int32_t GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas); 58c29fa5a6Sopenharmony_ci int32_t RemoveInputEventObserver(); 59c29fa5a6Sopenharmony_ci int32_t AddMmiSubscribedEventData(const NapStatusData& napData, int32_t syncState); 60c29fa5a6Sopenharmony_ci int32_t RemoveMmiSubscribedEventData(const NapStatusData& napData); 61c29fa5a6Sopenharmony_ci int32_t GetNapClientPid(); 62c29fa5a6Sopenharmony_ci bool IsNeedNotify(const NapStatusData& napData); 63c29fa5a6Sopenharmony_ci void Init(UDSServer& udsServer); 64c29fa5a6Sopenharmony_ci int32_t napClientPid_ { -1 }; 65c29fa5a6Sopenharmony_ci 66c29fa5a6Sopenharmony_ciprivate: 67c29fa5a6Sopenharmony_ci UDSServer* udsServer_ { nullptr }; 68c29fa5a6Sopenharmony_ci NapProcess() = default; 69c29fa5a6Sopenharmony_ci DISALLOW_COPY_AND_MOVE(NapProcess); 70c29fa5a6Sopenharmony_ci static NapProcess *instance_; 71c29fa5a6Sopenharmony_ci std::mutex mapMtx_; 72c29fa5a6Sopenharmony_ci}; 73c29fa5a6Sopenharmony_ci} // namespace MMI 74c29fa5a6Sopenharmony_ci} // namespace OHOS 75c29fa5a6Sopenharmony_ci#endif // NAP_PROCESS_H 76