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 __NETWORK_QUEUE_H__ 00008 #define __NETWORK_QUEUE_H__ 00009 00010 #include "NetworkTables/NetworkTable.h" 00011 #include <map> 00012 #include <deque> 00013 00014 namespace NetworkTables 00015 { 00016 class Entry; 00017 class Confirmation; 00018 class Denial; 00019 class TransactionStart; 00020 class TransactionEnd; 00021 class Data; 00022 00023 class NetworkQueue 00024 { 00025 typedef std::deque<std::pair<Data *, bool> > DataQueue_t; 00026 typedef std::map<UINT32, DataQueue_t::iterator> DataHash_t; 00027 public: 00028 NetworkQueue(); 00029 ~NetworkQueue(); 00030 00031 void Offer(TransactionStart *value); 00032 void Offer(TransactionEnd *value); 00033 void Offer(Data *value, bool needsDelete=false); 00034 void Offer(std::auto_ptr<Data> value); 00035 bool IsEmpty(); 00036 bool ContainsKey(Key *key); 00037 std::pair<Data *, bool> Poll(); 00038 void Clear(); 00039 Data *Peek(); 00040 DataQueue_t::const_iterator GetQueueHead() {return m_dataQueue.begin();} 00041 bool IsQueueEnd(DataQueue_t::const_iterator it) {return m_dataQueue.end() == it;} 00042 00043 private: 00044 SEM_ID m_dataLock; 00045 DataQueue_t m_dataQueue; 00046 DataHash_t m_latestDataHash; 00047 bool m_inTransaction; 00048 }; 00049 00050 } 00051 00052 #endif // __NETWORK_QUEUE_H__