/// <summary> /// Create a new instance of the <see cref="DeviceBase"/> class. /// </summary> /// <param name="poller">the <see cref="Poller"/> to use for detecting when messages are available</param> /// <param name="frontendSocket"> /// A <see cref="NetMQSocket"/> that will pass incoming messages to <paramref name="backendSocket"/>. /// </param> /// <param name="backendSocket"> /// A <see cref="NetMQSocket"/> that will receive messages from (and optionally send replies to) <paramref name="frontendSocket"/>. /// </param> /// <param name="mode">the <see cref="DeviceMode"/> (either Blocking or Threaded) for this device</param> protected DeviceBase(Poller poller, [NotNull] NetMQSocket frontendSocket, [NotNull] NetMQSocket backendSocket, DeviceMode mode) { if (frontendSocket == null) throw new ArgumentNullException("frontendSocket"); if (backendSocket == null) throw new ArgumentNullException("backendSocket"); FrontendSocket = frontendSocket; BackendSocket = backendSocket; FrontendSetup = new DeviceSocketSetup(FrontendSocket); BackendSetup = new DeviceSocketSetup(BackendSocket); m_poller = poller; FrontendSocket.ReceiveReady += FrontendHandler; BackendSocket.ReceiveReady += BackendHandler; m_poller.AddSocket(FrontendSocket); m_poller.AddSocket(BackendSocket); m_runner = mode == DeviceMode.Blocking ? new DeviceRunner(this) : new ThreadedDeviceRunner(this); }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="frontendSocket"> /// A <see cref="ZmqSocket"/> that will pass incoming messages to <paramref name="backendSocket"/>. /// </param> /// <param name="backendSocket"> /// A <see cref="ZmqSocket"/> that will receive messages from (and optionally send replies to) <paramref name="frontendSocket"/>. /// </param> /// <param name="mode">The <see cref="DeviceMode"/> for the current device.</param> protected Device(ZmqSocket frontendSocket, ZmqSocket backendSocket, DeviceMode mode) { if (frontendSocket == null) { throw new ArgumentNullException("frontendSocket"); } if (backendSocket == null) { throw new ArgumentNullException("backendSocket"); } FrontendSocket = frontendSocket; BackendSocket = backendSocket; FrontendSetup = new DeviceSocketSetup(FrontendSocket); BackendSetup = new DeviceSocketSetup(BackendSocket); DoneEvent = new ManualResetEvent(false); _poller = new Poller(); _runner = mode == DeviceMode.Blocking ? new DeviceRunner(this) : new ThreadedDeviceRunner(this); }