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 "sensor_agent_proxy.h"
17 #include "sensor_service.h"
18
GetServiceProxy()19 void *GetServiceProxy()
20 {
21 IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SENSOR_SERVICE);
22 if (iUnknown == NULL) {
23 HILOG_ERROR(HILOG_MODULE_APP, "%s get sensor service failed", __func__);
24 return NULL;
25 }
26 SensorFeatureApi *sensor = NULL;
27 int32_t result = iUnknown->QueryInterface(iUnknown, DEFAULT_VERSION, (void **)&sensor);
28 if ((result != 0) || (sensor == NULL)) {
29 HILOG_ERROR(HILOG_MODULE_APP, "%s query interface failed", __func__);
30 return NULL;
31 }
32 return sensor;
33 }
34
GetAllSensorsByProxy(const void * proxy,SensorInfo ** sensorInfo,int32_t * count)35 int32_t GetAllSensorsByProxy(const void *proxy, SensorInfo **sensorInfo, int32_t *count)
36 {
37 if ((proxy == NULL) || (count == NULL)) {
38 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy or count is NULL", __func__);
39 return SENSOR_ERROR_INVALID_PARAM;
40 }
41 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
42 return sensor->GetAllSensors(sensorInfo, count);
43 }
44
ActivateSensorByProxy(const void * proxy,int32_t sensorId,const SensorUser * sensorUser)45 int32_t ActivateSensorByProxy(const void *proxy, int32_t sensorId, const SensorUser *sensorUser)
46 {
47 if (proxy == NULL) {
48 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
49 return SENSOR_ERROR_INVALID_PARAM;
50 }
51 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
52 return sensor->ActivateSensor(sensorId);
53 }
54
DeactivateSensorByProxy(const void * proxy,int32_t sensorId,const SensorUser * sensorUser)55 int32_t DeactivateSensorByProxy(const void *proxy, int32_t sensorId, const SensorUser *sensorUser)
56 {
57 if (proxy == NULL) {
58 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
59 return SENSOR_ERROR_INVALID_PARAM;
60 }
61 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
62 return sensor->DeactivateSensor(sensorId);
63 }
64
SetBatchByProxy(const void * proxy,int32_t sensorId,const SensorUser * user,int64_t samplingInterval,int64_t reportInterval)65 int32_t SetBatchByProxy(const void *proxy, int32_t sensorId, const SensorUser *user, int64_t samplingInterval,
66 int64_t reportInterval)
67 {
68 if (proxy == NULL) {
69 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
70 return SENSOR_ERROR_INVALID_PARAM;
71 }
72 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
73 return sensor->SetBatch(sensorId, user, samplingInterval, reportInterval);
74 }
75
SubscribeSensorByProxy(const void * proxy,int32_t sensorId,const SensorUser * sensorUser)76 int32_t SubscribeSensorByProxy(const void *proxy, int32_t sensorId, const SensorUser *sensorUser)
77 {
78 if (proxy == NULL) {
79 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
80 return SENSOR_ERROR_INVALID_PARAM;
81 }
82 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
83 return sensor->SubscribeSensor(sensorId, sensorUser);
84 }
85
UnsubscribeSensorByProxy(const void * proxy,int32_t sensorId,const SensorUser * sensorUser)86 int32_t UnsubscribeSensorByProxy(const void *proxy, int32_t sensorId, const SensorUser *sensorUser)
87 {
88 if (proxy == NULL) {
89 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
90 return;
91 }
92 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
93 return sensor->UnsubscribeSensor(sensorId, sensorUser);
94 }
95
SetModeByProxy(const void * proxy,int32_t sensorId,const SensorUser * user,int32_t mode)96 int32_t SetModeByProxy(const void *proxy, int32_t sensorId, const SensorUser *user, int32_t mode)
97 {
98 if (proxy == NULL) {
99 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
100 return SENSOR_ERROR_INVALID_PARAM;
101 }
102 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
103 return sensor->SetMode(sensorId, user, mode);
104 }
105
SetOptionByProxy(const void * proxy,int32_t sensorId,const SensorUser * user,int32_t option)106 int32_t SetOptionByProxy(const void *proxy, int32_t sensorId, const SensorUser *user, int32_t option)
107 {
108 if (proxy == NULL) {
109 HILOG_ERROR(HILOG_MODULE_APP, "%s proxy is NULL", __func__);
110 return SENSOR_ERROR_INVALID_PARAM;
111 }
112 SensorFeatureApi *sensor = (SensorFeatureApi *)proxy;
113 return sensor->SetOption(sensorId, user, option);
114 }
115