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 <feature.h>
17 #include <samgr_lite.h>
18 #include "ibattery.h"
19 #include "battery_manage_feature.h"
20 #include "battery_device.h"
21
22 static const int BATT_INT_VALUE = 0;
23
GetFeatureName(Feature * feature)24 const char *GetFeatureName(Feature *feature)
25 {
26 (void)feature;
27 return BATTERY_INNER;
28 }
29
OnFeatureInitialize(Feature * feature,Service * parent,Identity identity)30 void OnFeatureInitialize(Feature *feature, Service *parent, Identity identity)
31 {
32 (void)feature;
33 (void)identity;
34 }
35
OnFeatureStop(Feature * feature,Identity identity)36 void OnFeatureStop(Feature *feature, Identity identity)
37 {
38 (void)feature;
39 (void)identity;
40 }
41
OnFeatureMessage(Feature * feature,Request * request)42 BOOL OnFeatureMessage(Feature *feature, Request *request)
43 {
44 return ((feature != NULL) && (request != NULL)) ? TRUE : FALSE;
45 }
46
BatterySocImpl(IUnknown * iUnknown)47 int32_t BatterySocImpl(IUnknown *iUnknown)
48 {
49 int32_t soc = BATT_INT_VALUE;
50 g_batteryDevice = NewBatterInterfaceInstance();
51 if (g_batteryDevice == NULL) {
52 return soc;
53 }
54 soc = g_batteryDevice->GetSoc();
55 return soc;
56 }
ChargingStatusImpl(IUnknown * iUnknown)57 BatteryChargeState ChargingStatusImpl(IUnknown *iUnknown)
58 {
59 BatteryChargeState chargingstate = CHARGE_STATE_BUTT;
60 g_batteryDevice = NewBatterInterfaceInstance();
61 if (g_batteryDevice == NULL) {
62 return chargingstate;
63 }
64 chargingstate = g_batteryDevice->GetChargingStatus();
65 return chargingstate;
66 }
HealthStatusImpl(IUnknown * iUnknown)67 BatteryHealthState HealthStatusImpl(IUnknown *iUnknown)
68 {
69 BatteryHealthState healthState = HEALTH_STATE_BUTT;
70 g_batteryDevice = NewBatterInterfaceInstance();
71 if (g_batteryDevice == NULL) {
72 return healthState;
73 }
74 healthState = g_batteryDevice->GetHealthStatus();
75 return healthState;
76 }
PluggedTypeImpl(IUnknown * iUnknown)77 BatteryPluggedType PluggedTypeImpl(IUnknown *iUnknown)
78 {
79 BatteryPluggedType pluggedType = PLUGGED_TYPE_BUTT;
80 g_batteryDevice = NewBatterInterfaceInstance();
81 if (g_batteryDevice == NULL) {
82 return pluggedType;
83 }
84 pluggedType = g_batteryDevice->GetPluggedType();
85 return pluggedType;
86 }
VoltageImpl(IUnknown * iUnknown)87 int32_t VoltageImpl(IUnknown *iUnknown)
88 {
89 int32_t voltage = BATT_INT_VALUE;
90 g_batteryDevice = NewBatterInterfaceInstance();
91 if (g_batteryDevice == NULL) {
92 return voltage;
93 }
94 voltage = g_batteryDevice->GetVoltage();
95 return voltage;
96 }
TechnologyImpl(IUnknown * iUnknown)97 char* TechnologyImpl(IUnknown *iUnknown)
98 {
99 char* technology = NULL;
100 g_batteryDevice = NewBatterInterfaceInstance();
101 if (g_batteryDevice == NULL) {
102 return technology;
103 }
104 technology = g_batteryDevice->GetTechnology();
105 return technology;
106 }
BatteryTemperatureImpl(IUnknown * iUnknown)107 int32_t BatteryTemperatureImpl(IUnknown *iUnknown)
108 {
109 int32_t temperature = BATT_INT_VALUE;
110 g_batteryDevice = NewBatterInterfaceInstance();
111 if (g_batteryDevice == NULL) {
112 return temperature;
113 }
114 temperature = g_batteryDevice->GetTemperature();
115 return temperature;
116 }
117
GInit()118 static void GInit()
119 {
120 BatteryFeatureApi *feature = GetBatteryFeatureImpl();
121 if (feature == NULL) {
122 return;
123 }
124
125 BOOL result = SAMGR_GetInstance()->RegisterFeature(BATTERY_SERVICE, (Feature *)feature);
126 if (result == FALSE) {
127 return;
128 }
129 BOOL apiResult = SAMGR_GetInstance()->RegisterFeatureApi(BATTERY_SERVICE, BATTERY_INNER, GET_IUNKNOWN(*feature));
130 if (apiResult == FALSE) {
131 return;
132 }
133 }
134 SYSEX_FEATURE_INIT(GInit);