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 #ifndef SENSOR_CLIENT_PROXY_H 16 #define SENSOR_CLIENT_PROXY_H 17 #include <cinttypes> 18 #include "iremote_proxy.h" 19 20 #include "sensor_agent_type.h" 21 #include "sensor_log.h" 22 23 namespace OHOS { 24 namespace Sensors { 25 class SensorClientProxy : public IRemoteProxy<ISensorClient> { 26 public: SensorClientProxy(const sptr<IRemoteObject> & impl)27 explicit SensorClientProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ISensorClient>(impl) 28 {} 29 virtual ~SensorClientProxy() = default; ProcessPlugEvent(const SensorPlugData & info)30 int32_t ProcessPlugEvent(const SensorPlugData &info) override 31 { 32 MessageOption option; 33 MessageParcel dataParcel; 34 MessageParcel replyParcel; 35 CHKCR(dataParcel.WriteInterfaceToken(GetDescriptor()), PARAMETER_ERROR); 36 CHKCR(dataParcel.WriteInt32(info.deviceId), PARAMETER_ERROR); 37 CHKCR(dataParcel.WriteInt32(info.sensorTypeId), PARAMETER_ERROR); 38 CHKCR(dataParcel.WriteInt32(info.sensorId), PARAMETER_ERROR); 39 CHKCR(dataParcel.WriteInt32(info.location), PARAMETER_ERROR); 40 CHKCR(dataParcel.WriteString(info.deviceName), PARAMETER_ERROR); 41 CHKCR(dataParcel.WriteInt32(info.status), PARAMETER_ERROR); 42 CHKCR(dataParcel.WriteInt32(info.reserved), PARAMETER_ERROR); 43 CHKCR(dataParcel.WriteInt64(info.timestamp), PARAMETER_ERROR); 44 CHKPR(Remote(), ERROR); 45 int error = Remote()->SendRequest(PROCESS_PLUG_EVENT, dataParcel, replyParcel, option); 46 if (error != ERR_NONE) { 47 SEN_HILOGE("failed, error code is: %{public}d", error); 48 return PARAMETER_ERROR; 49 } 50 return SUCCESS; 51 } 52 53 private: 54 DISALLOW_COPY_AND_MOVE(SensorClientProxy); 55 static inline BrokerDelegator<SensorClientProxy> delegator_; 56 }; 57 } // namespace Sensors 58 } // namespace OHOS 59 #endif // SENSOR_CLIENT_PROXY_H 60