1 /*
2 * Copyright (c) 2021 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 <cinttypes>
17 #include "sensor_client_stub.h"
18
19 #include "sensor_agent_proxy.h"
20 #include "sensor_errors.h"
21 #include "sensor_log.h"
22
23 #undef LOG_TAG
24 #define LOG_TAG "SensorClientStub"
25 namespace OHOS {
26 namespace Sensors {
27 using namespace OHOS::HiviewDFX;
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t SensorClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
30 MessageOption &option)
31 {
32 std::u16string descriptor = SensorClientStub::GetDescriptor();
33 std::u16string remoteDescriptor = data.ReadInterfaceToken();
34 if (descriptor != remoteDescriptor) {
35 SEN_HILOGE("Client and service descriptors are inconsistent");
36 return OBJECT_NULL;
37 }
38 SEN_HILOGD("Begin, cmd:%{public}u", code);
39 if (code != PROCESS_PLUG_EVENT) {
40 SEN_HILOGE("code parameter error.");
41 return PARAMETER_ERROR;
42 }
43 SensorPlugData info;
44 CHKCR(data.ReadInt32(info.deviceId), PARAMETER_ERROR);
45 CHKCR(data.ReadInt32(info.sensorTypeId), PARAMETER_ERROR);
46 CHKCR(data.ReadInt32(info.sensorId), PARAMETER_ERROR);
47 CHKCR(data.ReadInt32(info.location), PARAMETER_ERROR);
48 CHKCR(data.ReadString(info.deviceName), PARAMETER_ERROR);
49 CHKCR(data.ReadInt32(info.status), PARAMETER_ERROR);
50 CHKCR(data.ReadInt32(info.reserved), PARAMETER_ERROR);
51 CHKCR(data.ReadInt64(info.timestamp), PARAMETER_ERROR);
52 int32_t result = ProcessPlugEvent(info);
53 if (result != NO_ERROR) {
54 SEN_HILOGE("Process plug event failed");
55 }
56 return NO_ERROR;
57 }
58
ProcessPlugEvent(const SensorPlugData & info)59 int32_t SensorClientStub::ProcessPlugEvent(const SensorPlugData &info)
60 {
61 CALL_LOG_ENTER;
62 if (!(SENSOR_AGENT_IMPL->HandlePlugSensorData(info))) {
63 SEN_HILOGE("Handle sensor data failed");
64 return PARAMETER_ERROR;
65 }
66 SEN_HILOGD("Success to process plug event");
67 return NO_ERROR;
68 }
69 } // namespace Sensors
70 } // namespace OHOS
71