Skip to content

Commit

Permalink
Improved handling of working set timeouts
Browse files Browse the repository at this point in the history
Fixed timed out working sets never being removed from the active working set list
and render subcomponents.
  • Loading branch information
ad3154 committed Nov 29, 2023
1 parent d156713 commit 6cf4ee8
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/DataMaskRenderAreaComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class DataMaskRenderAreaComponent : public Component

void on_change_active_mask(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void on_working_set_disconnect(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void paint(Graphics &g) override;

// Used to calculate button press events
Expand Down
1 change: 1 addition & 0 deletions include/ServerMainComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ServerMainComponent : public juce::Component
void repaint_data_and_soft_key_mask();
void check_load_settings();
void save_settings();
void remove_working_set(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSetToRemove);

const std::string ISO_DATA_PATH = "iso_data";

Expand Down
2 changes: 2 additions & 0 deletions include/SoftKeyMaskRenderAreaComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SoftKeyMaskRenderAreaComponent : public Component

void on_change_active_mask(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void on_working_set_disconnect(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void paint(Graphics &g) override;

// Used to calculate button press events
Expand Down
10 changes: 10 additions & 0 deletions src/DataMaskRenderAreaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ void DataMaskRenderAreaComponent::on_change_active_mask(std::shared_ptr<isobus::
needToRepaintActiveArea = false;
}

void DataMaskRenderAreaComponent::on_working_set_disconnect(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet)
{
if ((nullptr != workingSet) && (parentWorkingSet == workingSet))
{
childComponents.clear();
parentWorkingSet.reset();
repaint();
}
}

void DataMaskRenderAreaComponent::paint(Graphics &g)
{
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
Expand Down
43 changes: 43 additions & 0 deletions src/ServerMainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,37 @@ void ServerMainComponent::timerCallback()
(isobus::SystemTiming::time_expired_ms(ws->get_working_set_maintenance_message_timestamp_ms(), 3000)))
{
workingSetSelector.remove_working_set(ws);
dataMaskRenderer.on_working_set_disconnect(ws);
softKeyMaskRenderer.on_working_set_disconnect(ws);

if (managedWorkingSetList.empty())
{
activeWorkingSetMasterAddress = isobus::NULL_CAN_ADDRESS;
activeWorkingSetDataMaskObjectID = isobus::NULL_OBJECT_ID;
}
else if (ws->get_control_function()->get_address() == activeWorkingSetMasterAddress)
{
bool newWorkingSetFound = false;

for (auto &nextWorkingSet : managedWorkingSetList)
{
if (nextWorkingSet->get_control_function()->get_address() != activeWorkingSetMasterAddress)
{
activeWorkingSetMasterAddress = nextWorkingSet->get_control_function()->get_address();
activeWorkingSetDataMaskObjectID = std::static_pointer_cast<isobus::WorkingSet>(nextWorkingSet->get_working_set_object())->get_active_mask();
newWorkingSetFound = true;
break;
}
}

if (!newWorkingSetFound)
{
activeWorkingSetMasterAddress = isobus::NULL_CAN_ADDRESS;
activeWorkingSetDataMaskObjectID = isobus::NULL_OBJECT_ID;
}
}
remove_working_set(ws);
break;
}
else if (isobus::VirtualTerminalServerManagedWorkingSet::ObjectPoolProcessingThreadState::Joined == ws->get_object_pool_processing_state())
{
Expand Down Expand Up @@ -879,3 +910,15 @@ void ServerMainComponent::save_settings()
}
}
}

void ServerMainComponent::remove_working_set(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSetToRemove)
{
for (auto it = managedWorkingSetList.begin(); it != managedWorkingSetList.end(); it++)
{
if (workingSetToRemove == *it)
{
managedWorkingSetList.erase(it);
break;
}
}
}
10 changes: 10 additions & 0 deletions src/SoftkeyMaskRenderArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ void SoftKeyMaskRenderAreaComponent::on_change_active_mask(std::shared_ptr<isobu
repaint();
}

void SoftKeyMaskRenderAreaComponent::on_working_set_disconnect(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet)
{
if ((nullptr != workingSet) && (workingSet == parentWorkingSet))
{
parentWorkingSet = nullptr;
childComponents.clear();
repaint();
}
}

void SoftKeyMaskRenderAreaComponent::paint(Graphics &g)
{
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
Expand Down

0 comments on commit 6cf4ee8

Please sign in to comment.