Subversion Repositories HomeAutomation

Rev

Rev 999 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function Service(type, name, id)
  3. {
  4.     this.myType = type;
  5.     this.myName = name;
  6.     this.myId = id;
  7.     this.myEventCallbacks = new Array();
  8.     this.myInitialArguments = new Array();
  9. }
  10.  
  11. Service.prototype.myType = null;
  12. Service.prototype.myName = null;
  13. Service.prototype.myId = null;
  14. Service.prototype.myInitialArguments = null;
  15. Service.prototype.myEventCallbacks = null;
  16.  
  17. Service.prototype.initialize = function(initialArguments)
  18. {
  19.     this.myInitialArguments = initialArguments;
  20. }
  21.  
  22. Service.prototype.getType = function()
  23. {
  24.     return this.myType;
  25. }
  26.  
  27. Service.prototype.getName = function()
  28. {
  29.     return this.myName;
  30. }
  31.  
  32. Service.prototype.getId = function()
  33. {
  34.     return this.myId;
  35. }
  36.  
  37. Service.prototype.registerEventCallback = function(eventName, callback)
  38. {
  39.     if (!this.myEventCallbacks[eventName])
  40.         this.myEventCallbacks[eventName] = new Array();
  41.        
  42.     this.myEventCallbacks[eventName].push(callback);
  43. }
  44.  
  45. Service.prototype.callEvent = function(eventName, args)
  46. {
  47.     if (this.myEventCallbacks[eventName])
  48.     {
  49.         for (var n = 0; n < this.myEventCallbacks[eventName].length; n++)
  50.         {
  51.             this.myEventCallbacks[eventName][n](args);
  52.         }
  53.     }
  54. }
  55.