diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 911a429bd..b2ba0af9b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,6 +37,10 @@ target_link_libraries(nuclear ${CMAKE_THREAD_LIBS_INIT}) set_target_properties(nuclear PROPERTIES POSITION_INDEPENDENT_CODE ON) target_compile_features(nuclear PUBLIC cxx_std_14) +if(QNX) + target_link_libraries(nuclear socket) +endif(QNX) + # Enable warnings, and all warnings are errors if(MSVC) target_compile_options(nuclear PRIVATE /W4 /WX) diff --git a/src/dsl/word/Network.hpp b/src/dsl/word/Network.hpp index e1377b015..760af8266 100644 --- a/src/dsl/word/Network.hpp +++ b/src/dsl/word/Network.hpp @@ -24,6 +24,7 @@ #define NUCLEAR_DSL_WORD_NETWORK_HPP #include "../../threading/Reaction.hpp" +#include "../../util/network/network_hash_t.hpp" #include "../../util/network/sock_t.hpp" #include "../../util/serialise/Serialise.hpp" #include "../store/ThreadStore.hpp" @@ -47,7 +48,7 @@ namespace dsl { }; struct NetworkListen { - uint64_t hash{0}; + util::network::network_hash_t hash{0}; std::shared_ptr reaction{nullptr}; }; diff --git a/src/extension/NetworkController.hpp b/src/extension/NetworkController.hpp index 30fff7baa..268afaaa8 100644 --- a/src/extension/NetworkController.hpp +++ b/src/extension/NetworkController.hpp @@ -30,6 +30,7 @@ #include "../PowerPlant.hpp" #include "../Reactor.hpp" #include "../util/get_hostname.hpp" +#include "../util/network/network_hash_t.hpp" #include "network/NUClearNetwork.hpp" namespace NUClear { @@ -49,7 +50,7 @@ namespace extension { // Set our function callback network.set_packet_callback([this](const network::NUClearNetwork::NetworkTarget& remote, - const uint64_t& hash, + const util::network::network_hash_t& hash, const bool& reliable, std::vector&& payload) { // Construct our NetworkSource information @@ -59,7 +60,7 @@ namespace extension { std::vector p(std::move(payload)); // Store in our thread local cache - dsl::store::ThreadStore>::value = &p; + dsl::store::ThreadStore>::value = &p; dsl::store::ThreadStore::value = &src; /* Mutex Scope */ { @@ -76,7 +77,7 @@ namespace extension { } // Clear our cache - dsl::store::ThreadStore>::value = nullptr; + dsl::store::ThreadStore>::value = nullptr; dsl::store::ThreadStore::value = nullptr; }); @@ -175,7 +176,7 @@ namespace extension { /// Mutex to guard the list of reactions std::mutex reaction_mutex; /// Map of type hashes to reactions that are interested in them - std::multimap> reactions{}; + std::multimap> reactions{}; }; } // namespace extension diff --git a/src/extension/network/NUClearNetwork.cpp b/src/extension/network/NUClearNetwork.cpp index 4a49886a1..51af03475 100644 --- a/src/extension/network/NUClearNetwork.cpp +++ b/src/extension/network/NUClearNetwork.cpp @@ -82,7 +82,9 @@ namespace extension { } void NUClearNetwork::set_packet_callback( - std::function&&)> f) { + std::function< + void(const NetworkTarget&, const util::network::network_hash_t&, const bool&, std::vector&&)> + f) { packet_callback = std::move(f); } @@ -1028,7 +1030,7 @@ namespace extension { } - void NUClearNetwork::send(const uint64_t& hash, + void NUClearNetwork::send(const util::network::network_hash_t& hash, const std::vector& payload, const std::string& target, bool reliable) { diff --git a/src/extension/network/NUClearNetwork.hpp b/src/extension/network/NUClearNetwork.hpp index fc3d93656..ba3ee7fd6 100644 --- a/src/extension/network/NUClearNetwork.hpp +++ b/src/extension/network/NUClearNetwork.hpp @@ -36,6 +36,7 @@ #include #include +#include "../../util/network/network_hash_t.hpp" #include "../../util/network/sock_t.hpp" #include "../../util/platform.hpp" #include "wire_protocol.hpp" @@ -130,15 +131,20 @@ namespace extension { * @param target who we are sending to (blank means everyone) * @param reliable if the delivery of the data should be ensured */ - void send(const uint64_t& hash, const std::vector& payload, const std::string& target, bool reliable); + void send(const util::network::network_hash_t& hash, + const std::vector& payload, + const std::string& target, + bool reliable); /** * @brief Set the callback to use when a data packet is completed * * @param f the callback function */ - void set_packet_callback( - std::function&&)> f); + void set_packet_callback(std::function&&)> f); /** * @brief Set the callback to use when a node joins the network @@ -313,7 +319,8 @@ namespace extension { std::atomic packet_id_source{0}; /// The callback to execute when a data packet is completed - std::function&&)> + std::function< + void(const NetworkTarget&, const util::network::network_hash_t&, const bool&, std::vector&&)> packet_callback; /// The callback to execute when a node joins the network std::function join_callback; diff --git a/src/message/CommandLineArguments.hpp b/src/message/CommandLineArguments.hpp index 3341a9d9d..1117d27aa 100644 --- a/src/message/CommandLineArguments.hpp +++ b/src/message/CommandLineArguments.hpp @@ -23,16 +23,16 @@ #ifndef NUCLEAR_MESSAGE_COMMANDLINEARGUMENTS_HPP #define NUCLEAR_MESSAGE_COMMANDLINEARGUMENTS_HPP +#include +#include + namespace NUClear { namespace message { /** * @brief This type is a NUClear message type that holds command line arguments */ - struct CommandLineArguments : public std::vector { - // Inherit constructors - using std::vector::vector; - }; + struct CommandLineArguments : public std::vector {}; } // namespace message } // namespace NUClear diff --git a/src/util/network/network_hash_t.hpp b/src/util/network/network_hash_t.hpp new file mode 100644 index 000000000..2f6589dde --- /dev/null +++ b/src/util/network/network_hash_t.hpp @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2017 NUClear Contributors + * + * This file is part of the NUClear codebase. + * See https://github.com/Fastcode/NUClear for further info. + * + * 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 NUCLEAR_UTIL_NETWORK_NETWORK_HASH_T_HPP +#define NUCLEAR_UTIL_NETWORK_NETWORK_HASH_T_HPP + +namespace NUClear { +namespace util { + namespace network { + +#ifdef __QNX__ + using network_hash_t = unsigned long long; +#else + using network_hash_t = uint64_t; +#endif + + } // namespace network +} // namespace util +} // namespace NUClear + +#endif // NUCLEAR_UTIL_NETWORK_NETWORK_HASH_T_HPP diff --git a/src/util/network/resolve.cpp b/src/util/network/resolve.cpp index 73435b41b..3ab545cee 100644 --- a/src/util/network/resolve.cpp +++ b/src/util/network/resolve.cpp @@ -37,7 +37,9 @@ namespace util { addrinfo hints{}; hints.ai_family = AF_UNSPEC; // don't care about IPv4 or IPv6 hints.ai_socktype = AF_UNSPEC; // don't care about TCP or UDP - hints.ai_flags = AI_ALL; // Get all addresses even if we don't have an interface for them +#ifdef AI_ALL + hints.ai_flags = AI_ALL; // Get all addresses even if we don't have an interface for them +#endif // Get our info on this address addrinfo* servinfo_ptr = nullptr; diff --git a/tests/dsl/emit/Delay.cpp b/tests/dsl/emit/Delay.cpp index 8e5fb5c1a..4ef44e0b8 100644 --- a/tests/dsl/emit/Delay.cpp +++ b/tests/dsl/emit/Delay.cpp @@ -32,7 +32,7 @@ namespace { std::vector events; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) /// @brief Test units are the time units the test is performed in -using TestUnits = std::chrono::duration>; +using TestUnits = std::chrono::duration>; /// @brief Perform this many different time points for the test constexpr int test_loops = 5;