• 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 #include "locating_required_data_callback_taihe.h"
16 
17 #include "ipc_skeleton.h"
18 
19 #include "common_utils.h"
20 #include "location_log.h"
21 #include "util.h"
22 
23 namespace OHOS {
24 namespace Location {
LocatingRequiredDataCallbackTaihe()25 LocatingRequiredDataCallbackTaihe::LocatingRequiredDataCallbackTaihe()
26 {
27 }
28 
~LocatingRequiredDataCallbackTaihe()29 LocatingRequiredDataCallbackTaihe::~LocatingRequiredDataCallbackTaihe()
30 {
31 }
32 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)33 int LocatingRequiredDataCallbackTaihe::OnRemoteRequest(
34     uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
35 {
36     LBSLOGD(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackTaihe::OnRemoteRequest!");
37     if (data.ReadInterfaceToken() != GetDescriptor()) {
38         LBSLOGE(LOCATING_DATA_CALLBACK, "invalid token.");
39         return -1;
40     }
41 
42     switch (code) {
43         case RECEIVE_INFO_EVENT: {
44             int cnt = data.ReadInt32();
45             if (cnt >= 0 && cnt <= MAXIMUM_LOCATING_REQUIRED_DATAS) {
46                 std::vector<std::shared_ptr<LocatingRequiredData>> res;
47                 for (int i = 0; cnt > 0 && i < cnt; i++) {
48                     res.push_back(LocatingRequiredData::Unmarshalling(data));
49                 }
50                 // update wifi info
51                 if (res.size() > 0 && res[0]->GetType() == LocatingRequiredDataType::WIFI) {
52                     SetSingleResult(res);
53                 }
54                 OnLocatingDataChange(res);
55             }
56             break;
57         }
58         default: {
59             IPCObjectStub::OnRemoteRequest(code, data, reply, option);
60             break;
61         }
62     }
63     return 0;
64 }
65 
OnLocatingDataChange(const std::vector<std::shared_ptr<LocatingRequiredData>> & data)66 void LocatingRequiredDataCallbackTaihe::OnLocatingDataChange(
67     const std::vector<std::shared_ptr<LocatingRequiredData>>& data)
68 {
69     LBSLOGI(LOCATING_DATA_CALLBACK, "LocatingRequiredDataCallbackTaihe::OnLocatingDataChange");
70     std::vector<::ohos::geoLocationManager::LocatingRequiredData> locatingRequiredDataList;
71     Util::LocatingRequiredDataToTaihe(locatingRequiredDataList, data);
72     if (callback_) {
73         (*callback_)(::taihe::array<::ohos::geoLocationManager::LocatingRequiredData>{taihe::copy_data_t{},
74             locatingRequiredDataList.data(), locatingRequiredDataList.size()});
75     }
76 }
77 
ClearSingleResult()78 void LocatingRequiredDataCallbackTaihe::ClearSingleResult()
79 {
80     singleResult_.clear();
81 }
82 
SetSingleResult(std::vector<std::shared_ptr<LocatingRequiredData>> singleResult)83 void LocatingRequiredDataCallbackTaihe::SetSingleResult(
84     std::vector<std::shared_ptr<LocatingRequiredData>> singleResult)
85 {
86     singleResult_.assign(singleResult.begin(), singleResult.end());
87 }
88 }  // namespace Location
89 }  // namespace OHOS
90