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      * @return Returns result code when get ability info.
85      */
86     int32_t GetAbilityInfo(const OHOS::AppExecFwk::ElementName &elementName, const std::string &localeInfo,
87         RemoteAbilityInfo &remoteAbilityInfo) override;
88 
89     /**
90      * @brief get ability infos
91      * @param elementNames Indicates the elementNames.
92      * @param remoteAbilityInfos Indicates the remote ability infos.
93      * @return Returns result code when get ability infos.
94      */
95     int32_t GetAbilityInfos(
96         const std::vector<ElementName> &elementNames, std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override;
97 
98     /**
99      * @brief get ability infos
100      * @param elementNames Indicates the elementNames.
101      * @param localeInfo Indicates the localeInfo.
102      * @param remoteAbilityInfos Indicates the remote ability infos.
103      * @return Returns result code when get ability infos.
104      */
105     int32_t GetAbilityInfos(const std::vector<ElementName> &elementNames, const std::string &localeInfo,
106         std::vector<RemoteAbilityInfo> &remoteAbilityInfos) override;
107 
108     bool GetDistributedBundleInfo(const std::string &networkId, const std::string &bundleName,
109         DistributedBundleInfo &distributedBundleInfo) override;
110 
111     /**
112      * @brief get distributedBundleName based on a given accessTokenId and networkId.
113      * @param networkId Indicates the networkId of remote device.
114      * @param accessTokenId AccessTokenId of the application
115      * @param bundleNames distributed bundle name.
116      * @return Returns ERR_OK on success, others on failure when get distributed bundle name.
117      */
118     int32_t GetDistributedBundleName(const std::string &networkId, uint32_t accessTokenId,
119         std::string &bundleName) override;
120 private:
121     int32_t SendRequest(DistributedInterfaceCode code, MessageParcel &data, MessageParcel &reply);
122     template<typename T>
123     bool WriteParcelableVector(const std::vector<T> &parcelableVector, Parcel &data);
124     template <typename T>
125     int32_t GetParcelableInfo(DistributedInterfaceCode code, MessageParcel &data, T &parcelableInfo);
126     template <typename T>
127     int32_t GetParcelableInfos(DistributedInterfaceCode code, MessageParcel &data, std::vector<T> &parcelableInfos);
128     int32_t CheckElementName(const ElementName &elementName);
129     static inline BrokerDelegator<DistributedBmsProxy> delegator_;
130 };
131 }  // namespace AppExecFwk
132 }  // namespace OHOS
133 #endif  // FOUNDATION_APPEXECFWK_SERVICES_DBMS_INCLUDE_DISTRIBUTED_BMS_PROXY_H