1 /*
2 * Copyright (c) 2024 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 "location_log.h"
17 #include "cj_lambda.h"
18 #include "location_error_callback.h"
19
20 namespace OHOS {
21 namespace GeoLocationManager {
LocationErrorCallback()22 LocationErrorCallback::LocationErrorCallback()
23 {
24 }
25
LocationErrorCallback(int64_t callbackId)26 LocationErrorCallback::LocationErrorCallback(int64_t callbackId)
27 {
28 this->callbackId_ = callbackId;
29 auto cFunc = reinterpret_cast<void(*)(int32_t errorCode)>(callbackId);
30 callback_ = [ lambda = CJLambda::Create(cFunc)](const int errorCode) ->
31 void { lambda(errorCode); };
32 }
33
~LocationErrorCallback()34 LocationErrorCallback::~LocationErrorCallback()
35 {
36 }
37
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int LocationErrorCallback::OnRemoteRequest(
39 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
40 {
41 LBSLOGD(Location::LOCATION_ERR_CALLBACK, "LocatorCallbackHost::OnRemoteRequest! code = %{public}d", code);
42 if (data.ReadInterfaceToken() != GetDescriptor()) {
43 LBSLOGE(Location::LOCATION_ERR_CALLBACK, "invalid token.");
44 return -1;
45 }
46
47 switch (code) {
48 case RECEIVE_ERROR_INFO_EVENT: {
49 OnErrorReport(data.ReadInt32());
50 break;
51 }
52 default: {
53 IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 break;
55 }
56 }
57 return 0;
58 }
59
OnLocationReport(const std::unique_ptr<Location::Location> & location)60 void LocationErrorCallback::OnLocationReport(const std::unique_ptr<Location::Location>& location)
61 {
62 }
63
OnLocatingStatusChange(const int status)64 void LocationErrorCallback::OnLocatingStatusChange(const int status)
65 {
66 }
67
OnErrorReport(const int errorCode)68 void LocationErrorCallback::OnErrorReport(const int errorCode)
69 {
70 LBSLOGI(Location::LOCATION_ERR_CALLBACK, "LocatorCallback::OnRemoteRequest! errorCode = %{public}d", errorCode);
71 std::unique_lock<std::mutex> guard(mutex_);
72 if (callback_ != nullptr) {
73 callback_(errorCode);
74 }
75 }
76 }
77 }
78