public void Subscribe(GenaMessage request, GenaMessage response) { VerifyHeaders(request); //subscribe var sub = new GenaSubscription(); lock (_subscriptions) { this._subscriptions.Add(sub.SubscriptionId, sub); } sub.Callbacks = request.Callbacks; sub.RenewInterval = request.Timeout ?? TimeSpan.MaxValue; if (sub.RenewInterval != TimeSpan.MaxValue) { _dispatcher.Add(() => CheckSubscription(sub), sub.RenewInterval); } //update timeout value if one is present RespondToSubscribe(request, response, sub); /** * SUBSCRIBE: * * SUBSCRIBE publisher path HTTP/1.1 * HOST: publisher host:publisher port * USER-AGENT: OS/version UPnP/1.1 product/version * CALLBACK: <delivery URL> * NT: upnp:event * TIMEOUT: Second-requested subscription duration * * SUBSCRIBE RESPONSE: * * HTTP/1.1 200 OK * DATE: when response was generated * SERVER: OS/version UPnP/1.1 product/version * SID: uuid:subscription-UUID * CONTENT-LENGTH: 0 * TIMEOUT: Second-actual subscription duration * * RENEWAL: * SUBSCRIBE publisher path HTTP/1.1 * HOST: publisher host:publisher port * SID: uuid:subscription UUID * TIMEOUT: Second-requested subscription duration * * RENEWAL RESPONSE is the same as SUBSCRIBE RESPONSE * */ }
public void Subscribe(GenaMessage request, GenaMessage response) { VerifyHeaders(request); //subscribe var sub = new GenaSubscription(); lock (_subscriptions) { this._subscriptions.Add(sub.SubscriptionId, sub); } sub.Callbacks = request.Callbacks; sub.RenewInterval = request.Timeout ?? TimeSpan.MaxValue; if(sub.RenewInterval != TimeSpan.MaxValue) _dispatcher.Add(() => CheckSubscription(sub), sub.RenewInterval); //update timeout value if one is present RespondToSubscribe(request, response, sub); /** * SUBSCRIBE: * * SUBSCRIBE publisher path HTTP/1.1 * HOST: publisher host:publisher port * USER-AGENT: OS/version UPnP/1.1 product/version * CALLBACK: <delivery URL> * NT: upnp:event * TIMEOUT: Second-requested subscription duration * * SUBSCRIBE RESPONSE: * * HTTP/1.1 200 OK * DATE: when response was generated * SERVER: OS/version UPnP/1.1 product/version * SID: uuid:subscription-UUID * CONTENT-LENGTH: 0 * TIMEOUT: Second-actual subscription duration * * RENEWAL: * SUBSCRIBE publisher path HTTP/1.1 * HOST: publisher host:publisher port * SID: uuid:subscription UUID * TIMEOUT: Second-requested subscription duration * * RENEWAL RESPONSE is the same as SUBSCRIBE RESPONSE * */ }
private void CheckSubscription(GenaSubscription sub) { var time = sub.NextRenewal.Subtract(DateTime.Now); if (time.TotalMilliseconds <= 0) { //expired so remove the sub lock (_subscriptions) { this._subscriptions.Remove(sub.SubscriptionId); } } else { //check again once our time is up _dispatcher.Add(() => CheckSubscription(sub), time); } }
private void CheckSubscription(GenaSubscription sub) { var time = sub.NextRenewal.Subtract(DateTime.Now); if (time.TotalMilliseconds <= 0) { //expired so remove the sub lock (_subscriptions) { this._subscriptions.Remove(sub.SubscriptionId); } } else { //check again once our time is up _dispatcher.Add(() => CheckSubscription(sub), time); } }
private static void RespondToSubscribe(GenaMessage request, GenaMessage response, GenaSubscription sub) { var timeout = request.Timeout; if (timeout.HasValue) sub.RenewInterval = timeout.Value; response.SubscriptionId = sub.SubscriptionId; response.Timeout = sub.RenewInterval; response.Date = DateTime.Now; response.UserAgent = String.Format("{0}/{1} UPnP/1.1 UPnPLib/1.1", Environment.OSVersion.Platform, Environment.OSVersion.Version); ; }
private static void RespondToSubscribe(GenaMessage request, GenaMessage response, GenaSubscription sub) { var timeout = request.Timeout; if (timeout.HasValue) { sub.RenewInterval = timeout.Value; } response.SubscriptionId = sub.SubscriptionId; response.Timeout = sub.RenewInterval; response.Date = DateTime.Now; response.UserAgent = String.Format("{0}/{1} UPnP/1.1 UPnPLib/1.1", Environment.OSVersion.Platform, Environment.OSVersion.Version);; }