lib/serial/globaldeviceloader.js
function(Device, filter) {
    var sub = new EventEmitter2({
      wildcard: true,
      delimiter: ':',
      maxListeners: 1000 // default would be 10!
    });
    sub.Device = Device;
    sub.filter = filter;
    sub.oldDevices = [];
    sub.newDevices = [];

    /**
     * Calls the callback with an array of devices.
     * @param  {Array}    ports    When called within this file this are the listed system ports. [optional]
     * @param  {Function} callback The function, that will be called when finished lookup.
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.lookup = function(ports, callback) {
      if (!callback) {
        callback = ports;
        ports = null;
      }

      if (this.newDevices.length > 0) {
        if (callback) { callback(null, this.newDevices); }
        return;
      } else {
        var self = this;
        globalSerialDeviceLoader.lookup(function(err) {
          if (err && !err.name) {
            err = new Error(err);
          }
          if (callback) { callback(err, self.newDevices); }
        });
      }
    };

    /**
     * Calls lookup function with optional callback
     * and emits 'plug' for new attached devices
     * and 'unplug' for removed devices.
     * @param  {Function} callback The function, that will be called when finished triggering. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.trigger = function(callback) {
      var self = this;
      globalSerialDeviceLoader.trigger(function(err) {
        if (err && !err.name) {
          err = new Error(err);
        }
        if (callback) { callback(err, self.newDevices); }
      });
    };

    /**
     * Starts to lookup.
     * @param  {Number}   interval The interval milliseconds. [optional]
     * @param  {Function} callback The function, that will be called when trigger has started. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.startLookup = function(interval, callback) {
      if (!callback && _.isFunction(interval)) {
        callback = interval;
        interval = null;
      }

      subscribers.push(this);

      var self = this;
      if (isRunning) {
        if (callback) { callback(null, self.newDevices); }
        return;
      } else {
        globalSerialDeviceLoader.startLookup(interval, function(err) {
          if (err && !err.name) {
            err = new Error(err);
          }
          if (callback) { callback(err, self.newDevices); }
        });
      }
    };

    /**
     * Removes itself as subscriber.
     * If last stops the interval that calls trigger function.
     */
    sub.stopLookup = function() {
      var self = this;
      if (!isRunning) {
        return;
      } else {
        subscribers = _.reject(function(s) {
          return s === self;
        });
        if (subscribers.length === 0) {
          globalSerialDeviceLoader.stopLookup();
        }
        return;
      }
    };

    return sub;
  }
function(Device, filter) {
    var sub = new EventEmitter2({
      wildcard: true,
      delimiter: ':',
      maxListeners: 1000 // default would be 10!
    });
    sub.Device = Device;
    sub.filter = filter;
    sub.oldDevices = [];
    sub.newDevices = [];

    /**
     * Calls the callback with an array of devices.
     * @param  {Array}    ports    When called within this file this are the listed system ports. [optional]
     * @param  {Function} callback The function, that will be called when finished lookup.
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.lookup = function(ports, callback) {
      if (!callback) {
        callback = ports;
        ports = null;
      }

      if (this.newDevices.length > 0) {
        if (callback) { callback(null, this.newDevices); }
        return;
      } else {
        var self = this;
        globalSerialDeviceLoader.lookup(function(err) {
          if (err && !err.name) {
            err = new Error(err);
          }
          if (callback) { callback(err, self.newDevices); }
        });
      }
    };

    /**
     * Calls lookup function with optional callback
     * and emits 'plug' for new attached devices
     * and 'unplug' for removed devices.
     * @param  {Function} callback The function, that will be called when finished triggering. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.trigger = function(callback) {
      var self = this;
      globalSerialDeviceLoader.trigger(function(err) {
        if (err && !err.name) {
          err = new Error(err);
        }
        if (callback) { callback(err, self.newDevices); }
      });
    };

    /**
     * Starts to lookup.
     * @param  {Number}   interval The interval milliseconds. [optional]
     * @param  {Function} callback The function, that will be called when trigger has started. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */
    sub.startLookup = function(interval, callback) {
      if (!callback && _.isFunction(interval)) {
        callback = interval;
        interval = null;
      }

      subscribers.push(this);

      var self = this;
      if (isRunning) {
        if (callback) { callback(null, self.newDevices); }
        return;
      } else {
        globalSerialDeviceLoader.startLookup(interval, function(err) {
          if (err && !err.name) {
            err = new Error(err);
          }
          if (callback) { callback(err, self.newDevices); }
        });
      }
    };

    /**
     * Removes itself as subscriber.
     * If last stops the interval that calls trigger function.
     */
    sub.stopLookup = function() {
      var self = this;
      if (!isRunning) {
        return;
      } else {
        subscribers = _.reject(function(s) {
          return s === self;
        });
        if (subscribers.length === 0) {
          globalSerialDeviceLoader.stopLookup();
        }
        return;
      }
    };

    return sub;
  }
function ( Device , filter ) { var sub = new EventEmitter2 ( { wildcard : true , delimiter : ':' , maxListeners : 1000 // default would be 10! } ) ; sub . Device = Device ; sub . filter = filter ; sub . oldDevices = [ ] ; sub . newDevices = [ ] ; /**
     * Calls the callback with an array of devices.
     * @param  {Array}    ports    When called within this file this are the listed system ports. [optional]
     * @param  {Function} callback The function, that will be called when finished lookup.
     *                             `function(err, devices){}` devices is an array of Device objects.
     */ sub . lookup = function ( ports , callback ) { if ( ! callback ) { callback = ports ; ports = null ; } if ( this . newDevices . length > 0 ) { if ( callback ) { callback ( null , this . newDevices ) ; } return ; } else { var self = this ; globalSerialDeviceLoader . lookup ( function ( err ) { if ( err && ! err . name ) { err = new Error ( err ) ; } if ( callback ) { callback ( err , self . newDevices ) ; } } ) ; } } ; /**
     * Calls lookup function with optional callback
     * and emits 'plug' for new attached devices
     * and 'unplug' for removed devices.
     * @param  {Function} callback The function, that will be called when finished triggering. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */ sub . trigger = function ( callback ) { var self = this ; globalSerialDeviceLoader . trigger ( function ( err ) { if ( err && ! err . name ) { err = new Error ( err ) ; } if ( callback ) { callback ( err , self . newDevices ) ; } } ) ; } ; /**
     * Starts to lookup.
     * @param  {Number}   interval The interval milliseconds. [optional]
     * @param  {Function} callback The function, that will be called when trigger has started. [optional]
     *                             `function(err, devices){}` devices is an array of Device objects.
     */ sub . startLookup = function ( interval , callback ) { if ( ! callback && _ . isFunction ( interval ) ) { callback = interval ; interval = null ; } subscribers . push ( this ) ; var self = this ; if ( isRunning ) { if ( callback ) { callback ( null , self . newDevices ) ; } return ; } else { globalSerialDeviceLoader . startLookup ( interval , function ( err ) { if ( err && ! err . name ) { err = new Error ( err ) ; } if ( callback ) { callback ( err , self . newDevices ) ; } } ) ; } } ; /**
     * Removes itself as subscriber.
     * If last stops the interval that calls trigger function.
     */ sub . stopLookup = function ( ) { var self = this ; if ( ! isRunning ) { return ; } else { subscribers = _ . reject ( function ( s ) { return s === self ; } ) ; if ( subscribers . length === 0 ) { globalSerialDeviceLoader . stopLookup ( ) ; } return ; } } ; return sub ; }
Creates a deviceloader.
@param  {Object}   Device The constructor function of the device.
@param  {Function} filter The filter function that will filter the needed devices.
@return {Object}          Represents a SerialDeviceLoader.
Creates a deviceloader .