-
Notifications
You must be signed in to change notification settings - Fork 1
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
Francesco Zanitti
authored and
Francesco Zanitti
committed
Feb 27, 2011
1 parent
e72b029
commit a090bfe
Showing
20 changed files
with
426 additions
and
124 deletions.
There are no files selected for viewing
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
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
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
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,8 @@ | ||
var wirez = require('wirez') | ||
, b = wirez.r('./b') | ||
, log = wirez.newLogger('C') | ||
|
||
module.exports.wirezStart = function() {log("Starting")} | ||
module.exports.wirezStop = function() {log("Stopping")} | ||
|
||
log("Hello from module 'c', " + b.who) |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var Wirez = require('./lib/wirez').Wirez | ||
var Reloader = require('./lib/reloader').Reloader | ||
var Bootstrap = require('./lib/bootstrap').Bootstrap | ||
var Manager = require('./lib/manager').Manager | ||
|
||
module.exports = new Wirez() | ||
module.exports.reloader = new Reloader(module.exports) | ||
module.exports.bootstrap = new Bootstrap(module.exports) | ||
module.exports.bootstrap = new Bootstrap(module.exports) | ||
module.exports.manager = new Manager(module.exports) |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
|
||
var p = require('path') | ||
|
||
var Bootstrap = module.exports = function(wirez) { | ||
this.wirez = wirez | ||
} | ||
Bootstrap.prototype.start = function( path ) { | ||
require( path||this.wirez.wpath ) | ||
index = p.join((path||this.wirez.wpath),'index.js') | ||
this.wirez.requireAbsolute( index ) | ||
//require( path||this.wirez.wpath ) | ||
} |
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,13 @@ | ||
var misc = require('../../reloader/misc') | ||
|
||
var path = require('path') | ||
|
||
module.exports.handle = function( wirez,modname ) { | ||
mod = wirez.getByName(modname) | ||
if(!mod) { return {response: 'Cannot find module '+mod, done:false} } | ||
|
||
misc.deleteCache( mod.mod + '.js' ) | ||
mod.reload() | ||
|
||
return {response: 'ok'} | ||
} |
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,36 @@ | ||
var wu = require('wu').wu | ||
|
||
module.exports.handle = function( wirez,modname ) { | ||
if(modname) { | ||
var mod = wirez.getByName(modname) | ||
if(!mod) { | ||
return {response: 'Cannot find module '+modname, done:false} | ||
} | ||
var out = {} | ||
out.name = mod.name() | ||
out.path = mod.mod | ||
out.state = mod.state() | ||
out.dependencies = [] | ||
wu( wirez.deps.dependencies(mod.mod) ).each(function(o) { | ||
var m = o[0] | ||
out.dependencies.push(m.name()) | ||
}) | ||
return {response: out} | ||
} | ||
|
||
var deps = wirez.deps | ||
var graph = deps.graph | ||
|
||
var out = {} | ||
out.dependencies = {} | ||
wu(graph.index).eachply(function(k,v){ | ||
var n = k | ||
if(wirez.wirezes[k]){n=wirez.wirezes[k].name()} | ||
out.dependencies[n] = [] | ||
wu( wirez.deps.dependencies(k) ).each(function(o) { | ||
var m = o[0] | ||
out.dependencies[n].push(m.name()) | ||
}) | ||
}) | ||
return {response:out} | ||
} |
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,7 @@ | ||
var path = require('path') | ||
|
||
module.exports.handle = function( wirez,modpath ) { | ||
if(modpath[0]!='/') { modpath = path.join( wirez.wpath,modpath ) } | ||
wirez.requireAbsolute(modpath) | ||
return {response: 'ok'} | ||
} |
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,9 @@ | ||
var wu = require('wu').wu | ||
|
||
module.exports.handle = function( wirez ) { | ||
return {response: wu(wirez.wirezes).mapply( | ||
function(path,w) { | ||
return w.name() + ' @' + w.state() | ||
} | ||
).toArray()} | ||
} |
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,6 @@ | ||
module.exports.handle = function( wirez,modname ) { | ||
return { | ||
response: 'ok' | ||
, onSent: function() { wirez.shutdown(1000) } | ||
} | ||
} |
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,10 @@ | ||
var wu = require('wu').wu | ||
|
||
module.exports.handle = function( wirez,modname ) { | ||
var mod = wirez.getByName(modname) | ||
if(!mod) { | ||
return {response: 'Cannot find module '+modname, done:false} | ||
} | ||
mod.start() | ||
return {response: mod.name() + ' @'+mod.state()} | ||
} |
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,10 @@ | ||
var wu = require('wu').wu | ||
|
||
module.exports.handle = function( wirez,modname ) { | ||
var mod = wirez.getByName(modname) | ||
if(!mod) { | ||
return {response: 'Cannot find module '+modname, done:false} | ||
} | ||
mod.stop() | ||
return {response: mod.name() + ' @'+mod.state()} | ||
} |
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 @@ | ||
module.exports.Manager = require('./manager') |
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,78 @@ | ||
var util = require('util') | ||
, net = require('net') | ||
|
||
module.exports.newServerSide = function( mngr,port,enc ) { | ||
return new Server(port,enc) | ||
} | ||
module.exports.newClientSide = function( port,enc,onresponse ) { | ||
return new Client(port,enc,onresponse) | ||
} | ||
|
||
var Server = function(port,enc) { | ||
var s = this | ||
this.enc = enc | ||
this.port = port | ||
this.ssock = net.createServer(function(socket){s.handle(socket)}) | ||
|
||
this.closed=false | ||
this.ssock.on('close',function(){s.closed=true}) | ||
} | ||
Server.prototype.start = function(cb) { | ||
this.ssock.listen(this.port) | ||
cb(this) | ||
} | ||
Server.prototype.stop = function() { | ||
if(this.closed) return | ||
this.ssock.close() | ||
} | ||
Server.prototype.onRPC = function( callback,context ) { | ||
this.RPCcallback = callback | ||
this.onRPCContext = context || this | ||
} | ||
Server.prototype.handle = function(socket) { | ||
var s = this | ||
socket.setEncoding(this.enc) | ||
socket.on('data',function(data) { | ||
var command = JSON.parse( data )//msg.toString( this.enc ) )//msg.toString( this.enc ).split('\n') | ||
var out = s.RPCcallback.apply( s.onRPCContext, [command] ) | ||
if(out.onSent){ | ||
var onsent = out.onSent | ||
socket.on('end',onsent) | ||
delete (out.onSent) | ||
} | ||
out = JSON.stringify(out) | ||
socket.end(out) | ||
}) | ||
} | ||
|
||
var Client = function(port,enc,onresponse) { | ||
var s = this | ||
this.sock = net.createConnection(port) | ||
this.sock.setEncoding(enc) | ||
this.sock.on('data',function(data) { | ||
onresponse(JSON.parse(data)) | ||
s.sock.end() | ||
}) | ||
this.closed=false | ||
this.sock.on('end',function(){s.closed=true}) | ||
} | ||
Client.prototype.stop = function() { | ||
if(this.closed) return | ||
this.sock.end() | ||
} | ||
Client.prototype.RPC = function( cmd,args ) { | ||
var command = { cmd:cmd } | ||
if(args&&!(args instanceof Array)){ args = [args] } | ||
command.args = args || [] | ||
var str = JSON.stringify(command) | ||
this.sock.write(str) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.