public IObservableWithTask <StartingWithNotification> ForCountersStartingWith(string groupName, string prefixForName) { if (string.IsNullOrWhiteSpace(groupName)) { throw new ArgumentException("Group name cannot be empty!"); } if (string.IsNullOrWhiteSpace(prefixForName)) { throw new ArgumentException("Prefix for counter name cannot be empty"); } var counterPrefix = CounterUtils.GetFullCounterName(groupName, prefixForName); var key = string.Concat("counters-starting-with/", counterPrefix); var counter = GetOrAddConnectionState(key, "watch-counters-prefix", "unwatch-counters-prefix", () => watchedPrefixes.TryAdd(counterPrefix), () => watchedPrefixes.TryRemove(counterPrefix), counterPrefix); var taskedObservable = new TaskedObservable <StartingWithNotification, CountersConnectionState>( counter, notification => { var t = string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) && notification.CounterName.StartsWith(prefixForName, StringComparison.OrdinalIgnoreCase); return(t); }); counter.OnCountersStartingWithNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <ChangeNotification> ForChange(string groupName, string counterName) { if (string.IsNullOrWhiteSpace(groupName)) { throw new ArgumentException("Group name cannot be empty!"); } if (string.IsNullOrWhiteSpace(counterName)) { throw new ArgumentException("Counter name cannot be empty"); } var fullCounterName = CounterUtils.GetFullCounterName(groupName, counterName); var key = "counter-change/" + fullCounterName; var counter = GetOrAddConnectionState(key, "watch-counter-change", "unwatch-counter-change", () => watchedChanges.TryAdd(fullCounterName), () => watchedChanges.TryRemove(fullCounterName), fullCounterName); var taskedObservable = new TaskedObservable <ChangeNotification, CountersConnectionState>( counter, notification => string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) && string.Equals(notification.CounterName, counterName, StringComparison.OrdinalIgnoreCase)); counter.OnChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
/// <summary> /// Copies data from QCam frame data structure to standardized VideoFrame structure /// which can be serialized over the wire /// </summary> void CopyDataForOutput(QCamM_Frame qFrame, VideoFrame outFrame) { outFrame.ErrorCode = qFrame.errorCode; outFrame.BitsPerPixel = qFrame.bits; outFrame.Width = qFrame.width; outFrame.Height = qFrame.height; lock (odometerLock) { uint newOdo = CounterUtils.UnwrapRolledCounter(QCam_counter_bits, odometer, qFrame.frameNumber); long nFrameDrops = newOdo - (long)odometer - 1; if (nFrameDrops > 0) { Trace.TraceWarning("QCam driver dropped {0} frames!", nFrameDrops); } odometer = newOdo; outFrame.FrameNumber = newOdo; } outFrame.TimeStamp = qFrame.timeStamp; IntPtr pSrc = qFrame.pBuffer; if (pSrc == IntPtr.Zero) { throw new ArgumentException("Got QCam frame buffer with null data pointer"); } uint nBytes = qFrame.size; outFrame.DataSizeBytes = nBytes; // if there is data available, there's a buffer of the correct size, and copy it if (nBytes > 0) { byte[] buffer = outFrame.Data; if ((buffer == null) || (buffer.Length != nBytes)) { buffer = new byte[nBytes]; } Lab.Utilities.CopyPointerToBuffer(pSrc, buffer, 0, nBytes); outFrame.Data = buffer; } else { outFrame.Data = new byte[0]; Trace.TraceWarning("Sending empty frame!"); } }
public void Send(ChangeNotification notification) { var counterPrefix = CounterUtils.GetFullCounterName(notification.GroupName, notification.CounterName); if (watchAllCounters > 0 || matchingChanges.Contains(counterPrefix)) { var value = new { Value = notification, Type = changeNotificationType }; enqueue(value); } if (matchingPrefixes.Any(prefix => counterPrefix.StartsWith(prefix))) { var value = new { Value = notification, Type = startingWithNotification }; enqueue(value); } if (matchingGroups.Contains(notification.GroupName)) { var value = new { Value = notification, Type = inGroupNotificationType }; enqueue(value); } }
protected BaseAdapter() { _counters = CounterUtils.GenerateDictionary(this); }