mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* AbstractNetworkTableEntryStore.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef ABSTRACTNETWORKTABLEENTRYSTORE_H_
|
||||
#define ABSTRACTNETWORKTABLEENTRYSTORE_H_
|
||||
|
||||
|
||||
|
||||
class TableListenerManager;
|
||||
class AbstractNetworkTableEntryStore;
|
||||
|
||||
|
||||
#include "OSAL/Synchronized.h"
|
||||
#include <string>
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "networktables2/IncomingEntryReceiver.h"
|
||||
#include "networktables2/OutgoingEntryReceiver.h"
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
#include "tables/ITable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
class TableListenerManager{
|
||||
public:
|
||||
virtual ~TableListenerManager(){}
|
||||
virtual void FireTableListeners(std::string& name, EntryValue value, bool isNew) = 0;
|
||||
};
|
||||
|
||||
class AbstractNetworkTableEntryStore : public IncomingEntryReceiver{
|
||||
protected:
|
||||
std::map<EntryId,NetworkTableEntry*> idEntries;
|
||||
std::map<std::string,NetworkTableEntry*> namedEntries;
|
||||
TableListenerManager& listenerManager;
|
||||
|
||||
AbstractNetworkTableEntryStore(TableListenerManager& lstnManager);
|
||||
|
||||
OutgoingEntryReceiver* outgoingReceiver;
|
||||
OutgoingEntryReceiver* incomingReceiver;
|
||||
|
||||
|
||||
|
||||
virtual bool addEntry(NetworkTableEntry* entry) = 0;
|
||||
virtual bool updateEntry(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value) = 0;
|
||||
|
||||
public:
|
||||
virtual ~AbstractNetworkTableEntryStore();
|
||||
|
||||
NTReentrantSemaphore LOCK;
|
||||
NetworkTableEntry* GetEntry(EntryId entryId);
|
||||
NetworkTableEntry* GetEntry(std::string& name);
|
||||
|
||||
std::vector<std::string>* keys();
|
||||
void clearEntries();
|
||||
void clearIds();
|
||||
|
||||
void SetOutgoingReceiver(OutgoingEntryReceiver* receiver);
|
||||
void SetIncomingReceiver(OutgoingEntryReceiver* receiver);
|
||||
|
||||
void PutOutgoing(std::string& name, NetworkTableEntryType* type, EntryValue value);
|
||||
void PutOutgoing(NetworkTableEntry* tableEntry, EntryValue value);
|
||||
|
||||
|
||||
void offerIncomingAssignment(NetworkTableEntry* entry);
|
||||
void offerIncomingUpdate(NetworkTableEntry* entry, EntryId sequenceNumber, EntryValue value);
|
||||
|
||||
void notifyEntries(ITable* table, ITableListener* listener);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* ABSTRACTNETWORKTABLEENTRYSTORE_H_ */
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* FlushableOutgoingEntryReceiver.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef FLUSHABLEOUTGOINGENTRYRECEIVER_H_
|
||||
#define FLUSHABLEOUTGOINGENTRYRECEIVER_H_
|
||||
|
||||
class FlushableOutgoingEntryReceiver;
|
||||
|
||||
#include "networktables2/OutgoingEntryReceiver.h"
|
||||
|
||||
class FlushableOutgoingEntryReceiver : public OutgoingEntryReceiver
|
||||
{
|
||||
public:
|
||||
virtual ~FlushableOutgoingEntryReceiver()
|
||||
{
|
||||
}
|
||||
virtual void flush() = 0;
|
||||
virtual void ensureAlive() = 0;
|
||||
};
|
||||
|
||||
#endif /* FLUSHABLEOUTGOINGENTRYRECEIVER_H_ */
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* IncomingEntryReceiver.h
|
||||
*
|
||||
* Created on: Sep 19, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef INCOMINGENTRYRECEIVER_H_
|
||||
#define INCOMINGENTRYRECEIVER_H_
|
||||
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "tables/ITable.h"
|
||||
|
||||
class IncomingEntryReceiver
|
||||
{
|
||||
public:
|
||||
virtual ~IncomingEntryReceiver()
|
||||
{
|
||||
}
|
||||
virtual void offerIncomingAssignment(NetworkTableEntry* entry) = 0;
|
||||
virtual void offerIncomingUpdate(NetworkTableEntry* entry, SequenceNumber entrySequenceNumber, EntryValue value) = 0;
|
||||
};
|
||||
|
||||
#endif /* INCOMINGENTRYRECEIVER_H_ */
|
||||
81
networktables/cpp/include/networktables2/NetworkTableEntry.h
Normal file
81
networktables/cpp/include/networktables2/NetworkTableEntry.h
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef NETWORKTABLEENTRY_H_
|
||||
#define NETWORKTABLEENTRY_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _WRS_KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef uint16_t EntryId;
|
||||
typedef uint16_t SequenceNumber;
|
||||
class NetworkTableEntry;
|
||||
class TableListenerManager;
|
||||
|
||||
|
||||
#include "networktables2/connection/DataIOStream.h"
|
||||
#include "networktables2/connection/NetworkTableConnection.h"
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
#include "networktables2/util/IllegalStateException.h"
|
||||
#include <string>
|
||||
#include "tables/ITable.h"
|
||||
|
||||
|
||||
/**
|
||||
* An entry in a network table
|
||||
*
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
class NetworkTableEntry {
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* the id that represents that an id is unknown for an entry
|
||||
*/
|
||||
static const EntryId UNKNOWN_ID = 0xFFFF;
|
||||
/**
|
||||
* the name of the entry
|
||||
*/
|
||||
std::string name;
|
||||
|
||||
NetworkTableEntry(std::string& name, NetworkTableEntryType* type, EntryValue value);
|
||||
NetworkTableEntry(EntryId id, std::string& name, SequenceNumber sequenceNumber, NetworkTableEntryType* type, EntryValue value);
|
||||
virtual ~NetworkTableEntry();
|
||||
|
||||
EntryId GetId();
|
||||
EntryValue GetValue();
|
||||
NetworkTableEntryType* GetType();
|
||||
bool PutValue(SequenceNumber newSequenceNumber, EntryValue newValue);
|
||||
void ForcePut(SequenceNumber newSequenceNumber, EntryValue newValue);
|
||||
void ForcePut(SequenceNumber newSequenceNumber, NetworkTableEntryType* type, EntryValue newValue);
|
||||
void MakeDirty();
|
||||
void MakeClean();
|
||||
bool IsDirty();
|
||||
void SendValue(DataIOStream& iostream);
|
||||
SequenceNumber GetSequenceNumber();
|
||||
void SetId(EntryId id);
|
||||
void ClearId();
|
||||
void Send(NetworkTableConnection& connection);
|
||||
void FireListener(TableListenerManager& listenerManager);
|
||||
|
||||
private:
|
||||
EntryId id;
|
||||
SequenceNumber sequenceNumber;
|
||||
/**
|
||||
* the type of the entry
|
||||
*/
|
||||
NetworkTableEntryType* type;
|
||||
EntryValue value;
|
||||
volatile bool m_isNew;
|
||||
volatile bool m_isDirty;
|
||||
|
||||
static const SequenceNumber HALF_OF_SEQUENCE_NUMBERS = 32768;
|
||||
|
||||
NetworkTableEntry& operator=(const NetworkTableEntry& other);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* NETWORKTABLEENTRY_H_ */
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* NetworkTableMessageType.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLEMESSAGETYPE_H_
|
||||
#define NETWORKTABLEMESSAGETYPE_H_
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The definitions of all of the protocol message types
|
||||
*
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
enum NetworkTableMessageType{
|
||||
/**
|
||||
* A keep alive message that the client sends
|
||||
*/
|
||||
KEEP_ALIVE = 0x00,
|
||||
/**
|
||||
* a client hello message that a client sends
|
||||
*/
|
||||
CLIENT_HELLO = 0x01,
|
||||
/**
|
||||
* a protocol version unsupported message that the server sends to a client
|
||||
*/
|
||||
PROTOCOL_VERSION_UNSUPPORTED = 0x02,
|
||||
SERVER_HELLO_COMPLETE = 0x03,
|
||||
/**
|
||||
* an entry assignment message
|
||||
*/
|
||||
ENTRY_ASSIGNMENT = 0x10,
|
||||
/**
|
||||
* a field update message
|
||||
*/
|
||||
FIELD_UPDATE = 0x11
|
||||
};
|
||||
|
||||
#endif /* NETWORKTABLEMESSAGETYPE_H_ */
|
||||
103
networktables/cpp/include/networktables2/NetworkTableNode.h
Normal file
103
networktables/cpp/include/networktables2/NetworkTableNode.h
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* NetworkTableNode.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLENODE_H_
|
||||
#define NETWORKTABLENODE_H_
|
||||
|
||||
|
||||
class NetworkTableNode;
|
||||
|
||||
#include "networktables2/AbstractNetworkTableEntryStore.h"
|
||||
#include "networktables2/client/ClientConnectionListenerManager.h"
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
#include "networktables2/type/ComplexData.h"
|
||||
#include "networktables2/type/ComplexEntryType.h"
|
||||
#include "tables/IRemote.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
/**
|
||||
* represents a node (either a client or a server) in a network tables 2.0
|
||||
* <br>
|
||||
* implementers of the class must ensure that they call {@link #init(NetworkTableTransactionPool, AbstractNetworkTableEntryStore)} before calling any other methods on this class
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class NetworkTableNode : public TableListenerManager, public ClientConnectionListenerManager, public IRemote{
|
||||
|
||||
protected:
|
||||
AbstractNetworkTableEntryStore& entryStore;
|
||||
NetworkTableNode(AbstractNetworkTableEntryStore& entryStore);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @return the entry store used by this node
|
||||
*/
|
||||
AbstractNetworkTableEntryStore& GetEntryStore();
|
||||
virtual ~NetworkTableNode();
|
||||
|
||||
|
||||
|
||||
void PutBoolean(std::string& name, bool value);
|
||||
bool GetBoolean(std::string& name);
|
||||
|
||||
void PutDouble(std::string& name, double value);
|
||||
double GetDouble(std::string& name);
|
||||
|
||||
void PutString(std::string& name, std::string& value);
|
||||
std::string& GetString(std::string& name);
|
||||
|
||||
void PutComplex(std::string& name, ComplexData& value);
|
||||
|
||||
void retrieveValue(std::string& name, ComplexData& externalData);
|
||||
|
||||
/**
|
||||
* Put a value with a specific network table type
|
||||
* @param name the name of the entry to associate with the given value
|
||||
* @param type the type of the entry
|
||||
* @param value the actual value of the entry
|
||||
*/
|
||||
void PutValue(std::string& name, NetworkTableEntryType* type, EntryValue value);
|
||||
void PutValue(NetworkTableEntry* entry, EntryValue value);
|
||||
|
||||
EntryValue GetValue(std::string& name);
|
||||
|
||||
|
||||
/**
|
||||
* @param key the key to check for existence
|
||||
* @return true if the table has the given key
|
||||
*/
|
||||
bool ContainsKey(std::string& key);
|
||||
|
||||
/**
|
||||
* close all networking activity related to this node
|
||||
*/
|
||||
virtual void Close() = 0;
|
||||
|
||||
private:
|
||||
std::vector<IRemoteConnectionListener*> remoteListeners;
|
||||
public:
|
||||
void AddConnectionListener(IRemoteConnectionListener* listener, bool immediateNotify);
|
||||
void RemoveConnectionListener(IRemoteConnectionListener* listener);
|
||||
void FireConnectedEvent();
|
||||
void FireDisconnectedEvent();
|
||||
|
||||
|
||||
private:
|
||||
std::vector<ITableListener*> tableListeners;
|
||||
public:
|
||||
void AddTableListener(ITableListener* listener, bool immediateNotify);
|
||||
void RemoveTableListener(ITableListener* listener);
|
||||
void FireTableListeners(std::string& key, EntryValue value, bool isNew);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* NETWORKTABLENODE_H_ */
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* OutgoingEntryReceiver.h
|
||||
*
|
||||
* Created on: Sep 19, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef OUTGOINGENTRYRECEIVER_H_
|
||||
#define OUTGOINGENTRYRECEIVER_H_
|
||||
|
||||
class OutgoingEntryReceiver;
|
||||
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
|
||||
class NetworkTableEntry;
|
||||
|
||||
class OutgoingEntryReceiver
|
||||
{
|
||||
public:
|
||||
virtual ~OutgoingEntryReceiver()
|
||||
{
|
||||
}
|
||||
virtual void offerOutgoingAssignment(NetworkTableEntry* entry) = 0;
|
||||
virtual void offerOutgoingUpdate(NetworkTableEntry* entry) = 0;
|
||||
};
|
||||
class OutgoingEntryReceiver_NULL_t : public OutgoingEntryReceiver {
|
||||
public:
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
};
|
||||
|
||||
extern OutgoingEntryReceiver_NULL_t OutgoingEntryReceiver_NULL;
|
||||
|
||||
#endif /* OUTGOINGENTRYRECEIVER_H_ */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* TableKeyExistsWithDifferentTypeException.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef TABLEKEYEXISTSWITHDIFFERENTTYPEEXCEPTION_H_
|
||||
#define TABLEKEYEXISTSWITHDIFFERENTTYPEEXCEPTION_H_
|
||||
|
||||
|
||||
class TableKeyExistsWithDifferentTypeException;
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Throw to indicate that an attempt to put data to a table is illegal because
|
||||
* the specified key exists with a different data type than the put data type.
|
||||
*
|
||||
* @author Paul Malmsten <pmalmsten@gmail.com>
|
||||
*/
|
||||
class TableKeyExistsWithDifferentTypeException : public std::exception {
|
||||
public:
|
||||
/**
|
||||
* Creates a new TableKeyExistsWithDifferentTypeException
|
||||
*
|
||||
* @param existingKey The name of the key which exists.
|
||||
* @param existingType The type of the key which exists.
|
||||
*/
|
||||
TableKeyExistsWithDifferentTypeException(const std::string existingKey, NetworkTableEntryType* existingType);
|
||||
|
||||
TableKeyExistsWithDifferentTypeException(const std::string existingKey, NetworkTableEntryType* existingType, const char* message);
|
||||
|
||||
const char* what(){return "TableKeyExistsWithDifferentTypeException";};
|
||||
|
||||
virtual ~TableKeyExistsWithDifferentTypeException() throw ();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* TABLEKEYEXISTSWITHDIFFERENTTYPEEXCEPTION_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* TransactionDirtier.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef TRANSACTIONDIRTIER_H_
|
||||
#define TRANSACTIONDIRTIER_H_
|
||||
|
||||
|
||||
class TransactionDirtier;
|
||||
|
||||
|
||||
#include "networktables2/OutgoingEntryReceiver.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A transaction receiver that marks all Table entries as dirty in the entry store. Entries will not be passed to the continuing receiver if they are already dirty
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class TransactionDirtier : public OutgoingEntryReceiver {
|
||||
private:
|
||||
OutgoingEntryReceiver& continuingReceiver;
|
||||
|
||||
public:
|
||||
TransactionDirtier(OutgoingEntryReceiver& continuingReceiver);
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
|
||||
};
|
||||
|
||||
#endif /* TRANSACTIONDIRTIER_H_ */
|
||||
87
networktables/cpp/include/networktables2/WriteManager.h
Normal file
87
networktables/cpp/include/networktables2/WriteManager.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* WriteManager.h
|
||||
*
|
||||
* Created on: Sep 25, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef WRITEMANAGER_H_
|
||||
#define WRITEMANAGER_H_
|
||||
|
||||
class AbstractNetworkTableEntryStore;
|
||||
class WriteManager;
|
||||
|
||||
|
||||
#include "networktables2/thread/PeriodicRunnable.h"
|
||||
#include "networktables2/OutgoingEntryReceiver.h"
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
#include "networktables2/thread/NTThreadManager.h"
|
||||
#include "networktables2/FlushableOutgoingEntryReceiver.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include <queue>
|
||||
#include "OSAL/Synchronized.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A write manager is a {@link IncomingEntryReceiver} that buffers transactions and then and then dispatches them to a flushable transaction receiver that is periodically offered all queued transaction and then flushed
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class WriteManager : public OutgoingEntryReceiver, public PeriodicRunnable{
|
||||
private:
|
||||
const static size_t queueSize = 500;
|
||||
|
||||
NTReentrantSemaphore transactionsLock;
|
||||
|
||||
NTThread* thread;
|
||||
|
||||
FlushableOutgoingEntryReceiver& receiver;
|
||||
NTThreadManager& threadManager;
|
||||
AbstractNetworkTableEntryStore& entryStore;
|
||||
|
||||
unsigned long keepAliveDelay;
|
||||
|
||||
volatile std::queue<NetworkTableEntry*>* incomingAssignmentQueue;
|
||||
volatile std::queue<NetworkTableEntry*>* incomingUpdateQueue;
|
||||
volatile std::queue<NetworkTableEntry*>* outgoingAssignmentQueue;
|
||||
volatile std::queue<NetworkTableEntry*>* outgoingUpdateQueue;
|
||||
|
||||
unsigned long lastWrite;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new Write manager
|
||||
* @param receiver
|
||||
* @param threadManager
|
||||
* @param transactionPool
|
||||
* @param entryStore
|
||||
*/
|
||||
WriteManager(FlushableOutgoingEntryReceiver& receiver, NTThreadManager& threadManager, AbstractNetworkTableEntryStore& entryStore, unsigned long keepAliveDelay);
|
||||
virtual ~WriteManager();
|
||||
/**
|
||||
* start the write thread
|
||||
*/
|
||||
void start();
|
||||
/**
|
||||
* stop the write thread
|
||||
*/
|
||||
void stop();
|
||||
|
||||
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
|
||||
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
|
||||
|
||||
/**
|
||||
* the periodic method that sends all buffered transactions
|
||||
*/
|
||||
void run();
|
||||
|
||||
};
|
||||
|
||||
#endif /* WRITEMANAGER_H_ */
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* ClientConnectionAdapter.h
|
||||
*
|
||||
* Created on: Nov 2, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CLIENTCONNECTIONADAPTER_H_
|
||||
#define CLIENTCONNECTIONADAPTER_H_
|
||||
|
||||
class ClientConnectionAdapter;
|
||||
|
||||
#include "networktables2/connection/ConnectionAdapter.h"
|
||||
#include "networktables2/IncomingEntryReceiver.h"
|
||||
#include "networktables2/FlushableOutgoingEntryReceiver.h"
|
||||
#include "networktables2/client/ClientNetworkTableEntryStore.h"
|
||||
#include "networktables2/stream/IOStreamFactory.h"
|
||||
#include "networktables2/thread/NTThreadManager.h"
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
#include "networktables2/client/ClientConnectionState.h"
|
||||
#include "networktables2/client/ClientConnectionListenerManager.h"
|
||||
#include "networktables2/connection/ConnectionMonitorThread.h"
|
||||
|
||||
|
||||
/**
|
||||
* Object that adapts messages from a server
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientConnectionAdapter : public ConnectionAdapter, public IncomingEntryReceiver, public FlushableOutgoingEntryReceiver{
|
||||
private:
|
||||
ClientNetworkTableEntryStore& entryStore;
|
||||
IOStreamFactory& streamFactory;
|
||||
NTThreadManager& threadManager;
|
||||
|
||||
ClientConnectionState* connectionState;
|
||||
ClientConnectionListenerManager& connectionListenerManager;
|
||||
NTReentrantSemaphore LOCK;
|
||||
NetworkTableEntryTypeManager& typeManager;
|
||||
NTThread* readThread;
|
||||
ConnectionMonitorThread* monitor;
|
||||
NetworkTableConnection* connection;
|
||||
|
||||
void gotoState(ClientConnectionState* newState);
|
||||
bool m_IsConnectionClosed; //Keep track of when this is closed to issue reconnect
|
||||
public:
|
||||
/**
|
||||
* @return the state of the connection
|
||||
*/
|
||||
ClientConnectionState* getConnectionState();
|
||||
/**
|
||||
* @return if the client is connected to the server
|
||||
*/
|
||||
bool isConnected();
|
||||
|
||||
/**
|
||||
* Create a new ClientConnectionAdapter
|
||||
* @param entryStore
|
||||
* @param threadManager
|
||||
* @param streamFactory
|
||||
* @param transactionPool
|
||||
* @param connectionListenerManager
|
||||
*/
|
||||
ClientConnectionAdapter(ClientNetworkTableEntryStore& entryStore, NTThreadManager& threadManager, IOStreamFactory& streamFactory, ClientConnectionListenerManager& connectionListenerManager, NetworkTableEntryTypeManager& typeManager);
|
||||
virtual ~ClientConnectionAdapter();
|
||||
|
||||
|
||||
/*
|
||||
* Connection management
|
||||
*/
|
||||
/**
|
||||
* Reconnect the client to the server (even if the client is not currently connected)
|
||||
*/
|
||||
void reconnect();
|
||||
|
||||
/**
|
||||
* Close the client connection
|
||||
*/
|
||||
void close();
|
||||
/**
|
||||
* Close the connection to the server and enter the given state
|
||||
* @param newState
|
||||
*/
|
||||
void close(ClientConnectionState* newState);
|
||||
|
||||
|
||||
|
||||
void badMessage(BadMessageException& e);
|
||||
|
||||
void ioException(IOException& e);
|
||||
|
||||
NetworkTableEntry* GetEntry(EntryId id);
|
||||
|
||||
|
||||
bool keepAlive();
|
||||
|
||||
void clientHello(ProtocolVersion protocolRevision);
|
||||
|
||||
void protocolVersionUnsupported(ProtocolVersion protocolRevision);
|
||||
|
||||
void serverHelloComplete();
|
||||
|
||||
|
||||
void offerIncomingAssignment(NetworkTableEntry* entry);
|
||||
void offerIncomingUpdate(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value);
|
||||
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
void flush();
|
||||
void ensureAlive();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* CLIENTCONNECTIONADAPTER_H_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ClientConnectionListenerManager.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CLIENTCONNECTIONLISTENERMANAGER_H_
|
||||
#define CLIENTCONNECTIONLISTENERMANAGER_H_
|
||||
|
||||
/**
|
||||
* An object that manages connection listeners and fires events for other listeners
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientConnectionListenerManager
|
||||
{
|
||||
public:
|
||||
virtual ~ClientConnectionListenerManager()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* called when something is connected
|
||||
*/
|
||||
virtual void FireConnectedEvent() = 0;
|
||||
/**
|
||||
* called when something is disconnected
|
||||
*/
|
||||
virtual void FireDisconnectedEvent() = 0;
|
||||
};
|
||||
|
||||
#endif /* CLIENTCONNECTIONLISTENERMANAGER_H_ */
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* ClientConnectionState.h
|
||||
*
|
||||
* Created on: Nov 2, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CLIENTCONNECTIONSTATE_H_
|
||||
#define CLIENTCONNECTIONSTATE_H_
|
||||
|
||||
|
||||
class ClientConnectionState;
|
||||
class ClientConnectionState_Error;
|
||||
class ClientConnectionState_ProtocolUnsuppotedByServer;
|
||||
|
||||
#include <exception>
|
||||
#include "networktables2/connection/NetworkTableConnection.h"
|
||||
|
||||
/**
|
||||
* Represents a state that the client is in
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientConnectionState {
|
||||
public:
|
||||
/**
|
||||
* indicates that the client is disconnected from the server
|
||||
*/
|
||||
static ClientConnectionState DISCONNECTED_FROM_SERVER;
|
||||
/**
|
||||
* indicates that the client is connected to the server but has not yet begun communication
|
||||
*/
|
||||
static ClientConnectionState CONNECTED_TO_SERVER;
|
||||
/**
|
||||
* represents that the client has sent the hello to the server and is waiting for a response
|
||||
*/
|
||||
static ClientConnectionState SENT_HELLO_TO_SERVER;
|
||||
/**
|
||||
* represents that the client is now in sync with the server
|
||||
*/
|
||||
static ClientConnectionState IN_SYNC_WITH_SERVER;
|
||||
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
protected:
|
||||
ClientConnectionState(const char* name);
|
||||
public:
|
||||
virtual const char* toString();
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Represents that a client received a message from the server indicating that the client's protocol revision is not supported by the server
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientConnectionState_ProtocolUnsuppotedByServer : public ClientConnectionState{
|
||||
private:
|
||||
const ProtocolVersion serverVersion;
|
||||
public:
|
||||
/**
|
||||
* Create a new protocol unsupported state
|
||||
* @param serverVersion
|
||||
*/
|
||||
ClientConnectionState_ProtocolUnsuppotedByServer(ProtocolVersion serverVersion);
|
||||
/**
|
||||
* @return the protocol version that the server reported it supports
|
||||
*/
|
||||
ProtocolVersion getServerVersion();
|
||||
const char* toString();
|
||||
};
|
||||
/**
|
||||
* Represents that the client is in an error state
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientConnectionState_Error : public ClientConnectionState{
|
||||
private:
|
||||
std::exception& e;
|
||||
char msg[100];
|
||||
public:
|
||||
/**
|
||||
* Create a new error state
|
||||
* @param e
|
||||
*/
|
||||
ClientConnectionState_Error(std::exception& e);
|
||||
/**
|
||||
* @return the exception that caused the client to enter an error state
|
||||
*/
|
||||
std::exception& getException();
|
||||
virtual const char* toString();
|
||||
};
|
||||
|
||||
|
||||
#endif /* CLIENTCONNECTIONSTATE_H_ */
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* ClientNetworkTableEntryStore.h
|
||||
*
|
||||
* Created on: Nov 2, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CLIENTNETWORKTABLEENTRYSTORE_H_
|
||||
#define CLIENTNETWORKTABLEENTRYSTORE_H_
|
||||
|
||||
|
||||
class ClientNetworkTableEntryStore;
|
||||
|
||||
|
||||
#include "networktables2/AbstractNetworkTableEntryStore.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "OSAL/Synchronized.h"
|
||||
|
||||
/**
|
||||
* The entry store for a {@link NetworkTableClient}
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ClientNetworkTableEntryStore : public AbstractNetworkTableEntryStore{
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new ClientNetworkTableEntryStore
|
||||
* @param transactionPool
|
||||
* @param listenerManager
|
||||
*/
|
||||
ClientNetworkTableEntryStore(TableListenerManager& listenerManager);
|
||||
virtual ~ClientNetworkTableEntryStore();
|
||||
|
||||
protected:
|
||||
bool addEntry(NetworkTableEntry* newEntry);
|
||||
bool updateEntry(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Send all unknown entries in the entry store to the given connection
|
||||
* @param connection
|
||||
* @throws IOException
|
||||
*/
|
||||
void sendUnknownEntries(NetworkTableConnection& connection);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* CLIENTNETWORKTABLEENTRYSTORE_H_ */
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* NetworkTableClient.h
|
||||
*
|
||||
* Created on: Nov 3, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLECLIENT_H_
|
||||
#define NETWORKTABLECLIENT_H_
|
||||
|
||||
class NetworkTableClient;
|
||||
|
||||
#include "networktables2/NetworkTableNode.h"
|
||||
#include "networktables2/client/ClientConnectionAdapter.h"
|
||||
#include "networktables2/WriteManager.h"
|
||||
#include "networktables2/TransactionDirtier.h"
|
||||
|
||||
/**
|
||||
* A client node in NetworkTables 2.0
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class NetworkTableClient : public NetworkTableNode{
|
||||
private:
|
||||
ClientConnectionAdapter& adapter;
|
||||
WriteManager& writeManager;
|
||||
TransactionDirtier* dirtier;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a new NetworkTable Client
|
||||
* @param streamFactory
|
||||
* @param threadManager
|
||||
* @param transactionPool
|
||||
*/
|
||||
NetworkTableClient(IOStreamFactory& streamFactory, NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager);
|
||||
~NetworkTableClient();
|
||||
|
||||
/**
|
||||
* force the client to disconnect and reconnect to the server again. Will connect if the client is currently disconnected
|
||||
*/
|
||||
void reconnect();
|
||||
|
||||
void Close();
|
||||
|
||||
void stop();
|
||||
|
||||
bool IsConnected();
|
||||
|
||||
bool IsServer();
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* NETWORKTABLECLIENT_H_ */
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* BadMessageException.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef BADMESSAGEEXCEPTION_H_
|
||||
#define BADMESSAGEEXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
class BadMessageException : public std::exception
|
||||
{
|
||||
public:
|
||||
BadMessageException(const char* message);
|
||||
~BadMessageException() throw ();
|
||||
const char* what();
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
#endif /* BADMESSAGEEXCEPTION_H_ */
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* ConnectionAdapter.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CONNECTIONADAPTER_H_
|
||||
#define CONNECTIONADAPTER_H_
|
||||
|
||||
class ConnectionAdapter;
|
||||
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "networktables2/connection/BadMessageException.h"
|
||||
#include "networktables2/util/IOException.h"
|
||||
#include "tables/ITable.h"
|
||||
|
||||
class ConnectionAdapter
|
||||
{
|
||||
public:
|
||||
virtual ~ConnectionAdapter()
|
||||
{
|
||||
}
|
||||
//returns true if the connection should still be alive
|
||||
virtual bool keepAlive() = 0;
|
||||
virtual void clientHello(ProtocolVersion protocolRevision) = 0;
|
||||
virtual void serverHelloComplete() = 0;
|
||||
virtual void protocolVersionUnsupported(ProtocolVersion protocolRevision) = 0;
|
||||
virtual void offerIncomingAssignment(NetworkTableEntry* newEntry) = 0;
|
||||
virtual void offerIncomingUpdate(NetworkTableEntry* newEntry, SequenceNumber sequenceNumber, EntryValue value) = 0;
|
||||
virtual NetworkTableEntry* GetEntry(EntryId) = 0;
|
||||
|
||||
/**
|
||||
* called if a bad message exception is thrown
|
||||
* @param e
|
||||
*/
|
||||
virtual void badMessage(BadMessageException& e) = 0;
|
||||
|
||||
/**
|
||||
* called if an io exception is thrown
|
||||
* @param e
|
||||
*/
|
||||
virtual void ioException(IOException& e) = 0;
|
||||
};
|
||||
|
||||
#endif /* CONNECTIONADAPTER_H_ */
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* ConnectionMonitorThread.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef CONNECTIONMONITORTHREAD_H_
|
||||
#define CONNECTIONMONITORTHREAD_H_
|
||||
|
||||
|
||||
class ConnectionMonitorThread;
|
||||
|
||||
#include "networktables2/connection/ConnectionAdapter.h"
|
||||
#include "networktables2/connection/NetworkTableConnection.h"
|
||||
#include "networktables2/thread/PeriodicRunnable.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A periodic thread that repeatedly reads from a connection
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ConnectionMonitorThread : public PeriodicRunnable{
|
||||
private:
|
||||
ConnectionAdapter& adapter;
|
||||
NetworkTableConnection& connection;
|
||||
|
||||
public:
|
||||
/**
|
||||
* create a new monitor thread
|
||||
* @param adapter
|
||||
* @param connection
|
||||
*/
|
||||
ConnectionMonitorThread(ConnectionAdapter& adapter, NetworkTableConnection& connection);
|
||||
//This can be used it identify which connection adapter instance the thread procedure is running (read-only)
|
||||
const NetworkTableConnection *GetNetworkTableConnection() const {return &connection;}
|
||||
|
||||
void run();
|
||||
};
|
||||
|
||||
|
||||
#endif /* CONNECTIONMONITORTHREAD_H_ */
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef DATAIOSTREAM_H_
|
||||
#define DATAIOSTREAM_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#ifndef _WRS_KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
|
||||
//WindRiver is 3.4 GCC. Recent GCC can do 0b01010101 style format, WR cannot
|
||||
|
||||
#define TO_HEX__(n) 0x##n##LU // LU for unsigned long
|
||||
#define BINARY_LITERAL_VIA_HEX__(n) (((n & 0x00000001LU) ? 1 : 0)\
|
||||
+ ((n & 0x00000010LU) ? 2 : 0) \
|
||||
+ ((n & 0x00000100LU) ? 4 : 0) \
|
||||
+ ((n & 0x00001000LU) ? 8 : 0) \
|
||||
+ ((n & 0x00010000LU) ? 16 : 0) \
|
||||
+ ((n & 0x00100000LU) ? 32 : 0) \
|
||||
+ ((n & 0x01000000LU) ? 64 : 0) \
|
||||
+ ((n & 0x10000000LU) ? 128 : 0))
|
||||
|
||||
#define b(n) ((unsigned char)BINARY_LITERAL_VIA_HEX__(TO_HEX__(n)))
|
||||
|
||||
class DataIOStream{
|
||||
public:
|
||||
DataIOStream(IOStream* stream);
|
||||
virtual ~DataIOStream();
|
||||
void writeByte(uint8_t b);
|
||||
void write2BytesBE(uint16_t s);
|
||||
void writeString(std::string& str);
|
||||
void flush();
|
||||
|
||||
uint8_t readByte();
|
||||
uint16_t read2BytesBE();
|
||||
std::string* readString();
|
||||
|
||||
void close();
|
||||
void SetIOStream(IOStream* stream);
|
||||
|
||||
//private:
|
||||
IOStream *iostream;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* An abstraction for the NetworkTable protocol
|
||||
*
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NETWORK_TABLE_CONNECTION_H_
|
||||
#define NETWORK_TABLE_CONNECTION_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "OSAL/Synchronized.h"
|
||||
#ifndef _WRS_KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
class NetworkTableConnection;
|
||||
typedef uint16_t ProtocolVersion;
|
||||
|
||||
#include "networktables2/connection/DataIOStream.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
#include "networktables2/type/NetworkTableEntryTypeManager.h"
|
||||
#include "networktables2/connection/ConnectionAdapter.h"
|
||||
#include "networktables2/NetworkTableMessageType.h"
|
||||
|
||||
|
||||
class NetworkTableConnection{
|
||||
public:
|
||||
static const ProtocolVersion PROTOCOL_REVISION = 0x0200;
|
||||
|
||||
NetworkTableConnection(IOStream* stream, NetworkTableEntryTypeManager& typeManager);
|
||||
~NetworkTableConnection();
|
||||
void close();
|
||||
void flush();
|
||||
void sendKeepAlive();
|
||||
void sendClientHello();
|
||||
void sendServerHelloComplete();
|
||||
void sendProtocolVersionUnsupported();
|
||||
void sendEntryAssignment(NetworkTableEntry& entry);
|
||||
void sendEntryUpdate(NetworkTableEntry& entry);
|
||||
void read(ConnectionAdapter& adapter);
|
||||
void SetIOStream(IOStream* stream);
|
||||
private:
|
||||
NTReentrantSemaphore WRITE_LOCK;
|
||||
DataIOStream* const ioStream;
|
||||
NetworkTableEntryTypeManager& typeManager;
|
||||
bool isValid;
|
||||
|
||||
void sendMessageHeader(NetworkTableMessageType messageType);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* NetworkTableServer.h
|
||||
*
|
||||
* Created on: Sep 27, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLESERVER_H_
|
||||
#define NETWORKTABLESERVER_H_
|
||||
|
||||
|
||||
class NetworkTableServer;
|
||||
|
||||
#include "networktables2/TransactionDirtier.h"
|
||||
#include "networktables2/NetworkTableNode.h"
|
||||
#include "networktables2/server/ServerIncomingStreamMonitor.h"
|
||||
#include "networktables2/server/ServerIncomingConnectionListener.h"
|
||||
#include "networktables2/WriteManager.h"
|
||||
#include "networktables2/stream/IOStreamProvider.h"
|
||||
#include "networktables2/server/ServerConnectionList.h"
|
||||
|
||||
/**
|
||||
* A server node in NetworkTables 2.0
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class NetworkTableServer : public NetworkTableNode, public ServerIncomingConnectionListener{
|
||||
private:
|
||||
IOStreamProvider& streamProvider;
|
||||
ServerIncomingStreamMonitor incomingStreamMonitor;
|
||||
ServerConnectionList connectionList;
|
||||
WriteManager writeManager;
|
||||
TransactionDirtier continuingReceiver;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a NetworkTable Server
|
||||
*
|
||||
* @param streamProvider
|
||||
* @param threadManager
|
||||
* @param transactionPool
|
||||
*/
|
||||
NetworkTableServer(IOStreamProvider& streamProvider, NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager);
|
||||
~NetworkTableServer();
|
||||
/**
|
||||
* Create a NetworkTable Server
|
||||
*
|
||||
* @param streamProvider
|
||||
*/
|
||||
NetworkTableServer(IOStreamProvider& streamProvider);
|
||||
|
||||
void Close();
|
||||
|
||||
void OnNewConnection(ServerConnectionAdapter& connectionAdapter);
|
||||
|
||||
|
||||
bool IsConnected();
|
||||
|
||||
|
||||
bool IsServer();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* NETWORKTABLESERVER_H_ */
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ServerAdapterManager.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERADAPTERMANAGER_H_
|
||||
#define SERVERADAPTERMANAGER_H_
|
||||
|
||||
class ServerAdapterManager;
|
||||
|
||||
#include "networktables2/server/ServerConnectionAdapter.h"
|
||||
|
||||
/**
|
||||
* A class that manages connections to a server
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerAdapterManager
|
||||
{
|
||||
public:
|
||||
virtual ~ServerAdapterManager()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Called when a connection adapter has been closed
|
||||
* @param connectionAdapter the adapter that was closed
|
||||
*/
|
||||
virtual void close(ServerConnectionAdapter& connectionAdapter, bool closeStream) = 0;
|
||||
};
|
||||
|
||||
#endif /* SERVERADAPTERMANAGER_H_ */
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* ServerConnectionAdapter.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERCONNECTIONADAPTER_H_
|
||||
#define SERVERCONNECTIONADAPTER_H_
|
||||
|
||||
class ServerConnectionAdapter;
|
||||
|
||||
#include "networktables2/connection/ConnectionMonitorThread.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "networktables2/connection/ConnectionAdapter.h"
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
#include "networktables2/IncomingEntryReceiver.h"
|
||||
#include "networktables2/FlushableOutgoingEntryReceiver.h"
|
||||
#include "networktables2/server/ServerNetworkTableEntryStore.h"
|
||||
#include "networktables2/server/ServerAdapterManager.h"
|
||||
#include "networktables2/server/ServerConnectionState.h"
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
#include "networktables2/thread/NTThreadManager.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Object that adapts messages from a client to the server
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerConnectionAdapter : public ConnectionAdapter, public IncomingEntryReceiver, public FlushableOutgoingEntryReceiver{
|
||||
private:
|
||||
ServerNetworkTableEntryStore& entryStore;
|
||||
IncomingEntryReceiver& transactionReceiver;
|
||||
ServerAdapterManager& adapterListener;
|
||||
public:
|
||||
/**
|
||||
* the connection this adapter uses
|
||||
*/
|
||||
NetworkTableConnection connection;
|
||||
private:
|
||||
NTThread* readThread;
|
||||
ConnectionMonitorThread monitorThread;
|
||||
private:
|
||||
|
||||
ServerConnectionState* connectionState;
|
||||
|
||||
void gotoState(ServerConnectionState* newState);
|
||||
bool m_IsAdapterListenerClosed;
|
||||
public:
|
||||
/**
|
||||
* Create a server connection adapter for a given stream
|
||||
*
|
||||
* @param stream
|
||||
* @param transactionPool
|
||||
* @param entryStore
|
||||
* @param transactionReceiver
|
||||
* @param adapterListener
|
||||
* @param threadManager
|
||||
*/
|
||||
ServerConnectionAdapter(IOStream* stream, ServerNetworkTableEntryStore& entryStore, IncomingEntryReceiver& transactionReceiver, ServerAdapterManager& adapterListener, NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager);
|
||||
virtual ~ServerConnectionAdapter();
|
||||
|
||||
/**
|
||||
* stop the read thread and close the stream
|
||||
*/
|
||||
void shutdown(bool closeStream);
|
||||
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
|
||||
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* @return the state of the connection
|
||||
*/
|
||||
ServerConnectionState* getConnectionState();
|
||||
|
||||
void ensureAlive();
|
||||
|
||||
//return true once the close has been issued
|
||||
bool IsAdapterListenerClosed() const {return m_IsAdapterListenerClosed;}
|
||||
ConnectionAdapter &AsConnectionAdapter() {return *this;}
|
||||
protected: //from ConnectionAdapter
|
||||
|
||||
bool keepAlive();
|
||||
void badMessage(BadMessageException& e);
|
||||
void ioException(IOException& e);
|
||||
void clientHello(ProtocolVersion protocolRevision);
|
||||
void protocolVersionUnsupported(ProtocolVersion protocolRevision);
|
||||
void serverHelloComplete();
|
||||
void offerIncomingAssignment(NetworkTableEntry* entry);
|
||||
void offerIncomingUpdate(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value);
|
||||
NetworkTableEntry* GetEntry(EntryId id);
|
||||
};
|
||||
|
||||
|
||||
#endif /* SERVERCONNECTIONADAPTER_H_ */
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* ServerConnectionList.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERCONNECTIONLIST_H_
|
||||
#define SERVERCONNECTIONLIST_H_
|
||||
|
||||
|
||||
|
||||
class ServerConnectionList;
|
||||
class ServerIncomingStreamMonitor;
|
||||
|
||||
#include "networktables2/FlushableOutgoingEntryReceiver.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "networktables2/server/ServerAdapterManager.h"
|
||||
#include "networktables2/server/ServerConnectionAdapter.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A list of connections that the server currently has
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerConnectionList : public FlushableOutgoingEntryReceiver, public ServerAdapterManager{
|
||||
private:
|
||||
NTReentrantSemaphore connectionsLock;
|
||||
std::vector<ServerConnectionAdapter*> connections;
|
||||
ServerIncomingStreamMonitor * const m_Factory; //make call to close connection
|
||||
public:
|
||||
ServerConnectionList(ServerIncomingStreamMonitor *Factory);
|
||||
virtual ~ServerConnectionList();
|
||||
/**
|
||||
* Add a connection to the list
|
||||
* @param connection
|
||||
*/
|
||||
void add(ServerConnectionAdapter& connection);
|
||||
|
||||
|
||||
void close(ServerConnectionAdapter& connectionAdapter, bool closeStream);
|
||||
/**
|
||||
* close all connections and remove them
|
||||
*/
|
||||
void closeAll();
|
||||
|
||||
void offerOutgoingAssignment(NetworkTableEntry* entry);
|
||||
void offerOutgoingUpdate(NetworkTableEntry* entry);
|
||||
void flush();
|
||||
void ensureAlive();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SERVERCONNECTIONLIST_H_ */
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* ServerConnectionState.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERCONNECTIONSTATE_H_
|
||||
#define SERVERCONNECTIONSTATE_H_
|
||||
|
||||
class ServerConnectionState;
|
||||
class ServerConnectionState_Error;
|
||||
|
||||
#include <exception>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Represents the state of a connection to the server
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerConnectionState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* represents that the server has received the connection from the client but has not yet received the client hello
|
||||
*/
|
||||
static ServerConnectionState GOT_CONNECTION_FROM_CLIENT;
|
||||
/**
|
||||
* represents that the client is in a connected non-error state
|
||||
*/
|
||||
static ServerConnectionState CONNECTED_TO_CLIENT;
|
||||
/**
|
||||
* represents that the client has disconnected from the server
|
||||
*/
|
||||
static ServerConnectionState CLIENT_DISCONNECTED;
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
protected:
|
||||
ServerConnectionState(const char* name);
|
||||
public:
|
||||
virtual const char* toString();
|
||||
virtual ~ServerConnectionState()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents that the client is in an error state
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerConnectionState_Error : public ServerConnectionState
|
||||
{
|
||||
private:
|
||||
std::exception& e;
|
||||
public:
|
||||
/**
|
||||
* Create a new error state
|
||||
* @param e
|
||||
*/
|
||||
ServerConnectionState_Error(std::exception& e);
|
||||
|
||||
virtual const char* toString();
|
||||
/**
|
||||
* @return the exception that caused the client connection to enter an error state
|
||||
*/
|
||||
std::exception& getException();
|
||||
};
|
||||
|
||||
#endif /* SERVERCONNECTIONSTATE_H_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* ServerIncomingConnectionListener.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERINCOMINGCONNECTIONLISTENER_H_
|
||||
#define SERVERINCOMINGCONNECTIONLISTENER_H_
|
||||
|
||||
#include "networktables2/server/ServerConnectionAdapter.h"
|
||||
|
||||
/**
|
||||
* Listener for new incoming server connections
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerIncomingConnectionListener
|
||||
{
|
||||
public:
|
||||
virtual ~ServerIncomingConnectionListener()
|
||||
{
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Called on create of a new connection
|
||||
* @param connectionAdapter the server connection adapter
|
||||
*/
|
||||
virtual void OnNewConnection(ServerConnectionAdapter& connectionAdapter) = 0;
|
||||
};
|
||||
|
||||
#endif /* SERVERINCOMINGCONNECTIONLISTENER_H_ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* ServerIncomingStreamMonitor.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERINCOMINGSTREAMMONITOR_H_
|
||||
#define SERVERINCOMINGSTREAMMONITOR_H_
|
||||
|
||||
|
||||
class ServerIncomingStreamMonitor;
|
||||
|
||||
|
||||
#include "networktables2/thread/PeriodicRunnable.h"
|
||||
#include "networktables2/thread/NTThreadManager.h"
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
#include "networktables2/stream/IOStreamProvider.h"
|
||||
#include "networktables2/server/ServerIncomingConnectionListener.h"
|
||||
#include "networktables2/server/ServerNetworkTableEntryStore.h"
|
||||
#include "networktables2/server/ServerAdapterManager.h"
|
||||
#include "networktables2/server/ServerConnectionAdapter.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Thread that monitors for incoming connections
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerIncomingStreamMonitor : PeriodicRunnable{
|
||||
private:
|
||||
IOStreamProvider& streamProvider;
|
||||
ServerNetworkTableEntryStore& entryStore;
|
||||
ServerIncomingConnectionListener& incomingListener;
|
||||
|
||||
ServerAdapterManager& adapterListener;
|
||||
NetworkTableEntryTypeManager& typeManager;
|
||||
NTThreadManager& threadManager;
|
||||
NTThread* monitorThread;
|
||||
|
||||
NTReentrantSemaphore BlockDeletionList;
|
||||
std::vector<ServerConnectionAdapter *> m_DeletionList;
|
||||
public:
|
||||
/**
|
||||
* Create a new incoming stream monitor
|
||||
* @param streamProvider the stream provider to retrieve streams from
|
||||
* @param entryStore the entry store for the server
|
||||
* @param transactionPool transaction pool for the server
|
||||
* @param incomingListener the listener that is notified of new connections
|
||||
* @param adapterListener the listener that will listen to adapter events
|
||||
* @param threadManager the thread manager used to create the incoming thread and provided to the Connection Adapters
|
||||
*/
|
||||
ServerIncomingStreamMonitor(IOStreamProvider& streamProvider, ServerNetworkTableEntryStore& entryStore,
|
||||
ServerIncomingConnectionListener& incomingListener,
|
||||
ServerAdapterManager& adapterListener,
|
||||
NetworkTableEntryTypeManager& typeManager, NTThreadManager& threadManager);
|
||||
|
||||
~ServerIncomingStreamMonitor();
|
||||
/**
|
||||
* Start the monitor thread
|
||||
*/
|
||||
void start();
|
||||
/**
|
||||
* Stop the monitor thread
|
||||
*/
|
||||
void stop();
|
||||
|
||||
void run();
|
||||
|
||||
void close(ServerConnectionAdapter *Adapter);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SERVERINCOMINGSTREAMMONITOR_H_ */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* ServerNetworkTableEntryStore.h
|
||||
*
|
||||
* Created on: Sep 26, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SERVERNETWORKTABLEENTRYSTORE_H_
|
||||
#define SERVERNETWORKTABLEENTRYSTORE_H_
|
||||
|
||||
|
||||
class ServerNetworkTableEntryStore;
|
||||
|
||||
|
||||
#include "networktables2/AbstractNetworkTableEntryStore.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "OSAL/Synchronized.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The entry store for a {@link NetworkTableServer}
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class ServerNetworkTableEntryStore : public AbstractNetworkTableEntryStore{
|
||||
private:
|
||||
EntryId nextId;
|
||||
public:
|
||||
/**
|
||||
* Create a new Server entry store
|
||||
* @param transactionPool the transaction pool
|
||||
* @param listenerManager the listener manager that fires events from this entry store
|
||||
*/
|
||||
ServerNetworkTableEntryStore(TableListenerManager& listenerManager);
|
||||
virtual ~ServerNetworkTableEntryStore();
|
||||
|
||||
protected:
|
||||
bool addEntry(NetworkTableEntry* newEntry);
|
||||
|
||||
bool updateEntry(NetworkTableEntry* entry, SequenceNumber sequenceNumber, EntryValue value);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Send all entries in the entry store as entry assignments in a single transaction
|
||||
* @param connection
|
||||
* @throws IOException
|
||||
*/
|
||||
void sendServerHello(NetworkTableConnection& connection);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SERVERNETWORKTABLEENTRYSTORE_H_ */
|
||||
36
networktables/cpp/include/networktables2/stream/FDIOStream.h
Normal file
36
networktables/cpp/include/networktables2/stream/FDIOStream.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* FDIOStream.h
|
||||
*
|
||||
* Created on: Sep 27, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef FDIOSTREAM_H_
|
||||
#define FDIOSTREAM_H_
|
||||
|
||||
|
||||
|
||||
class FDIOStream;
|
||||
|
||||
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
class FDIOStream : public IOStream{
|
||||
private:
|
||||
//FILE* f;
|
||||
int fd;
|
||||
public:
|
||||
FDIOStream(int fd);
|
||||
virtual ~FDIOStream();
|
||||
int read(void* ptr, int numbytes);
|
||||
int write(const void* ptr, int numbytes);
|
||||
void flush();
|
||||
void close();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FDIOSTREAM_H_ */
|
||||
25
networktables/cpp/include/networktables2/stream/IOStream.h
Normal file
25
networktables/cpp/include/networktables2/stream/IOStream.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* IOStream.h
|
||||
*
|
||||
* Created on: Sep 27, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef IOSTREAM_H_
|
||||
#define IOSTREAM_H_
|
||||
|
||||
class IOStream;
|
||||
|
||||
class IOStream
|
||||
{
|
||||
public:
|
||||
virtual ~IOStream()
|
||||
{
|
||||
}
|
||||
virtual int read(void* ptr, int numbytes) = 0;
|
||||
virtual int write(const void* ptr, int numbytes) = 0;
|
||||
virtual void flush() = 0;
|
||||
virtual void close() = 0;
|
||||
};
|
||||
|
||||
#endif /* IOSTREAM_H_ */
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* IOStreamFactory.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef IOSTREAMFACTORY_H_
|
||||
#define IOSTREAMFACTORY_H_
|
||||
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
|
||||
/**
|
||||
* A factory that will create the same IOStream. A stream returned by this factory should be closed before calling createStream again
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class IOStreamFactory
|
||||
{
|
||||
public:
|
||||
virtual ~IOStreamFactory()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @return create a new stream
|
||||
* @throws IOException
|
||||
*/
|
||||
virtual IOStream* createStream() = 0;
|
||||
};
|
||||
|
||||
#endif /* IOSTREAMFACTORY_H_ */
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* IOStreamProvider.h
|
||||
*
|
||||
* Created on: Sep 22, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef IOSTREAMPROVIDER_H_
|
||||
#define IOSTREAMPROVIDER_H_
|
||||
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
|
||||
/**
|
||||
* An object that will provide the IOStream of clients to a NetworkTable Server
|
||||
*
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
class IOStreamProvider
|
||||
{
|
||||
public:
|
||||
virtual ~IOStreamProvider()
|
||||
{
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return a new IOStream normally from a server
|
||||
* @throws IOException
|
||||
*/
|
||||
virtual IOStream* accept() = 0;
|
||||
/**
|
||||
* Close the source of the IOStreams. {@link #accept()} should not be called after this is called
|
||||
* @throws IOException
|
||||
*/
|
||||
virtual void close() = 0;
|
||||
};
|
||||
|
||||
#endif /* IOSTREAMPROVIDER_H_ */
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* SocketServerStreamProvider.h
|
||||
*
|
||||
* Created on: Sep 27, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SOCKETSERVERSTREAMPROVIDER_H_
|
||||
#define SOCKETSERVERSTREAMPROVIDER_H_
|
||||
|
||||
|
||||
class SocketServerStreamProvider;
|
||||
|
||||
#include "networktables2/stream/IOStream.h"
|
||||
#include "networktables2/stream/IOStreamProvider.h"
|
||||
|
||||
|
||||
|
||||
|
||||
class SocketServerStreamProvider : public IOStreamProvider{
|
||||
private:
|
||||
int serverSocket;
|
||||
public:
|
||||
SocketServerStreamProvider(int port);
|
||||
virtual ~SocketServerStreamProvider();
|
||||
IOStream* accept();
|
||||
void close();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* SOCKETSERVERSTREAMPROVIDER_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* SocketStreamFactory.h
|
||||
*
|
||||
* Created on: Nov 3, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SOCKETSTREAMFACTORY_H_
|
||||
#define SOCKETSTREAMFACTORY_H_
|
||||
|
||||
class SocketStreamFactory;
|
||||
|
||||
#include "networktables2/stream/IOStreamFactory.h"
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
class SocketStreamFactory : public IOStreamFactory{
|
||||
private:
|
||||
const char* host;
|
||||
const int port;
|
||||
|
||||
public:
|
||||
SocketStreamFactory(const char* host, int port);
|
||||
virtual ~SocketStreamFactory();
|
||||
|
||||
IOStream* createStream();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SOCKETSTREAMFACTORY_H_ */
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* SocketStreams.h
|
||||
*
|
||||
* Created on: Sep 27, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef SOCKETSTREAMS_H_
|
||||
#define SOCKETSTREAMS_H_
|
||||
|
||||
|
||||
class SocketStreams;
|
||||
|
||||
|
||||
#include "networktables2/stream/IOStreamFactory.h"
|
||||
#include "networktables2/stream/IOStreamProvider.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Static factory for socket stream factories and providers
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class SocketStreams {
|
||||
public:
|
||||
/**
|
||||
* Create a new IOStream factory
|
||||
* @param host
|
||||
* @param port
|
||||
* @return a IOStreamFactory that will create Socket Connections on the given host and port
|
||||
* @throws IOException
|
||||
*/
|
||||
static IOStreamFactory& newStreamFactory(const char* host, int port);
|
||||
|
||||
/**
|
||||
* Create a new IOStream provider
|
||||
* @param port
|
||||
* @return an IOStreamProvider for a socket server on the given port
|
||||
* @throws IOException
|
||||
*/
|
||||
static IOStreamProvider& newStreamProvider(int port);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SOCKETSTREAMS_H_ */
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* DefaultThreadManager.h
|
||||
* Desktop
|
||||
*
|
||||
* Created on: Sep 21, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef DEFAULTTHREADMANAGER_H_
|
||||
#define DEFAULTTHREADMANAGER_H_
|
||||
|
||||
|
||||
class DefaultThreadManager;
|
||||
class PeriodicNTThread;
|
||||
|
||||
#include "networktables2/thread/PeriodicRunnable.h"
|
||||
#include "networktables2/thread/NTThreadManager.h"
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
|
||||
#if (defined __vxworks || defined WIN32)
|
||||
#include "OSAL/Task.h"
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
class DefaultThreadManager : public NTThreadManager{
|
||||
public:
|
||||
virtual NTThread* newBlockingPeriodicThread(PeriodicRunnable* r, const char* name);
|
||||
};
|
||||
|
||||
class PeriodicNTThread : public NTThread {
|
||||
private:
|
||||
#if (defined __vxworks || defined WIN32)
|
||||
const char* name;
|
||||
NTTask* thread;
|
||||
#else
|
||||
pthread_t thread;
|
||||
#endif
|
||||
PeriodicRunnable* r;
|
||||
bool run;
|
||||
#if (defined __vxworks || defined WIN32)
|
||||
int _taskMain();
|
||||
static int taskMain(PeriodicNTThread* o);
|
||||
#else//TODO make return int for pthread as well
|
||||
void _taskMain();
|
||||
static void* taskMain(PeriodicNTThread* o);
|
||||
#endif
|
||||
public:
|
||||
PeriodicNTThread(PeriodicRunnable* r, const char* name);
|
||||
virtual ~PeriodicNTThread();
|
||||
virtual void stop();
|
||||
virtual bool isRunning();
|
||||
};
|
||||
|
||||
#endif /* DEFAULTTHREADMANAGER_H_ */
|
||||
34
networktables/cpp/include/networktables2/thread/NTThread.h
Normal file
34
networktables/cpp/include/networktables2/thread/NTThread.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* NTThread.h
|
||||
*
|
||||
* Created on: Sep 21, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NTTHREAD_H_
|
||||
#define NTTHREAD_H_
|
||||
|
||||
/**
|
||||
* Represents a thread in the network tables system
|
||||
* @author mwills
|
||||
*
|
||||
*/
|
||||
class NTThread
|
||||
{
|
||||
public:
|
||||
virtual ~NTThread()
|
||||
{
|
||||
}
|
||||
;
|
||||
/**
|
||||
* stop the thread
|
||||
*/
|
||||
virtual void stop() = 0;
|
||||
|
||||
/**
|
||||
* @return true if the thread is running
|
||||
*/
|
||||
virtual bool isRunning() = 0;
|
||||
};
|
||||
|
||||
#endif /* NTTHREAD_H_ */
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* NTThreadManager.h
|
||||
*
|
||||
* Created on: Sep 21, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NTTHREADMANAGER_H_
|
||||
#define NTTHREADMANAGER_H_
|
||||
|
||||
class NTThreadManager;
|
||||
|
||||
#include "networktables2/thread/NTThread.h"
|
||||
#include "networktables2/thread/PeriodicRunnable.h"
|
||||
|
||||
/**
|
||||
* A thread manager that can be used to obtain new threads
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class NTThreadManager
|
||||
{
|
||||
public:
|
||||
virtual ~NTThreadManager()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* @param r
|
||||
* @param name the name of the thread
|
||||
* @return a thread that will run the provided runnable repeatedly with the assumption that the runnable will block
|
||||
*/
|
||||
virtual NTThread* newBlockingPeriodicThread(PeriodicRunnable* r, const char* name) = 0;
|
||||
};
|
||||
|
||||
#endif /* NTTHREADMANAGER_H_ */
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* PeriodicRunnable.h
|
||||
*
|
||||
* Created on: Sep 21, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef PERIODICRUNNABLE_H_
|
||||
#define PERIODICRUNNABLE_H_
|
||||
|
||||
/**
|
||||
* A runnable where the run method will be called periodically
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class PeriodicRunnable
|
||||
{
|
||||
public:
|
||||
virtual ~PeriodicRunnable()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* the method that will be called periodically on a thread
|
||||
*
|
||||
* @throws InterruptedException thrown when the thread is supposed to be interrupted and stop (implementers should always let this exception fall through)
|
||||
*/
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
#endif /* PERIODICRUNNABLE_H_ */
|
||||
88
networktables/cpp/include/networktables2/type/ArrayData.h
Normal file
88
networktables/cpp/include/networktables2/type/ArrayData.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* ArrayData.h
|
||||
*
|
||||
* Created on: Nov 14, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef ARRAYDATA_H_
|
||||
#define ARRAYDATA_H_
|
||||
|
||||
class ArrayData;
|
||||
|
||||
#include "networktables2/type/ArrayEntryType.h"
|
||||
#include "networktables2/type/ComplexData.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
|
||||
/**
|
||||
* Defines the internal representation for an array.
|
||||
*/
|
||||
class ArrayData : public ComplexData{
|
||||
private:
|
||||
ArrayEntryType& m_data_type;
|
||||
unsigned int m_size;
|
||||
EntryValue* data;
|
||||
public:
|
||||
/**
|
||||
* Creates a new ArrayData of the given type.
|
||||
*
|
||||
* @param type The ArrayEntryType representing the type
|
||||
* information that this ArrayData should satisfy.
|
||||
*/
|
||||
ArrayData(ArrayEntryType& type);
|
||||
virtual ~ArrayData();
|
||||
protected:
|
||||
/**
|
||||
* Gets the value stored at the specified index.
|
||||
*
|
||||
* @param index The array index to retrieve.
|
||||
*/
|
||||
EntryValue _get(unsigned int index);
|
||||
|
||||
/**
|
||||
* Updates the value stored at the specified index.
|
||||
*
|
||||
* The value currently stored at the given index is deleted.
|
||||
*
|
||||
* @param index The array index to update.
|
||||
* @param value The value to store. This value must have
|
||||
* the same type as the ArrayEntryType indicates.
|
||||
*/
|
||||
void _set(unsigned int index, EntryValue value);
|
||||
|
||||
/**
|
||||
* Appends the given value to the end of this array.
|
||||
*
|
||||
* @param value The value to store. This value must have
|
||||
* the same type as the ArrayEntryType indicates.
|
||||
*/
|
||||
void _add(EntryValue value);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Removes and deletes the value stored at the specified index.
|
||||
*
|
||||
* @param index The index of the value to remove.
|
||||
*/
|
||||
void remove(unsigned int index);
|
||||
|
||||
/**
|
||||
* Sets the new size of this array data structure.
|
||||
*
|
||||
* @param size The new size that this array should assume.
|
||||
*/
|
||||
void setSize(unsigned int size);
|
||||
|
||||
/**
|
||||
* Gets the current size of this array data structure.
|
||||
*
|
||||
* @return The current number of elements that this array may contain.
|
||||
*/
|
||||
unsigned int size();
|
||||
|
||||
friend class ArrayEntryType;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* ARRAYDATA_H_ */
|
||||
113
networktables/cpp/include/networktables2/type/ArrayEntryType.h
Normal file
113
networktables/cpp/include/networktables2/type/ArrayEntryType.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* ArrayEntryType.h
|
||||
*
|
||||
* Created on: Nov 14, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef ARRAYENTRYTYPE_H_
|
||||
#define ARRAYENTRYTYPE_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _WRS_KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
class ArrayEntryType;
|
||||
|
||||
#include "networktables2/type/ArrayData.h"
|
||||
#include "networktables2/type/ComplexEntryType.h"
|
||||
|
||||
struct ArrayEntryData{
|
||||
uint8_t length;
|
||||
EntryValue* array;
|
||||
};
|
||||
/**
|
||||
* Represents the size and contents of an array.
|
||||
*/
|
||||
typedef struct ArrayEntryData ArrayEntryData;
|
||||
|
||||
/**
|
||||
* Represents the type of an array entry value.
|
||||
*/
|
||||
class ArrayEntryType : public ComplexEntryType {//TODO allow for array of complex type
|
||||
private:
|
||||
NetworkTableEntryType& m_elementType;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a new ArrayEntryType.
|
||||
*
|
||||
* @param id The ID which identifies this type to other nodes on
|
||||
* across the network.
|
||||
* @param elementType The type of the elements this array contains.
|
||||
*/
|
||||
ArrayEntryType(TypeId id, NetworkTableEntryType& elementType);
|
||||
|
||||
/**
|
||||
* Creates a copy of an value which is of the type contained by
|
||||
* this array.
|
||||
*
|
||||
* @param value The element, of this array's contained type, to
|
||||
* copy.
|
||||
* @return A copy of the given value.
|
||||
*/
|
||||
EntryValue copyElement(EntryValue value);
|
||||
|
||||
/**
|
||||
* Deletes a entry value which is of the type contained by
|
||||
* this array.
|
||||
*
|
||||
* After calling this method, the given entry value is
|
||||
* no longer valid.
|
||||
*
|
||||
* @param value The value to delete.
|
||||
*/
|
||||
void deleteElement(EntryValue value);
|
||||
|
||||
/**
|
||||
* Compares two elements of the type of the array
|
||||
*
|
||||
* @return true if the elements are equal
|
||||
*/
|
||||
bool areElementsEqual(EntryValue v1, EntryValue v2);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
void sendValue(EntryValue value, DataIOStream& os);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::readValue
|
||||
*/
|
||||
EntryValue readValue(DataIOStream& is);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::copyValue
|
||||
*/
|
||||
EntryValue copyValue(EntryValue value);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::deleteValue
|
||||
*/
|
||||
void deleteValue(EntryValue value);
|
||||
|
||||
|
||||
bool areEqual(EntryValue v1, EntryValue v2);
|
||||
|
||||
/**
|
||||
* See {@link ComplexEntryType}::internalizeValue
|
||||
*/
|
||||
EntryValue internalizeValue(std::string& key, ComplexData& externalRepresentation, EntryValue currentInteralValue);
|
||||
|
||||
/**
|
||||
* See {@link ComplexEntryType}::exportValue
|
||||
*/
|
||||
void exportValue(std::string& key, EntryValue internalData, ComplexData& externalRepresentation);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* ARRAYENTRYTYPE_H_ */
|
||||
31
networktables/cpp/include/networktables2/type/BooleanArray.h
Normal file
31
networktables/cpp/include/networktables2/type/BooleanArray.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* BooleanArray.h
|
||||
*
|
||||
* Created on: Nov 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef BOOLEANARRAY_H_
|
||||
#define BOOLEANARRAY_H_
|
||||
|
||||
#include "networktables2/type/ArrayData.h"
|
||||
#include "networktables2/type/ArrayEntryType.h"
|
||||
|
||||
//TODO: BooleanArray appears unused; replace with namespace?
|
||||
class BooleanArray : public ArrayData{
|
||||
|
||||
public:
|
||||
static const TypeId BOOLEAN_ARRAY_RAW_ID;
|
||||
static ArrayEntryType TYPE;
|
||||
|
||||
|
||||
BooleanArray();
|
||||
|
||||
bool get(int index);
|
||||
void set(int index, bool value);
|
||||
void add(bool value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* BOOLEANARRAY_H_ */
|
||||
43
networktables/cpp/include/networktables2/type/ComplexData.h
Normal file
43
networktables/cpp/include/networktables2/type/ComplexData.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* ComplexData.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef COMPLEXDATA_H_
|
||||
#define COMPLEXDATA_H_
|
||||
|
||||
|
||||
class ComplexData;
|
||||
|
||||
|
||||
//#include "networktables2/type/ComplexEntryType.h" can't do this cause it causes order of definition issues
|
||||
class ComplexEntryType;
|
||||
|
||||
/**
|
||||
* Base class for non-primitive data structures.
|
||||
*/
|
||||
class ComplexData{
|
||||
private:
|
||||
ComplexEntryType& type;
|
||||
public:
|
||||
/**
|
||||
* Creates a new ComplexData of the given type.
|
||||
*
|
||||
* @param type The type of this data structure.
|
||||
*/
|
||||
ComplexData(ComplexEntryType& type);
|
||||
|
||||
/**
|
||||
* Gets the type of this data structure.
|
||||
*
|
||||
* @return The type of this data structure.
|
||||
*/
|
||||
ComplexEntryType& GetType();
|
||||
virtual ~ComplexData(){};
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* COMPLEXDATA_H_ */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* ComplexEntryType.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef COMPLEXENTRYTYPE_H_
|
||||
#define COMPLEXENTRYTYPE_H_
|
||||
|
||||
class ComplexEntryType;
|
||||
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
|
||||
/**
|
||||
* Represents a non-primitive data type (i.e. not a string, double,
|
||||
* or boolean).
|
||||
*/
|
||||
class ComplexEntryType : public NetworkTableEntryType
|
||||
{
|
||||
protected:
|
||||
ComplexEntryType(TypeId id, const char* name);
|
||||
public:
|
||||
virtual ~ComplexEntryType()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::isComplex.
|
||||
*/
|
||||
virtual bool isComplex();
|
||||
|
||||
/**
|
||||
* Updates the internal representation for an entry of this type with the
|
||||
* given value.
|
||||
*
|
||||
* @param key The name of the field to update.
|
||||
* @param externalRepresentation The existing data structure to update.
|
||||
* @param currentInternalValue The value to update the external representation with.
|
||||
*/
|
||||
virtual EntryValue internalizeValue(std::string& key, ComplexData& externalRepresentation, EntryValue currentInteralValue) = 0;
|
||||
|
||||
/**
|
||||
* Updates the given external representation for an entry of this type with
|
||||
* the given internal value.
|
||||
*
|
||||
* @param key The name of the field to export.
|
||||
* @param internalData The current value to reference.
|
||||
* @param externalRepresentation The external representation to update.
|
||||
*/
|
||||
virtual void exportValue(std::string& key, EntryValue internalData, ComplexData& externalRepresentation) = 0;
|
||||
};
|
||||
|
||||
#endif /* COMPLEXENTRYTYPE_H_ */
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* DefaultEntryTypes.h
|
||||
*
|
||||
* Created on: Sep 24, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef DEFAULTENTRYTYPES_H_
|
||||
#define DEFAULTENTRYTYPES_H_
|
||||
|
||||
class DefaultEntryTypes;
|
||||
|
||||
#include "networktables2/type/NetworkTableEntryTypeManager.h"
|
||||
|
||||
|
||||
|
||||
static const TypeId BOOLEAN_RAW_ID = 0x00;
|
||||
static const TypeId DOUBLE_RAW_ID = 0x01;
|
||||
static const TypeId STRING_RAW_ID = 0x02;
|
||||
|
||||
class DefaultEntryTypes{
|
||||
private:
|
||||
/**
|
||||
* a boolean entry type
|
||||
*/
|
||||
class BOOLEAN_t : public NetworkTableEntryType{
|
||||
public:
|
||||
BOOLEAN_t();
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
virtual void sendValue(EntryValue value, DataIOStream& os);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::readValue
|
||||
*/
|
||||
virtual EntryValue readValue(DataIOStream& is);
|
||||
|
||||
virtual bool areEqual(EntryValue v1, EntryValue v2);
|
||||
};
|
||||
/**
|
||||
* a double floating point entry type
|
||||
*/
|
||||
class DOUBLE_t : public NetworkTableEntryType{
|
||||
public:
|
||||
DOUBLE_t();
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
virtual void sendValue(EntryValue value, DataIOStream& os);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
virtual EntryValue readValue(DataIOStream& is);
|
||||
|
||||
virtual bool areEqual(EntryValue v1, EntryValue v2);
|
||||
};
|
||||
/**
|
||||
* a string entry type
|
||||
*/
|
||||
class STRING_t : public NetworkTableEntryType{
|
||||
public:
|
||||
STRING_t();
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
virtual void sendValue(EntryValue value, DataIOStream& os);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::sendValue
|
||||
*/
|
||||
virtual EntryValue readValue(DataIOStream& is);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::copyValue
|
||||
*/
|
||||
virtual EntryValue copyValue(EntryValue value);
|
||||
|
||||
/**
|
||||
* See {@link NetworkTableEntryType}::deleteValue
|
||||
*/
|
||||
virtual void deleteValue(EntryValue value);
|
||||
|
||||
virtual bool areEqual(EntryValue v1, EntryValue v2);
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* Registers the set of default entry types with the given
|
||||
* entry type manager.
|
||||
*
|
||||
* @param typeManager The entry type manager to update. Pointer must not be null.
|
||||
*/
|
||||
static void registerTypes(NetworkTableEntryTypeManager* typeManager);
|
||||
|
||||
static BOOLEAN_t BOOLEAN;
|
||||
static DOUBLE_t DOUBLE;
|
||||
static STRING_t STRING;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DEFAULTENTRYTYPES_H_ */
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* NetworkTableEntryType.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLEENTRYTYPE_H_
|
||||
#define NETWORKTABLEENTRYTYPE_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifndef _WRS_KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* An ID which identifies a type to other nodes on the network.
|
||||
*/
|
||||
typedef uint8_t TypeId;
|
||||
class NetworkTableEntryType;
|
||||
|
||||
#define MAX_NUM_TABLE_ENTRY_TYPES 256
|
||||
|
||||
#include <string>
|
||||
#include "networktables2/connection/DataIOStream.h"
|
||||
#include "networktables2/NetworkTableEntry.h"
|
||||
#include "tables/ITable.h"
|
||||
|
||||
/**
|
||||
* Represents the type associated with a network tables value.
|
||||
*/
|
||||
class NetworkTableEntryType{
|
||||
public:
|
||||
const TypeId id;
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* Determines whether this data type is complex (i.e. it does not
|
||||
* represent a number, string, or boolean).
|
||||
*
|
||||
* @return True of this type is complex. False otherwise.
|
||||
*/
|
||||
virtual bool isComplex();
|
||||
|
||||
/**
|
||||
* Serializes the given value on the given output stream.
|
||||
*
|
||||
* @param value The value to serialize.
|
||||
* @param os The output stream to use.
|
||||
*/
|
||||
virtual void sendValue(EntryValue value, DataIOStream& os) = 0;
|
||||
|
||||
/**
|
||||
* Unserializes the a value of this type from the given
|
||||
* input stream.
|
||||
*
|
||||
* @param is The input stream to read from.
|
||||
* @return The unserialized value.
|
||||
*/
|
||||
virtual EntryValue readValue(DataIOStream& is) = 0;
|
||||
|
||||
/**
|
||||
* Creates a copy of the given value of this type.
|
||||
*
|
||||
* @param value The value to copy.
|
||||
* @return A copy of the given value of this type.
|
||||
*/
|
||||
virtual EntryValue copyValue(EntryValue value);
|
||||
|
||||
/**
|
||||
* Compares two values to determine if they are equal
|
||||
* and should not push an update to other nodes
|
||||
*
|
||||
* @param v1
|
||||
* @param v2
|
||||
* @return true if the two values are equal
|
||||
*/
|
||||
virtual bool areEqual(EntryValue v1, EntryValue v2) = 0;
|
||||
|
||||
/**
|
||||
* Deletes a value of this type.
|
||||
*
|
||||
* After calling this function, the given value is
|
||||
* no longer valid.
|
||||
*
|
||||
* @param value The value to delete.
|
||||
*/
|
||||
virtual void deleteValue(EntryValue value);
|
||||
virtual ~NetworkTableEntryType();
|
||||
protected:
|
||||
/**
|
||||
* Creates a new NetworkTablesEntryType.
|
||||
*
|
||||
* @param id The numeric ID associated with this type. This ID
|
||||
* represents this data type to other nodes on the network.
|
||||
* @param name The string name associated with this type.
|
||||
*/
|
||||
NetworkTableEntryType(TypeId id, const char* name);
|
||||
};
|
||||
|
||||
#endif /* NETWORKTABLEENTRYTYPE_H_ */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* NetworkTableEntryTypeManager.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NETWORKTABLEENTRYTYPEMANAGER_H_
|
||||
#define NETWORKTABLEENTRYTYPEMANAGER_H_
|
||||
|
||||
class NetworkTableEntryTypeManager;
|
||||
|
||||
#include "networktables2/type/NetworkTableEntryType.h"
|
||||
|
||||
class NetworkTableEntryTypeManager
|
||||
{
|
||||
private:
|
||||
NetworkTableEntryType* entryTypes[MAX_NUM_TABLE_ENTRY_TYPES];
|
||||
public:
|
||||
/**
|
||||
* Creates a new NetworkTableEntryTypeManager, with the default
|
||||
* types registered under their respective TypeID's, and all other
|
||||
* TypeID's null.
|
||||
*/
|
||||
NetworkTableEntryTypeManager();
|
||||
|
||||
/**
|
||||
* Retrieves the entry type associated with the given
|
||||
* type id, if one exists.
|
||||
*
|
||||
* @param type The identifier by which to retrieve a type.
|
||||
* @return The NetworkTableEntryType associated with the given
|
||||
* type identifier, if one exists. Otherwise, null.
|
||||
*/
|
||||
NetworkTableEntryType* GetType(TypeId type);
|
||||
|
||||
/**
|
||||
* Registers the given NetworkTableEntryType with this type
|
||||
* manager, such that is is returned by subsequent calls
|
||||
* to GetType with the appropriate ID.
|
||||
*
|
||||
* @param type The type to register.
|
||||
*/
|
||||
void RegisterType(NetworkTableEntryType& type);
|
||||
};
|
||||
|
||||
#endif /* NETWORKTABLEENTRYTYPEMANAGER_H_ */
|
||||
31
networktables/cpp/include/networktables2/type/NumberArray.h
Normal file
31
networktables/cpp/include/networktables2/type/NumberArray.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* NumberArray.h
|
||||
*
|
||||
* Created on: Nov 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef NUMBERARRAY_H_
|
||||
#define NUMBERARRAY_H_
|
||||
|
||||
#include "networktables2/type/ArrayData.h"
|
||||
#include "networktables2/type/ArrayEntryType.h"
|
||||
|
||||
//TODO: NumberArray appears unused; replace with namespace?
|
||||
class NumberArray : public ArrayData{
|
||||
|
||||
public:
|
||||
static const TypeId NUMBER_ARRAY_RAW_ID;
|
||||
static ArrayEntryType TYPE;
|
||||
|
||||
|
||||
NumberArray();
|
||||
|
||||
double get(int index);
|
||||
void set(int index, double value);
|
||||
void add(double value);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* NUMBERARRAY_H_ */
|
||||
30
networktables/cpp/include/networktables2/type/StringArray.h
Normal file
30
networktables/cpp/include/networktables2/type/StringArray.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* StringArray.h
|
||||
*
|
||||
* Created on: Nov 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef STRINGARRAY_H_
|
||||
#define STRINGARRAY_H_
|
||||
|
||||
|
||||
#include "networktables2/type/ArrayData.h"
|
||||
#include "networktables2/type/ArrayEntryType.h"
|
||||
|
||||
//TODO: StringArray appears unused; replace with namespace?
|
||||
class StringArray : public ArrayData{
|
||||
|
||||
public:
|
||||
static const TypeId STRING_ARRAY_RAW_ID;
|
||||
static ArrayEntryType TYPE;
|
||||
|
||||
|
||||
StringArray();
|
||||
|
||||
std::string get(int index);
|
||||
void set(int index, std::string value);
|
||||
void add(std::string value);
|
||||
};
|
||||
|
||||
#endif /* STRINGARRAY_H_ */
|
||||
35
networktables/cpp/include/networktables2/util/EOFException.h
Normal file
35
networktables/cpp/include/networktables2/util/EOFException.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* EOFException.h
|
||||
*
|
||||
* Created on: Oct 1, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef EOFEXCEPTION_H_
|
||||
#define EOFEXCEPTION_H_
|
||||
|
||||
#include "networktables2/util/IOException.h"
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that an EOF was encountered during an I/O operation,
|
||||
* and therefore the operation could not be completed.
|
||||
*/
|
||||
class EOFException : public IOException{
|
||||
public:
|
||||
/**
|
||||
* Creates an EOFException.
|
||||
*/
|
||||
EOFException();
|
||||
virtual ~EOFException() throw ();
|
||||
|
||||
/**
|
||||
* Implements {@link IOException}::isEOF()
|
||||
*/
|
||||
virtual bool isEOF();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* EOFEXCEPTION_H_ */
|
||||
56
networktables/cpp/include/networktables2/util/IOException.h
Normal file
56
networktables/cpp/include/networktables2/util/IOException.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* IOException.h
|
||||
*
|
||||
* Created on: Oct 1, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef IOEXCEPTION_H_
|
||||
#define IOEXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
|
||||
/**
|
||||
* Inidcates that an unrecoverable I/O failure occured.
|
||||
*/
|
||||
class IOException : public std::exception{
|
||||
public:
|
||||
/**
|
||||
* Creates a new IOException with the given message.
|
||||
*
|
||||
* @param message The message to associate with this exception.
|
||||
*/
|
||||
IOException(const char* message);
|
||||
|
||||
/**
|
||||
* Creates a new IOException with the given message and
|
||||
* error value.
|
||||
*
|
||||
* @param message The message to associate with this exception.
|
||||
* @param errorValue The integer code to associate with this exception.
|
||||
*/
|
||||
IOException(const char* message, int errorValue);
|
||||
|
||||
/**
|
||||
* Gets the message associated with this exception.
|
||||
*
|
||||
* @return The message associated with this exception.
|
||||
*/
|
||||
const char* what();
|
||||
|
||||
/**
|
||||
* Determines whether this exception indicates that an EOF
|
||||
* was encountered.
|
||||
*
|
||||
* @return True if this exception indicates that an EOF was encountered.
|
||||
* False otherwise.
|
||||
*/
|
||||
virtual bool isEOF();
|
||||
virtual ~IOException() throw ();
|
||||
private:
|
||||
const char* message;
|
||||
int errorValue;
|
||||
};
|
||||
|
||||
|
||||
#endif /* IOEXCEPTION_H_ */
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* IllegalStateException.h
|
||||
*
|
||||
* Created on: Sep 16, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef ILLEGALSTATEEXCEPTION_H_
|
||||
#define ILLEGALSTATEEXCEPTION_H_
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
class IllegalStateException : public std::exception{
|
||||
public:
|
||||
IllegalStateException(const char* message);
|
||||
const char* what(){return message.c_str();};
|
||||
~IllegalStateException() throw ();
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
#endif /* ILLEGALSTATEEXCEPTION_H_ */
|
||||
39
networktables/cpp/include/networktables2/util/StringCache.h
Normal file
39
networktables/cpp/include/networktables2/util/StringCache.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef _STRINGCACHE_H_
|
||||
#define _STRINGCACHE_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* A simple cache that allows for caching the mapping of one string to another calculated one
|
||||
*
|
||||
* @author Mitchell
|
||||
*
|
||||
*/
|
||||
class StringCache {
|
||||
private:
|
||||
map<std::string, std::string> cache;
|
||||
|
||||
|
||||
/**
|
||||
* @param input
|
||||
* @return the value for a given input
|
||||
*/
|
||||
public:
|
||||
StringCache();
|
||||
virtual ~StringCache();
|
||||
|
||||
|
||||
std::string& Get(const std::string& input);
|
||||
|
||||
/**
|
||||
* Will only be called if a value has not already been calculated
|
||||
* @param input
|
||||
* @return the calculated value for a given input
|
||||
*/
|
||||
virtual std::string Calc(const std::string& input) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
37
networktables/cpp/include/networktables2/util/System.h
Normal file
37
networktables/cpp/include/networktables2/util/System.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* System.h
|
||||
*
|
||||
* For some platform specific code related to the system
|
||||
*
|
||||
* Created on: Sep 25, 2012
|
||||
* Author: Mitchell Wills
|
||||
*/
|
||||
|
||||
#ifndef TIME_H_
|
||||
#define TIME_H_
|
||||
|
||||
/**
|
||||
* Causes the current thread to sleep at least the
|
||||
* given number of milliseconds.
|
||||
*
|
||||
* @param ms The number of milliseconds to sleep.
|
||||
*/
|
||||
void sleep_ms(unsigned long ms);
|
||||
|
||||
/**
|
||||
* Retrieves the current time in milliseconds.
|
||||
*
|
||||
* @return The current time in milliseconds.
|
||||
*/
|
||||
unsigned long currentTimeMillis();
|
||||
|
||||
/**
|
||||
* Writes a warning message to the standard error
|
||||
* stream.
|
||||
*
|
||||
* @param message The string message to write.
|
||||
*/
|
||||
void writeWarning(const char* message);
|
||||
|
||||
|
||||
#endif /* TIME_H_ */
|
||||
Reference in New Issue
Block a user