• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 HISYSEVENT_LISTENER_PROXY_H
17 #define HISYSEVENT_LISTENER_PROXY_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "hisysevent_base_listener.h"
23 #include "sys_event_callback_stub.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 class CallbackDeathRecipient : public IRemoteObject::DeathRecipient {
28 public:
CallbackDeathRecipient(const std::shared_ptr<HiSysEventBaseListener> listener)29     explicit CallbackDeathRecipient(const std::shared_ptr<HiSysEventBaseListener> listener)
30         : eventListener(listener) {}
~CallbackDeathRecipient()31     virtual ~CallbackDeathRecipient() {}
32 
33 public:
34     void OnRemoteDied(const wptr<IRemoteObject> &object) override;
35     std::shared_ptr<HiSysEventBaseListener> GetEventListener() const;
36 
37 private:
38     std::shared_ptr<HiSysEventBaseListener> eventListener;
39 };
40 
41 class HiSysEventListenerProxy : public SysEventCallbackStub {
42 public:
HiSysEventListenerProxy(const std::shared_ptr<HiSysEventBaseListener> listener)43     explicit HiSysEventListenerProxy(const std::shared_ptr<HiSysEventBaseListener> listener)
44         : callbackDeathRecipient(new CallbackDeathRecipient(listener)) {}
~HiSysEventListenerProxy()45     virtual ~HiSysEventListenerProxy() {}
46 
47 public:
48     void Handle(const std::u16string& domain, const std::u16string& eventName, uint32_t eventType,
49         const std::u16string& eventDetail) override;
50     sptr<CallbackDeathRecipient> GetCallbackDeathRecipient() const;
51     std::shared_ptr<HiSysEventBaseListener> GetEventListener() const;
52 
53 private:
54     sptr<CallbackDeathRecipient> callbackDeathRecipient;
55 };
56 } // namespace HiviewDFX
57 } // namespace OHOS
58 
59 #endif // HISYSEVENT_LISTENER_PROXY_H
60