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 "country_code_callback_taihe.h"
17 #include "location_log.h"
18
19 namespace OHOS {
20 namespace Location {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)21 int CountryCodeCallbackTaihe::OnRemoteRequest(
22 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
23 {
24 LBSLOGD(COUNTRY_CODE_CALLBACK, "CountryCodeCallbackTaihe::OnRemoteRequest! code %{punlic}d", code);
25 if (data.ReadInterfaceToken() != GetDescriptor()) {
26 LBSLOGE(COUNTRY_CODE_CALLBACK, "invalid token.");
27 return -1;
28 }
29
30 switch (code) {
31 case COUNTRY_CODE_CHANGE_EVENT: {
32 auto countryCodePtr = CountryCode::Unmarshalling(data);
33 OnCountryCodeChange(countryCodePtr);
34 break;
35 }
36 default: {
37 IPCObjectStub::OnRemoteRequest(code, data, reply, option);
38 break;
39 }
40 }
41 return 0;
42 }
43
OnCountryCodeChange(const std::shared_ptr<CountryCode> & country)44 void CountryCodeCallbackTaihe::OnCountryCodeChange(const std::shared_ptr<CountryCode>& country)
45 {
46 ::ohos::geoLocationManager::CountryCode countryTaihe = {
47 country->GetCountryCodeStr(),
48 static_cast<::ohos::geoLocationManager::CountryCodeType::key_t>(country->GetCountryCodeType())};
49 if (callback_) {
50 (*callback_)(countryTaihe);
51 }
52 }
53 } // namespace Location
54 } // namespace OHOS
55