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 :
11 : #pragma once
12 :
13 : #include <features/communication/dummy_serviceCommon.h>
14 : #include <features/communication/dummy_serviceSkeleton.h>
15 :
16 : #include <middleware/svc/core/ResponseBufferBase.h>
17 :
18 : #include <cstdint>
19 :
20 : namespace application
21 : {
22 :
23 : namespace
24 : {
25 : constexpr uint32_t BROADCAST_VALUE = 0x00FF00FFU;
26 : } // namespace
27 :
28 : // [service-skeleton-wrapper-start]
29 : class SkeletonApp : public features::communication::DummyService::skeleton::DummyServiceSkeleton
30 : {
31 : public:
32 : using Base = features::communication::DummyService::skeleton::DummyServiceSkeleton;
33 : using Foo = features::communication::DummyService::Foo;
34 : using Baz = features::communication::DummyService::Baz;
35 : using FireAndForgetPayload = features::communication::DummyService::FireAndForgetPayload;
36 : using MwInstanceId = features::communication::DummyService::internal::InstanceId;
37 : using SkeletonResponseInfo = ::middleware::svc::core::ResponseBufferBase::SkeletonResponseInfo;
38 :
39 6 : bool init()
40 : {
41 6 : return Base::init(MwInstanceId::Core0ProviderDummy) == ::middleware::svc::core::HRESULT::Ok;
42 : }
43 :
44 : void shutdown() { Base::deInit(); }
45 :
46 : // [service-skeleton-method-start]
47 1 : void asyncMethod([[maybe_unused]] Foo const& input, SkeletonResponseInfo& response) override
48 : {
49 1 : Base::asyncMethod(input, response);
50 1 : pendingAsyncResponse_ = &response;
51 1 : }
52 :
53 : // [service-skeleton-method-end]
54 :
55 : // [service-skeleton-fire-and-forget-method-start]
56 1 : void fireAndForgetMethod(FireAndForgetPayload const& payload) override
57 : {
58 1 : Base::fireAndForgetMethod(payload);
59 1 : }
60 :
61 : // [service-skeleton-fire-and-forget-method-end]
62 :
63 : // [service-skeleton-execute-start]
64 1 : void execute()
65 : {
66 : /* Disabled for the mock unit test: init() is mocked, so isInitialized() stays false. */
67 1 : if (/* Base::isInitialized() && */ pendingAsyncResponse_ != nullptr)
68 : {
69 : [[maybe_unused]] ::middleware::svc::core::HRESULT const result
70 2 : = Base::respondAsyncMethod(
71 1 : *pendingAsyncResponse_,
72 1 : features::communication::DummyService::Baz{9U, 8U, 7U, 6U});
73 1 : pendingAsyncResponse_ = nullptr;
74 : }
75 1 : }
76 :
77 : // [service-skeleton-execute-end]
78 :
79 : // [service-skeleton-broadcast-start]
80 : void publishBroadcast()
81 : {
82 : if (Base::isInitialized())
83 : {
84 : [[maybe_unused]] ::middleware::svc::core::HRESULT const result
85 : = this->simpleBroadcast.send(BROADCAST_VALUE);
86 : }
87 : }
88 :
89 : // [service-skeleton-broadcast-end]
90 :
91 : // [service-skeleton-attribute-broadcast-start]
92 : void publishAttribute(uint32_t const value)
93 : {
94 : if (Base::isInitialized())
95 : {
96 : this->simpleField.set(value);
97 : [[maybe_unused]] ::middleware::svc::core::HRESULT const result
98 : = this->simpleField.send();
99 : }
100 : }
101 :
102 : // [service-skeleton-attribute-broadcast-end]
103 :
104 : // [service-skeleton-attribute-get-start]
105 1 : void getSimpleFieldAttribute(SkeletonResponseInfo& response) override
106 : {
107 1 : Base::getSimpleFieldAttribute(response);
108 1 : }
109 :
110 : // [service-skeleton-attribute-get-end]
111 :
112 : // [service-skeleton-attribute-set-start]
113 1 : void setSimpleFieldAttribute(uint32_t const& value) override
114 : {
115 1 : Base::setSimpleFieldAttribute(value);
116 1 : }
117 :
118 : // [service-skeleton-attribute-set-end]
119 :
120 : private:
121 : SkeletonResponseInfo* pendingAsyncResponse_{};
122 : };
123 :
124 : // [service-skeleton-wrapper-end]
125 :
126 : } // namespace application
|