• 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_OBJECT_HOLDER_IMPL_H
17 #define REMOTE_OBJECT_HOLDER_IMPL_H
18 
19 #include <mutex>
20 
21 #include "ffi_remote_data.h"
22 #include "remote_object_internal_impl.h"
23 
24 namespace OHOS {
25 class RemoteObjectHolderImpl : public OHOS::FFI::FFIData {
26     DECL_TYPE(RemoteObjectHolderImpl, OHOS::FFI::FFIData)
27 public:
28     explicit RemoteObjectHolderImpl(const std::u16string& descriptor);
29     ~RemoteObjectHolderImpl();
30     sptr<IRemoteObject> Get();
31     void Set(sptr<IRemoteObject> object);
32     void attachLocalInterface(std::string& descriptor);
Lock()33     void Lock()
34     {
35         mutex_.lock();
36     };
37 
Unlock()38     void Unlock()
39     {
40         mutex_.unlock();
41     };
42 
IncAttachCount()43     void IncAttachCount()
44     {
45         ++attachCount_;
46     };
47 
DecAttachCount()48     int32_t DecAttachCount()
49     {
50         if (attachCount_ > 0) {
51             --attachCount_;
52         }
53         return attachCount_;
54     };
55 
GetDescriptor()56     std::u16string GetDescriptor()
57     {
58         return descriptor_;
59     };
60 
61 private:
62     std::mutex mutex_;
63     std::thread::id jsThreadId_;
64     std::u16string descriptor_;
65     sptr<IRemoteObject> sptrCachedObject_;
66     wptr<IRemoteObject> wptrCachedObject_;
67     int32_t attachCount_;
68 };
69 } // namespace OHOS
70 #endif // REMOTE_OBJECT_HOLDER_IMPL_H