• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 REMOTE_PROXY_HOLDER_IMPL_H
17 #define REMOTE_PROXY_HOLDER_IMPL_H
18 
19 #include <set>
20 
21 #include "ffi_remote_data.h"
22 #include "message_sequence_impl.h"
23 #include "iremote_object_impl.h"
24 
25 namespace OHOS {
26 class CJDeathRecipient : public IRemoteObject::DeathRecipient {
27 public:
28     explicit CJDeathRecipient(int64_t funcId);
29 
30     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
31 
32     bool Matches(int64_t funcId);
33 
34 protected:
35     virtual ~CJDeathRecipient() = default;
36 
37 private:
38     int64_t funcId_;
39 };
40 
41 class CJDeathRecipientList : public RefBase {
42 public:
43     CJDeathRecipientList();
44 
45     ~CJDeathRecipientList();
46 
47     bool Add(const sptr<CJDeathRecipient>& recipient);
48 
49     bool Remove(const sptr<CJDeathRecipient>& recipient);
50 
51     sptr<CJDeathRecipient> Find(int64_t funcId);
52 
53 private:
54     std::mutex mutex_;
55     std::set<sptr<CJDeathRecipient>> set_;
56 };
57 
58 class RemoteProxyHolderImpl : public CjIRemoteObjectImpl {
59     DECL_TYPE(RemoteProxyHolderImpl, OHOS::FFI::FFIData)
60 public:
61     RemoteProxyHolderImpl();
62     ~RemoteProxyHolderImpl();
63     sptr<CJDeathRecipientList> list_;
64     sptr<IRemoteObject> object_;
65 
66     int32_t SendMessageRequest(uint32_t code, int64_t dataId, int64_t replyId, MessageOption option, int64_t funcId);
67     char* GetDescriptor(int32_t* errCode);
68     bool IsObjectDead();
69     int32_t RegisterDeathRecipient(int64_t funcId, int32_t flag);
70     int32_t UnregisterDeathRecipient(int64_t funcId, int32_t flag);
71     bool IsProxyObject() override;
72     sptr<IRemoteObject> GetRemoteObject() override;
73 };
74 } // namespace OHOS
75 #endif // REMOTE_PROXY_HOLDER_IMPL_H