Merging changes
This commit is contained in:
1 parent
c4216d2272
commit
797816be7e
437 files changed
+54228
-28
No files matched your search
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BCG.Utilities.General;
|
||||
|
||||
namespace BCG
|
||||
{
|
||||
/*
|
||||
* The threadsafe stream wraps around an input stream, and amalgamates all the values from that stream
|
||||
* locally. It only fires packets on the thread where the VSD's doWork function is called.
|
||||
*
|
||||
* */
|
||||
public class ThreadSafeStream : ViewStream, IWorker
|
||||
{
|
||||
|
||||
private ViewStream myParentStream;
|
||||
private ThreadSafeQueue<DataPacket> myQueuedUpdates;
|
||||
private ViewStreamDatabase myVSD;
|
||||
|
||||
public ThreadSafeStream(ViewStream parent) : this(ViewStreamDatabase.instance, parent) { }
|
||||
public ThreadSafeStream(ViewStreamDatabase vsd, ViewStream parentStream)
|
||||
{
|
||||
myParentStream = parentStream;
|
||||
myVSD = vsd;
|
||||
myQueuedUpdates = new ThreadSafeQueue<DataPacket>();
|
||||
}
|
||||
|
||||
protected override void myOnFirstSubscriber()
|
||||
{
|
||||
myParentStream.onChange += new ChangeDelegate(myParentStreamChangeHandler);
|
||||
myVSD.addWorker(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void myOnLastSubscriber()
|
||||
{
|
||||
myParentStream.onChange -= new ChangeDelegate(myParentStreamChangeHandler);
|
||||
myVSD.removeWorker(this);
|
||||
}
|
||||
|
||||
void myParentStreamChangeHandler(object newValue)
|
||||
{
|
||||
myQueuedUpdates.enqueue(newValue as DataPacket);
|
||||
}
|
||||
|
||||
public void doWork()
|
||||
{
|
||||
foreach (DataPacket dp in myQueuedUpdates.dequeueAll())
|
||||
{
|
||||
myFireEvent(dp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user