158ec469eSopenharmony_ci/*
258ec469eSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
358ec469eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
458ec469eSopenharmony_ci * you may not use this file except in compliance with the License.
558ec469eSopenharmony_ci * You may obtain a copy of the License at
658ec469eSopenharmony_ci *
758ec469eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
858ec469eSopenharmony_ci *
958ec469eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1058ec469eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1158ec469eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1258ec469eSopenharmony_ci * See the License for the specific language governing permissions and
1358ec469eSopenharmony_ci * limitations under the License.
1458ec469eSopenharmony_ci */
1558ec469eSopenharmony_ci#include "light_agent.h"
1658ec469eSopenharmony_ci
1758ec469eSopenharmony_ci#include "light_client.h"
1858ec469eSopenharmony_ci#include "sensors_errors.h"
1958ec469eSopenharmony_ci
2058ec469eSopenharmony_ci#undef LOG_TAG
2158ec469eSopenharmony_ci#define LOG_TAG "LightNDK"
2258ec469eSopenharmony_ci
2358ec469eSopenharmony_cinamespace OHOS {
2458ec469eSopenharmony_cinamespace Sensors {
2558ec469eSopenharmony_ci
2658ec469eSopenharmony_ciint32_t GetLightList(LightInfo **lightInfo, int32_t &count)
2758ec469eSopenharmony_ci{
2858ec469eSopenharmony_ci    CHKPR(lightInfo, ERROR);
2958ec469eSopenharmony_ci    auto &client = LightClient::GetInstance();
3058ec469eSopenharmony_ci    int32_t ret = client.GetLightList(lightInfo, count);
3158ec469eSopenharmony_ci    if (ret != ERR_OK) {
3258ec469eSopenharmony_ci        MISC_HILOGE("GetLightList failed");
3358ec469eSopenharmony_ci        return ERROR;
3458ec469eSopenharmony_ci    }
3558ec469eSopenharmony_ci    return SUCCESS;
3658ec469eSopenharmony_ci}
3758ec469eSopenharmony_ci
3858ec469eSopenharmony_ciint32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation)
3958ec469eSopenharmony_ci{
4058ec469eSopenharmony_ci    if (lightId < 0) {
4158ec469eSopenharmony_ci        MISC_HILOGE("lightId is invalid");
4258ec469eSopenharmony_ci        return ERROR;
4358ec469eSopenharmony_ci    }
4458ec469eSopenharmony_ci    auto &client = LightClient::GetInstance();
4558ec469eSopenharmony_ci    int32_t ret = client.TurnOn(lightId, color, animation);
4658ec469eSopenharmony_ci    if (ret != ERR_OK) {
4758ec469eSopenharmony_ci        MISC_HILOGE("TurnOn failed, lightId:%{public}d, ret:%{public}d ", lightId, ret);
4858ec469eSopenharmony_ci        return ERROR;
4958ec469eSopenharmony_ci    }
5058ec469eSopenharmony_ci    return SUCCESS;
5158ec469eSopenharmony_ci}
5258ec469eSopenharmony_ci
5358ec469eSopenharmony_ciint32_t TurnOff(int32_t lightId)
5458ec469eSopenharmony_ci{
5558ec469eSopenharmony_ci    if (lightId < 0) {
5658ec469eSopenharmony_ci        MISC_HILOGE("lightId is error");
5758ec469eSopenharmony_ci        return ERROR;
5858ec469eSopenharmony_ci    }
5958ec469eSopenharmony_ci    auto &client = LightClient::GetInstance();
6058ec469eSopenharmony_ci    int32_t ret = client.TurnOff(lightId);
6158ec469eSopenharmony_ci    if (ret != ERR_OK) {
6258ec469eSopenharmony_ci        MISC_HILOGE("TurnOff failed, lightId:%{public}d, ret:%{public}d", lightId, ret);
6358ec469eSopenharmony_ci        return ERROR;
6458ec469eSopenharmony_ci    }
6558ec469eSopenharmony_ci    return SUCCESS;
6658ec469eSopenharmony_ci}
6758ec469eSopenharmony_ci}  // namespace Sensors
6858ec469eSopenharmony_ci}  // namespace OHOS
69