blob: ca8fbabe569bcf233e256c579757e1071694e399 [file] [log] [blame]
Hui.Li-TCLdc95a302022-04-02 00:54:00 +08001/*
2 *
3 * Copyright (c) 2022 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#pragma once
18
19#include <app-common/zap-generated/cluster-objects.h>
20#include <cstdint>
21#include <jni.h>
22
23/**
24 * @brief Handles interfacing between java code and C++ code for the purposes of LevelControl clusters.
25 */
26class LevelManager
27{
28public:
29 // installed a bridege for a LevelControl cluster endpoint and java object
30 static void NewManager(jint endpoint, jobject manager);
31
32 // helps for java to set attributes::CurrentLevel of LevelControl cluster
33 static jboolean SetLevel(jint endpoint, jint value);
34
35 // posts a CurrentLevelChanged event to suitable LevelManager
36 static void PostLevelChanged(chip::EndpointId endpoint, uint8_t value);
37
38 // handles `Changed` callbacks by calling the java `void HandleLevelChanged()` method
39 void HandleLevelChanged(uint8_t value);
40
41private:
42 // init with java objects
43 CHIP_ERROR InitializeWithObjects(jobject managerObject);
44 jobject mLevelManagerObject = nullptr;
45 jmethodID mHandleLevelChangedMethod = nullptr;
46};