CMake Changes

This is the changes made by Patrick Plenefisch converting the native
code to use CMake and the CMake Maven Plugin, as opposed to the
native Maven plugin. This is to allow for compatibility with newer
versions of the GCC toolchain. All the cpp sources were moved from
maven style directories to cpp style directories for CMake.

Change-Id: I67f5e3608948f37c83b0990d232105a3784f8593
This commit is contained in:
Brad Miller
2014-03-24 16:13:08 -04:00
parent 33134bef1d
commit 69d9ad70ab
804 changed files with 586 additions and 9377 deletions

View File

@@ -0,0 +1,58 @@
/*
* NetworkTableServer.cpp
*
* Created on: Sep 27, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/NetworkTableServer.h"
#include "networktables2/server/ServerNetworkTableEntryStore.h"
#include <iostream>
#include <limits.h>
NetworkTableServer::NetworkTableServer(IOStreamProvider& _streamProvider, NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager):
NetworkTableNode(*new ServerNetworkTableEntryStore(*this)),
streamProvider(_streamProvider),
incomingStreamMonitor(streamProvider, (ServerNetworkTableEntryStore&)entryStore, *this, connectionList, typeManager, threadManager),
connectionList(&incomingStreamMonitor),
writeManager(connectionList, threadManager, GetEntryStore(), ULONG_MAX),
continuingReceiver(writeManager){
GetEntryStore().SetIncomingReceiver(&continuingReceiver);
GetEntryStore().SetOutgoingReceiver(&continuingReceiver);
incomingStreamMonitor.start();
writeManager.start();
}
//TODO implement simplified NetworkTableServer constructor
/*NetworkTableServer::NetworkTableServer(IOStreamProvider& streamProvider){
this(streamProvider, new NetworkTableEntryTypeManager(), new DefaultThreadManager());
}*/
NetworkTableServer::~NetworkTableServer(){
Close();
delete &entryStore;
}
void NetworkTableServer::Close(){
try{
incomingStreamMonitor.stop();
writeManager.stop();
connectionList.closeAll();
} catch (const std::exception& ex) {
//TODO print stack trace?
}
}
void NetworkTableServer::OnNewConnection(ServerConnectionAdapter& connectionAdapter) {
connectionList.add(connectionAdapter);
}
bool NetworkTableServer::IsConnected() {
return true;
}
bool NetworkTableServer::IsServer() {
return true;
}

View File

@@ -0,0 +1,135 @@
/*
* ServerConnectionAdapter.cpp
*
* Created on: Sep 26, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/ServerConnectionAdapter.h"
#include <stdio.h>
void ServerConnectionAdapter::gotoState(ServerConnectionState* newState){
if(connectionState!=newState){
fprintf(stdout, "[NT] %p entered connection state: %s\n", (void*)this, newState->toString());
fflush(stdout);
connectionState = newState;
}
}
ServerConnectionAdapter::ServerConnectionAdapter(IOStream* stream, ServerNetworkTableEntryStore& _entryStore, IncomingEntryReceiver& _transactionReceiver, ServerAdapterManager& _adapterListener, NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager) :
entryStore(_entryStore), transactionReceiver(_transactionReceiver), adapterListener(_adapterListener),
connection(stream, typeManager), monitorThread(*this, connection), m_IsAdapterListenerClosed(false) {
connectionState = &ServerConnectionState::CLIENT_DISCONNECTED;
gotoState(&ServerConnectionState::GOT_CONNECTION_FROM_CLIENT);
readThread = threadManager.newBlockingPeriodicThread(&monitorThread, "Server Connection Reader Thread");
}
ServerConnectionAdapter::~ServerConnectionAdapter(){
delete readThread;
}
void ServerConnectionAdapter::badMessage(BadMessageException& e) {
fprintf(stdout, "[NT] Bad message: %s\n", e.what());
fflush(stdout);
gotoState(new ServerConnectionState_Error(e));
adapterListener.close(*this, true);
m_IsAdapterListenerClosed=true;
}
void ServerConnectionAdapter::ioException(IOException& e) {
fprintf(stdout, "[NT] IOException message: %s\n", e.what());
fflush(stdout);
if(e.isEOF())
gotoState(&ServerConnectionState::CLIENT_DISCONNECTED);
else
gotoState(new ServerConnectionState_Error(e));
adapterListener.close(*this, false);
m_IsAdapterListenerClosed=true;
}
void ServerConnectionAdapter::shutdown(bool closeStream) {
readThread->stop();
if(closeStream)
connection.close();
}
bool ServerConnectionAdapter::keepAlive() {
return !m_IsAdapterListenerClosed; //returns true as long as the adapter listener has not been flagged for closing
}
void ServerConnectionAdapter::clientHello(ProtocolVersion protocolRevision) {
if(connectionState!=&ServerConnectionState::GOT_CONNECTION_FROM_CLIENT)
throw BadMessageException("A server should not receive a client hello after it has already connected/entered an error state");
if(protocolRevision!=NetworkTableConnection::PROTOCOL_REVISION){
connection.sendProtocolVersionUnsupported();
throw BadMessageException("Client Connected with bad protocol revision");
}
else{
entryStore.sendServerHello(connection);
gotoState(&ServerConnectionState::CONNECTED_TO_CLIENT);
}
}
void ServerConnectionAdapter::protocolVersionUnsupported(ProtocolVersion protocolRevision) {
throw BadMessageException("A server should not receive a protocol version unsupported message");
}
void ServerConnectionAdapter::serverHelloComplete() {
throw BadMessageException("A server should not receive a server hello complete message");
}
void ServerConnectionAdapter::offerIncomingAssignment(NetworkTableEntry* entry) {
transactionReceiver.offerIncomingAssignment(entry);
}
void ServerConnectionAdapter::offerIncomingUpdate(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value) {
transactionReceiver.offerIncomingUpdate(entry, sequenceNumber, value);
}
NetworkTableEntry* ServerConnectionAdapter::GetEntry(EntryId id) {
return entryStore.GetEntry(id);
}
void ServerConnectionAdapter::offerOutgoingAssignment(NetworkTableEntry* entry) {
try {
if(connectionState==&ServerConnectionState::CONNECTED_TO_CLIENT)
connection.sendEntryAssignment(*entry);
} catch (IOException& e) {
ioException(e);
}
}
void ServerConnectionAdapter::offerOutgoingUpdate(NetworkTableEntry* entry) {
try {
if(connectionState==&ServerConnectionState::CONNECTED_TO_CLIENT)
connection.sendEntryUpdate(*entry);
} catch (IOException& e) {
ioException(e);
}
}
void ServerConnectionAdapter::flush() {
try {
connection.flush();
} catch (IOException& e) {
ioException(e);
}
}
/**
* @return the state of the connection
*/
ServerConnectionState* ServerConnectionAdapter::getConnectionState() {
return connectionState;
}
void ServerConnectionAdapter::ensureAlive() {
try {
connection.sendKeepAlive();
} catch (IOException& e) {
ioException(e);
}
}

View File

@@ -0,0 +1,85 @@
/*
* ServerConnectionList.cpp
*
* Created on: Sep 26, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/ServerConnectionList.h"
#include "networktables2/server/ServerIncomingStreamMonitor.h"
#include <algorithm>
#include <stdio.h>
ServerConnectionList::ServerConnectionList(ServerIncomingStreamMonitor *Factory) : m_Factory(Factory)
{
}
ServerConnectionList::~ServerConnectionList()
{
connectionsLock.take();
closeAll();
}
void ServerConnectionList::add(ServerConnectionAdapter& connection)
{
NTSynchronized sync(connectionsLock);
connections.push_back(&connection);
}
void ServerConnectionList::close(ServerConnectionAdapter& connectionAdapter, bool closeStream)
{
NTSynchronized sync(connectionsLock);
std::vector<ServerConnectionAdapter*>::iterator connectionPosition = std::find(connections.begin(), connections.end(), &connectionAdapter);
if (connectionPosition != connections.end() && (*connectionPosition)==&connectionAdapter)
{
fprintf(stdout, "[NT] Close: %p\n", (void*)&connectionAdapter);
fflush(stdout);
connections.erase(connectionPosition);
m_Factory->close(&connectionAdapter);
//connectionAdapter.shutdown(closeStream);
//delete &connectionAdapter;
}
}
void ServerConnectionList::closeAll()
{
NTSynchronized sync(connectionsLock);
while(connections.size() > 0)
{
close(*connections[0], true);
}
}
void ServerConnectionList::offerOutgoingAssignment(NetworkTableEntry* entry)
{
NTSynchronized sync(connectionsLock);
for(unsigned int i = 0; i < connections.size(); ++i)
{
connections[i]->offerOutgoingAssignment(entry);
}
}
void ServerConnectionList::offerOutgoingUpdate(NetworkTableEntry* entry)
{
NTSynchronized sync(connectionsLock);
for(unsigned int i = 0; i < connections.size(); ++i)
{
connections[i]->offerOutgoingUpdate(entry);
}
}
void ServerConnectionList::flush()
{
NTSynchronized sync(connectionsLock);
for(unsigned int i = 0; i < connections.size(); ++i)
{
connections[i]->flush();
}
}
void ServerConnectionList::ensureAlive()
{
NTSynchronized sync(connectionsLock);
for(unsigned int i = 0; i < connections.size(); ++i)
{
connections[i]->ensureAlive();
}
}

View File

@@ -0,0 +1,31 @@
/*
* ServerConnectionState.cpp
*
* Created on: Sep 27, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/ServerConnectionState.h"
ServerConnectionState ServerConnectionState::GOT_CONNECTION_FROM_CLIENT("GOT_CONNECTION_FROM_CLIENT");
ServerConnectionState ServerConnectionState::CONNECTED_TO_CLIENT("CONNECTED_TO_CLIENT");
ServerConnectionState ServerConnectionState::CLIENT_DISCONNECTED("CLIENT_DISCONNECTED");
ServerConnectionState::ServerConnectionState(const char* _name):name(_name){
}
const char* ServerConnectionState::toString(){
return name;
}
ServerConnectionState_Error::ServerConnectionState_Error(std::exception& _e):ServerConnectionState("SERVER_ERROR"),e(_e){
}
const char* ServerConnectionState_Error::toString(){
return "SERVER_ERROR";
//TODO return "SERVER_ERROR: "+e.getClass()+": "+e.what();
}
std::exception& ServerConnectionState_Error::getException(){
return e;
}

View File

@@ -0,0 +1,84 @@
/*
* ServerIncomingStreamMonitor.cpp
*
* Created on: Sep 26, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/ServerIncomingStreamMonitor.h"
#include "networktables2/stream/IOStream.h"
ServerIncomingStreamMonitor::ServerIncomingStreamMonitor(IOStreamProvider& _streamProvider, ServerNetworkTableEntryStore& _entryStore,
ServerIncomingConnectionListener& _incomingListener, ServerAdapterManager& _adapterListener, NetworkTableEntryTypeManager& _typeManager,
NTThreadManager& _threadManager) :
streamProvider(_streamProvider), entryStore(_entryStore), incomingListener(_incomingListener), adapterListener(_adapterListener),
typeManager(_typeManager), threadManager(_threadManager), monitorThread(NULL)
{
}
ServerIncomingStreamMonitor::~ServerIncomingStreamMonitor()
{
stop();
}
/**
* Start the monitor thread
*/
void ServerIncomingStreamMonitor::start()
{
if (monitorThread != NULL)
stop();
monitorThread = threadManager.newBlockingPeriodicThread(this, "Server Incoming Stream Monitor Thread");
}
/**
* Stop the monitor thread
*/
void ServerIncomingStreamMonitor::stop()
{
if (monitorThread != NULL)
{
streamProvider.close(); //This would get called on deletion too
NTThread *temp=monitorThread;
monitorThread = NULL; //call this before stop for the check below to ensure a new server connection adapter will not happen
temp->stop();
delete temp;
}
}
void ServerIncomingStreamMonitor::run()
{
try
{
while (monitorThread!=NULL)
{
IOStream* newStream = streamProvider.accept();
{
NTSynchronized sync(BlockDeletionList);
for (size_t i=0;i<m_DeletionList.size();i++)
{
ServerConnectionAdapter *Element=m_DeletionList[i];
Element->shutdown(true); //TODO assume to always close stream
delete Element;
}
m_DeletionList.clear();
}
//Note: monitorThread must be checked to avoid crash on exit
// [8/31/2013 Terminator]
if ((monitorThread!=NULL)&&(newStream != NULL))
{
ServerConnectionAdapter* connectionAdapter = new ServerConnectionAdapter(newStream, entryStore, entryStore, adapterListener, typeManager, threadManager);
incomingListener.OnNewConnection(*connectionAdapter);
}
}
}
catch (IOException& e)
{
//could not get a new stream for some reason. ignore and continue
}
}
void ServerIncomingStreamMonitor::close(ServerConnectionAdapter *Adapter)
{
NTSynchronized sync(BlockDeletionList);
m_DeletionList.push_back(Adapter);
}

View File

@@ -0,0 +1,56 @@
/*
* ServerNetworkTableEntryStore.cpp
*
* Created on: Sep 26, 2012
* Author: Mitchell Wills
*/
#include "networktables2/server/ServerNetworkTableEntryStore.h"
ServerNetworkTableEntryStore::ServerNetworkTableEntryStore(TableListenerManager& _listenerManager) :
AbstractNetworkTableEntryStore(_listenerManager)
{
nextId = (EntryId)0;
}
ServerNetworkTableEntryStore::~ServerNetworkTableEntryStore()
{
}
bool ServerNetworkTableEntryStore::addEntry(NetworkTableEntry* newEntry)
{
NTSynchronized sync(LOCK);
NetworkTableEntry* entry = namedEntries[newEntry->name];
if (entry == NULL)
{
newEntry->SetId(nextId++);
idEntries[newEntry->GetId()] = newEntry;
namedEntries[newEntry->name] = newEntry;
return true;
}
return false;
}
bool ServerNetworkTableEntryStore::updateEntry(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value)
{
NTSynchronized sync(LOCK);
return entry->PutValue(sequenceNumber, value);
}
/**
* Send all entries in the entry store as entry assignments in a single transaction
* @param connection
* @throws IOException
*/
void ServerNetworkTableEntryStore::sendServerHello(NetworkTableConnection& connection)
{
NTSynchronized sync(LOCK);
std::map<std::string, NetworkTableEntry*>::iterator itr;
for (itr = namedEntries.begin(); itr != namedEntries.end(); itr++)
{
NetworkTableEntry* entry = itr->second;
connection.sendEntryAssignment(*entry);
}
connection.sendServerHelloComplete();
connection.flush();
}