Skip to content
Snippets Groups Projects
Commit e06ba526 authored by Sean Radigan's avatar Sean Radigan Committed by Kitware Robot
Browse files

Merge topic 'CorrectVRPNDeviceServerShutdown'


f7d0354c BUG: Fixed examples to properly shutdown

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarRicardo Ortiz <ricardo.ortiz@kitware.com>
Merge-request: !65
parents b3b04413 f7d0354c
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,8 @@
Module::Module() :
isInitialized(false),
terminateExecution(false)
terminateExecution(false),
terminationCompleted(false)
{
this->name = "Module";
}
......@@ -57,10 +58,10 @@ bool Module::isTerminated()
//---------------------------------------------------------------------------
void Module::waitTermination()
{
while ( 1 )
while (1)
{
//std::cout << this->name << std::endl;
if ( this->terminationCompleted == true )
if (true == isTerminationDone())
{
break;
}
......
......@@ -178,7 +178,7 @@ void SDK::run()
this->viewer->exec();
}
// Tell framework threads to shutdown if the viewer returs
// Tell framework threads to shutdown if the viewer returns
this->shutDown();
this->terminateAll();
......
......@@ -36,7 +36,7 @@
#include <server_src/vrpn_Phantom.h>
#endif
VRPNDeviceServer::VRPNDeviceServer() : connection(vrpn_create_server_connection())
VRPNDeviceServer::VRPNDeviceServer() : connection(nullptr)
{
this->name = "VRPNDeviceServer";
......@@ -45,32 +45,41 @@ VRPNDeviceServer::VRPNDeviceServer() : connection(vrpn_create_server_connection(
//---------------------------------------------------------------------------
void VRPNDeviceServer::exec()
{
connection = vrpn_create_server_connection();
if(!connection)
{
this->terminateExecution = true;
this->terminationCompleted = true;
return;
}
// Create the various device objects
std::shared_ptr<vrpn_3DConnexion_SpaceExplorer> explorer =
std::make_shared<vrpn_3DConnexion_SpaceExplorer>("explorer",
this->connection.get());
this->connection);
std::shared_ptr<vrpn_3DConnexion_Navigator> navigator =
std::make_shared<vrpn_3DConnexion_Navigator>("navigator",
this->connection.get());
this->connection);
std::shared_ptr<vrpn_Tracker_RazerHydra> razer =
std::make_shared<vrpn_Tracker_RazerHydra>("razer", this->connection.get());
std::make_shared<vrpn_Tracker_RazerHydra>("razer", this->connection);
std::shared_ptr<vrpn_Tracker_FilterOneEuro> razerFiltered =
std::make_shared<vrpn_Tracker_FilterOneEuro>("razer_filtered",
this->connection.get(),
this->connection,
"*razer",
7);
std::shared_ptr<vrpn_Xkeys_XK3> xkeys =
std::make_shared<vrpn_Xkeys_XK3>("xkeys", this->connection.get());
std::make_shared<vrpn_Xkeys_XK3>("xkeys", this->connection);
#ifdef VRPN_USE_PHANTOM_SERVER
std::shared_ptr<vrpn_Phantom> phantom =
std::make_shared<vrpn_Phantom>("Phantom0",
this->connection.get(),
this->connection,
60.0f,
"Default PHANToM");
std::shared_ptr<vrpn_Tracker_FilterOneEuro> phantomFiltered =
std::make_shared<vrpn_Tracker_FilterOneEuro>("phantom_filtered",
this->connection.get(),
this->connection,
"*phantom",
7);
#endif
......@@ -93,5 +102,9 @@ void VRPNDeviceServer::exec()
std::this_thread::sleep_for(this->pollDelay);
}
// connections allocated with vrpn_create_server_connection()
// must decrement their reference to be auto-deleted by VRPN
connection->removeReference();
this->terminationCompleted = true;
}
......@@ -27,9 +27,6 @@
#include "Devices/DeviceInterface.h"
class vrpn_Analog;
class vrpn_Tracker;
class vrpn_ForceDeviceServer;
class vrpn_Connection;
class VRPNDeviceServer : public DeviceInterface
......@@ -44,10 +41,7 @@ public:
void exec() override;
private:
std::vector<std::shared_ptr<vrpn_Analog>> analogServers;
std::vector<std::shared_ptr<vrpn_Tracker>> trackerServers;
std::vector<std::shared_ptr<vrpn_ForceDeviceServer>> forceServers;
std::shared_ptr<vrpn_Connection> connection;
vrpn_Connection *connection;
};
#endif // VRPNSERVERDEVICE_H
......@@ -73,7 +73,7 @@ public:
///
/// \brief Set the tolerance for the iterative solver
///
void setTolerance(const double epsilon)
void setTolerance(const double epsilon) override
{
this->minTolerance = epsilon;
this->solver.setTolerance(epsilon);
......@@ -82,7 +82,7 @@ public:
///
/// \brief Set the maximum number of iterations for the iterative solver
///
void setMaximumIterations(const int maxIter)
void setMaximumIterations(const int maxIter) override
{
this->maxIterations = maxIter;
this->solver.setMaxIterations(maxIter);
......
......@@ -159,9 +159,16 @@ void LaparoscopicCameraController::exec()
std::this_thread::sleep_for(this->poolDelay);
}
// Ensure proper shutdown takes place for the inputDevice
// -Thread MUST be terminated before calling closeDevice()
// -This is to prevent mainloops that do not check for deleted objects
// from running.
this->inputDevice->terminate();
this->inputDevice->waitTermination();
this->inputDevice->closeDevice();
this->terminate();
this->terminationCompleted = true;
}
bool LaparoscopicCameraController::updateCamera()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment