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 #ifndef SENSOR_SERVICE_CLIENT_H 17 #define SENSOR_SERVICE_CLIENT_H 18 19 #include <map> 20 #include <vector> 21 22 #include "iservice_registry.h" 23 #include "singleton.h" 24 25 #include "sensor_agent_type.h" 26 #include "sensor_basic_data_channel.h" 27 #include "sensor_basic_info.h" 28 #include "sensor_client_stub.h" 29 #include "sensor_data_channel.h" 30 #include "sensor.h" 31 #include "sensor_service_proxy.h" 32 33 34 namespace OHOS { 35 namespace Sensors { 36 class SensorServiceClient : public Singleton<SensorServiceClient> { 37 public: 38 std::vector<Sensor> GetSensorList(); 39 int32_t EnableSensor(uint32_t sensorId, int64_t samplingPeroid, int64_t maxReportDelay); 40 int32_t DisableSensor(uint32_t sensorId); 41 int32_t TransferDataChannel(sptr<SensorDataChannel> sensorDataChannel); 42 int32_t DestroyDataChannel(); 43 void ProcessDeathObserver(const wptr<IRemoteObject> &object); 44 bool IsValid(uint32_t sensorId); 45 46 private: 47 int32_t InitServiceClient(); 48 void UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeroid, int64_t maxReportDelay); 49 void DeleteSensorInfoItem(uint32_t sensorId); 50 std::mutex clientMutex_; 51 sptr<IRemoteObject::DeathRecipient> serviceDeathObserver_; 52 sptr<ISensorService> sensorServer_; 53 std::vector<Sensor> sensorList_; 54 sptr<SensorDataChannel> dataChannel_; 55 sptr<SensorClientStub> sensorClientStub_; 56 std::mutex mapMutex_; 57 std::map<uint32_t, SensorBasicInfo> sensorInfoMap_; 58 }; 59 } // namespace Sensors 60 } // namespace OHOS 61 62 #endif // SENSOR_SERVICE_CLIENT_H 63