Skip to content

Commit

Permalink
FEATURE
Browse files Browse the repository at this point in the history
Added AnalogServer and MutexServer classes.
  • Loading branch information
cvanderknyff committed Feb 28, 2009
1 parent 9c79d6d commit b3ad6bb
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 5 deletions.
122 changes: 122 additions & 0 deletions VrpnNet/AnalogServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// AnalogServer.cpp: Implementation for Vrpn.AnalogServer
//
// Copyright (c) 2008-2009 Chris VanderKnyff
//
// 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.

#include "stdafx.h"
#include "AnalogServer.h"

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

AnalogServer::AnalogServer(System::String ^name, Vrpn::Connection ^connection)
{
Initialize(name, connection, MaxChannels);
}

AnalogServer::AnalogServer(System::String ^name, Vrpn::Connection ^connection, int numChannels)
{
Initialize(name, connection, numChannels);
}

void AnalogServer::Initialize(System::String ^name, Vrpn::Connection ^connection, int numChannels)
{
if (numChannels > MaxChannels || numChannels < 1)
throw gcnew ArgumentOutOfRangeException("Number of channels must be less than or equal to AnalogServer.MaxChannels.");

IntPtr hName = Marshal::StringToHGlobalAnsi(name);
const char *cName = static_cast<const char *>(hName.ToPointer());

m_server = new ::vrpn_Analog_Server(cName, connection->ToPointer(), numChannels);
Marshal::FreeHGlobal(hName);

m_channels = gcnew cli::array<AnalogServerChannel ^>(numChannels);
for (int i = 0; i < numChannels; i++)
m_channels[i] = gcnew AnalogServerChannel();
}

AnalogServer::~AnalogServer()
{
delete m_server;
}

void AnalogServer::UpdateChannels()
{
vrpn_float64 *serverChannels = m_server->channels();

for (int i = 0; i < m_channels->Length; i++)
{
if (m_channels[i]->Dirty)
{
serverChannels[i] = m_channels[i]->Value;
m_channels[i]->Dirty = false;
}
}
}

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

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

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

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

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

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

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

UpdateChannels();
m_server->report(safe_cast<vrpn_uint32>(classOfService), tm);
}

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

UpdateChannels();
m_server->report_changes(safe_cast<vrpn_uint32>(classOfService), tm);
}
62 changes: 62 additions & 0 deletions VrpnNet/AnalogServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// AnalogServer.h: Interface description for Vrpn.AnalogServer
//
// Copyright (c) 2008-2009 Chris VanderKnyff
//
// 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.

#pragma once

#include "vrpn_Analog.h"

#include "AnalogServerChannel.h"
#include "BaseTypes.h"
#include "Connection.h"

namespace Vrpn {
public ref class AnalogServer: public Vrpn::IVrpnObject
{
public:
AnalogServer(System::String ^name, Vrpn::Connection ^connection);
AnalogServer(System::String ^name, Vrpn::Connection ^connection, System::Int32 numChannels);
~AnalogServer();

virtual void Update(); // from IVrpnObject
virtual Connection^ GetConnection(); // from IVrpnObject
property System::Boolean MuteWarnings // from IVrpnObject
{
virtual void set(System::Boolean);
virtual System::Boolean get();
}

void Report();
void Report(ServiceClass classOfService, System::DateTime time);

void ReportChanges();
void ReportChanges(ServiceClass classOfService, System::DateTime time);

literal System::Int32 MaxChannels = vrpn_CHANNEL_MAX;

private:
void Initialize(System::String ^name, Vrpn::Connection ^connection, System::Int32 numChannels);
void UpdateChannels();

::vrpn_Analog_Server *m_server;
cli::array<AnalogServerChannel ^> ^m_channels;
};
}
60 changes: 60 additions & 0 deletions VrpnNet/AnalogServerChannel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// AnalogServerChannel.cpp: Implementation for Vrpn.AnalogServerChannel
//
// Copyright (c) 2008-2009 Chris VanderKnyff
//
// 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.

#include "stdafx.h"
#include "AnalogServerChannel.h"

using namespace System;
using namespace Vrpn;

AnalogServerChannel::AnalogServerChannel()
{
m_value = 0;
ClipValues = false;
Dirty = true;
}

double AnalogServerChannel::Value::get()
{
return m_value;
}

void AnalogServerChannel::Value::set(double value)
{
if (ClipValues)
{
if (value <= Minimum)
m_value = -1;
else if (value < ZeroMin)
m_value = (value - ZeroMin) / (ZeroMin - Minimum);
else if (value <= ZeroMax)
m_value = 0;
else
m_value = (value - ZeroMax) / (Maximum - ZeroMax);
}
else
{
m_value = value;
}

Dirty = true;
}
50 changes: 50 additions & 0 deletions VrpnNet/AnalogServerChannel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// AnalogServerChannel.h: Interface description for Vrpn.AnalogServerChannel
//
// Copyright (c) 2008-2009 Chris VanderKnyff
//
// 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.

#pragma once

namespace Vrpn {
public ref class AnalogServerChannel
{
public:
AnalogServerChannel();

property System::Double Value
{
System::Double get();
void set(System::Double value);
}

property System::Boolean ClipValues;

property System::Double Minimum;
property System::Double ZeroMin;
property System::Double ZeroMax;
property System::Double Maximum;

internal:
property System::Boolean Dirty;

private:
System::Double m_value;
};
}
5 changes: 0 additions & 5 deletions VrpnNet/MutexRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ MutexRemote::MutexRemote(System::String ^name, Vrpn::Connection ^connection)

void MutexRemote::Initialize(System::String ^name, vrpn_Connection *lpConn)
{
/*
throw gcnew NotImplementedException(
"Mutex event handlers are currently incompatible with managed code.");
*/

IntPtr hAnsiName = Marshal::StringToHGlobalAnsi(name);

const char *ansiName = static_cast<const char *>(hAnsiName.ToPointer());
Expand Down
64 changes: 64 additions & 0 deletions VrpnNet/MutexServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// MutexServer.cpp: Implementation for Vrpn.MutexServer
//
// Copyright (c) 2008-2009 Chris VanderKnyff
//
// 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.

#include "stdafx.h"
#include "MutexServer.h"

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

MutexServer::MutexServer(System::String ^name, Vrpn::Connection ^connection)
{
IntPtr hName = Marshal::StringToHGlobalAnsi(name);
const char *cName = static_cast<const char *>(hName.ToPointer());

m_server = new ::vrpn_Mutex_Server(cName, connection->ToPointer());
m_connection = connection;
Marshal::FreeHGlobal(hName);
}

MutexServer::~MutexServer()
{
delete m_server;
m_server = 0;
}

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

Connection ^MutexServer::GetConnection()
{
return m_connection;
}

void MutexServer::MuteWarnings::set(bool)
{
throw gcnew NotSupportedException("vrpn_Mutex_Server does not expose the shutup property.");
}

bool MutexServer::MuteWarnings::get()
{
throw gcnew NotSupportedException("vrpn_Mutex_Server does not expose the shutup property.");
}
Loading

0 comments on commit b3ad6bb

Please sign in to comment.