From a906ca0fde125e15a98a912dd41d640621c13dfe Mon Sep 17 00:00:00 2001
From: Alain Carlucci <alain.carlucci@skywarder.eu>
Date: Sun, 14 May 2017 11:44:58 +0200
Subject: [PATCH] [Linter] Fixed stuff and added check on 'using namespace' in
 Header files

---
 scripts/linter.sh                     |  1 +
 src/entrypoints/dma-lowlevel-test.cpp | 33 ++++++++++++++--
 src/entrypoints/test-busfault.cpp     | 22 +++++++++++
 src/shared/boards/AnakinBoard.cpp     | 22 +++++++++++
 src/shared/boards/AnakinBoard.h       | 22 +++++++++++
 src/shared/diagnostic/Log.h           | 22 +++++++++++
 src/shared/events/Scheduler.cpp       | 57 +++++++++++++++++++--------
 7 files changed, 160 insertions(+), 19 deletions(-)

diff --git a/scripts/linter.sh b/scripts/linter.sh
index cd5a8c6bf..2140f27f5 100755
--- a/scripts/linter.sh
+++ b/scripts/linter.sh
@@ -25,5 +25,6 @@ check OUT "Checking for files not having the copyright" "grep -rL '* Permission
 check OUT "Checking for tabulations instead of spaces" "grep -Pr '\t' src"
 check OUT "MMP wants his full name" "grep -rl 'Matteo Piazzolla' src/"
 check OUT "Launching cppcheck" "cppcheck -q --suppress=unusedFunction --suppress=missingInclude --std=c++11 --enable=all src/ 2>&1"
+check OUT "Checking for using namespace in header files" "grep -rl 'using namespace' src | egrep '.h(pp)?$'"
 
 exit 0
diff --git a/src/entrypoints/dma-lowlevel-test.cpp b/src/entrypoints/dma-lowlevel-test.cpp
index aab6ff58f..668947b5e 100644
--- a/src/entrypoints/dma-lowlevel-test.cpp
+++ b/src/entrypoints/dma-lowlevel-test.cpp
@@ -1,3 +1,24 @@
+/* Copyright (c) 2015-2017 Skyward Experimental Rocketry
+ * Authors: Federico Terraneo
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
 
 #include <sensors/iNemo.h>
 #include <sensors/FXAS21002.h>
@@ -29,10 +50,16 @@ int main()
     spiINEMOG::init();
     auto& spi=SPIDriver::instance();
     
-    inemo_t inemo(inemo_t::ACC_FS_16G,inemo_t::GYRO_FS_245,inemo_t::COMPASS_FS_2);
-    if(inemo.init()==false) puts("init failed");
+    inemo_t inemo (inemo_t::ACC_FS_16G,
+                   inemo_t::GYRO_FS_245,
+                   inemo_t::COMPASS_FS_2);
+
+    if(inemo.init()==false) 
+    {
+        puts("init failed");
+    }
+
     auto req=inemo.buildDMARequest();
-    
     auto sample=[&]()
     {
         if(spi.transaction(req)==false) puts("DMA error");
diff --git a/src/entrypoints/test-busfault.cpp b/src/entrypoints/test-busfault.cpp
index d537de76e..20bb12255 100644
--- a/src/entrypoints/test-busfault.cpp
+++ b/src/entrypoints/test-busfault.cpp
@@ -1,3 +1,25 @@
+/* Copyright (c) 2015-2017 Skyward Experimental Rocketry
+ * Authors: Alain Carlucci
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #include <Common.h>
 
 using namespace miosix;
diff --git a/src/shared/boards/AnakinBoard.cpp b/src/shared/boards/AnakinBoard.cpp
index 4a0a5be17..abcf58d50 100644
--- a/src/shared/boards/AnakinBoard.cpp
+++ b/src/shared/boards/AnakinBoard.cpp
@@ -1,3 +1,25 @@
+/* Copyright (c) 2015-2017 Skyward Experimental Rocketry
+ * Authors: Alain Carlucci, Federico Terraneo
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #include "AnakinBoard.h"
 
 #define INIT_AND_CHECK(x) do {                                       \
diff --git a/src/shared/boards/AnakinBoard.h b/src/shared/boards/AnakinBoard.h
index 388f617b9..5bb9c39f6 100644
--- a/src/shared/boards/AnakinBoard.h
+++ b/src/shared/boards/AnakinBoard.h
@@ -1,3 +1,25 @@
+/* Copyright (c) 2015-2017 Skyward Experimental Rocketry
+ * Authors: Alain Carlucci
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #ifndef BOARDS_ANAKINBOARD_H
 #define BOARDS_ANAKINBOARD_H
 
diff --git a/src/shared/diagnostic/Log.h b/src/shared/diagnostic/Log.h
index 6e691edf4..5ee8c8061 100644
--- a/src/shared/diagnostic/Log.h
+++ b/src/shared/diagnostic/Log.h
@@ -1,3 +1,25 @@
+/* Copyright (c) 2015-2017 Skyward Experimental Rocketry
+ * Authors: Alain Carlucci
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
 #ifndef SHARED_LOG_H
 #define SHARED_LOG_H
 
diff --git a/src/shared/events/Scheduler.cpp b/src/shared/events/Scheduler.cpp
index 350f8a8de..a41e70ff4 100644
--- a/src/shared/events/Scheduler.cpp
+++ b/src/shared/events/Scheduler.cpp
@@ -41,12 +41,14 @@ std::ostream& operator<<(std::ostream& os, const TaskStatResult& sr)
 //
 
 void EventScheduler::add(function_t func, uint32_t intervalMs, 
-        const string& name, int64_t start) {
+                         const string& name, int64_t start)
+{
     task_t task = { func, intervalMs, name, false, -1 };
     addTask(task, start);
 }
 
-void EventScheduler::addOnce(function_t func, uint32_t delayMs, int64_t start) {
+void EventScheduler::addOnce(function_t func, uint32_t delayMs, int64_t start)
+{
     task_t task = { func, delayMs, "", true, -1 };
     addTask(task, start);
 }
@@ -65,49 +67,65 @@ vector<TaskStatResult> EventScheduler::getTaskStats()
                 it.activationStats.getStats(),
                 it.periodStats.getStats(),
                 it.workloadStats.getStats(),
-            });
+            }
+        );
     }
     return result;
 }
 
-void EventScheduler::run() {
+void EventScheduler::run()
+{
     Lock<FastMutex> l(mutex);
-    for(;;) {
-        while(agenda.size() == 0) condvar.wait(mutex);
+    for(;;)
+    {
+        while(agenda.size() == 0) 
+            condvar.wait(mutex);
         
         int64_t now = getTick();
         int64_t nextTick = agenda.top().nextTick;
-        if(nextTick <= now) {
+        if(nextTick <= now)
+        {
             event_t e = agenda.top();
             agenda.pop();
             
             {
                 Unlock<FastMutex> u(l);
                 #ifndef __NO_EXCEPTIONS
-                try {
+                try
+                {
                 #endif
                     e.task->function();
                 #ifndef __NO_EXCEPTIONS
-                } catch(...) {
+                }
+                catch(...)
+                {
                     //TODO: can't propagate exception or the event scheduler
                     //will stop working, but we may want to log it
                 }
                 #endif
             }
             
-            if(e.task->once==false) {
+            if(e.task->once==false)
+            {
                 updateStats(e,now,getTick());
                 //NOTE: enqueue writes in nextTick, so has to be called after
                 enqueue(e);
-            } else tasks.erase(e.task);
-        } else {
+            } 
+            else 
+            {
+                tasks.erase(e.task);
+            }
+        }
+        else
+        {
             Unlock<FastMutex> u(l);
             Thread::sleepUntil(nextTick);
         }
     }
 }
 
-void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start) {
+void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start)
+{
     Lock<FastMutex> l(mutex);
     tasks.push_back(task);
     if(task.once==false) permanentTasks++;
@@ -118,13 +136,15 @@ void EventScheduler::addTask(const EventScheduler::task_t& task, int64_t start)
     enqueue(event);
 }
 
-void EventScheduler::enqueue(event_t& event) {
+void EventScheduler::enqueue(event_t& event)
+{
     event.nextTick += event.task->intervalMs * TICK_FREQ / 1000;
     agenda.push(event);
     condvar.broadcast();
 }
 
-void EventScheduler::updateStats(event_t& e, int64_t startTime, int64_t endTime)
+void EventScheduler::updateStats(event_t& e, int64_t startTime, 
+                                 int64_t endTime)
 {
     const float tickToMs = 1000.f / TICK_FREQ;
     
@@ -145,4 +165,9 @@ void EventScheduler::updateStats(event_t& e, int64_t startTime, int64_t endTime)
     e.task->workloadStats.add(endTime - startTime);
 }
 
-EventScheduler::EventScheduler() : ActiveObject(1024,PRIORITY_MAX-1), permanentTasks(0) {}
+EventScheduler::EventScheduler() : 
+    ActiveObject(1024,PRIORITY_MAX-1), permanentTasks(0) 
+{
+
+}
+
-- 
GitLab