Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions score/mw/com/impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ cc_library(
deps = [
":skeleton_event",
":skeleton_field_base",
"//score/mw/com/impl/methods:method_signature_element_ptr",
"//score/mw/com/impl/methods:skeleton_method",
"//score/mw/com/impl/mocking:i_skeleton_field",
"//score/mw/com/impl/plumbing:field",
"//score/mw/com/impl/plumbing:sample_allocatee_ptr",
Expand Down Expand Up @@ -246,6 +248,7 @@ cc_library(
deps = [
":error",
":skeleton_event_base",
"//score/mw/com/impl/methods:skeleton_method_base",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/result",
"@score_logging//score/mw/log",
Expand Down
5 changes: 5 additions & 0 deletions score/mw/com/impl/skeleton_base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ class DummyField : public SkeletonFieldBase
{
return ResultBlank{};
};

bool IsSetHandlerRegistered() const noexcept override
{
return false;
}
};
const auto kServiceIdentifier = make_ServiceIdentifierType("foo", 13, 37);
const LolaServiceInstanceId kLolaInstanceId{23U};
Expand Down
5 changes: 3 additions & 2 deletions score/mw/com/impl/skeleton_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace score::mw::com::impl

// False Positive: this is a normal forward declaration.
// coverity[autosar_cpp14_m3_2_3_violation]
template <typename>
template <typename SampleDataType, const bool EnableSet, const bool EnableNotifier>
class SkeletonField;

template <typename SampleDataType>
Expand All @@ -51,7 +51,8 @@ class SkeletonEvent : public SkeletonEventBase
// SkeletonField uses composition pattern to reuse code from SkeletonEvent. These two classes also have shared
// private APIs which necessitates the use of the friend keyword.
// coverity[autosar_cpp14_a11_3_1_violation]
friend class SkeletonField<SampleDataType>;
template <typename T, bool ES, bool EN>
friend class SkeletonField;

// Empty struct that is used to make the second constructor only accessible to SkeletonEvent and SkeletonField (as
// the latter is a friend).
Expand Down
227 changes: 188 additions & 39 deletions score/mw/com/impl/skeleton_field.h

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions score/mw/com/impl/skeleton_field_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define SCORE_MW_COM_IMPL_SKELETON_FIELD_BASE_H

#include "score/mw/com/impl/com_error.h"
#include "score/mw/com/impl/methods/skeleton_method_base.h"
#include "score/mw/com/impl/skeleton_event_base.h"

#include "score/mw/log/logging.h"
Expand Down Expand Up @@ -61,6 +62,15 @@ class SkeletonFieldBase
// after calling PrepareOffer() on the binding
if (!was_prepare_offer_called_)
{
// If the field is configured with a setter, the application must register
// a set handler before calling OfferService(), otherwise Offer() shall fail.
if (!IsSetHandlerRegistered())
{
score::mw::log::LogWarn("lola")
<< "Set handler must be registered before offering field: " << field_name_;
return MakeUnexpected(ComErrc::kSetHandlerNotSet);
}

if (!IsInitialValueSaved())
{
score::mw::log::LogWarn("lola") << "Initial value must be set before offering field: " << field_name_;
Expand Down Expand Up @@ -121,6 +131,9 @@ class SkeletonFieldBase
/// \brief Returns whether the initial value has been saved by the user to be used by DoDeferredUpdate
virtual bool IsInitialValueSaved() const noexcept = 0;

/// \brief Returns whether a set handler has been registered.
virtual bool IsSetHandlerRegistered() const noexcept = 0;

/// \brief Sets the initial value of the field.
///
/// The existence of the value is a precondition of this function, so IsInitialValueSaved() should be checked before
Expand Down
10 changes: 10 additions & 0 deletions score/mw/com/impl/skeleton_field_base_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class MyDummyField : public SkeletonFieldBase
return {};
}

bool IsSetHandlerRegistered() const noexcept override
{
return true;
}

bool was_deferred_update_called_{false};
bool is_initial_value_saved_{true};
};
Expand All @@ -94,6 +99,11 @@ class MyDummyFieldFailingDeferredUpdate final : public MyDummyField
{
return MakeUnexpected(ComErrc::kCommunicationLinkError);
}

bool IsSetHandlerRegistered() const noexcept override
{
return true;
}
};

class SkeletonFieldBaseFixture : public ::testing::Test
Expand Down
5 changes: 5 additions & 0 deletions score/mw/com/impl/tracing/skeleton_tracing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class MyDummyField : public SkeletonFieldBase
{
return {};
}

bool IsSetHandlerRegistered() const noexcept override
{
return true;
}
};

class SkeletonTracingFixture : public ::testing::Test
Expand Down
4 changes: 2 additions & 2 deletions score/mw/com/impl/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class SkeletonTrait
template <typename SampleType>
using Event = SkeletonEvent<SampleType>;

template <typename SampleType>
using Field = SkeletonField<SampleType>;
template <typename SampleType, bool EnableSet = false, bool EnableNotifier = false>
using Field = SkeletonField<SampleType, EnableSet, EnableNotifier>;

template <typename MethodSignature>
using Method = SkeletonMethod<MethodSignature>;
Expand Down
Loading