Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ECSS Services
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AcubeSat-OBC
ECSS Services
Commits
fd77363f
Unverified
Commit
fd77363f
authored
5 years ago
by
Grigoris Pavlakis
Browse files
Options
Downloads
Patches
Plain Diff
Add warning for the Parameter setter's type safety
parent
65dd8bdb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+0
-1
0 additions, 1 deletion
CMakeLists.txt
inc/Parameters/Parameters.hpp
+5
-0
5 additions, 0 deletions
inc/Parameters/Parameters.hpp
inc/Services/Parameter.hpp
+27
-42
27 additions, 42 deletions
inc/Services/Parameter.hpp
with
32 additions
and
43 deletions
CMakeLists.txt
+
0
−
1
View file @
fd77363f
...
...
@@ -33,7 +33,6 @@ add_library(common OBJECT
src/Helpers/TimeHelper.cpp
src/Services/EventReportService.cpp
src/Services/MemoryManagementService.cpp
src/Services/Parameter.cpp
src/Services/ParameterService.cpp
src/Services/RequestVerificationService.cpp
src/Services/TestService.cpp
...
...
This diff is collapsed.
Click to expand it.
src/Service
s/Parameter
.c
pp
→
inc/Parameter
s/Parameter
s.h
pp
+
5
−
0
View file @
fd77363f
#include
"Services/Parameter.hpp"
namespace
SystemParameters
{
// initialize all system parameters here
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
inc/Services/Parameter.hpp
+
27
−
42
View file @
fd77363f
...
...
@@ -9,76 +9,61 @@
* Fully compliant with the standard's requirements.
*
* @author Grigoris Pavlakis <grigpavl@ece.auth.gr>
* @author Athanasios Theocharis <athatheo@csd.auth.gr>
*
*
* The Parameter class implements a way of storing and updating system parameters
* of arbitrary size and type, while avoiding std::any and dynamic memory allocation.
*
* It is split in two parts: an abstract ParameterBase class which contains the setter,
* and a
*/
/**
* Useful type definitions
*
*
(DEPRECATED - MARK FOR REMOVAL)
* @typedef ParamId: the unique ID of a parameter, used for searching
*/
typedef
uint16_t
ParamId
;
/**
* Parameter class - Breakdown of fields
/*
* MILLION DOLLAR QUESTIONS:
* setCurrentValue is templated. Since Parameter (a template class) inherits ParameterBase
* (a class containing a template member), does a specialization of Parameter also specialize
* setCurrentValue? If not, we have a problem, since Parameter won't necessarily specialize
* setCurrentValue with the correct type => our setter is *not* typesafe.
*
* @private ptr: Pointer of the function that will update the parameter
* @private currentValue: The current (as in last good) value of the parameter
* Answer: NO! After a discussion on ##C++-general@Freenode, it turns out that this specialization
* does not happen! What this means is that, while a Parameter can be specialized as e.g. int, there
* is no way to prevent the setter from being called with a non-int (e.g. string or float) argument,
* resulting in an attempt to write data inside the Parameter that have a different type from what the
* template is carrying.
*
* Proof of concept:
* Parameter<int> ircTest = Parameter<int>(1337);
* ircTest.setCurrentValue("Hello this is a problem speaking");
* auto s = ircTest.getValueAsString();
*
* This snippet will overwrite the 4 bytes of the Parameter field with garbage and most importantly,
* it will do so silently.
*
* Methods:
* @public Parameter(uint32_t initialValue = 0, UpdatePtr newPtr = nullptr):
* Create a new Parameter object with initialValue as its starting value and newPtr
* as its update function pointer. Arguments initialValue and newPtr are optional, and have default values of
* 0 and nullptr respectively.
*
* @public setCurrentValue(): Changes the current value of the parameter
* @public getCurrentValue(): Gets the current value of the parameter
*/
// class DataField {
// protected:
// uint8_t sizeInBytes;
// void* dataFieldAddress;
// // possible race: setCurrentValue may be ran when dataFieldAddress is uninitialized
// public:
// template <typename DataType>
// void setCurrentValue(DataType newValue) {
// DataType* typedDataFieldAddress = reinterpret_cast<DataType*>(dataFieldAddress);
// *typedDataFieldAddress = newValue;
// }
// };
/**
* Highly likely that valuePtr is redundant! Then, ParameterBase could only contain
* virtual methods and act as a mere interface, moving all specific functionality to
* the Parameter class and ensuring type safety.
*/
class
ParameterBase
{
protected:
uint8_t
sizeInBytes
;
void
*
valuePtr
=
nullptr
;
void
*
valuePtr
;
public:
virtual
String
<
ECSS_ST_20_MAX_STRING_LENGTH
>
getValueAsString
()
=
0
;
template
<
typename
ValueType
>
void
setCurrentValue
(
ValueType
newVal
)
{
if
(
valuePtr
==
nullptr
)
{
std
::
cout
<<
"THIS IS NULL!"
<<
std
::
endl
;
}
*
reinterpret_cast
<
ValueType
*>
(
valuePtr
)
=
newVal
;
}
};
/**
* MILLION DOLLAR QUESTIONS:
* setCurrentValue is templated. Since Parameter (a template class) inherits ParameterBase
* (a class containing a template member), does a specialization of Parameter also specialize
* setCurrentValue? If not, we have a problem, since Parameter won't necessarily specialize
* setCurrentValue with the correct type => our setter is *not* typesafe.
*/
template
<
typename
ValueType
>
class
Parameter
:
public
ParameterBase
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment