Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

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