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
674a529d
Commit
674a529d
authored
6 years ago
by
Grigoris Pavlakis
Committed by
kongr45gpen
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix unnecessary code duplication at call()
parent
e1c18787
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inc/Services/FunctionManagementService.hpp
+7
-13
7 additions, 13 deletions
inc/Services/FunctionManagementService.hpp
src/Services/FunctionManagementService.cpp
+1
-62
1 addition, 62 deletions
src/Services/FunctionManagementService.cpp
with
8 additions
and
75 deletions
inc/Services/FunctionManagementService.hpp
+
7
−
13
View file @
674a529d
...
@@ -39,16 +39,16 @@
...
@@ -39,16 +39,16 @@
typedef
String
<
MAXFUNCNAMELENGTH
>
functionName
;
typedef
String
<
MAXFUNCNAMELENGTH
>
functionName
;
typedef
etl
::
map
<
functionName
,
void
(
*
)(
String
<
MAXARGLENGTH
>
),
FUNCMAPSIZE
>
typedef
etl
::
map
<
functionName
,
void
(
*
)(
String
<
MAXARGLENGTH
>
),
FUNCMAPSIZE
>
Pointer
Map
;
Function
Map
;
class
FunctionManagementService
:
public
Service
{
class
FunctionManagementService
:
public
Service
{
/**
/**
* Map of the function names to their respective pointers. Size controlled by FUNCMAPSIZE
* Map of the function names to their respective pointers. Size controlled by FUNCMAPSIZE
*/
*/
#ifdef TESTMODE
#ifdef TESTMODE
public:
Pointer
Map
funcPtrIndex
;
public:
Function
Map
funcPtrIndex
;
#else
#else
Pointer
Map
funcPtrIndex
;
Function
Map
funcPtrIndex
;
#endif
#endif
public:
public:
...
@@ -62,28 +62,22 @@ public:
...
@@ -62,28 +62,22 @@ public:
/**
/**
* Calls the function described in the TC[8,1] message *msg*, passing the arguments contained
* Calls the function described in the TC[8,1] message *msg*, passing the arguments contained
* and, if non-existent, generates a failed start of execution notification.
* and, if non-existent, generates a failed start of execution notification. Returns an unneeded
* int, for testing purposes.
* @param msg A TC[8,1] message
* @param msg A TC[8,1] message
*/
*/
#ifdef TESTMODE
int
call
(
Message
msg
);
int
call
(
Message
msg
);
#else
void
call
(
Message
msg
);
#endif
/**
/**
* Includes a new function in the pointer map. This enables it to be called by way of a valid
* Includes a new function in the pointer map. This enables it to be called by way of a valid
* TC [8,1] message.
* TC [8,1] message. After inclusion it returns an unneeded int signalling insertion success
* (0) or failure (2). These returns are there for testing purposes only.
*
*
* @param funcName the function's name. Max. length is MAXFUNCNAMELENGTH bytes.
* @param funcName the function's name. Max. length is MAXFUNCNAMELENGTH bytes.
* @param ptr pointer to a function of void return type and a MAXARGLENGTH-lengthed byte
* @param ptr pointer to a function of void return type and a MAXARGLENGTH-lengthed byte
* string as argument (which contains the actual arguments of the function)
* string as argument (which contains the actual arguments of the function)
*/
*/
#ifdef TESTMODE
int
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)(
String
<
MAXARGLENGTH
>
));
int
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)(
String
<
MAXARGLENGTH
>
));
#else
void
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)(
String
<
MAXARGLENGTH
>
));
#endif
};
};
#endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
#endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
This diff is collapsed.
Click to expand it.
src/Services/FunctionManagementService.cpp
+
1
−
62
View file @
674a529d
...
@@ -31,7 +31,6 @@ FunctionManagementService::FunctionManagementService() {
...
@@ -31,7 +31,6 @@ FunctionManagementService::FunctionManagementService() {
}
}
#endif
#endif
#ifdef TESTMODE
int
FunctionManagementService
::
call
(
Message
msg
){
int
FunctionManagementService
::
call
(
Message
msg
){
assert
(
msg
.
messageType
==
1
);
assert
(
msg
.
messageType
==
1
);
assert
(
msg
.
serviceType
==
8
);
assert
(
msg
.
serviceType
==
8
);
...
@@ -51,7 +50,7 @@ int FunctionManagementService::call(Message msg){
...
@@ -51,7 +50,7 @@ int FunctionManagementService::call(Message msg){
// locate the appropriate function pointer
// locate the appropriate function pointer
String
<
MAXFUNCNAMELENGTH
>
name
(
funcName
);
String
<
MAXFUNCNAMELENGTH
>
name
(
funcName
);
Pointer
Map
::
iterator
iter
=
funcPtrIndex
.
find
(
name
);
Function
Map
::
iterator
iter
=
funcPtrIndex
.
find
(
name
);
void
(
*
selected
)(
String
<
MAXARGLENGTH
>
);
void
(
*
selected
)(
String
<
MAXARGLENGTH
>
);
if
(
iter
!=
funcPtrIndex
.
end
())
{
if
(
iter
!=
funcPtrIndex
.
end
())
{
...
@@ -69,7 +68,6 @@ int FunctionManagementService::call(Message msg){
...
@@ -69,7 +68,6 @@ int FunctionManagementService::call(Message msg){
return
0
;
return
0
;
}
}
// TEST VERSION OF include()!
int
FunctionManagementService
::
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)
int
FunctionManagementService
::
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)
(
String
<
MAXARGLENGTH
>
))
{
(
String
<
MAXARGLENGTH
>
))
{
...
@@ -85,62 +83,3 @@ int FunctionManagementService::include(String<MAXFUNCNAMELENGTH> funcName, void(
...
@@ -85,62 +83,3 @@ int FunctionManagementService::include(String<MAXFUNCNAMELENGTH> funcName, void(
return
0
;
return
0
;
}
}
#else
void
FunctionManagementService
::
call
(
Message
msg
){
assert
(
msg
.
messageType
==
1
);
assert
(
msg
.
serviceType
==
8
);
uint8_t
funcName
[
MAXFUNCNAMELENGTH
];
// the function's name
uint8_t
funcArgs
[
MAXARGLENGTH
];
// arguments for the function
msg
.
readString
(
funcName
,
MAXFUNCNAMELENGTH
);
msg
.
readString
(
funcArgs
,
MAXARGLENGTH
);
if
(
msg
.
readPosition
<
MAXFUNCNAMELENGTH
+
MAXARGLENGTH
)
{
/**
* @todo Send failed start of execution (too long message)
*/
return
;
}
// locate the appropriate function pointer
String
<
MAXFUNCNAMELENGTH
>
name
(
funcName
);
PointerMap
::
iterator
iter
=
funcPtrIndex
.
find
(
name
);
void
(
*
selected
)(
String
<
MAXARGLENGTH
>
);
if
(
iter
!=
funcPtrIndex
.
end
())
{
selected
=
*
iter
->
second
;
}
else
{
/**
* @todo Send failed start of execution (function not found)
*/
return
;
}
// execute the function if there are no obvious flaws (defined in the standard, pg.158)
selected
(
funcArgs
);
}
void
FunctionManagementService
::
include
(
String
<
MAXFUNCNAMELENGTH
>
funcName
,
void
(
*
ptr
)(
String
<
MAXARGLENGTH
>
))
{
if
(
funcName
.
length
()
>
MAXFUNCNAMELENGTH
)
{
/**
* @todo Generate suitable notification (function name exceeds maximum allowed length)
*/
return
;
}
else
if
(
funcPtrIndex
.
full
())
{
/**
* @todo Generate suitable notification (index is full)
*/
return
;
}
else
{
funcName
.
append
(
MAXFUNCNAMELENGTH
-
funcName
.
length
(),
'\0'
);
funcPtrIndex
.
insert
(
std
::
make_pair
(
funcName
,
ptr
));
}
}
#endif
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