WPILib 2012
WPILibRoboticsLibraryforFRC
NetworkTables/ConnectionManager.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2011. All Rights Reserved.                             */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef __CONNECTION_MANAGER_H__
00008 #define __CONNECTION_MANAGER_H__
00009 
00010 #include "NetworkTables/Data.h"
00011 #include "SensorBase.h"
00012 #include "Task.h"
00013 #include <set>
00014 
00015 namespace NetworkTables
00016 {
00017 class Connection;
00018 
00019 class ConnectionManager : public SensorBase
00020 {
00021         friend class Connection;
00022 public:
00023         static ConnectionManager *GetInstance();
00024 
00025 private:
00026         ConnectionManager();
00027         ~ConnectionManager();
00028 
00029         int ListenTaskRun();
00030         bool IsServer() {return m_isServer;}
00031         void AddConnection(Connection *connection);
00032         void RemoveConnection(Connection *connection);
00033 
00034         static int InitListenTask(ConnectionManager *obj) {obj->ListenTaskRun();return 0;}
00035 
00036         typedef std::set<Connection *> ConnectionSet;
00037         bool m_isServer;
00038         ConnectionSet m_connections;
00039         Task m_listener;
00040         bool m_run;
00041         int m_listenSocket;
00042         SEM_ID m_connectionLock;
00043 
00044         static ConnectionManager *_instance;
00045 };
00046 
00047 }
00048 
00049 #endif
 All Classes Functions Variables