• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_hdi_connection.h"
16 
17 #include <list>
18 
19 #include "compatible_light_connection.h"
20 #include "hdi_light_connection.h"
21 #include "hitrace_meter.h"
22 #include "sensors_errors.h"
23 
24 namespace OHOS {
25 namespace Sensors {
26 using namespace OHOS::HiviewDFX;
27 
28 namespace {
29 constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "LightHdiConnection" };
30 }
31 
ConnectHdi()32 int32_t LightHdiConnection::ConnectHdi()
33 {
34     iLightHdiConnection_ = std::make_unique<HdiLightConnection>();
35     int32_t ret = iLightHdiConnection_->ConnectHdi();
36     if (ret != 0) {
37         MISC_HILOGE("hdi direct failed");
38         iLightHdiConnection_ = std::make_unique<CompatibleLightConnection>();
39         CHKPR(iLightHdiConnection_, ERROR);
40         ret = iLightHdiConnection_->ConnectHdi();
41     }
42     if (ret != 0) {
43         MISC_HILOGE("hdi connection failed");
44         return LIGHT_HDF_CONNECT_ERR;
45     }
46     ret = iLightHdiConnection_->GetLightList(lightInfoList_);
47     if (ret != 0) {
48         MISC_HILOGE("GetLightList failed");
49         return LIGHT_ERR;
50     }
51     return ERR_OK;
52 }
53 
GetLightList(std::vector<LightInfo> & lightList) const54 int32_t LightHdiConnection::GetLightList(std::vector<LightInfo>& lightList) const
55 {
56     lightList.assign(lightInfoList_.begin(), lightInfoList_.end());
57     return ERR_OK;
58 }
59 
TurnOn(int32_t lightId,const LightColor & color,const LightAnimation & animation)60 int32_t LightHdiConnection::TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation)
61 {
62     CHKPR(iLightHdiConnection_, ERROR);
63     int32_t ret = iLightHdiConnection_->TurnOn(lightId, color, animation);
64     if (ret != 0) {
65         MISC_HILOGE("TurnOn failed");
66         return LIGHT_ID_NOT_SUPPORT;
67     }
68     return ERR_OK;
69 }
70 
TurnOff(int32_t lightId)71 int32_t LightHdiConnection::TurnOff(int32_t lightId)
72 {
73     CHKPR(iLightHdiConnection_, ERROR);
74     int32_t ret = iLightHdiConnection_->TurnOff(lightId);
75     if (ret != 0) {
76         MISC_HILOGE("TurnOff failed");
77         return LIGHT_ERR;
78     }
79     return ERR_OK;
80 }
81 
DestroyHdiConnection()82 int32_t LightHdiConnection::DestroyHdiConnection()
83 {
84     CHKPR(iLightHdiConnection_, ERROR);
85     int32_t ret = iLightHdiConnection_->DestroyHdiConnection();
86     if (ret != 0) {
87         MISC_HILOGE("DestroyHdiConnection failed");
88         return LIGHT_HDF_CONNECT_ERR;
89     }
90     return ERR_OK;
91 }
92 }  // namespace Sensors
93 }  // namespace OHOS
94