Permalink
Browse files

Working lib implementation

  • Loading branch information...
1 parent 15f1ab8 commit 98d8e228217cb740b83ad472307468c5246eb0a5 @spolu spolu committed Oct 10, 2014
Showing with 57 additions and 42 deletions.
  1. +1 −1 index.js
  2. +4 −2 lib/api.base.js
  3. +24 −16 lib/api.js
  4. +5 −3 lib/api.menu.js
  5. +5 −3 lib/api.session.js
  6. +5 −3 lib/api.shell.js
  7. +10 −11 lib/thrust.js
  8. +3 −3 test.js
View
@@ -10,4 +10,4 @@
*/
"use strict"
-module.exports = require('./lib/thurst.js').thurst({}).spawn;
+module.exports = require('./lib/thrust.js').thrust({}).spawn;
View
@@ -111,7 +111,7 @@ var base = function(spec, my) {
return cb_(err);
}
else if(!that[method]) {
- return cb_(common.err('Method not found [' my.type + ']: ' + method,
+ return cb_(common.err('Method not found [' + my.type + ']: ' + method,
'thrust:method_not_found'));
}
else {
@@ -143,7 +143,9 @@ var base = function(spec, my) {
});
};
- create(spec.args);
+ process.nextTick(function() {
+ that.create(spec.args);
+ });
common.method(that, 'pre', pre, _super);
common.method(that, 'call', call, _super);
View
@@ -45,17 +45,6 @@ var api = function(spec, my) {
my.actions = {};
my.acc = '';
- if (os.platform() === 'win32') {
- my.thrust_sock = '\\\\.\\pipe\\thrust.' + uid() + '.sock';
- }
- else {
- my.thrust_sock = path.join(os.tmpdir(),
- 'thrust.' + uid() + '.sock');
- }
- /* TODO(spolu): Remove temporary solution */
- my.thrust_sock = '/tmp/_exo_shell.sock';
-
-
//
// #### _public_
//
@@ -65,6 +54,7 @@ var api = function(spec, my) {
// #### _protected_
//
var uid; /* uid(); */
+ var action_id; /* action_id(); */
var perform; /* peform(action, cb_); */
//
@@ -152,7 +142,7 @@ var api = function(spec, my) {
clearTimeout(itv);
return cb_(err, res);
};
- client.write(JSON.stringify(action) + "\n" + BOUNDARY);
+ my.client.write(JSON.stringify(action) + "\n" + my.BOUNDARY);
};
/****************************************************************************/
@@ -167,19 +157,37 @@ var api = function(spec, my) {
init = function(cb_) {
var now = Date.now();
+ that.session = function(args) {
+ return require('./api.session.js').session({ api: that, args: args });
+ };
+ that.shell = function(args) {
+ return require('./api.shell.js').shell({ api: that, args: args });
+ };
+ that.menu = function(args) {
+ return require('./api.menu.js').menu({ api: that, args: args });
+ };
+
my.client = net.connect({ path: my.thrust_sock }, function(err) {
if(err) {
return cb_(err);
}
return cb_(null, that);
});
my.client.on('data', client_data_handler);
-
- that.shell = require('./api.shell.js').shell;
- that.session = require('./api.shell.js').session;
- that.menu = require('./api.shell.js').menu;
};
+
+ if (os.platform() === 'win32') {
+ my.thrust_sock = '\\\\.\\pipe\\thrust.' + uid() + '.sock';
+ }
+ else {
+ my.thrust_sock = path.join(os.tmpdir(),
+ 'thrust.' + uid() + '.sock');
+ }
+ /* TODO(spolu): Remove temporary solution */
+ my.thrust_sock = '/tmp/_exo_shell.sock';
+
+
common.getter(that, 'thrust_sock', my, 'thrust_sock');
common.method(that, 'uid', uid, _super);
View
@@ -44,9 +44,11 @@ var menu = function(spec, my) {
//
// #### _that_
//
- var that = base({ api: spec.api,
- type: 'menu',
- args: spec.args });
+ var that = require('./api.base.js').base({
+ api: spec.api,
+ type: 'menu',
+ args: spec.args
+ });
/****************************************************************************/
/* PRIVATE HELPERS */
View
@@ -41,9 +41,11 @@ var session = function(spec, my) {
//
// #### _that_
//
- var that = base({ api: spec.api,
- type: 'session',
- args: spec.args });
+ var that = require('./api.base.js').base({
+ api: spec.api,
+ type: 'session',
+ args: spec.args
+ });
/****************************************************************************/
/* PRIVATE HELPERS */
View
@@ -50,9 +50,11 @@ var shell = function(spec, my) {
//
// #### _that_
//
- var that = base({ api: spec.api,
- type: 'shell',
- args: spec.args });
+ var that = require('./api.base.js').base({
+ api: spec.api,
+ type: 'shell',
+ args: spec.args
+ });
/****************************************************************************/
/* PRIVATE HELPERS */
View
@@ -11,7 +11,10 @@
"use strict"
var common = require('./common.js');
+
var async = require('async');
+var path = require('path');
+var os = require('os');
// ## thrust
//
@@ -71,17 +74,13 @@ var thrust = function(spec, my) {
'thrust:platform_not_supported'));
}
- require('./api.js').api({}).init(function(err, api) {
- /*
- var p = require('child_process').spawn(my.THRUST_EXEC[os.platform()],
- [api.thrust_sock()],
- { stdio: 'inherit' });
- api.set_process(p);
- */
- api.on('ready', function() {
- return cb_(null, api);
- });
- });
+ /*
+ var p = require('child_process').spawn(my.THRUST_EXEC[os.platform()],
+ [api.thrust_sock()],
+ { stdio: 'inherit' });
+ api.set_process(p);
+ */
+ require('./api.js').api({}).init(cb_);
};
common.method(that, 'spawn', spawn, _super);
View
@@ -5,13 +5,13 @@ var shell = null;
async.series([
function(cb_) {
- require('thrust')(function(err, api) {
+ require('./index.js')(function(err, api) {
API = api;
return cb_(err);
});
},
function(cb_) {
- shell = api.shell({
+ shell = API.shell({
size: {
width: 640,
height: 480
@@ -20,7 +20,7 @@ async.series([
shell.show(cb_);
}
], function(err) {
- console.log('DONE: ' + err);
+ console.log('DONE [' + err + ']');
});
/*

0 comments on commit 98d8e22

Please sign in to comment.