diff --git a/platform/features/conductor-v2/src/timeSystems/LocalClock.js b/platform/features/conductor-v2/src/timeSystems/LocalClock.js new file mode 100644 index 0000000000..07996ecae4 --- /dev/null +++ b/platform/features/conductor-v2/src/timeSystems/LocalClock.js @@ -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; +}); diff --git a/platform/features/conductor-v2/src/timeSystems/TickSource.js b/platform/features/conductor-v2/src/timeSystems/TickSource.js new file mode 100644 index 0000000000..9d3516d026 --- /dev/null +++ b/platform/features/conductor-v2/src/timeSystems/TickSource.js @@ -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; +}); diff --git a/platform/features/conductor-v2/src/timeSystems/TimeSystem.js b/platform/features/conductor-v2/src/timeSystems/TimeSystem.js new file mode 100644 index 0000000000..e3605f79c5 --- /dev/null +++ b/platform/features/conductor-v2/src/timeSystems/TimeSystem.js @@ -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; +}); diff --git a/platform/features/conductor-v2/src/timeSystems/UTCTimeSystem.js b/platform/features/conductor-v2/src/timeSystems/UTCTimeSystem.js new file mode 100644 index 0000000000..1a93fde598 --- /dev/null +++ b/platform/features/conductor-v2/src/timeSystems/UTCTimeSystem.js @@ -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; +});