public CoapObserveRelation(Request request, IEndPoint endpoint, ICoapConfig config) { _config = config; _request = request; _endpoint = endpoint; _orderer = new ObserveNotificationOrderer(config); request.Reregistering += OnReregister; }
private void OnReregister(Object sender, ReregisterEventArgs e) { // TODO: update request in observe handle for correct cancellation? //_request = e.RefreshRequest; // reset orderer to accept any sequence number since server might have rebooted _orderer = new ObserveNotificationOrderer(_config); }
private CoapObserveRelation ObserveAsync(Request request, Action<Response> notify, Action<FailReason> error) { IEndPoint endpoint = GetEffectiveEndpoint(request); ObserveNotificationOrderer orderer = new ObserveNotificationOrderer(_config); CoapObserveRelation relation = new CoapObserveRelation(request, endpoint); request.Respond += (o, e) => { Response resp = e.Response; lock (orderer) { if (orderer.IsNew(resp)) { relation.Current = resp; Deliver(notify, e); } else { if (log.IsDebugEnabled) log.Debug("Dropping old notification: " + resp); } } }; Action<FailReason> fail = r => { relation.Canceled = true; Fail(error, r); }; request.Reject += (o, e) => fail(FailReason.Rejected); request.Timeout += (o, e) => fail(FailReason.TimedOut); Prepare(request, endpoint).Send(); return relation; }