-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
platform/features/conductor-v2/src/timeSystems/LocalClock.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/***************************************************************************** | ||
* Open MCT Web, Copyright (c) 2014-2015, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT Web includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
define(['./TickSource'], function (TickSource) { | ||
/** | ||
* @interface | ||
* @constructor | ||
*/ | ||
function PeriodicTickSource ($timeout, interval) { | ||
TickSource.call(this); | ||
|
||
this.interval = interval; | ||
this.$timeout = $timeout; | ||
this.timeoutHandle = undefined; | ||
} | ||
|
||
PeriodicTickSource.prototype = Object.create(TickSource.prototype); | ||
|
||
PeriodicTickSource.prototype.start = function () { | ||
this.timeoutHandle = this.$timeout(this.tick.bind(this), this.interval); | ||
}; | ||
|
||
PeriodicTickSource.prototype.stop = function () { | ||
if (this.timeoutHandle) { | ||
this.$timeout.cancel(this.timeoutHandle); | ||
} | ||
}; | ||
|
||
PeriodicTickSource.prototype.tick = function () { | ||
this.listeners.forEach(function (listener){ | ||
listener(); | ||
}); | ||
}; | ||
|
||
PeriodicTickSource.prototype.listen = function (listener) { | ||
this.listeners.push(listener); | ||
|
||
if (this.listeners.length === 1){ | ||
this.start(); | ||
} | ||
|
||
return function () { | ||
this.listeners.splice(listeners.indexOf(listener)); | ||
if (this.listeners.length === 0) { | ||
this.stop(); | ||
} | ||
}.bind(this); | ||
}; | ||
|
||
return TimeSystem; | ||
}); |
45 changes: 45 additions & 0 deletions
45
platform/features/conductor-v2/src/timeSystems/TickSource.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/***************************************************************************** | ||
* Open MCT Web, Copyright (c) 2014-2015, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT Web includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
define([], function () { | ||
/** | ||
* A tick source is a timing of timing signals. Usage is simple, a | ||
* listener registers a callback which is invoked when this source 'ticks'. | ||
* | ||
* @interface | ||
* @constructor | ||
*/ | ||
function TickSource () { | ||
this.listeners = []; | ||
} | ||
|
||
/** | ||
* @param callback Function to be called when this tick source ticks. | ||
* @returns an 'unlisten' function that will remove the callback from | ||
* the registered listeners | ||
*/ | ||
TickSource.prototype.listen = function (callback) { | ||
throw new Error('Not implemented'); | ||
}; | ||
|
||
return TimeSystem; | ||
}); |
45 changes: 45 additions & 0 deletions
45
platform/features/conductor-v2/src/timeSystems/TimeSystem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/***************************************************************************** | ||
* Open MCT Web, Copyright (c) 2014-2015, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT Web includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
define([], function () { | ||
/** | ||
* @interface | ||
* @constructor | ||
*/ | ||
function TimeSystem () { | ||
this.metadata = undefined; | ||
} | ||
|
||
TimeSystem.prototype.formats = function () { | ||
throw new Error('Not implemented'); | ||
}; | ||
|
||
TimeSystem.prototype.tickSources = function () { | ||
throw new Error('Not implemented'); | ||
}; | ||
|
||
TimeSystem.prototype.defaultBounds = function () { | ||
throw new Error('Not implemented'); | ||
}; | ||
|
||
return TimeSystem; | ||
}); |
52 changes: 52 additions & 0 deletions
52
platform/features/conductor-v2/src/timeSystems/UTCTimeSystem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/***************************************************************************** | ||
* Open MCT Web, Copyright (c) 2014-2015, United States Government | ||
* as represented by the Administrator of the National Aeronautics and Space | ||
* Administration. All rights reserved. | ||
* | ||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* Open MCT Web includes source code licensed under additional open source | ||
* licenses. See the Open Source Licenses file (LICENSES.md) included with | ||
* this source code distribution or the Licensing information page available | ||
* at runtime from the About dialog for additional information. | ||
*****************************************************************************/ | ||
|
||
define(['./TimeSystem'], function (TimeSystem) { | ||
var FIFTEEN_MINUTES = 15 * 60 * 1000; | ||
/** | ||
* @implements TimeSystem | ||
* @constructor | ||
*/ | ||
function UTCTimeSystem () { | ||
TimeSystem.call(this); | ||
|
||
this._formats = []; | ||
this._tickSources = []; | ||
} | ||
|
||
UTCTimeSystem.prototype = Object.create(TimeSystem.prototype); | ||
|
||
UTCTimeSystem.prototype.formats = function () { | ||
return this._formats; | ||
}; | ||
|
||
UTCTimeSystem.prototype.tickSources = function () { | ||
return this._tickSources; | ||
}; | ||
|
||
UTCTimeSystem.prototype.defaultBounds = function () { | ||
var now = Math.ceil(Date.now() / 1000) * 1000; | ||
return {start: now - FIFTEEN_MINUTES, end: now}; | ||
}; | ||
|
||
return UTCTimeSystem; | ||
}); |