-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Format Fw and add to CI #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format Fw and add to CI #3976
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,7 @@ jobs: | |
| env: | ||
| CHECKED_DIRS: >- | ||
| Drv | ||
| Fw/Buffer | ||
| Fw/Cmd | ||
| Fw/Com | ||
| Fw | ||
| Os | ||
| Svc/Ccsds | ||
| Svc/EventManager | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,138 +1,127 @@ | ||
| #include <Fw/FPrimeBasicTypes.hpp> | ||
| #include <Fw/Comp/ActiveComponentBase.hpp> | ||
| #include <Fw/FPrimeBasicTypes.hpp> | ||
| #include <Fw/Types/Assert.hpp> | ||
| #include <Os/TaskString.hpp> | ||
|
|
||
| namespace Fw { | ||
|
|
||
| class ActiveComponentExitSerializableBuffer : public Fw::SerializeBufferBase { | ||
|
|
||
| public: | ||
| FwSizeType getBuffCapacity() const { | ||
| return sizeof(m_buff); | ||
| } | ||
|
|
||
| U8* getBuffAddr() { | ||
| return m_buff; | ||
| } | ||
| class ActiveComponentExitSerializableBuffer : public Fw::SerializeBufferBase { | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
| public: | ||
| FwSizeType getBuffCapacity() const { return sizeof(m_buff); } | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| const U8* getBuffAddr() const { | ||
| return m_buff; | ||
| } | ||
| U8* getBuffAddr() { return m_buff; } | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| private: | ||
| const U8* getBuffAddr() const { return m_buff; } | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| U8 m_buff[sizeof(ActiveComponentBase::ACTIVE_COMPONENT_EXIT)]; | ||
| private: | ||
| U8 m_buff[sizeof(ActiveComponentBase::ACTIVE_COMPONENT_EXIT)]; | ||
| }; | ||
|
|
||
| }; | ||
| ActiveComponentBase::ActiveComponentBase(const char* name) : QueuedComponentBase(name) {} | ||
Check noticeCode scanning / CodeQL Use of basic integral type Note
name uses the basic integral type char rather than a typedef with size and signedness.
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| ActiveComponentBase::ActiveComponentBase(const char* name) : QueuedComponentBase(name) { | ||
| ActiveComponentBase::~ActiveComponentBase() {} | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| } | ||
|
|
||
| ActiveComponentBase::~ActiveComponentBase() { | ||
| } | ||
|
|
||
| void ActiveComponentBase::init(FwEnumStoreType instance) { | ||
| QueuedComponentBase::init(instance); | ||
| } | ||
| void ActiveComponentBase::init(FwEnumStoreType instance) { | ||
| QueuedComponentBase::init(instance); | ||
Check warningCode scanning / CodeQL Unchecked function argument Warning
This use of parameter instance has not been checked.
|
||
| } | ||
|
|
||
| #if FW_OBJECT_TO_STRING == 1 | ||
| const char* ActiveComponentBase::getToStringFormatString() { | ||
| return "ActComp: %s"; | ||
| } | ||
| const char* ActiveComponentBase::getToStringFormatString() { | ||
Check noticeCode scanning / CodeQL Use of basic integral type Note
getToStringFormatString uses the basic integral type char rather than a typedef with size and signedness.
|
||
| return "ActComp: %s"; | ||
| } | ||
| #endif | ||
|
|
||
| void ActiveComponentBase::start(FwTaskPriorityType priority, FwSizeType stackSize, FwSizeType cpuAffinity, FwTaskIdType identifier) { | ||
| Os::TaskString taskName; | ||
| void ActiveComponentBase::start(FwTaskPriorityType priority, | ||
Check noticeCode scanning / CodeQL Long function without assertion Note
All functions of more than 10 lines should have at least one assertion.
|
||
| FwSizeType stackSize, | ||
| FwSizeType cpuAffinity, | ||
| FwTaskIdType identifier) { | ||
| Os::TaskString taskName; | ||
|
|
||
| #if FW_OBJECT_NAMES == 1 | ||
| taskName = this->getObjName(); | ||
| taskName = this->getObjName(); | ||
Check warningCode scanning / CodeQL Unchecked return value Warning
The return value of non-void function
operator= Error loading related location Loading |
||
| #else | ||
| (void) taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks()); | ||
| (void)taskName.format("ActComp_%" PRI_FwSizeType, Os::Task::getNumTasks()); | ||
| #endif | ||
| // Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function | ||
| // Standard multithreading tasks use the task loop to respectively call the state machine | ||
| Os::Task::taskRoutine routine = (m_task.isCooperative()) ? this->s_taskStateMachine : this->s_taskLoop; | ||
| Os::Task::Arguments arguments(taskName, routine, this, priority, stackSize, cpuAffinity, identifier); | ||
| Os::Task::Status status = this->m_task.start(arguments); | ||
| FW_ASSERT(status == Os::Task::Status::OP_OK,static_cast<FwAssertArgType>(status)); | ||
| } | ||
| // Cooperative threads tasks externalize the task loop, and as such use the state machine as their task function | ||
| // Standard multithreading tasks use the task loop to respectively call the state machine | ||
| Os::Task::taskRoutine routine = (m_task.isCooperative()) ? this->s_taskStateMachine : this->s_taskLoop; | ||
| Os::Task::Arguments arguments(taskName, routine, this, priority, stackSize, cpuAffinity, identifier); | ||
Check warningCode scanning / CodeQL Unchecked function argument Warning
This use of parameter priority has not been checked.
Check warningCode scanning / CodeQL Unchecked function argument Warning
This use of parameter stackSize has not been checked.
Check warningCode scanning / CodeQL Unchecked function argument Warning
This use of parameter cpuAffinity has not been checked.
Check warningCode scanning / CodeQL Unchecked function argument Warning
This use of parameter identifier has not been checked.
|
||
| Os::Task::Status status = this->m_task.start(arguments); | ||
| FW_ASSERT(status == Os::Task::Status::OP_OK, static_cast<FwAssertArgType>(status)); | ||
| } | ||
|
|
||
| void ActiveComponentBase::exit() { | ||
| ActiveComponentExitSerializableBuffer exitBuff; | ||
| SerializeStatus stat = exitBuff.serialize(static_cast<I32>(ACTIVE_COMPONENT_EXIT)); | ||
| FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast<FwAssertArgType>(stat)); | ||
| (void)this->m_queue.send(exitBuff,0,Os::Queue::BlockingType::NONBLOCKING); | ||
| } | ||
| void ActiveComponentBase::exit() { | ||
| ActiveComponentExitSerializableBuffer exitBuff; | ||
| SerializeStatus stat = exitBuff.serialize(static_cast<I32>(ACTIVE_COMPONENT_EXIT)); | ||
| FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat)); | ||
| (void)this->m_queue.send(exitBuff, 0, Os::Queue::BlockingType::NONBLOCKING); | ||
| } | ||
|
|
||
| Os::Task::Status ActiveComponentBase::join() { | ||
| return this->m_task.join(); | ||
| } | ||
| Os::Task::Status ActiveComponentBase::join() { | ||
| return this->m_task.join(); | ||
| } | ||
|
|
||
| Os::Task::Status ActiveComponentBase::join(void** pointer) { | ||
| return this->m_task.join(); | ||
| } | ||
| Os::Task::Status ActiveComponentBase::join(void** pointer) { | ||
| return this->m_task.join(); | ||
| } | ||
|
|
||
| void ActiveComponentBase::s_taskStateMachine(void* component_pointer) { | ||
| FW_ASSERT(component_pointer != nullptr); | ||
| // cast void* back to active component | ||
| ActiveComponentBase* component = static_cast<ActiveComponentBase*>(component_pointer); | ||
|
|
||
| // Each invocation of this function runs a single stage of the thread lifecycle. This has moved the thread | ||
| // while loop to the top level such that it can be replaced by something else (e.g. cooperative thread | ||
| // dispatcher) and is not intrinsic to this code. | ||
| switch (component->m_stage) { | ||
| // The first stage the active component triggers the "preamble" call before moving into the dispatching | ||
| // stage of the component thread. | ||
| case Lifecycle::CREATED: | ||
| component->preamble(); | ||
| component->m_stage = Lifecycle::DISPATCHING; | ||
| break; | ||
| // The second stage of the active component triggers the dispatching loop dispatching messages until an | ||
| // exit message is received. | ||
| case Lifecycle::DISPATCHING: | ||
| if (component->dispatch() == MsgDispatchStatus::MSG_DISPATCH_EXIT) { | ||
| component->m_stage = Lifecycle::FINALIZING; | ||
| } | ||
| break; | ||
| // The second-to-last stage is where the finalizer is called. This will transition to the final stage | ||
| // automatically after the finalizer is called | ||
| case Lifecycle::FINALIZING: | ||
| component->finalizer(); | ||
| component->m_stage = Lifecycle::DONE; | ||
| break; | ||
| // The last stage does nothing, cooperative tasks live here forever, threaded tasks exit on this condition | ||
| case Lifecycle::DONE: | ||
| break; | ||
| default: | ||
| FW_ASSERT(0); | ||
| break; | ||
| } | ||
| void ActiveComponentBase::s_taskStateMachine(void* component_pointer) { | ||
Check noticeCode scanning / CodeQL Long function without assertion Note
All functions of more than 10 lines should have at least one assertion.
|
||
| FW_ASSERT(component_pointer != nullptr); | ||
| // cast void* back to active component | ||
| ActiveComponentBase* component = static_cast<ActiveComponentBase*>(component_pointer); | ||
|
|
||
| // Each invocation of this function runs a single stage of the thread lifecycle. This has moved the thread | ||
| // while loop to the top level such that it can be replaced by something else (e.g. cooperative thread | ||
| // dispatcher) and is not intrinsic to this code. | ||
| switch (component->m_stage) { | ||
| // The first stage the active component triggers the "preamble" call before moving into the dispatching | ||
| // stage of the component thread. | ||
| case Lifecycle::CREATED: | ||
| component->preamble(); | ||
| component->m_stage = Lifecycle::DISPATCHING; | ||
| break; | ||
| // The second stage of the active component triggers the dispatching loop dispatching messages until an | ||
| // exit message is received. | ||
| case Lifecycle::DISPATCHING: | ||
| if (component->dispatch() == MsgDispatchStatus::MSG_DISPATCH_EXIT) { | ||
| component->m_stage = Lifecycle::FINALIZING; | ||
| } | ||
| break; | ||
| // The second-to-last stage is where the finalizer is called. This will transition to the final stage | ||
| // automatically after the finalizer is called | ||
| case Lifecycle::FINALIZING: | ||
| component->finalizer(); | ||
| component->m_stage = Lifecycle::DONE; | ||
| break; | ||
| // The last stage does nothing, cooperative tasks live here forever, threaded tasks exit on this condition | ||
| case Lifecycle::DONE: | ||
| break; | ||
| default: | ||
| FW_ASSERT(0); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| void ActiveComponentBase::s_taskLoop(void* component_pointer) { | ||
| FW_ASSERT(component_pointer != nullptr); | ||
| ActiveComponentBase* component = static_cast<ActiveComponentBase*>(component_pointer); | ||
| // A non-cooperative task switching implementation is just a while-loop around the active component | ||
| // state-machine. Here the while loop is at top-level. | ||
| while (component->m_stage != ActiveComponentBase::Lifecycle::DONE) { | ||
| ActiveComponentBase::s_taskStateMachine(component); | ||
| } | ||
| void ActiveComponentBase::s_taskLoop(void* component_pointer) { | ||
| FW_ASSERT(component_pointer != nullptr); | ||
| ActiveComponentBase* component = static_cast<ActiveComponentBase*>(component_pointer); | ||
| // A non-cooperative task switching implementation is just a while-loop around the active component | ||
| // state-machine. Here the while loop is at top-level. | ||
| while (component->m_stage != ActiveComponentBase::Lifecycle::DONE) { | ||
| ActiveComponentBase::s_taskStateMachine(component); | ||
| } | ||
Check warningCode scanning / CodeQL Unbounded loop Warning
This loop does not have a fixed bound.
|
||
| } | ||
|
|
||
| ActiveComponentBase::MsgDispatchStatus ActiveComponentBase::dispatch() { | ||
| // Cooperative tasks should return rather than block when no messages are available | ||
| if (this->m_task.isCooperative() and m_queue.getMessagesAvailable() == 0) { | ||
| return MsgDispatchStatus::MSG_DISPATCH_EMPTY; | ||
| } | ||
| return this->doDispatch(); | ||
| ActiveComponentBase::MsgDispatchStatus ActiveComponentBase::dispatch() { | ||
| // Cooperative tasks should return rather than block when no messages are available | ||
| if (this->m_task.isCooperative() and m_queue.getMessagesAvailable() == 0) { | ||
| return MsgDispatchStatus::MSG_DISPATCH_EMPTY; | ||
| } | ||
| return this->doDispatch(); | ||
| } | ||
|
|
||
| void ActiveComponentBase::preamble() { | ||
| } | ||
| void ActiveComponentBase::preamble() {} | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| void ActiveComponentBase::finalizer() { | ||
| } | ||
| void ActiveComponentBase::finalizer() {} | ||
Check noticeCode scanning / CodeQL More than one statement per line Note
This line contains 2 statements; only one is allowed.
|
||
|
|
||
| } | ||
| } // namespace Fw | ||
Check warning
Code scanning / CppCheck
Member variable 'ActiveComponentBase::m_stage' is not initialized in the constructor. Warning