The Information Service is a database for storing and manipulating configuration objects. These objects hold information such as the IP-STB's IP address, DNS settings, language and subtitling settings, channel table and so on. You can create your own objecs too, perhaps holding user authentication details, a shopping cart, or the last channel visited. Objects can be broadcast from an Infocast Server to a population of IP-STBs. Other objects are set by the platform so applications can read information from them. Applications ask the Information Service for the values of objects, and also subscribe to them. A subscription results in a callback when the value of that particular object changes. Objects may be permanently stored to the flash memory, or volatile (lose their value on a reboot).
Your Javascript code can access the Information Service via the global variable toi.informationService
. The other platform services are also accessed in a similiar manner.
In this code example, an event listener is set up to listen for changes to the values of objects (ON_OBJECTS_CHANGED). Whenever the value of a subscribed object changes the listener function (in this example, OnEvent) gets called. The 'true' parameter when subscribing results in an immediate call to the listener (this is used in the example to initialize the page). The portal subscribes to several interesting objects.
is = toi.informationService;
is.addEventListener(is.ON_OBJECTS_CHANGED, onEvent);
is.subscribeObject(onEvent, "cfg.media.subtitling.autoselection", true);
is.subscribeObject(onEvent, "var.ip.eth0.addr", true);
is.subscribeObject(onEvent, "var.io.state", true);
Different platform Services create different types of events, so look in the TOI 2 interface documentation to find the relevant type. Here, we receive an event containing an array. It holds the names of objects which have changed.
The example code shows the value of the objects on-screen, so when an object value changes, the portal searches the DOM for the text element, and writes the new object value to the element.
if ( !is.isObjectDefined(objectName) ) {
configObjectValue = "Undefined";
}
else {
configObjectValue = is.getObject(objectName);
}
// the object names use a '.' character, but the DOM element ID used for
// display uses an '_' instead, so we need to do a replace...
var elementId = objectName.replace(/\./g, '_');
element = document.getElementById(elementId);
if (!element) {
alert("Cannot find element " + elementId);
return;
}
element.textContent = configObjectValue;
The rest of the code is non-essential. It changes the font colour to red so the user can see that the configuration object just changed state. The colour is reset after 1 second by using a timer.
To test the configuration object functionality, telnet into the IP-STB and create the custom object as follows:
# toish is SetObject cfg.custom.object hello
When the object is created, the onEvent
callback will be called. This results in the objects value being displayed on the TV screen. You can then change the value with:
# toish is SetObject cfg.custom.object world
Again, the onEvent function is called and the new value of the object, "world", is now displayed. If you have an Infocast Server up and running, it is also possible to configure it to send an object called cfg.custom.object with different values. When these are received by the IP-STB the portal will display them onscreen.
If you want the object to be saved to flash memory, so it retains it's value during a reboot, then the permanent
keyword should be used:
# toish is SetObject cfg.custom.object "hello world" permanent
Note that several versions of an object may exist (for instance, one from infocast, one with permanent, one with volatile) but only the highest priority objects value will be returned. Unsetting this object will reveal the value of the next. See the manual section on the Information Service and also Storage Structure for further information.