blob: 1f48d38f969d55b633b9f16e9a5c490cea35d31d [file] [log] [blame]
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
#pragma GCC diagnostic push
#include <Weave/DeviceLayer/internal/WeaveDeviceLayerInternal.h>
#pragma GCC diagnostic pop
// clang-format on
#include <lib/syslog/cpp/macros.h>
#include <memory>
namespace nl::Weave::DeviceLayer {
class TraitUpdaterImpl {
TraitUpdaterImpl() = default;
class Delegate {
virtual ~Delegate() = default;
// Provides a handle to ConnectivityManagerImpl object that this delegate
// was attached to. This allows the delegate to invoke functions on
// GenericConnectivityManagerImpl if required.
void SetTraitUpdaterImpl(TraitUpdaterImpl* impl) { impl_ = impl; }
// Receives |event| and sends it to the all the registered applets.
virtual void HandleWeaveDeviceEvent(const WeaveDeviceEvent* event) = 0;
virtual WEAVE_ERROR Init() = 0;
TraitUpdaterImpl* impl_;
// Sets the delegate containing the platform-specific implementation. It is
// invalid to invoke the TraitUpdaterImpl without setting a delegate
// first.
void SetDelegate(std::unique_ptr<Delegate> delegate);
// Gets the delegate currently in use. This may return nullptr if no delegate
// was set on this class.
Delegate* GetDelegate();
// Receives |event| and sends it to the all the registered applets.
void HandleWeaveDeviceEvent(const WeaveDeviceEvent* event);
// Static handler to trampoline event calls into an instance. |arg|
// is a pointer to the instance.
static void TrampolineEvent(const WeaveDeviceEvent* event, intptr_t arg);
friend TraitUpdaterImpl& TraitUpdater();
static TraitUpdaterImpl sInstance;
std::unique_ptr<Delegate> delegate_;
inline TraitUpdaterImpl& TraitUpdater() { return TraitUpdaterImpl::sInstance; }
} // namespace nl::Weave::DeviceLayer