Line data Source code
1 : /********************************************************************************
2 : * Copyright (c) 2026 BMW AG
3 : *
4 : * This program and the accompanying materials are made available under the
5 : * terms of the Apache License Version 2.0 which is available at
6 : * https://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : ********************************************************************************/
10 : #pragma once
11 :
12 : #include "Logger.h"
13 : #include "org/test/foo/FooSkeleton.h"
14 :
15 : /**
16 : * Concrete FooSkeleton implementation for the simulation Cluster0 provider.
17 : *
18 : * Stores a FooStruct value, handles get/set requests and answers FooMethod calls.
19 : * On every set, the new value is broadcast to all subscribed proxies.
20 : */
21 : class FooSkeletonWrapper : public org::test::foo::Foo::skeleton::FooSkeleton
22 : {
23 : public:
24 12 : void init() { FooSkeleton::init(org::test::foo::Foo::internal::InstanceId::InstanceId_1); }
25 :
26 20 : void sendBroadcast()
27 : {
28 20 : data_.fooValue++;
29 20 : fooDefault.set(data_);
30 20 : auto const result = fooDefault.send();
31 20 : if (result == ::middleware::core::HRESULT::Ok)
32 : {
33 20 : simulation::Logger::log(
34 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
35 : "Foo broadcast sent, fooValue=",
36 20 : data_.fooValue);
37 : }
38 20 : }
39 :
40 30 : void getFooDefaultAttribute(
41 : ::middleware::core::ResponseBufferBase::SkeletonResponseInfo& response) override
42 : {
43 30 : respondGetFooDefaultAttribute(response, data_);
44 30 : }
45 :
46 17 : void fooMethod(
47 : uint32_t const& startValue,
48 : ::middleware::core::ResponseBufferBase::SkeletonResponseInfo& response) override
49 : {
50 17 : org::test::foo::Foo::FooMethodResult values{};
51 17 : uint32_t value = startValue;
52 85 : for (auto& element : values)
53 : {
54 68 : element = value;
55 68 : ++value;
56 : }
57 :
58 17 : auto const result = respondFooMethod(response, values);
59 17 : if (result != ::middleware::core::HRESULT::Ok)
60 : {
61 0 : simulation::Logger::log(
62 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
63 : "FooMethod response failed, error=",
64 0 : static_cast<unsigned>(result));
65 : }
66 17 : }
67 :
68 0 : void setFooDefaultAttribute(org::test::foo::Foo::FooStruct const& value) override
69 : {
70 0 : data_ = value;
71 0 : fooDefault.set(data_);
72 0 : (void)fooDefault.send();
73 0 : simulation::Logger::log(
74 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
75 : "Foo set received, fooValue=",
76 0 : data_.fooValue);
77 0 : }
78 :
79 : private:
80 : org::test::foo::Foo::FooStruct data_{};
81 : };
|