LevelManager.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  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. #include <app-common/zap-generated/cluster-objects.h>
  19. #include <cstdint>
  20. #include <jni.h>
  21. /**
  22. * @brief Handles interfacing between java code and C++ code for the purposes of LevelControl clusters.
  23. */
  24. class LevelManager
  25. {
  26. public:
  27. // installed a bridege for a LevelControl cluster endpoint and java object
  28. static void NewManager(jint endpoint, jobject manager);
  29. // helps for java to set attributes::CurrentLevel of LevelControl cluster
  30. static jboolean SetLevel(jint endpoint, jint value);
  31. // posts a CurrentLevelChanged event to suitable LevelManager
  32. static void PostLevelChanged(chip::EndpointId endpoint, uint8_t value);
  33. // handles `Changed` callbacks by calling the java `void HandleLevelChanged()` method
  34. void HandleLevelChanged(uint8_t value);
  35. private:
  36. // init with java objects
  37. CHIP_ERROR InitializeWithObjects(jobject managerObject);
  38. jobject mLevelManagerObject = nullptr;
  39. jmethodID mHandleLevelChangedMethod = nullptr;
  40. };