• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_ABILITY_RUNTIME_QUERY_ERMS_OBSERVER_MANAGER_H
17 #define OHOS_ABILITY_RUNTIME_QUERY_ERMS_OBSERVER_MANAGER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <unordered_map>
22 #include "cpp/mutex.h"
23 
24 #include "query_erms_observer_interface.h"
25 #include "singleton.h"
26 
27 namespace OHOS {
28 namespace AAFwk {
29 using namespace OHOS::AbilityRuntime;
30 class QueryERMSObserverManager {
31 public:
32     static QueryERMSObserverManager &GetInstance();
33 
34     int32_t AddObserver(int32_t recordId, const sptr<IQueryERMSObserver> &observer);
35 
36     void OnQueryFinished(int32_t recordId, const std::string &appId, const std::string &startTime,
37         const AtomicServiceStartupRule &rule, int resultCode);
38 
39     void OnObserverDied(const wptr<IRemoteObject> &remote);
40 
41     void HandleOnQueryFinished(int32_t recordId, const std::string &appId, const std::string &startTime,
42         const AtomicServiceStartupRule &rule, int resultCode);
43 
44 private:
45     QueryERMSObserverManager();
46     ~QueryERMSObserverManager();
47 
48 private:
49     ffrt::mutex observerLock_;
50     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
51     std::unordered_map<int32_t, sptr<IQueryERMSObserver>> observerMap_;
52     DISALLOW_COPY_AND_MOVE(QueryERMSObserverManager);
53 };
54 
55 class QueryERMSObserverRecipient : public IRemoteObject::DeathRecipient {
56 public:
57     using RemoteDiedHandler = std::function<void(const wptr<IRemoteObject> &)>;
58     explicit QueryERMSObserverRecipient(RemoteDiedHandler handler);
59     virtual ~QueryERMSObserverRecipient();
60     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
61 
62 private:
63     RemoteDiedHandler handler_;
64 };
65 } // namespace AAFwk
66 } // namespace OHOS
67 #endif // OHOS_ABILITY_RUNTIME_QUERY_ERMS_OBSERVER_MANAGER_H