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 
16 #ifndef LIGHT_CLIENT_H
17 #define LIGHT_CLIENT_H
18 
19 #include <mutex>
20 
21 #include "iremote_object.h"
22 #include "miscdevice_service_proxy.h"
23 #include "singleton.h"
24 
25 namespace OHOS {
26 namespace Sensors {
27 class LightClient : public Singleton<LightClient> {
28 public:
29     ~LightClient() override;
30     int32_t GetLightList(LightInfo **lightInfo, int32_t &count);
31     int32_t TurnOn(int32_t lightId, const LightColor &color, const LightAnimation &animation);
32     int32_t TurnOff(int32_t lightId);
33     void ProcessDeathObserver(wptr<IRemoteObject> object);
34 
35 private:
36     bool IsValid(int32_t lightId);
37     void ClearLightInfos();
38     int32_t ConvertLightInfos();
39     int32_t InitLightClient();
40     bool IsLightAnimationValid(const LightAnimation &animation);
41     bool IsLightIdValid(int32_t lightId);
42     std::mutex lightInfosMutex_;
43     LightInfo *lightInfos_ {nullptr};
44     int32_t lightInfoCount_ {-1};
45     sptr<IRemoteObject::DeathRecipient> serviceDeathObserver_ = nullptr;
46     sptr<IMiscdeviceService> miscdeviceProxy_ = nullptr;
47     std::vector<LightInfoIPC> lightInfoList_;
48     std::mutex clientMutex_;
49 };
50 }  // namespace Sensors
51 }  // namespace OHOS
52 #endif  // LIGHT_CLIENT_H
53