Skip to content
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

Add QNX as a build target #98

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/dsl/word/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,7 +48,7 @@ namespace dsl {
};

struct NetworkListen {
uint64_t hash{0};
util::network::network_hash_t hash{0};
std::shared_ptr<threading::Reaction> reaction{nullptr};
};

Expand Down
9 changes: 5 additions & 4 deletions src/extension/NetworkController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<uint8_t>&& payload) {
// Construct our NetworkSource information
Expand All @@ -59,7 +60,7 @@ namespace extension {
std::vector<uint8_t> p(std::move(payload));

// Store in our thread local cache
dsl::store::ThreadStore<std::vector<uint8_t>>::value = &p;
dsl::store::ThreadStore<std::vector<uint8_t>>::value = &p;
dsl::store::ThreadStore<dsl::word::NetworkSource>::value = &src;

/* Mutex Scope */ {
Expand All @@ -76,7 +77,7 @@ namespace extension {
}

// Clear our cache
dsl::store::ThreadStore<std::vector<uint8_t>>::value = nullptr;
dsl::store::ThreadStore<std::vector<uint8_t>>::value = nullptr;
dsl::store::ThreadStore<dsl::word::NetworkSource>::value = nullptr;
});

Expand Down Expand Up @@ -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<uint64_t, std::shared_ptr<threading::Reaction>> reactions{};
std::multimap<util::network::network_hash_t, std::shared_ptr<threading::Reaction>> reactions{};
};

} // namespace extension
Expand Down
6 changes: 4 additions & 2 deletions src/extension/network/NUClearNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ namespace extension {
}

void NUClearNetwork::set_packet_callback(
std::function<void(const NetworkTarget&, const uint64_t&, const bool&, std::vector<uint8_t>&&)> f) {
std::function<
void(const NetworkTarget&, const util::network::network_hash_t&, const bool&, std::vector<uint8_t>&&)>
f) {
packet_callback = std::move(f);
}

Expand Down Expand Up @@ -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<uint8_t>& payload,
const std::string& target,
bool reliable) {
Expand Down
15 changes: 11 additions & 4 deletions src/extension/network/NUClearNetwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <thread>
#include <vector>

#include "../../util/network/network_hash_t.hpp"
#include "../../util/network/sock_t.hpp"
#include "../../util/platform.hpp"
#include "wire_protocol.hpp"
Expand Down Expand Up @@ -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<uint8_t>& payload, const std::string& target, bool reliable);
void send(const util::network::network_hash_t& hash,
const std::vector<uint8_t>& 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<void(const NetworkTarget&, const uint64_t&, const bool&, std::vector<uint8_t>&&)> f);
void set_packet_callback(std::function<void(const NetworkTarget&,
const util::network::network_hash_t&,
const bool&,
std::vector<uint8_t>&&)> f);

/**
* @brief Set the callback to use when a node joins the network
Expand Down Expand Up @@ -313,7 +319,8 @@ namespace extension {
std::atomic<uint16_t> packet_id_source{0};

/// The callback to execute when a data packet is completed
std::function<void(const NetworkTarget&, const uint64_t&, const bool&, std::vector<uint8_t>&&)>
std::function<
void(const NetworkTarget&, const util::network::network_hash_t&, const bool&, std::vector<uint8_t>&&)>
packet_callback;
/// The callback to execute when a node joins the network
std::function<void(const NetworkTarget&)> join_callback;
Expand Down
8 changes: 4 additions & 4 deletions src/message/CommandLineArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
#ifndef NUCLEAR_MESSAGE_COMMANDLINEARGUMENTS_HPP
#define NUCLEAR_MESSAGE_COMMANDLINEARGUMENTS_HPP

#include <string>
#include <vector>

namespace NUClear {
namespace message {

/**
* @brief This type is a NUClear message type that holds command line arguments
*/
struct CommandLineArguments : public std::vector<std::string> {
// Inherit constructors
using std::vector<std::string>::vector;
};
struct CommandLineArguments : public std::vector<std::string> {};

} // namespace message
} // namespace NUClear
Expand Down
40 changes: 40 additions & 0 deletions src/util/network/network_hash_t.hpp
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion src/util/network/resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/dsl/emit/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace {
std::vector<std::string> 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<int64_t, std::ratio<1, 20>>;
using TestUnits = std::chrono::duration<int, std::ratio<1, 20>>;
/// @brief Perform this many different time points for the test
constexpr int test_loops = 5;

Expand Down