CHIPDeviceManager.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. *
  3. * Copyright (c) 2020 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. /**
  18. * @file
  19. * This file contains definitions for the CHIP DeviceManager Interface
  20. *
  21. * This object will co-ordinate multiple activities such as
  22. * initialisation, rendezvous, session mgmt and other such
  23. * activities within the CHIP stack. This is a singleton object.
  24. */
  25. #pragma once
  26. #include <lib/core/CHIPCore.h>
  27. #include <lib/core/CHIPError.h>
  28. #include <platform/CHIPDeviceLayer.h>
  29. #include <lib/support/DLLUtil.h>
  30. #include <stdarg.h>
  31. #include <stdlib.h>
  32. #include <app/util/af-types.h>
  33. namespace chip {
  34. namespace DeviceManager {
  35. /**
  36. * @brief
  37. * This class provides a skeleton for all the callback functions. The functions will be
  38. * called by other objects within the CHIP stack for specific events.
  39. * Applications interested in receiving specific callbacks can specialize this class and handle
  40. * these events in their implementation of this class.
  41. */
  42. class CHIPDeviceManagerCallbacks
  43. {
  44. public:
  45. /**
  46. * @brief
  47. * Called when CHIP Device events (PublicEventTypes) are triggered.
  48. *
  49. * @param event ChipDeviceEvent that occurred
  50. * @param arg arguments specific to the event, if any
  51. */
  52. virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) {}
  53. /**
  54. * @brief
  55. * Called after an attribute has been changed
  56. *
  57. * @param endpoint endpoint id
  58. * @param clusterID cluster id
  59. * @param attributeId attribute id that was changed
  60. * @param mask mask of the attribute
  61. * @param manufacturerCode manufacturer code
  62. * @param type attribute type
  63. * @param size size of the attribute
  64. * @param value pointer to the new value
  65. */
  66. virtual void PostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId,
  67. uint8_t type, uint16_t size, uint8_t * value)
  68. {}
  69. virtual ~CHIPDeviceManagerCallbacks() {}
  70. };
  71. /**
  72. * @brief
  73. * A common class that drives other components of the CHIP stack
  74. */
  75. class DLL_EXPORT CHIPDeviceManager
  76. {
  77. public:
  78. CHIPDeviceManager(const CHIPDeviceManager &) = delete;
  79. CHIPDeviceManager(const CHIPDeviceManager &&) = delete;
  80. CHIPDeviceManager & operator=(const CHIPDeviceManager &) = delete;
  81. static CHIPDeviceManager & GetInstance()
  82. {
  83. static CHIPDeviceManager instance;
  84. return instance;
  85. }
  86. /**
  87. * @brief
  88. * Initialise CHIPDeviceManager
  89. *
  90. * @param cb Application's instance of the CHIPDeviceManagerCallbacks for consuming events
  91. */
  92. CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb);
  93. /**
  94. * @brief
  95. * Fetch a pointer to the registered CHIPDeviceManagerCallbacks object.
  96. *
  97. */
  98. CHIPDeviceManagerCallbacks * GetCHIPDeviceManagerCallbacks() { return mCB; }
  99. /**
  100. * Use internally for registration of the ChipDeviceEvents
  101. */
  102. static void CommonDeviceEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
  103. private:
  104. CHIPDeviceManagerCallbacks * mCB = nullptr;
  105. CHIPDeviceManager() {}
  106. };
  107. } // namespace DeviceManager
  108. } // namespace chip