The resource container is a component that can dynamically load resource definitions. The resource definitions are grouped together in resource bundles. A typical use case is to provide translations to external protocols and to make 3rd party devices or services available as OIC resource servers.
The main use case of the resource container is acting as a bridge to non-OIC ecosystems. The container runs on a bridge device and can be configured to load resource bundles, which map non-OIC devices. The container creates OIC resource server, that OIC clients can use to access the non-OIC resources.
The resource container is a component used by many different stakeholders. The main stakeholders are device manufacturers that provide a device bridge to other technologies, a bundle provider providing bundles that map other technologies to IoTivity or offer software-defined resources (e.g. algorithms, sensor fusioning), system integrator or end-user which configure the resource container and its bundles for a concrete environment. For an application developer the resource container is transparent and the developer has only to adhere to the OIC specified interfaces. A stakeholder overview is given in the following figure.
The figure below illustrates the architecture of the resource container. It offers a container API that can be used to start the container. A common XML configuration file is used for all resource bundles. The configuration contains parameters specific to the bundle but also to every resource instance. A resource bundle contains an activator and bundle resources. A bundle resource can be the definition of a soft sensor(= logical sensor, virtual sensor) resource that contains an algorithm to derive new knowledge and offer it as a resource and protocol bridge resources which map other technologies to OIC resources. The bundles only contain the mapping logic, whereas the actual creation of OIC resource servers happens in the resource container. The bundle provider is agnostic of the base and resource encapsulation layer APIs of IoTivity and only needs to adhere to the bundle API.
The interaction flow for the activation of a bundle is shown in next figure.
The resource container comes with an extension for the Android platform that enables the usage of native bundles to be loaded within an Android application, as well as the loading of Android based bundles. The main difference between native bundles and Android bundles is the availability to access the Android APIs based on the application context. The design of the extension is illustrated in the figure below. The core is a wrapper layer provided as .aar library, offering the APIs to control the resource container which runs in the native code and the interface to the bundle APIs. The main advantage of using the resource container on Android is to only depend on the resource container libraries to define a resource on Android. For a bundle developer, there is no dependency to the IoTivity base libraries. Further, the bundles can be provided as standalone .jar files and an Android application running the container can load these bundles based on the configuration. Resource bundles based on .jar files are loaded by the application that starts the resource-container. Therefore, all bundles share a common application process and common security permissions.
The APIs of the resource container can be used to start the container configured with the path to an XML configuration file. The configuration file describes the available resource bundles and the resouce instance configuration.
A dynamic configuration API is provided to add/remove bundles and resources during runtime.
A sample application demonstrates the resource container. Example bundles and a configuration is provided. The configuration can be found in the examples folder and a snippet of the XML file is shown below. You can inspect the configuration to see how to configure bundles to be loaded by the resource container.
… <bundle> <id>oic.bundle.hueSample</id> <path>libHueBundle.so</path> <activator>huesample</activator> <version>1.0.0</version> <resources> <resourceInfo> <name>light</name> <resourceType>oic.r.light</resourceType> <address>http://192.168.0.2/api/newdeveloper/lights/1</address> </resourceInfo> </resources> </bundle> …
First run the ContainerSample:
~/[release-folder]/service/resource-container/ $ ./ContainerSample
The resource container starts. Follow the instructions and press [ENTER] to see the demonstration of how bundles get loaded, stopped, activated and the whole container gets stopped. After the container is started you can execute in parallel the ContainerClientSample, which executes the test requests against container provided resources. To execute the ContainerSampleClient run:
~/[release-folder]/service/resource-container/ $ ./ContainerSampleClient
This sections covers the Tizen Sample Applications of Resource Container module.
This section describes the working flow of the ContainerClientApp and ContainerServerApp Tizen Applications.
ContainerServerApp show the functionalities provided by Resource Container module. ContainerClientApp is to discover the resource created by ContainerServerApp.
Running the ContainerServerApp provides two options on the home screen:
On selecting the start container options, it trigeers the container to start with default bundle provided in the configuration file. Once the container has started successfully the remaining container option is displayed to test the resource container APIs. The following images show the homescreen of the application and screen for container APIs.
Note : In sample application we have the configuration file (.xml) with hue bundle.
The remaining container APIs can be tested now as the container has been successfully started. On selecting the first option i.e. List Bundles, it displayes the list of all bundles in the container.
On selecting the option for List Hue resources, it displayes all resources added to the Hue bundle. Since we have not added amy resources it displayes the resource bundle size as 0.
Using the Add HUE Bundle Resource option, light resources can be added to the HUE bundle. On selecting this option a new resource is created and added.
Using the Add HUE Bundle Resource option, light resources can be added to the HUE bundle. On selecting this option a new resource is created and added. The following logs will be displayed.
Hue Bundle is added and started by default on starting the container. Addition bundles can also be added to the container. These APIs can be tested using the add and start bundle options. ‘Add BMI bundle’ and ‘Start BMI bundle’ options in the applications add a BMISensorBundle to the already started resource container. On selecting the ‘Add BMI bundle’ option first and then ‘Start BMI bundle’ option, BMISensor bundle is added to the container.
We can verify the authenticity by checking the list of bundles of the container. This can be done using the first option ‘List Bundles’.
Here we can see the bundle list size has increased and BMISensor bundle has been added to the container. Now similarly to stop and remove a bundle from the container, stop bundle and remove bundle options can be used. The ‘Stop BMI Bundle’ and ‘Remove BMI Bundle’ options will stop and remove the BMISensor bundle if added to the container.
The container can be stopped using the stop container button on the top right hand corner of the screen. Selecting this button automatically removes all bundles added to the container and stops the container. If the container is not yet started then this button has no effect what so ever.
ContainerClientApp provides the feature to discover the resource created by ContainerServiceApp. Running the ContainerClientApp provides only one option to start the container client. On selecting the start container client option new menu is shown.
If Resources have been created by the ContainerServiceApp, is can be discovered by this application. If a light resource discovery is to be made, selet the ‘Start light resource Discovery’ option to begin the discovery request. If the a light resource is running in the same network it will get a callback.
Once the desired resource has been found, the discovery request can be terminated by selecting the ‘Stop Discovery’ option. Once the discovery has been canceled, we will get a list of all the resources discovered to select from for our use. Similarly discovery can be made for a soft sensor resource also.
This sections covers the Android Sample Applications of Resource Container module.
This section describes the working flow of the RCSampleClientApp and RCSampleServerApp Android Applications.
This section describes the working flow of the RCSampleClientApp and RCSampleServerApp Android Applications. RCSampleServerApp show the functionalities provided by Resource Container module. RCSampleClientApp is to discover the resource created by RCSampleServerApp. AndroidBundle is a sample bundle for android with several bundle resources