• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 FOUNDATION_APPEXECFWK_SERVICES_DBMS_INCLUDE_DISTRIBUTED_BMS_PROXY_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_DBMS_INCLUDE_DISTRIBUTED_BMS_PROXY_H
18 
19 #include <string>
20 
21 #include "distributed_bms_interface.h"
22 #include "distributed_bundle_ipc_interface_code.h"
23 #include "iremote_proxy.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class DistributedBmsProxy : public IRemoteProxy<IDistributedBms> {
28 public:
29     explicit DistributedBmsProxy(const sptr<IRemoteObject> &object);
30     virtual ~DistributedBmsProxy() override;
31 
32     /**
33      * @brief get remote ability info
34      * @param elementName Indicates the elementName.
35      * @param remoteAbilityInfo Indicates the remote ability info.
36      * @return Returns result code when get ability info.
37      */
38     int32_t GetRemoteAbilityInfo(
39         const OHOS::AppExecFwk::ElementName &elementName, RemoteAbilityInfo &remoteAbilityInfo) override;
40 
41     /**
42      * @brief get remote ability info
43      * @param elementName Indicates the elementName.
44      * @param localeInfo Indicates the localeInfo.
45      * @param remoteAbilityInfo Indicates the remote ability info.
46      * @return Returns result code when get remote ability info.
47      */
48     int32_t GetRemoteAbilityInfo(const OHOS::AppExecFwk::ElementName &elementName, const std::string &localeInfo,
49         RemoteAbilityInfo &remoteAbilityInfo) override;
50 
51     /**
52      * @brief get remote ability infos
53      * @param elementNames Indicates the elementNames.
54      * @param remoteAbilityInfos Indicates the remote ability infos.
55      * @return Returns result code when get remote ability infos.
56      */
57     int32_t GetRemoteAbilityInfos(
58         const std::vector<ElementName> &elementNames, std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override;
59 
60     /**
61      * @brief get remote ability infos
62      * @param elementNames Indicates the elementNames.
63      * @param localeInfo Indicates the localeInfo.
64      * @param remoteAbilityInfos Indicates the remote ability infos.
65      * @return Returns result code when get remote ability infos.
66      */
67     int32_t GetRemoteAbilityInfos(const std::vector<ElementName> &elementNames, const std::string &localeInfo,
68         std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override;
69 
70     /**
71      * @brief get ability info
72      * @param elementName Indicates the elementName.
73      * @param remoteAbilityInfo Indicates the remote ability info.
74      * @return Returns result code when get ability info.
75      */
76     int32_t GetAbilityInfo(
77         const OHOS::AppExecFwk::ElementName &elementName, RemoteAbilityInfo &remoteAbilityInfo) override;
78 
79     /**
80      * @brief get ability info
81      * @param elementName Indicates the elementName.
82      * @param localeInfo Indicates the localeInfo.
83      * @param remoteAbilityInfo Indicates the remote ability info.
84      * @param info Indicates the acl info.
85      * @return Returns result code when get ability info.
86      */
87     int32_t GetAbilityInfo(const OHOS::AppExecFwk::ElementName &elementName, const std::string &localeInfo,
88         RemoteAbilityInfo &remoteAbilityInfo, DistributedBmsAclInfo *info = nullptr) override;
89 
90     /**
91      * @brief get ability infos
92      * @param elementNames Indicates the elementNames.
93      * @param remoteAbilityInfos Indicates the remote ability infos.
94      * @return Returns result code when get ability infos.
95      */
96     int32_t GetAbilityInfos(
97         const std::vector<ElementName> &elementNames, std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override;
98 
99     /**
100      * @brief get ability infos
101      * @param elementNames Indicates the elementNames.
102      * @param localeInfo Indicates the localeInfo.
103      * @param remoteAbilityInfos Indicates the remote ability infos.
104      * @param info Indicates the acl info.
105      * @return Returns result code when get ability infos.
106      */
107     int32_t GetAbilityInfos(const std::vector<ElementName> &elementNames, const std::string &localeInfo,
108         std::vector<RemoteAbilityInfo> &remoteAbilityInfos, DistributedBmsAclInfo *info = nullptr) override;
109 
110     bool GetDistributedBundleInfo(const std::string &networkId, const std::string &bundleName,
111         DistributedBundleInfo &distributedBundleInfo) override;
112 
113     /**
114      * @brief get distributedBundleName based on a given accessTokenId and networkId.
115      * @param networkId Indicates the networkId of remote device.
116      * @param accessTokenId AccessTokenId of the application
117      * @param bundleNames distributed bundle name.
118      * @return Returns ERR_OK on success, others on failure when get distributed bundle name.
119      */
120     int32_t GetDistributedBundleName(const std::string &networkId, uint32_t accessTokenId,
121         std::string &bundleName) override;
122 private:
123     int32_t SendRequest(DistributedInterfaceCode code, MessageParcel &data, MessageParcel &reply);
124     template<typename T>
125     bool WriteParcelableVector(const std::vector<T> &parcelableVector, Parcel &data);
126     template <typename T>
127     int32_t GetParcelableInfo(DistributedInterfaceCode code, MessageParcel &data, T &parcelableInfo);
128     template <typename T>
129     int32_t GetParcelableInfos(DistributedInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos);
130     int32_t CheckElementName(const ElementName &elementName);
131     static inline BrokerDelegator<DistributedBmsProxy> delegator_;
132 };
133 }  // namespace AppExecFwk
134 }  // namespace OHOS
135 #endif  // FOUNDATION_APPEXECFWK_SERVICES_DBMS_INCLUDE_DISTRIBUTED_BMS_PROXY_H