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()
25 : {
26 12 : FooSkeleton::init(org::test::foo::Foo::internal::InstanceId::Cluster0ProviderFoo);
27 12 : }
28 :
29 20 : void sendBroadcast()
30 : {
31 20 : data_.fooValue++;
32 20 : fooDefault.set(data_);
33 20 : auto const result = fooDefault.send();
34 20 : if (result == ::middleware::core::HRESULT::Ok)
35 : {
36 20 : simulation::Logger::log(
37 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
38 : "Foo broadcast sent, fooValue=",
39 20 : data_.fooValue);
40 : }
41 20 : }
42 :
43 30 : void getFooDefaultAttribute(
44 : ::middleware::core::ResponseBufferBase::SkeletonResponseInfo& response) override
45 : {
46 30 : respondGetFooDefaultAttribute(response, data_);
47 30 : }
48 :
49 17 : void fooMethod(
50 : uint32_t const& startValue,
51 : ::middleware::core::ResponseBufferBase::SkeletonResponseInfo& response) override
52 : {
53 17 : org::test::foo::Foo::FooMethodResult values{};
54 17 : uint32_t value = startValue;
55 85 : for (auto& element : values)
56 : {
57 68 : element = value;
58 68 : ++value;
59 : }
60 :
61 17 : auto const result = respondFooMethod(response, values);
62 17 : if (result != ::middleware::core::HRESULT::Ok)
63 : {
64 0 : simulation::Logger::log(
65 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
66 : "FooMethod response failed, error=",
67 0 : static_cast<unsigned>(result));
68 : }
69 17 : }
70 :
71 0 : void setFooDefaultAttribute(org::test::foo::Foo::FooStruct const& value) override
72 : {
73 0 : data_ = value;
74 0 : fooDefault.set(data_);
75 0 : (void)fooDefault.send();
76 0 : simulation::Logger::log(
77 : static_cast<uint8_t>(::middleware::core::ClusterId::Cluster0),
78 : "Foo set received, fooValue=",
79 0 : data_.fooValue);
80 0 : }
81 :
82 : private:
83 : org::test::foo::Foo::FooStruct data_{};
84 : };
|