Now you can download a copy of these docs so you can use them offline! Download now
ServerIncomingStreamMonitor.cpp
1 /*
2  * ServerIncomingStreamMonitor.cpp
3  *
4  * Created on: Sep 26, 2012
5  * Author: Mitchell Wills
6  */
7 
8 #include "networktables2/server/ServerIncomingStreamMonitor.h"
9 #include "networktables2/stream/IOStream.h"
10 
12  ServerIncomingConnectionListener& _incomingListener, ServerAdapterManager& _adapterListener, NetworkTableEntryTypeManager& _typeManager,
13  NTThreadManager& _threadManager) :
14  streamProvider(_streamProvider), entryStore(_entryStore), incomingListener(_incomingListener), adapterListener(_adapterListener),
15  typeManager(_typeManager), threadManager(_threadManager), monitorThread(NULL)
16 {
17 }
18 
19 ServerIncomingStreamMonitor::~ServerIncomingStreamMonitor()
20 {
21  stop();
22 }
23 
28 {
29  if (monitorThread != NULL)
30  stop();
31  monitorThread = threadManager.newBlockingPeriodicThread(this, "Server Incoming Stream Monitor Thread");
32 }
37 {
38  if (monitorThread != NULL)
39  {
40  streamProvider.close(); //This would get called on deletion too
41  NTThread *temp=monitorThread;
42  monitorThread = NULL; //call this before stop for the check below to ensure a new server connection adapter will not happen
43  temp->stop();
44  delete temp;
45  }
46 }
47 
49 {
50  try
51  {
52  while (monitorThread!=NULL)
53  {
54  IOStream* newStream = streamProvider.accept();
55  {
56  NTSynchronized sync(BlockDeletionList);
57  for (size_t i=0;i<m_DeletionList.size();i++)
58  {
59  ServerConnectionAdapter *Element=m_DeletionList[i];
60  Element->shutdown(true); //TODO assume to always close stream
61  delete Element;
62  }
63  m_DeletionList.clear();
64  }
65  //Note: monitorThread must be checked to avoid crash on exit
66  // [8/31/2013 Terminator]
67  if ((monitorThread!=NULL)&&(newStream != NULL))
68  {
69  ServerConnectionAdapter* connectionAdapter = new ServerConnectionAdapter(newStream, entryStore, entryStore, adapterListener, typeManager, threadManager);
70  incomingListener.OnNewConnection(*connectionAdapter);
71  }
72  }
73  }
74  catch (IOException& e)
75  {
76  //could not get a new stream for some reason. ignore and continue
77  }
78 }
79 
80 void ServerIncomingStreamMonitor::close(ServerConnectionAdapter *Adapter)
81 {
82  NTSynchronized sync(BlockDeletionList);
83  m_DeletionList.push_back(Adapter);
84 }
virtual NTThread * newBlockingPeriodicThread(PeriodicRunnable *r, const char *name)=0
ServerIncomingStreamMonitor(IOStreamProvider &streamProvider, ServerNetworkTableEntryStore &entryStore, ServerIncomingConnectionListener &incomingListener, ServerAdapterManager &adapterListener, NetworkTableEntryTypeManager &typeManager, NTThreadManager &threadManager)
virtual void stop()=0
virtual IOStream * accept()=0
void shutdown(bool closeStream)
virtual void OnNewConnection(ServerConnectionAdapter &connectionAdapter)=0
virtual void close()=0

Generated on Sat Apr 26 2014 12:26:45 for WPILibC++ by doxygen 1.8.6