// ----------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // ----------------------------------------------------------------------- namespace Microsoft.Samples.Kinect.Webserver.Sensor { using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using Microsoft.Kinect; /// /// Interface called upon to: /// a) Process Kinect sensor data associated with a specific stream or set of streams. /// b) Handle requests to deliver data associated with the same stream(s). /// /// /// /// Objects that implement this interface are not expected to be thread-safe but are expected /// to support async operations, so instances should be created and instance methods should /// always be called from a single thread that is associated with a SynchronizationContext /// that provides single-threaded message dispatch /// (e.g.: System.Windows.Threading.DispatcherSynchronizationContext). /// /// /// This means that IHttpRequestHandlers still have to be aware of potential reentrancy /// resulting from asynchronous operations, but they don't have to protect data access with /// locks. /// /// public interface ISensorStreamHandler { /// /// Get the names of the stream(s) supported by this stream handler. /// /// /// An array of stream names. /// /// /// These names will be used in JSON objects to refer to individual streams. /// string[] GetSupportedStreamNames(); /// /// Lets ISensorStreamHandler know that Kinect Sensor associated with this stream /// handler has changed. /// /// /// New KinectSensor. /// void OnSensorChanged(KinectSensor newSensor); /// /// Process data from one Kinect color frame. /// /// /// Kinect color data. /// /// /// from which we obtained color data. /// void ProcessColor(byte[] colorData, ColorImageFrame colorFrame); /// /// Process data from one Kinect depth frame. /// /// /// Kinect depth data. /// /// /// from which we obtained depth data. /// void ProcessDepth(DepthImagePixel[] depthData, DepthImageFrame depthFrame); /// /// Process data from one Kinect skeleton frame. /// /// /// Kinect skeleton data. /// /// /// from which we obtained skeleton data. /// void ProcessSkeleton(Skeleton[] skeletons, SkeletonFrame skeletonFrame); /// /// Gets the state property values associated with the specified stream name. /// /// /// Name of stream for which property values should be returned. /// /// /// Dictionary mapping property names to property values. /// IDictionary GetState(string streamName); /// /// Attempts to set the specified state property values associated with the specified /// stream name. /// /// /// Name of stream for which property values should be set. /// /// /// Dictionary mapping property names to property values that should be set. /// Must not be null. /// /// /// Dictionary meant to receive mappings between property names to errors encountered /// while trying to set each property value. /// May be null. /// /// /// true if there were no errors encountered while setting state. false otherwise. /// /// /// If is non-null, it is expected that it will be empty /// when method is called. /// bool SetState(string streamName, IReadOnlyDictionary properties, IDictionary errors); /// /// Handle an http request. /// /// /// Name of stream for which property values should be set. /// /// /// Context containing HTTP request data, which will also contain associated /// response upon return. /// /// /// Request URI path relative to the stream name associated with this sensor stream /// handler in the stream handler owner. /// /// /// Await-able task. /// /// /// Return value should never be null. Implementations should use Task.FromResult(0) /// if function is implemented synchronously so that callers can await without /// needing to check for null. /// Task HandleRequestAsync(string streamName, HttpListenerContext requestContext, string subpath); /// /// Cancel all pending operations /// void Cancel(); /// /// Lets handler know that it should clean up resources associated with sensor stream /// handling. /// /// /// Await-able task. /// /// /// Return value should never be null. Implementations should use Task.FromResult(0) /// if function is implemented synchronously so that callers can await without /// needing to check for null. /// Task UninitializeAsync(); } }