123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- namespace Universal.IO;
- public class MessageQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data>? _receiveQueue;
- private EventQueue<Data>? _sendQueue;
- private bool disposedValue;
- public bool Initialize()
- {
- if (this._receiveQueue is not null)
- return false;
- if (this._sendQueue is not null)
- return false;
- this._receiveQueue = new(ReceivedQueueHandler);
- this._sendQueue = new(SendQueueHandler);
- return true;
- }
- public override bool Send(Data data)
- {
- if (_sendQueue is null)
- return false;
- this._sendQueue?.Enqueue(data);
- return true;
- }
- public override bool Receive(Data data)
- {
- if (this._receiveQueue is null)
- return false;
- this._receiveQueue?.Enqueue(data);
- return true;
- }
- private void SendQueueHandler(Data data)
- {
- base.Send(data);
- }
- private void ReceivedQueueHandler(Data data)
- {
- base.Receive(data);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- this._receiveQueue?.Dispose();
- this._sendQueue?.Dispose();
- this._receiveQueue = null;
- this._sendQueue = null;
- }
- disposedValue = true;
- }
- }
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
- public class MessageReceiveQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data>? _receiveQueue;
- private bool disposedValue;
- public bool Initialize()
- {
- if (this._receiveQueue is not null)
- return false;
- this._receiveQueue = new(ReceivedQueueHandler);
- return true;
- }
- public override bool Receive(Data data)
- {
- if (this._receiveQueue is null)
- return false;
- this._receiveQueue?.Enqueue(data);
- return true;
- }
- private void ReceivedQueueHandler(Data data)
- {
- base.Receive(data);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- this._receiveQueue?.Dispose();
- this._receiveQueue = null;
- }
- disposedValue = true;
- }
- }
- public void Dispose()
- {
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
- public class MessageSendQueue : BaseFilter, IDisposable
- {
- private EventQueue<Data>? _sendQueue;
- private bool disposedValue;
- public bool Initialize()
- {
- if (this._sendQueue is not null)
- return false;
- this._sendQueue = new(SendQueueHandler);
- return true;
- }
- //void IDisposable.Dispose()
- //{
- // this._sendQueue?.Dispose();
- // this._sendQueue = null;
- //}
- public override bool Send(Data data)
- {
- if (_sendQueue is null)
- return false;
- this._sendQueue?.Enqueue(data);
- return true;
- }
- private void SendQueueHandler(Data data)
- {
- base.Send(data);
- }
- protected virtual void Dispose(bool disposing)
- {
- if (!disposedValue)
- {
- if (disposing)
- {
- this._sendQueue?.Dispose();
- this._sendQueue = null;
- }
- disposedValue = true;
- }
- }
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
- Dispose(disposing: true);
- GC.SuppressFinalize(this);
- }
- }
|