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

Actually pass the parent pointer to periodic updates. #196

Merged
merged 2 commits into from
Mar 2, 2023
Merged
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
2 changes: 1 addition & 1 deletion examples/diagnostic_protocol/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nmea2000/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pgn_requests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/transport_layer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vt_aux_n/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vt_version_3_object_pool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void signal_handler(int)
running = false;
}

void update_CAN_network()
void update_CAN_network(void *)
{
isobus::CANNetworkManager::CANNetwork.update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ class CANHardwareInterface
/// @param[in] callback The callback to add
/// @param[in] parentPointer Generic context variable, usually a pointer to the owner class for this callback
/// @returns `true` if the callback was added, `false` if it was already in the list
static bool add_can_lib_update_callback(void (*callback)(), void *parentPointer);
static bool add_can_lib_update_callback(void (*callback)(void *parentPointer), void *parentPointer);

/// @brief Removes a periodic update callback
/// @param[in] callback The callback to remove
/// @param[in] parentPointer Generic context variable, usually a pointer to the owner class for this callback
/// @returns `true` if the callback was removed, `false` if no callback matched the two parameters
static bool remove_can_lib_update_callback(void (*callback)(), void *parentPointer);
static bool remove_can_lib_update_callback(void (*callback)(void *parentPointer), void *parentPointer);

private:
/// @brief A class to store information about CAN lib update callbacks
Expand All @@ -112,7 +112,7 @@ class CANHardwareInterface
/// @param obj the object to compare against
bool operator==(const CanLibUpdateCallbackInfo &obj) const;

void (*callback)() = nullptr; ///< The callback
void (*callback)(void *parentPointer) = nullptr; ///< The callback
void *parent = nullptr; ///< Context variable, the owner of the callback
};

Expand Down
6 changes: 3 additions & 3 deletions hardware_integration/src/can_hardware_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void CANHardwareInterface::set_can_driver_update_period(std::uint32_t value)
canLibUpdatePeriod = value;
}

bool CANHardwareInterface::add_can_lib_update_callback(void (*callback)(), void *parentPointer)
bool CANHardwareInterface::add_can_lib_update_callback(void (*callback)(void *parentPointer), void *parentPointer)
{
std::lock_guard<std::mutex> lock(periodicUpdateCallbacksMutex);

Expand All @@ -292,7 +292,7 @@ bool CANHardwareInterface::add_can_lib_update_callback(void (*callback)(), void
return false;
}

bool CANHardwareInterface::remove_can_lib_update_callback(void (*callback)(), void *parentPointer)
bool CANHardwareInterface::remove_can_lib_update_callback(void (*callback)(void *parentPointer), void *parentPointer)
{
std::lock_guard<std::mutex> lock(periodicUpdateCallbacksMutex);

Expand Down Expand Up @@ -362,7 +362,7 @@ void CANHardwareInterface::can_thread_function()
{
if (nullptr != periodicUpdateCallbacks[j].callback)
{
periodicUpdateCallbacks[j].callback();
periodicUpdateCallbacks[j].callback(periodicUpdateCallbacks[j].parent);
}
}
periodicUpdateCallbacksMutex.unlock();
Expand Down
2 changes: 1 addition & 1 deletion test/address_claim_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TEST(ADDRESS_CLAIM_TESTS, PartneredClaim)
CANHardwareInterface::start();

CANHardwareInterface::add_can_lib_update_callback(
[] {
[](void *) {
CANNetworkManager::CANNetwork.update();
},
nullptr);
Expand Down