1 | /*
|
2 | * Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
|
3 | *
|
4 | * Permission is hereby granted, free of charge, to any person obtaining a
|
5 | * copy of this software and associated documentation files (the "Software"),
|
6 | * to deal in the Software without restriction, including without limitation
|
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
8 | * and/or sell copies of the Software, and to permit persons to whom the
|
9 | * Software is furnished to do so, subject to the following conditions:
|
10 | *
|
11 | * The above copyright notice and this permission notice shall be included in
|
12 | * all copies or substantial portions of the Software.
|
13 | *
|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
20 | * DEALINGS IN THE SOFTWARE.
|
21 | *
|
22 | */
|
23 |
|
24 | (function () {
|
25 | ;
|
26 |
|
27 | var //Launcher = require("./Launcher"),
|
28 | Logger = require("./Logger");
|
29 |
|
30 | /**
|
31 | * @private
|
32 | * @type {DomainManager}
|
33 | * DomainManager provided at initialization time
|
34 | */
|
35 | var _domainManager = null;
|
36 |
|
37 | /**
|
38 | * @private
|
39 | * Implementation of base.enableDebugger commnad.
|
40 | * In the future, process._debugProcess may go away. In that case
|
41 | * we will probably have to implement re-launching of the Node process
|
42 | * with the --debug command line switch.
|
43 | */
|
44 | function cmdEnableDebugger() {
|
45 | // Unfortunately, there's no indication of whether this succeeded
|
46 | // This is the case for _all_ of the methods for enabling the debugger.
|
47 | process._debugProcess(process.pid);
|
48 | }
|
49 |
|
50 | /**
|
51 | * @private
|
52 | * Implementation of base.restartNode command.
|
53 | */
|
54 | function cmdRestartNode() {
|
55 | // Launcher.exit();
|
56 | }
|
57 |
|
58 | /**
|
59 | * @private
|
60 | * Implementation of base.loadDomainModulesFromPaths
|
61 | * @param {Array.<string>} paths Paths to load
|
62 | * @return {boolean} Whether the load succeeded
|
63 | */
|
64 | function cmdLoadDomainModulesFromPaths(paths) {
|
65 | if (_domainManager) {
|
66 | var success = _domainManager.loadDomainModulesFromPaths(paths);
|
67 | if (success) {
|
68 | _domainManager.emitEvent("base", "newDomains");
|
69 | }
|
70 | return success;
|
71 | } else {
|
72 | return false;
|
73 | }
|
74 | }
|
75 |
|
76 | /**
|
77 | *
|
78 | * Registers commands with the DomainManager
|
79 | * @param {DomainManager} domainManager The DomainManager to use
|
80 | */
|
81 | function init(domainManager) {
|
82 | _domainManager = domainManager;
|
83 |
|
84 | _domainManager.registerDomain("base", {major: 0, minor: 1});
|
85 | _domainManager.registerCommand(
|
86 | "base",
|
87 | "enableDebugger",
|
88 | cmdEnableDebugger,
|
89 | false,
|
90 | "Attempt to enable the debugger",
|
91 | [], // no parameters
|
92 | [] // no return type
|
93 | );
|
94 | _domainManager.registerCommand(
|
95 | "base",
|
96 | "restartNode",
|
97 | cmdRestartNode,
|
98 | false,
|
99 | "Attempt to restart the Node server",
|
100 | [], // no parameters
|
101 | [] // no return type
|
102 | );
|
103 | _domainManager.registerCommand(
|
104 | "base",
|
105 | "loadDomainModulesFromPaths",
|
106 | cmdLoadDomainModulesFromPaths,
|
107 | false,
|
108 | "Attempt to load command modules from the given paths. " +
|
109 | "The paths should be absolute.",
|
110 | [{name: "paths", type: "array<string>"}],
|
111 | [{name: "success", type: "boolean"}]
|
112 | );
|
113 |
|
114 | _domainManager.registerEvent(
|
115 | "base",
|
116 | "log",
|
117 | [{name: "level", type: "string"},
|
118 | {name: "timestamp", type: "Date"},
|
119 | {name: "message", type: "string"}]
|
120 | );
|
121 | Logger.on(
|
122 | "log",
|
123 | function (level, timestamp, message) {
|
124 | _domainManager.emitEvent(
|
125 | "base",
|
126 | "log",
|
127 | [level, timestamp, message]
|
128 | );
|
129 | }
|
130 | );
|
131 |
|
132 | _domainManager.registerEvent("base", "newDomains", []);
|
133 | }
|
134 |
|
135 | exports.init = init;
|
136 |
|
137 | }());
|