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 <iproxy_server.h>
17 #include "battery_manage_feature.h"
18
19 typedef int32_t (*InvokeFunc)(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
20 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply);
21
22 static int32_t BatterySocInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
23 static int32_t ChargingStatusInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
24 static int32_t HealthStatusInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
25 static int32_t PluggedTypeInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
26 static int32_t VoltageInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
27 static int32_t TechnologyInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
28 static int32_t BatteryTemperatureInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply);
29
30 static BatteryFeatureApi g_feature = {
31 BATTERY_FEATURE_INTERFACE_IMPL,
32 SERVER_IPROXY_IMPL_BEGIN,
33 .Invoke = FeatureInvoke,
34 BATTERY_INTERFACE_IMPL,
35 IPROXY_END,
36 .identity_ = { -1, -1, NULL },
37 };
38
39 static InvokeFunc g_invokeFuncs[BATTERY_FUNCID_END] = {
40 BatterySocInvoke,
41 ChargingStatusInvoke,
42 HealthStatusInvoke,
43 PluggedTypeInvoke,
44 VoltageInvoke,
45 TechnologyInvoke,
46 BatteryTemperatureInvoke
47 };
48
GetBatteryFeatureImpl(void)49 BatteryFeatureApi *GetBatteryFeatureImpl(void)
50 {
51 return &g_feature;
52 }
53
FeatureInvoke(IServerProxy * iProxy,int32_t funcId,void * origin,IpcIo * req,IpcIo * reply)54 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply)
55 {
56 if ((iProxy == NULL) || (origin == NULL) || (req == NULL)) {
57 return EC_INVALID;
58 }
59 return (funcId >= 0 && funcId < BATTERY_FUNCID_END) ? g_invokeFuncs[funcId](iProxy, origin, req, reply) :
60 EC_FAILURE;
61 }
62
BatterySocInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)63 static int32_t BatterySocInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
64 {
65 if (iProxy == NULL) {
66 return EC_FAILURE;
67 }
68
69 int32_t retSoc = BatterySocImpl((IUnknown *)iProxy);
70 IpcIoPushInt32(reply, retSoc);
71 return EC_SUCCESS;
72 }
ChargingStatusInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)73 static int32_t ChargingStatusInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
74 {
75 if (iProxy == NULL) {
76 return EC_FAILURE;
77 }
78
79 BatteryChargeState chargingStatus = ChargingStatusImpl((IUnknown *)iProxy);
80 IpcIoPushInt32(reply, chargingStatus);
81 return EC_SUCCESS;
82 }
HealthStatusInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)83 static int32_t HealthStatusInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
84 {
85 if (iProxy == NULL) {
86 return EC_FAILURE;
87 }
88
89 BatteryHealthState healthStatus = HealthStatusImpl((IUnknown *)iProxy);
90 IpcIoPushInt32(reply, healthStatus);
91 return EC_SUCCESS;
92 }
PluggedTypeInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)93 static int32_t PluggedTypeInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
94 {
95 if (iProxy == NULL) {
96 return EC_FAILURE;
97 }
98
99 BatteryPluggedType status = PluggedTypeImpl((IUnknown *)iProxy);
100 IpcIoPushInt32(reply, status);
101 return EC_SUCCESS;
102 }
VoltageInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)103 static int32_t VoltageInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
104 {
105 if (iProxy == NULL) {
106 return EC_FAILURE;
107 }
108
109 int32_t retVoltage = VoltageImpl((IUnknown *)iProxy);
110 IpcIoPushInt32(reply, retVoltage);
111 return EC_SUCCESS;
112 }
TechnologyInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)113 static int32_t TechnologyInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
114 {
115 if (iProxy == NULL) {
116 return EC_FAILURE;
117 }
118
119 char *strBuff = TechnologyImpl((IUnknown *)iProxy);
120 IpcIoPushString(reply, strBuff);
121
122 return EC_SUCCESS;
123 }
BatteryTemperatureInvoke(IServerProxy * iProxy,void * origin,IpcIo * req,IpcIo * reply)124 static int32_t BatteryTemperatureInvoke(IServerProxy *iProxy, void *origin, IpcIo *req, IpcIo *reply)
125 {
126 if (iProxy == NULL) {
127 return EC_FAILURE;
128 }
129
130 int32_t retTemperature = BatteryTemperatureImpl((IUnknown*)iProxy);
131 IpcIoPushInt32(reply, retTemperature);
132 return EC_SUCCESS;
133 }