1 /*
2 * Copyright (c) 2022 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 #include "light_agent.h"
16
17 #include "light_client.h"
18 #include "sensors_errors.h"
19
20 namespace OHOS {
21 namespace Sensors {
22 using OHOS::HiviewDFX::HiLog;
23 using OHOS::HiviewDFX::HiLogLabel;
24
25 namespace {
26 constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightNDK" };
27 } // namespace
28
GetLightList(LightInfo ** lightInfo,int32_t & count)29 int32_t GetLightList(LightInfo **lightInfo, int32_t &count)
30 {
31 CHKPR(lightInfo, ERROR);
32 auto &client = LightClient::GetInstance();
33 int32_t ret = client.GetLightList(lightInfo, count);
34 if (ret != ERR_OK) {
35 MISC_HILOGE("GetLightList failed");
36 return ERROR;
37 }
38 return SUCCESS;
39 }
40
TurnOn(int32_t lightId,const LightColor & color,const LightAnimation & animation)41 int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation)
42 {
43 if (lightId < 0) {
44 MISC_HILOGE("lightId is invalid");
45 return ERROR;
46 }
47 auto &client = LightClient::GetInstance();
48 int32_t ret = client.TurnOn(lightId, color, animation);
49 if (ret != ERR_OK) {
50 MISC_HILOGE("TurnOn failed, lightId:%{public}d,ret:%{public}d ", lightId, ret);
51 return ERROR;
52 }
53 return SUCCESS;
54 }
55
TurnOff(int32_t lightId)56 int32_t TurnOff(int32_t lightId)
57 {
58 if (lightId < 0) {
59 MISC_HILOGE("lightId is error");
60 return ERROR;
61 }
62 auto &client = LightClient::GetInstance();
63 int32_t ret = client.TurnOff(lightId);
64 if (ret != ERR_OK) {
65 MISC_HILOGE("TurnOff failed, lightId:%{public}d,ret:%{public}d", lightId, ret);
66 return ERROR;
67 }
68 return SUCCESS;
69 }
70 } // namespace Sensors
71 } // namespace OHOS
72