• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DATASHARESERVICE_EXTENSION_PROXY_H
17 #define DATASHARESERVICE_EXTENSION_PROXY_H
18 
19 #include <memory>
20 #include <string>
21 
22 #include "extension_manager_proxy.h"
23 namespace OHOS::DataShare {
24 class ExtensionMgrProxy final : public std::enable_shared_from_this<ExtensionMgrProxy> {
25 public:
26     // do not use
27     ExtensionMgrProxy() = default;
28     ~ExtensionMgrProxy();
29     static std::shared_ptr<ExtensionMgrProxy> GetInstance();
30     int Connect(const std::string &uri, const sptr<IRemoteObject> &connect, const sptr<IRemoteObject> &callerToken);
31     int DisConnect(sptr<IRemoteObject> connect);
32 private:
33     using Proxy = AAFwk::ExtensionManagerProxy;
34     class ServiceDeathRecipient : public IRemoteObject::DeathRecipient {
35     public:
ServiceDeathRecipient(std::weak_ptr<ExtensionMgrProxy> owner)36         explicit ServiceDeathRecipient(std::weak_ptr<ExtensionMgrProxy> owner) : owner_(owner)
37         {
38         }
OnRemoteDied(const wptr<IRemoteObject> & object)39         void OnRemoteDied(const wptr<IRemoteObject> &object) override
40         {
41             auto owner = owner_.lock();
42             if (owner != nullptr) {
43                 owner->OnProxyDied();
44             }
45         }
46 
47     private:
48         std::weak_ptr<ExtensionMgrProxy> owner_;
49     };
50     void OnProxyDied();
51     bool ConnectSA();
52     std::mutex mutex_;
53     sptr<IRemoteObject> sa_;
54     sptr<Proxy> proxy_;
55     sptr<ExtensionMgrProxy::ServiceDeathRecipient> deathRecipient_;
56 };
57 } // namespace OHOS::DataShare
58 #endif // DATASHARESERVICE_BUNDLEMGR_PROXY_H
59