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 #include "boomerang_client.h"
17
18 #include "default_params.h"
19 #include "devicestatus_define.h"
20 #include "boomerang_params.h"
21
22 #undef LOG_TAG
23 #define LOG_TAG "BoomerangClient"
24
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28
SubscribeCallback(ITunnelClient & tunnel,BoomerangType type,std::string bundleName,sptr<IRemoteBoomerangCallback> callback)29 int32_t BoomerangClient::SubscribeCallback(ITunnelClient &tunnel, BoomerangType type, std::string bundleName,
30 sptr<IRemoteBoomerangCallback> callback)
31 {
32 SubscribeBoomerangParam param { type, bundleName, callback };
33 DefaultReply reply {};
34 int32_t ret = tunnel.AddWatch(Intention::BOOMERANG, BoomerangRequestID::ADD_BOOMERAMG_LISTENER, param, reply);
35 if (ret != RET_OK) {
36 FI_HILOGE("SubscribeBoomerang fail, error:%{public}d", ret);
37 }
38 return ret;
39 }
40
UnsubscribeCallback(ITunnelClient & tunnel,BoomerangType type,std::string bundleName,sptr<IRemoteBoomerangCallback> callback)41 int32_t BoomerangClient::UnsubscribeCallback(ITunnelClient &tunnel, BoomerangType type, std::string bundleName,
42 sptr<IRemoteBoomerangCallback> callback)
43 {
44 SubscribeBoomerangParam param { type, bundleName, callback };
45 DefaultReply reply {};
46 int32_t ret = tunnel.RemoveWatch(Intention::BOOMERANG, BoomerangRequestID::REMOVE_BOOMERAMG_LISTENER, param, reply);
47 if (ret != RET_OK) {
48 FI_HILOGE("UnsubscribeBoomerang fail, error:%{public}d", ret);
49 }
50 return ret;
51 }
52
NotifyMetadataBindingEvent(ITunnelClient & tunnel,std::string bundleName,sptr<IRemoteBoomerangCallback> callback)53 int32_t BoomerangClient::NotifyMetadataBindingEvent(ITunnelClient &tunnel, std::string bundleName,
54 sptr<IRemoteBoomerangCallback> callback)
55 {
56 NotifyMetadataParam param { bundleName, callback };
57 DefaultReply reply {};
58 int32_t ret = tunnel.AddWatch(Intention::BOOMERANG, BoomerangRequestID::NOTIFY_METADATA, param, reply);
59 if (ret != RET_OK) {
60 FI_HILOGE("UnsubscribeBoomerang fail, error:%{public}d", ret);
61 }
62 return ret;
63 }
64
SubmitMetadata(ITunnelClient & tunnel,std::string metadata)65 int32_t BoomerangClient::SubmitMetadata(ITunnelClient &tunnel, std::string metadata)
66 {
67 MetadataParam param { metadata };
68 DefaultReply reply {};
69 int32_t ret = tunnel.SetParam(Intention::BOOMERANG, BoomerangRequestID::SUBMIT_METADATA, param, reply);
70 if (ret != RET_OK) {
71 FI_HILOGE("UnsubscribeBoomerang fail, error:%{public}d", ret);
72 }
73 return ret;
74 }
75
BoomerangEncodeImage(ITunnelClient & tunnel,std::shared_ptr<Media::PixelMap> pixelMap,std::string matedata,sptr<IRemoteBoomerangCallback> callback)76 int32_t BoomerangClient::BoomerangEncodeImage(ITunnelClient &tunnel, std::shared_ptr<Media::PixelMap> pixelMap,
77 std::string matedata, sptr<IRemoteBoomerangCallback> callback)
78 {
79 EncodeImageParam param { pixelMap, matedata, callback };
80 DefaultReply reply {};
81 int32_t ret = tunnel.AddWatch(Intention::BOOMERANG, BoomerangRequestID::ENCODE_IMAGE, param, reply);
82 if (ret != RET_OK) {
83 FI_HILOGE("BoomerangEncodeImage fail, error:%{public}d", ret);
84 }
85 return ret;
86 }
87
BoomerangDecodeImage(ITunnelClient & tunnel,std::shared_ptr<Media::PixelMap> pixelMap,sptr<IRemoteBoomerangCallback> callback)88 int32_t BoomerangClient::BoomerangDecodeImage(ITunnelClient &tunnel, std::shared_ptr<Media::PixelMap> pixelMap,
89 sptr<IRemoteBoomerangCallback> callback)
90 {
91 DecodeImageParam param { pixelMap, callback };
92 DefaultReply reply {};
93 int32_t ret = tunnel.AddWatch(Intention::BOOMERANG, BoomerangRequestID::DECODE_IMAGE, param, reply);
94 if (ret != RET_OK) {
95 FI_HILOGE("BoomerangEncodeImage fail, error:%{public}d", ret);
96 }
97 return ret;
98 }
99 } // namespace DeviceStatus
100 } // namespace Msdp
101 } // namespace OHOS