1 /* 2 * Copyright (c) 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 POWERMGR_RUNNING_LOCK_PROXY_H 17 #define POWERMGR_RUNNING_LOCK_PROXY_H 18 19 #include <map> 20 #include <vector> 21 22 #include <iremote_object.h> 23 #include <functional> 24 25 namespace OHOS { 26 namespace PowerMgr { 27 using RunningLockProxyMap = std::map<std::string, std::pair<std::vector<sptr<IRemoteObject>>, int32_t>>; 28 class RunningLockProxy { 29 public: 30 RunningLockProxy() = default; 31 ~RunningLockProxy() = default; 32 33 void AddRunningLock(pid_t pid, pid_t uid, const sptr<IRemoteObject>& remoteObj); 34 void RemoveRunningLock(pid_t pid, pid_t uid, const sptr<IRemoteObject>& remoteObj); 35 std::vector<sptr<IRemoteObject>> GetRemoteObjectList(pid_t pid, pid_t uid); 36 bool IsProxied(pid_t pid, pid_t uid); 37 bool IncreaseProxyCnt(pid_t pid, pid_t uid, const std::function<void(void)>& proxyRunningLock); 38 bool DecreaseProxyCnt(pid_t pid, pid_t uid, const std::function<void(void)>& unProxyRunningLock); 39 void Clear(); 40 std::string DumpProxyInfo(); 41 void ResetRunningLocks(); 42 private: 43 std::string AssembleProxyKey(pid_t pid, pid_t uid); 44 RunningLockProxyMap proxyMap_; 45 }; 46 } // namespace PowerMgr 47 } // namespace OHOS 48 #endif // POWERMGR_RUNNING_LOCK_PROXY_H 49 50