
exports.NAME = "ednt-plugin-ping";
exports.FRIENDLY_NAME = "ping";
exports.VERSION = "0.0.1";
exports.MOUNTPOINT = "ping";
exports.SU_REQUIRED = true;

exports.ROUTES = {
  "/": {
    "method": "GET",
    "params": {
      "target": {
        "mandatory": true,
        "type": "String"
      },
      "count": {
        "type": "Integer"
      },
      "timeout": {
        "type": "Integer"
      }        
    }
  }
};


var ping = require('net-ping');


exports.init = function(options) {
  this.session = ping.createSession();
  this.session.on('error', function(e) {
    console.log('session error');
    console.dir(e);
  });
  return true;
}

exports.newRequest = function(req, res, callback) {
  target = req.query['target'];
  if(target === undefined || target === '') callback(null,'This would return the partial view \
to query the params, I guess');
  this.session.pingHost (target, function (error, target, sent, rcvd) {
    var ms = rcvd - sent;
    if (error)
        result = target + ": " + error.toString ();
    else
        result = target + ": Alive (ms=" + ms + ")";
    callback(null, result);
  });
}

exports.cancelRequest = function(requestId) {
  
}

exports.getView = function(viewName) {
  viewName = viewName || "default";
}



@@ -1,16 +1,163 @@
 %0A
-exports
+%0Avar ping = require('net-ping');%0Avar events = require('events');%0Avar Plugin = function() %7B%7D;%0APlugin.prototype = new events.EventEmitter;%0A%0APlugin.prototype
 .NAME = 
@@ -176,23 +176,32 @@
 -ping%22;%0A
-exports
+Plugin.prototype
 .FRIENDL
@@ -217,23 +217,32 @@
 %22ping%22;%0A
-exports
+Plugin.prototype
 .VERSION
@@ -253,23 +253,32 @@
 0.0.1%22;%0A
-exports
+Plugin.prototype
 .MOUNTPO
@@ -291,23 +291,32 @@
 %22ping%22;%0A
-exports
+Plugin.prototype
 .SU_REQU
@@ -329,23 +329,32 @@
  true;%0A%0A
-exports
+Plugin.prototype
 .ROUTES 
@@ -614,49 +614,24 @@
 ;%0A%0A%0A
-var ping = require('net-ping');%0A%0A%0Aexports
+Plugin.prototype
 .ini
@@ -812,23 +812,32 @@
 rue;%0A%7D%0A%0A
-exports
+Plugin.prototype
 .newRequ
@@ -858,26 +858,30 @@
 (req
-, res, callback) %7B
+) %7B%0A  var self = this;
 %0A  t
@@ -909,16 +909,51 @@
 rget'%5D;%0A
+  count = req.query%5B'count'%5D %7C%7C 5;%0A
   if(tar
@@ -1241,16 +1241,17 @@
 ();%0A    
+ 
 else%0A   
@@ -1304,16 +1304,18 @@
 )%22;%0A    
+//
 callback
@@ -1336,22 +1336,98 @@
 ;%0A  
-%7D);%0A%7D%0A%0Aexports
+  self.emit('output', null, result);%0A    self.emit('end', null);%0A  %7D);%0A%7D%0A%0APlugin.prototype
 .can
@@ -1471,15 +1471,14 @@
 %0A%7D%0A%0A
-exports
+Plugin
 .get
@@ -1544,9 +1544,40 @@
 lt%22;%0A%7D%0A%0A
+module.exports = new Plugin();%0A
 %0A

Test with events