Skip to content

Commit

Permalink
MAINTENANCE
Browse files Browse the repository at this point in the history
Moved destruction logic to finalizers, and added ObjectDisposedException when accessing a dead object.
Moved anonymous namespace objects to Vrpn.Internal.
  • Loading branch information
cvanderknyff committed Feb 28, 2009
1 parent 071cc22 commit d68acd6
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 50 deletions.
16 changes: 16 additions & 0 deletions VrpnNet/AnalogOutputRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ AnalogOutputRemote::AnalogOutputRemote(String ^name, Connection ^c)
}

AnalogOutputRemote::~AnalogOutputRemote()
{
this->!AnalogOutputRemote();
}

AnalogOutputRemote::!AnalogOutputRemote()
{
delete m_analogOut;
m_disposed = true;
}

void AnalogOutputRemote::Initialize(String ^name, vrpn_Connection *lpConn)
Expand All @@ -50,35 +56,43 @@ void AnalogOutputRemote::Initialize(String ^name, vrpn_Connection *lpConn)
m_analogOut = new ::vrpn_Analog_Output_Remote(ansiName, lpConn);

Marshal::FreeHGlobal(hAnsiName);

m_disposed = false;
}

void AnalogOutputRemote::Update()
{
CHECK_DISPOSAL_STATUS();
m_analogOut->mainloop();
}

void AnalogOutputRemote::MuteWarnings::set(Boolean shutUp)
{
CHECK_DISPOSAL_STATUS();
m_analogOut->shutup = shutUp;
}

Boolean AnalogOutputRemote::MuteWarnings::get()
{
CHECK_DISPOSAL_STATUS();
return m_analogOut->shutup;
}

Connection^ AnalogOutputRemote::GetConnection()
{
CHECK_DISPOSAL_STATUS();
return Connection::FromPointer(m_analogOut->connectionPtr());
}

Boolean AnalogOutputRemote::RequestChannelChange(Int64 channel, Double value)
{
CHECK_DISPOSAL_STATUS();
return RequestChannelChange(channel, value, ServiceClass::Reliable);
}

Boolean AnalogOutputRemote::RequestChannelChange(Int64 channel, Double value, ServiceClass sc)
{
CHECK_DISPOSAL_STATUS();
if (channel > 0xFFFFFFFFUL)
throw gcnew ArgumentOutOfRangeException("channel", "Value must fit in a vrpn_uint32 type");

Expand All @@ -89,11 +103,13 @@ Boolean AnalogOutputRemote::RequestChannelChange(Int64 channel, Double value, Se

Boolean AnalogOutputRemote::RequestChannelChange(array<Double> ^channels)
{
CHECK_DISPOSAL_STATUS();
return RequestChannelChange(channels, ServiceClass::Reliable);
}

Boolean AnalogOutputRemote::RequestChannelChange(array<Double> ^channels, ServiceClass sc)
{
CHECK_DISPOSAL_STATUS();
if (channels->LongLength > 0xFFFFFFFFUL)
throw gcnew ArgumentException(
"VRPN AnalogOutput class supports only 2^32-1 channels", "channels");
Expand Down
2 changes: 2 additions & 0 deletions VrpnNet/AnalogOutputRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Vrpn {
AnalogOutputRemote(System::String ^name);
AnalogOutputRemote(System::String ^name, Vrpn::Connection ^connection);
~AnalogOutputRemote();
!AnalogOutputRemote();

virtual void Update(); // from IVrpnObject
virtual Connection^ GetConnection(); // from IVrpnObject
Expand All @@ -54,6 +55,7 @@ namespace Vrpn {

private:
::vrpn_Analog_Output_Remote *m_analogOut;
System::Boolean m_disposed;

void Initialize(System::String ^name, vrpn_Connection *lpConn);
};
Expand Down
23 changes: 19 additions & 4 deletions VrpnNet/AnalogRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
#include "stdafx.h"
#include "AnalogRemote.h"

namespace Vrpn {
namespace Internal {
delegate void AnalogChangeCallback(void *userData, const vrpn_ANALOGCB info);
}
}

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace Vrpn;

namespace {
delegate void AnalogChangeCallback(void *userData, const vrpn_ANALOGCB info);
}
using namespace Vrpn::Internal;

AnalogRemote::AnalogRemote(String ^name)
{
Expand Down Expand Up @@ -57,32 +60,44 @@ void AnalogRemote::Initialize(System::String ^name, vrpn_Connection *lpConn)
static_cast<vrpn_ANALOGCHANGEHANDLER>(pAnalogChange.ToPointer());

m_analog->register_change_handler(0, pCallbackFunc);

m_disposed = false;
}

AnalogRemote::~AnalogRemote()
{
this->!AnalogRemote();
}

AnalogRemote::!AnalogRemote()
{
delete m_analog;

gc_callback.Free();
m_disposed = true;
}

void AnalogRemote::Update()
{
CHECK_DISPOSAL_STATUS();
m_analog->mainloop();
}

void AnalogRemote::MuteWarnings::set(Boolean shutUp)
{
CHECK_DISPOSAL_STATUS();
m_analog->shutup = shutUp;
}

Boolean AnalogRemote::MuteWarnings::get()
{
CHECK_DISPOSAL_STATUS();
return m_analog->shutup;
}

Connection^ AnalogRemote::GetConnection()
{
CHECK_DISPOSAL_STATUS();
return Connection::FromPointer(m_analog->connectionPtr());
}

Expand Down
2 changes: 2 additions & 0 deletions VrpnNet/AnalogRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Vrpn {
AnalogRemote(System::String ^name);
AnalogRemote(System::String ^name, Vrpn::Connection ^connection);
~AnalogRemote();
!AnalogRemote();

virtual void Update(); // from IVrpnObject
virtual Connection^ GetConnection(); // from IVrpnObject
Expand All @@ -55,6 +56,7 @@ namespace Vrpn {

private:
::vrpn_Analog_Remote *m_analog;
System::Boolean m_disposed;

void Initialize(System::String ^name, vrpn_Connection *lpConn);
void onAnalogChange(void *userData, const vrpn_ANALOGCB info);
Expand Down
18 changes: 17 additions & 1 deletion VrpnNet/AnalogServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ void AnalogServer::Initialize(System::String ^name, Vrpn::Connection ^connection
m_channels = gcnew cli::array<AnalogServerChannel ^>(numChannels);
for (int i = 0; i < numChannels; i++)
m_channels[i] = gcnew AnalogServerChannel();

m_disposed = false;
}

AnalogServer::~AnalogServer()
AnalogServer::!AnalogServer()
{
delete m_server;
m_disposed = true;
}

AnalogServer::~AnalogServer()
{
this->!AnalogServer();
}

void AnalogServer::UpdateChannels()
Expand All @@ -75,36 +83,43 @@ void AnalogServer::UpdateChannels()

void AnalogServer::Update()
{
CHECK_DISPOSAL_STATUS();
m_server->mainloop();
}

Connection^ AnalogServer::GetConnection()
{
CHECK_DISPOSAL_STATUS();
return Connection::FromPointer(m_server->connectionPtr());
}

void AnalogServer::MuteWarnings::set(bool shutUp)
{
CHECK_DISPOSAL_STATUS();
m_server->shutup = shutUp;
}

bool AnalogServer::MuteWarnings::get()
{
CHECK_DISPOSAL_STATUS();
return m_server->shutup;
}

void AnalogServer::Report()
{
CHECK_DISPOSAL_STATUS();
Report(ServiceClass::LowLatency, DateTime::Now);
}

void AnalogServer::ReportChanges()
{
CHECK_DISPOSAL_STATUS();
Report(ServiceClass::LowLatency, DateTime::Now);
}

void AnalogServer::Report(Vrpn::ServiceClass classOfService, System::DateTime time)
{
CHECK_DISPOSAL_STATUS();
timeval tm;
VrpnUtils::CreateTimeval(time, &tm);

Expand All @@ -114,6 +129,7 @@ void AnalogServer::Report(Vrpn::ServiceClass classOfService, System::DateTime ti

void AnalogServer::ReportChanges(Vrpn::ServiceClass classOfService, System::DateTime time)
{
CHECK_DISPOSAL_STATUS();
timeval tm;
VrpnUtils::CreateTimeval(time, &tm);

Expand Down
2 changes: 2 additions & 0 deletions VrpnNet/AnalogServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Vrpn {
AnalogServer(System::String ^name, Vrpn::Connection ^connection);
AnalogServer(System::String ^name, Vrpn::Connection ^connection, System::Int32 numChannels);
~AnalogServer();
!AnalogServer();

virtual void Update(); // from IVrpnObject
virtual Connection^ GetConnection(); // from IVrpnObject
Expand All @@ -58,5 +59,6 @@ namespace Vrpn {

::vrpn_Analog_Server *m_server;
cli::array<AnalogServerChannel ^> ^m_channels;
System::Boolean m_disposed;
};
}
27 changes: 22 additions & 5 deletions VrpnNet/ButtonRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
#include "stdafx.h"
#include "ButtonRemote.h"

namespace Vrpn {
namespace Internal {
delegate void ButtonChangeCallback(void *userData, const vrpn_BUTTONCB info);
}
}

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace Vrpn;

namespace {
delegate void ButtonChangeCallback(void *userData, const vrpn_BUTTONCB info);
}
using namespace Vrpn::Internal;

ButtonRemote::ButtonRemote(String ^name)
{
Expand All @@ -41,6 +44,8 @@ ButtonRemote::ButtonRemote(String ^name)
Marshal::FreeHGlobal(hAnsiName);

RegisterHandler();

m_disposed = false;
}

ButtonRemote::ButtonRemote(System::String ^name, Vrpn::Connection ^connection)
Expand All @@ -53,32 +58,44 @@ ButtonRemote::ButtonRemote(System::String ^name, Vrpn::Connection ^connection)
Marshal::FreeHGlobal(hAnsiName);

RegisterHandler();

m_disposed = false;
}

ButtonRemote::~ButtonRemote()
ButtonRemote::!ButtonRemote()
{
delete m_button;

gc_callback.Free();
m_disposed = true;
}

ButtonRemote::~ButtonRemote()
{
this->!ButtonRemote();
}

void ButtonRemote::Update()
{
CHECK_DISPOSAL_STATUS();
m_button->mainloop();
}

void ButtonRemote::MuteWarnings::set(Boolean shutUp)
{
CHECK_DISPOSAL_STATUS();
m_button->shutup = shutUp;
}

Boolean ButtonRemote::MuteWarnings::get()
{
CHECK_DISPOSAL_STATUS();
return m_button->shutup;
}

Connection^ ButtonRemote::GetConnection()
{
CHECK_DISPOSAL_STATUS();
return Connection::FromPointer(m_button->connectionPtr());
}

Expand Down
2 changes: 2 additions & 0 deletions VrpnNet/ButtonRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Vrpn {
ButtonRemote(System::String ^name);
ButtonRemote(System::String ^name, Vrpn::Connection ^connection);
~ButtonRemote();
!ButtonRemote();

virtual void Update(); // from IVrpnObject
virtual Connection^ GetConnection(); // from IVrpnObject
Expand All @@ -63,5 +64,6 @@ namespace Vrpn {
void onButtonChange(void *userData, const vrpn_BUTTONCB info);

System::Runtime::InteropServices::GCHandle gc_callback;
System::Boolean m_disposed;
};
}
Loading

0 comments on commit d68acd6

Please sign in to comment.