History

GSF.Core: 1) Modified ProcessQueue to use ISynchronizedOperation for real-time processing mode. 2) Fixed Enabled state of MultiSourceFrameImageParserBase to not continue parsing buffers when disabled. 3) Added SynchronizedOperationType enum to ISynchronizedOperation.cs.

StephenCWills committed 12 years ago

Commit aa6665d1 parent a4927c53 files · +103 −195Browse files

Showing the changes to Source/Libraries/GSF.Core/Parsing/MultiSourceFrameImageParserBase.cs (1 of 3 files). Show all

Unified · Split

Source/Libraries/GSF.Core/Parsing/MultiSourceFrameImageParserBase.cs+33−62
@@ -219,7 +219,7 @@ namespace GSF.Parsing · 218 unmodified lines
219219 public event EventHandler<EventArgs<TSourceIdentifier, IList<TOutputType>>> SourceDataParsed;
220220
221221 // Fields
222− private AsyncDoubleBufferedQueue<SourceIdentifiableBuffer> m_bufferQueue;
222+ private readonly AsyncDoubleBufferedQueue<SourceIdentifiableBuffer> m_bufferQueue;
223223 private readonly ConcurrentDictionary<TSourceIdentifier, bool> m_sourceInitialized;
224224 private readonly ConcurrentDictionary<TSourceIdentifier, byte[]> m_unparsedBuffers;
225225 private readonly ConcurrentDictionary<TSourceIdentifier, List<TOutputType>> m_parsedSourceData;
@@ -234,7 +234,8 @@ namespace GSF.Parsing · 8 unmodified lines
234234 /// </summary>
235235 protected MultiSourceFrameImageParserBase()
236236 {
237− m_bufferQueue = CreateBufferQueue();
237+ m_bufferQueue = new AsyncDoubleBufferedQueue<SourceIdentifiableBuffer>();
238+ m_bufferQueue.ProcessItemsFunction = ParseQueuedBuffers;
238239 m_bufferQueue.ProcessException += ProcessExceptionHandler;
239240
240241 if (ProtocolUsesSyncBytes)
@@ -255,10 +256,7 @@ namespace GSF.Parsing · 14 unmodified lines
255256 {
256257 get
257258 {
258− if ((object)m_bufferQueue != null)
259− return m_bufferQueue.Count;
260−
261− return 0;
259+ return m_bufferQueue.Count;
262260 }
263261 }
264262
@@ -400,75 +398,48 @@ namespace GSF.Parsing · 135 unmodified lines
400398 throw new NotImplementedException("This method should not be called directly, call the Parse(TSourceIdentifier,byte[],int,int) method to queue data for parsing instead.");
401399 }
402400
403− /// <summary>
404− /// Creates the internal buffer queue.
405− /// </summary>
406− /// <remarks>
407− /// <para>
408− /// This method is virtual to allow derived classes to customize the style of processing queue used when consumers
409− /// choose to implement an internal buffer queue. Default type is a real-time queue with the default settings.
410− /// When overriding, use the <see cref="ParseQueuedBuffers"/> method for the <see cref="ProcessQueue{T}"/>) item
411− /// processing delegate.
412− /// </para>
413− /// <para>
414− /// Note that current design only supports serial processing - consumer overriding this method to return an asynchronous
415− /// process queue to process multiple items at once on separate threads will need to redesign the processing delegate.
416− /// </para>
417− /// </remarks>
418− /// <returns>New internal buffer processing queue (i.e., a new <see cref="ProcessQueue{T}"/>).</returns>
419− protected virtual AsyncDoubleBufferedQueue<SourceIdentifiableBuffer> CreateBufferQueue()
420− {
421− AsyncDoubleBufferedQueue<SourceIdentifiableBuffer> queue = new AsyncDoubleBufferedQueue<SourceIdentifiableBuffer>();
422− queue.ProcessItemsFunction = ParseQueuedBuffers;
423− queue.ProcessException += ProcessExceptionHandler;
424− return queue;
425− }
426−
427− /// <summary>
428− /// This method is used by the internal <see cref="ProcessQueue{T}"/> to process all queued data buffers.
429− /// </summary>
430− /// <param name="buffers">Identifiable buffers to process.</param>
431− /// <remarks>
432− /// This is the <see cref="SourceIdentifiableBuffer"/> processing delegate to use when overriding the <see cref="CreateBufferQueue"/> method.
433− /// </remarks>
434− protected virtual void ParseQueuedBuffers(IList<SourceIdentifiableBuffer> buffers)
401+ // This method is used by the internal <see cref="ProcessQueue{T}"/> to process all queued data buffers.
402+ private void ParseQueuedBuffers(IList<SourceIdentifiableBuffer> buffers)
435403 {
436− try
404+ if (Enabled)
437405 {
438− // Process all queued data buffers...
439− foreach (SourceIdentifiableBuffer buffer in buffers)
406+ try
440407 {
441− // Track current buffer source
442− m_source = buffer.Source;
408+ // Process all queued data buffers...
409+ foreach (SourceIdentifiableBuffer buffer in buffers)
410+ {
411+ // Track current buffer source
412+ m_source = buffer.Source;
443413
444− // Check to see if this data source has been initialized
445− if ((object)m_sourceInitialized != null)
446− StreamInitialized = m_sourceInitialized.GetOrAdd(m_source, true);
414+ // Check to see if this data source has been initialized
415+ if ((object)m_sourceInitialized != null)
416+ StreamInitialized = m_sourceInitialized.GetOrAdd(m_source, true);
447417
448− // Restore any unparsed buffers for this data source, if any
449− UnparsedBuffer = m_unparsedBuffers.GetOrAdd(m_source, (byte[])null);
418+ // Restore any unparsed buffers for this data source, if any
419+ UnparsedBuffer = m_unparsedBuffers.GetOrAdd(m_source, (byte[])null);
450420
451− // Start parsing sequence for this buffer - this will begin publication of new parsed outputs
452− base.Write(buffer.Buffer, 0, buffer.Count);
421+ // Start parsing sequence for this buffer - this will begin publication of new parsed outputs
422+ base.Write(buffer.Buffer, 0, buffer.Count);
453423
454− // Track last unparsed buffer for this data source
455− m_unparsedBuffers[m_source] = UnparsedBuffer;
424+ // Track last unparsed buffer for this data source
425+ m_unparsedBuffers[m_source] = UnparsedBuffer;
426+ }
456427 }
457− }
458− finally
459− {
460− // If user has attached to SourceDataParsed event, expose list of parsed data per source
461− if ((object)SourceDataParsed != null)
428+ finally
462429 {
463− foreach (KeyValuePair<TSourceIdentifier, List<TOutputType>> parsedData in m_parsedSourceData)
430+ // If user has attached to SourceDataParsed event, expose list of parsed data per source
431+ if ((object)SourceDataParsed != null)
464432 {
465− OnSourceDataParsed(parsedData.Key, parsedData.Value);
433+ foreach (KeyValuePair<TSourceIdentifier, List<TOutputType>> parsedData in m_parsedSourceData)
434+ {
435+ OnSourceDataParsed(parsedData.Key, parsedData.Value);
436+ }
437+
438+ // Clear parsed data dictionary for next pass
439+ m_parsedSourceData.Clear();
466440 }
467441
468− // Clear parsed data dictionary for next pass
469− m_parsedSourceData.Clear();
470442 }
471−
472443 }
473444
474445 // Dispose of source buffers - no rush

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t