diff --git a/lib/cwmp.coffee b/lib/cwmp.coffee index c416e36..23a6bfe 100644 --- a/lib/cwmp.coffee +++ b/lib/cwmp.coffee @@ -356,6 +356,9 @@ applyPresets = (sessionContext) -> session.clearProvisions(sessionContext) return sendAcsRequest(sessionContext) + sessionContext.deviceData.timestamps.dirty = 0; + sessionContext.deviceData.attributes.dirty = 0; + session.rpcRequest(sessionContext, null, (err, fault, id, acsRequest) -> return throwError(err, sessionContext.httpResponse) if err @@ -374,6 +377,10 @@ applyPresets = (sessionContext) -> if whiteList? return applyPresets(sessionContext) + if sessionContext.deviceData.timestamps.dirty > 1 or + sessionContext.deviceData.attributes.dirty > 1 + return applyPresets(sessionContext) + sendAcsRequest(sessionContext, id, acsRequest) ) ) diff --git a/lib/versioned-map.js b/lib/versioned-map.js index af27e9a..2a6de6d 100644 --- a/lib/versioned-map.js +++ b/lib/versioned-map.js @@ -36,6 +36,7 @@ class VersionedMap { this._sizeDiff = [0]; this._revision = 0; this.map = new Map(); + this.dirty = 0; } @@ -100,6 +101,7 @@ class VersionedMap { var v = this.map.get(key); if (!v) { + this.dirty |= 1 << rev; for (let i = 0; i < rev; ++ i) this._sizeDiff[i] -= 1; @@ -118,6 +120,7 @@ class VersionedMap { throw new Error('Cannot modify old revisions'); } + this.dirty |= 1 << rev; if (old === NONEXISTENT) ++ this._sizeDiff[rev]; @@ -140,6 +143,7 @@ class VersionedMap { if (old === NONEXISTENT) return false; + this.dirty |= 1 << rev; -- this._sizeDiff[rev]; v[rev] = NONEXISTENT; @@ -177,6 +181,7 @@ class VersionedMap { for (let i = this._sizeDiff.length; i <= r; ++ i) this._sizeDiff[i] = this._sizeDiff[i - 1]; + this.dirty |= 1 << r; rev[r] = revisions[k]; } } @@ -184,6 +189,8 @@ class VersionedMap { for (let i = 0; i < minKey; ++ i) -- this._sizeDiff[i]; + this.dirty |= del; + for (let i = 0; del > 0; del >>= 1, ++ i) if (del & 1) rev[i] = NONEXISTENT; @@ -233,6 +240,10 @@ class VersionedMap { this._sizeDiff[revision] = this._sizeDiff[this._sizeDiff.length - 1]; this._sizeDiff.splice(revision + 1, this._sizeDiff.length); + let d = this.dirty >> revision; + this.dirty = this.dirty ^ (d << revision); + this.dirty |= (+!!d) << revision; + for (let pair of this.map) { let k = pair[0]; let v = pair[1];