Rev 1299 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 969 | runge | 1 | |
| 2 | function ServiceManager() {} |
||
| 3 | |||
| 4 | ServiceManager.Services = new Array(); |
||
| 1299 | runge | 5 | ServiceManager.Callbacks = new Array(); |
| 969 | runge | 6 | |
| 1299 | runge | 7 | ServiceManager.addCallback = function(callback) |
| 8 | { |
||
| 9 | ServiceManager.Callbacks[ServiceManager.Callbacks.length] = callback; |
||
| 10 | } |
||
| 11 | |||
| 969 | runge | 12 | ServiceManager.getService = function(type, name, id) |
| 13 | { |
||
| 14 | var fullId = name + id; |
||
| 15 | |||
| 16 | if (!ServiceManager.Services[fullId]) |
||
| 17 | { |
||
| 18 | if (eval("typeof " + name + " != 'function'"))///FIXME: eval = evil! |
||
| 19 | { |
||
| 20 | if (!loadScript(type + "/" + name + ".js")) |
||
| 21 | { |
||
| 972 | runge | 22 | //log("Could not load " + name + ".js\n"); |
| 969 | runge | 23 | return null; |
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 999 | runge | 27 | ServiceManager.Services[fullId] = eval("(new " + name + "('" + type + "', '" + name + "', " + id + "))");///FIXME: Can we do this without eval?? |
| 1299 | runge | 28 | |
| 29 | for (var n in ServiceManager.Callbacks) |
||
| 30 | { |
||
| 31 | ServiceManager.Callbacks[n](ServiceManager.Services[fullId]); |
||
| 32 | } |
||
| 969 | runge | 33 | } |
| 34 | |||
| 35 | return ServiceManager.Services[fullId]; |
||
| 36 | } |
||
| 37 | |||
| 38 | ServiceManager.startService = function(type, name, id, args) |
||
| 39 | { |
||
| 40 | var service = ServiceManager.getService(type, name, id); |
||
| 41 | if (service != null) |
||
| 42 | { |
||
| 43 | service.initialize(args); |
||
| 44 | } |
||
| 45 | } |
||
| 1402 | runge | 46 | |
| 47 | ServiceManager.numServices = function() |
||
| 48 | { |
||
| 49 | return ServiceManager.Services.length; |
||
| 50 | } |
||
| 51 | |||
| 52 | ServiceManager.numCallbacks = function() |
||
| 53 | { |
||
| 54 | return ServiceManager.Callbacks.length; |
||
| 55 | } |
||
| 56 |