WPILib 2012
WPILibRoboticsLibraryforFRC
|
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_H__ 00008 #define __CONNECTION_H__ 00009 00010 #include "ErrorBase.h" 00011 #include "Task.h" 00012 #include <map> 00013 #include <deque> 00014 00015 class NetworkTable; 00016 00017 namespace NetworkTables 00018 { 00019 class Data; 00020 class Entry; 00021 class Key; 00022 class NetworkQueue; 00023 class TransactionEnd; 00024 class TransactionStart; 00025 00026 class Connection : public ErrorBase 00027 { 00028 friend class ConnectionManager; 00029 friend class NetworkTable; 00030 friend class Reader; 00031 public: 00032 static const UINT32 kWriteDelay = 250; 00033 static const UINT32 kTimeout = 1000; 00034 00035 private: 00036 Connection(int socket); 00037 ~Connection(); 00038 void OfferTransaction(NetworkQueue *transaction); 00039 void Offer(Data *data); 00040 void Offer(std::auto_ptr<Data> autoData); 00041 void Start(); 00042 void ReadTaskRun(); 00043 void WriteTaskRun(); 00044 void Close(); 00045 bool IsConnected() {return m_connected;} 00046 NetworkTable *GetTable(bool local, UINT32 id); 00047 bool ConfirmationsContainsKey(Key *key); 00048 void WatchdogActivate(); 00049 void WatchdogFeed(); 00050 void WatchdogTaskRun(); 00051 00052 static int InitReadTask(Connection *obj) {obj->ReadTaskRun();return 0;} 00053 static int InitWriteTask(Connection *obj) {obj->WriteTaskRun();return 0;} 00054 static int InitWatchdogTask(Connection *obj) {obj->WatchdogTaskRun();return 0;} 00055 00056 int m_socket; 00057 SEM_ID m_dataLock; 00058 SEM_ID m_dataAvailable; 00059 SEM_ID m_watchdogLock; 00060 SEM_ID m_watchdogFood; 00061 typedef std::map<UINT32, UINT32> IDMap_t; 00062 IDMap_t m_tableMap; 00063 IDMap_t m_fieldMap; 00064 NetworkQueue *m_queue; 00065 std::deque<Entry *> m_confirmations; 00066 NetworkQueue *m_transaction; 00067 bool m_connected; 00068 bool m_inTransaction; 00069 bool m_denyTransaction; 00070 bool m_watchdogActive; 00071 bool m_watchdogFed; 00072 Task m_readTask; 00073 Task m_writeTask; 00074 Task m_watchdogTask; 00075 TransactionStart *m_transactionStart; 00076 TransactionEnd *m_transactionEnd; 00077 }; 00078 00079 } // namespace 00080 00081 #endif 00082