From 64cbf76fe289afa0a1149795859bb015b6dfc7ac Mon Sep 17 00:00:00 2001 From: Per Malmberg Date: Thu, 15 Nov 2018 20:50:23 +0100 Subject: [PATCH] Removed some unneeded includes. Bonus: Added example project for ISRTaskEventQueue. Closes #5 --- .idea/misc.xml | 2 +- CMakeLists.txt | 1 + lib/smooth/core/ipc/QueueNotification.cpp | 7 +- lib/smooth/core/network/SocketDispatcher.cpp | 1 + .../smooth/core/ipc/QueueNotification.h | 10 +- .../include/smooth/core/ipc/TaskEventQueue.h | 1 - .../include/smooth/core/timer/TimerService.h | 5 +- old_CMakeLists.txt | 174 ------------------ old_component.mk | 28 --- test/interrupt_queue/CMakeLists.txt | 1 + test/interrupt_queue/interrupt_queue.cpp | 29 +++ test/interrupt_queue/interrupt_queue.h | 27 +++ test/json_test/json_test.cpp | 2 + 13 files changed, 70 insertions(+), 218 deletions(-) delete mode 100644 old_CMakeLists.txt delete mode 100644 old_component.mk create mode 100644 test/interrupt_queue/CMakeLists.txt create mode 100644 test/interrupt_queue/interrupt_queue.cpp create mode 100644 test/interrupt_queue/interrupt_queue.h diff --git a/.idea/misc.xml b/.idea/misc.xml index 8822db8f..9de97e8b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/CMakeLists.txt b/CMakeLists.txt index e5240ce6..24037b42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,5 +32,6 @@ else () add_subdirectory(test/spiflash) add_subdirectory(test/sdcard_test) add_subdirectory(test/sntp) + #add_subdirectory(test/interrupt_queue) // Only compiles for ESP add_subdirectory(test/main) endif () \ No newline at end of file diff --git a/lib/smooth/core/ipc/QueueNotification.cpp b/lib/smooth/core/ipc/QueueNotification.cpp index 2b832906..39d675e5 100644 --- a/lib/smooth/core/ipc/QueueNotification.cpp +++ b/lib/smooth/core/ipc/QueueNotification.cpp @@ -3,10 +3,7 @@ // #include -#include #include -#include -#include namespace smooth @@ -21,7 +18,7 @@ namespace smooth // as TaskEventQueues only call this method when they have successfully added the // data item to their internal queue. As such, the queue can only be as large as // the sum of all queues within the same Task. - std::unique_lock lock(guard); + std::unique_lock lock{guard}; queues.push(queue); cond.notify_one(); } @@ -30,7 +27,7 @@ namespace smooth { ITaskEventQueue* res = nullptr; - std::unique_lock lock(guard); + std::unique_lock lock{guard}; if (queues.empty()) { diff --git a/lib/smooth/core/network/SocketDispatcher.cpp b/lib/smooth/core/network/SocketDispatcher.cpp index e7ebc1e2..65ac1a6d 100644 --- a/lib/smooth/core/network/SocketDispatcher.cpp +++ b/lib/smooth/core/network/SocketDispatcher.cpp @@ -2,6 +2,7 @@ // Created by permal on 7/1/17. // +#include #include #include #include diff --git a/lib/smooth/include/smooth/core/ipc/QueueNotification.h b/lib/smooth/include/smooth/core/ipc/QueueNotification.h index 27de9da6..ecff093e 100644 --- a/lib/smooth/include/smooth/core/ipc/QueueNotification.h +++ b/lib/smooth/include/smooth/core/ipc/QueueNotification.h @@ -4,19 +4,15 @@ #pragma once -#include -#include +#include #include -#include +#include #include "ITaskEventQueue.h" -#include namespace smooth { namespace core { - class Task; - namespace ipc { class QueueNotification @@ -31,7 +27,7 @@ namespace smooth void clear() { std::lock_guard lock(guard); - while(queues.size()) + while(!queues.empty()) { queues.pop(); } diff --git a/lib/smooth/include/smooth/core/ipc/TaskEventQueue.h b/lib/smooth/include/smooth/core/ipc/TaskEventQueue.h index db093ec2..a1447184 100644 --- a/lib/smooth/include/smooth/core/ipc/TaskEventQueue.h +++ b/lib/smooth/include/smooth/core/ipc/TaskEventQueue.h @@ -7,7 +7,6 @@ #include #include "ITaskEventQueue.h" #include "IEventListener.h" -#include "Link.h" #include "QueueNotification.h" namespace smooth diff --git a/lib/smooth/include/smooth/core/timer/TimerService.h b/lib/smooth/include/smooth/core/timer/TimerService.h index ce28b914..a21d8f04 100644 --- a/lib/smooth/include/smooth/core/timer/TimerService.h +++ b/lib/smooth/include/smooth/core/timer/TimerService.h @@ -4,11 +4,12 @@ #pragma once +#include +#include #include #include -#include #include -#include +#include #include namespace smooth diff --git a/old_CMakeLists.txt b/old_CMakeLists.txt deleted file mode 100644 index d8097818..00000000 --- a/old_CMakeLists.txt +++ /dev/null @@ -1,174 +0,0 @@ -cmake_minimum_required(VERSION 3.8) -project(Smooth) - -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=bounds -fsanitize=leak -fsanitize=return -fsanitize=null") - -include_directories(include) - -add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_MESSAGE_SIZE=3500") -add_definitions("-DCONFIG_SMOOTH_MAX_MQTT_OUTGOING_MESSAGES=10") - -set(SOURCE_FILES - application/network/mqtt/packet/ConnAck.cpp - application/network/mqtt/packet/Connect.cpp - application/network/mqtt/packet/Disconnect.cpp - application/network/mqtt/packet/MQTTPacket.cpp - application/network/mqtt/packet/MQTTProtocolDefinitions.cpp - application/network/mqtt/packet/PacketDecoder.cpp - application/network/mqtt/packet/PacketIdentifierFactory.cpp - application/network/mqtt/packet/PingReq.cpp - application/network/mqtt/packet/PingResp.cpp - application/network/mqtt/packet/PubAck.cpp - application/network/mqtt/packet/PubComp.cpp - application/network/mqtt/packet/Publish.cpp - application/network/mqtt/packet/PubRec.cpp - application/network/mqtt/packet/PubRel.cpp - application/network/mqtt/packet/SubAck.cpp - application/network/mqtt/packet/Subscribe.cpp - application/network/mqtt/packet/UnsubAck.cpp - application/network/mqtt/packet/Unsubscribe.cpp - application/network/mqtt/state/ConnectedState.cpp - application/network/mqtt/state/ConnectToBrokerState.cpp - application/network/mqtt/state/DisconnectedState.cpp - application/network/mqtt/state/DisconnectState.cpp - application/network/mqtt/state/MQTTBaseState.cpp - application/network/mqtt/state/RunState.cpp - application/network/mqtt/MqttClient.cpp - application/network/mqtt/Publication.cpp - application/network/mqtt/Subscription.cpp - core/ipc/QueueNotification.cpp - core/logging/posix/posix_log.cpp - core/network/IPv4.cpp - #core/network/IPv6.cpp - core/network/SocketDispatcher.cpp - core/timer/ElapsedTime.cpp - core/timer/Timer.cpp - core/timer/TimerService.cpp - core/Application.cpp - core/Task.cpp - include/smooth/application/display/ST7735.h - include/smooth/application/io/ADS1115.h - include/smooth/application/io/MCP23017.h - include/smooth/application/network/mqtt/event/BaseEvent.h - include/smooth/application/network/mqtt/event/ConnectEvent.h - include/smooth/application/network/mqtt/event/DisconnectEvent.h - include/smooth/application/network/mqtt/packet/ConnAck.h - include/smooth/application/network/mqtt/packet/Connect.h - include/smooth/application/network/mqtt/packet/Disconnect.h - include/smooth/application/network/mqtt/packet/IPacketReceiver.h - include/smooth/application/network/mqtt/packet/MQTTPacket.h - include/smooth/application/network/mqtt/packet/PacketDecoder.h - include/smooth/application/network/mqtt/packet/PacketIdentifierFactory.h - include/smooth/application/network/mqtt/packet/PingReq.h - include/smooth/application/network/mqtt/packet/PingResp.h - include/smooth/application/network/mqtt/packet/PubAck.h - include/smooth/application/network/mqtt/packet/PubComp.h - include/smooth/application/network/mqtt/packet/Publish.h - include/smooth/application/network/mqtt/packet/PubRec.h - include/smooth/application/network/mqtt/packet/PubRel.h - include/smooth/application/network/mqtt/packet/SubAck.h - include/smooth/application/network/mqtt/packet/Subscribe.h - include/smooth/application/network/mqtt/packet/UnsubAck.h - include/smooth/application/network/mqtt/packet/Unsubscribe.h - include/smooth/application/network/mqtt/state/ConnectedState.h - include/smooth/application/network/mqtt/state/ConnectToBrokerState.h - include/smooth/application/network/mqtt/state/DisconnectedState.h - include/smooth/application/network/mqtt/state/DisconnectState.h - include/smooth/application/network/mqtt/state/IdleState.h - include/smooth/application/network/mqtt/state/MQTTBaseState.h - include/smooth/application/network/mqtt/state/MqttFSM.h - include/smooth/application/network/mqtt/state/MqttFsmConstants.h - include/smooth/application/network/mqtt/state/RunState.h - include/smooth/application/network/mqtt/state/StartupState.h - include/smooth/application/network/mqtt/IMqttClient.h - include/smooth/application/network/mqtt/InFlight.h - include/smooth/application/network/mqtt/Logging.h - include/smooth/application/network/mqtt/MqttClient.h - include/smooth/application/network/mqtt/MQTTProtocolDefinitions.h - include/smooth/application/network/mqtt/Publication.h - include/smooth/application/network/mqtt/Subscription.h - include/smooth/core/fsm/StaticFSM.h - include/smooth/core/ipc/IEventListener.h - include/smooth/core/ipc/ITaskEventQueue.h - include/smooth/core/ipc/Link.h - include/smooth/core/ipc/Publisher.h - include/smooth/core/ipc/Queue.h - include/smooth/core/ipc/QueueNotification.h - include/smooth/core/ipc/SubscribingTaskEventQueue.h - include/smooth/core/ipc/TaskEventQueue.h - include/smooth/core/logging/log.h - include/smooth/core/network/ConnectionStatusEvent.h - include/smooth/core/network/DataAvailableEvent.h - include/smooth/core/network/InetAddress.h - include/smooth/core/network/IPacketAssembly.h - include/smooth/core/network/IPacketDisassembly.h - include/smooth/core/network/IPacketReceiveBuffer.h - include/smooth/core/network/IPacketSendBuffer.h - include/smooth/core/network/IPv4.h - include/smooth/core/network/IPv6.h - include/smooth/core/network/ISocket.h - include/smooth/core/network/NetworkStatus.h - include/smooth/core/network/SocketOperation.h - include/smooth/core/network/PacketReceiveBuffer.h - include/smooth/core/network/PacketSendBuffer.h - include/smooth/core/network/Socket.h - include/smooth/core/network/SocketDispatcher.h - include/smooth/core/network/TransmitBufferEmptyEvent.h - include/smooth/core/timer/ElapsedTime.h - include/smooth/core/timer/ITimer.h - include/smooth/core/timer/Timer.h - include/smooth/core/timer/TimerExpiredEvent.h - include/smooth/core/timer/TimerService.h - include/smooth/core/util/advance_iterator.h - include/smooth/core/util/ByteSet.h - include/smooth/core/util/CircularBuffer.h - include/smooth/core/util/FixedBuffer.h - include/smooth/core/util/FixedBufferBase.h - include/smooth/core/util/make_unique.h - include/smooth/core/Application.h - include/smooth/core/Task.h - include/smooth/core/TaskStatus.h - include/smooth/core/task_priorities.h - include/smooth/core/ipc/ILinkSubscriber.h - include/smooth/core/ipc/IPolledTaskQueue.h - - ${IDF_PATH}/components/json/cJSON/cJSON.c - ${IDF_PATH}/components/json/cJSON/cJSON.h - include/smooth/core/json/Value.h - core/json/Value.cpp) - -add_library(${PROJECT_NAME} ${SOURCE_FILES}) - -set(COMPONENTS - freertos - cxx - esp32 - driver - log - tcpip_adapter - lwip - openssl - fatfs/src - vfs - storage - wear_levelling - nvs_flash - json/cJSON - spi_flash - ) - -set(COMPONENT_INCLUDE_DIRS "") - -foreach (COMP ${COMPONENTS}) - if(EXISTS ${IDF_PATH}/components/${COMP}/include) - list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP}/include) - else() - list(APPEND COMPONENT_INCLUDE_DIRS ${IDF_PATH}/components/${COMP}) - endif() -endforeach () - -include_directories(${COMPONENT_INCLUDE_DIRS}) - -set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${COMPONENT_INCLUDE_DIRS}) \ No newline at end of file diff --git a/old_component.mk b/old_component.mk deleted file mode 100644 index 9c00be33..00000000 --- a/old_component.mk +++ /dev/null @@ -1,28 +0,0 @@ -# Enable use of things requiring C99 things, like std::to_string -CPPFLAGS += -D_GLIBCXX_USE_C99 - -# Add the include directory to include paths so that files can be included using -COMPONENT_ADD_INCLUDEDIRS := include - -COMPONENT_SRCDIRS := \ - . \ - core \ - core/network \ - core/timer \ - core/io \ - core/ipc \ - core/io/i2c \ - core/io/rmt \ - core/io/spi \ - core/logging/idf \ - core/filesystem \ - core/json \ - application \ - application/display \ - application/sensor \ - application/io \ - application/rgb_led \ - application/network \ - application/network/mqtt \ - application/network/mqtt/state \ - application/network/mqtt/packet \ No newline at end of file diff --git a/test/interrupt_queue/CMakeLists.txt b/test/interrupt_queue/CMakeLists.txt new file mode 100644 index 00000000..e6f6c069 --- /dev/null +++ b/test/interrupt_queue/CMakeLists.txt @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/../common_project.cmake) diff --git a/test/interrupt_queue/interrupt_queue.cpp b/test/interrupt_queue/interrupt_queue.cpp new file mode 100644 index 00000000..b9c9a76a --- /dev/null +++ b/test/interrupt_queue/interrupt_queue.cpp @@ -0,0 +1,29 @@ +// +// Created by permal on 2018-10-21. +// + +#include "interrupt_queue.h" +#include +#include + +using namespace smooth::core; + +namespace interrupt_queue +{ + App::App() + : Application(smooth::core::APPLICATION_BASE_PRIO, std::chrono::seconds(1)), + queue(*this, *this), + input(queue, GPIO_NUM_21, true, false, GPIO_INTR_ANYEDGE) + { + } + + void App::init() + { + std::cout << "Trigger the input!" << std::endl; + } + + void App::event(const smooth::core::io::InterruptInputEvent& value) + { + std::cout << "Value from interrupt: " << value.get_state() << std::endl; + } +} \ No newline at end of file diff --git a/test/interrupt_queue/interrupt_queue.h b/test/interrupt_queue/interrupt_queue.h new file mode 100644 index 00000000..ee40d840 --- /dev/null +++ b/test/interrupt_queue/interrupt_queue.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace interrupt_queue +{ + class App + : public smooth::core::Application, + public smooth::core::ipc::IEventListener + { + public: + App(); + + void init() override; + + void event(const smooth::core::io::InterruptInputEvent& value) override; + + protected: + smooth::core::ipc::ISRTaskEventQueue queue; + smooth::core::io::InterruptInput input; + }; +} \ No newline at end of file diff --git a/test/json_test/json_test.cpp b/test/json_test/json_test.cpp index 8c330443..1cf04a54 100644 --- a/test/json_test/json_test.cpp +++ b/test/json_test/json_test.cpp @@ -1,4 +1,6 @@ #include "json_test.h" + +#include #include #include #include