blob: 553e1ba8388fcb9c5e82fe033e623ecd99fa568d [file] [log] [blame]
Jeff Thompson6ad5c362012-12-27 17:57:02 -08001/*
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6var EXPORTED_SYMBOLS = ["addNdnHubChangedListener", "setConnectedNdnHub"];
7
8const Cc = Components.classes;
9const Ci = Components.interfaces;
10const Cr = Components.results;
11
12Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
13
14var ndnHubHost = null;
15var ndnHubPort = null;
16var ndnHubChangedListenerList = [];
17
18/*
19 * When the NDN hub host or port is changed, the system calls listener(host, port).
20 */
21function addNdnHubChangedListener(listener) {
22 ndnHubChangedListenerList.push(listener);
23}
24
25/*
26 * If host and port are different than ndnHubHost or ndnHubPort, set them and call each
27 * listener in ndnHubChangedListenerList.
28 */
29function setConnectedNdnHub(host, port) {
30 if (host == ndnHubHost && port == ndnHubPort)
31 // No change.
32 return;
33
34 ndnHubHost = host;
35 ndnHubPort = port;
36 for (var i = 0; i < ndnHubChangedListenerList.length; ++i) {
37 try {
38 ndnHubChangedListenerList[i](host, port);
39 }
40 catch (ex) {
41 // Ignore error from the listener.
42 }
43 }
44}