Iotcon API

The Iotcon API provides functions for IoT connectivity.

It allows to register, discover and access to resources via RESTful API.

Since: 3.0

Summary of Interfaces and Methods

Interface Method
IotconObject

Iotcon

void initialize (DOMString filePath)

Client getClient ()

Server getServer ()

long getTimeout ()

void setTimeout (long timeout)

long addGeneratedPinListener (GeneratedPinCallback successCallback)

void removeGeneratedPinListener (long watchId)

Client

void findResource (DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundResourceSuccessCallback successCallback, optional ErrorCallback? errorCallback)

long addPresenceEventListener (DOMString? hostAddress, ResourceType? resourceType, ConnectivityType connectivityType, PresenceEventCallback successCallback)

void removePresenceEventListener (long watchId)

void findDeviceInfo (DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundDeviceInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback)

void findPlatformInfo (DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundPlatformInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback)

Server

Resource[] getResources ()

Resource createResource (DOMString uriPath, ResourceType[] resourceTypes, ResourceInterface[] resourceInterfaces, RequestCallback listener, optional ResourcePolicy policy)

void removeResource (Resource resource)

void startPresence (unsigned long timeToLive)

void stopPresence ()

RemoteResource

void methodGet (RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback)

void methodPut (Representation representation, RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback)

void methodPost (Representation representation, RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback)

void methodDelete (RemoteResourceResponseCallback responseCallback, optional ErrorCallback? errorCallback)

void startObserving (ObservePolicy observePolicy, RemoteResourceResponseCallback successCallback, optional Query? query)

void stopObserving ()

void startCaching (optional CacheUpdatedCallback? updatedCallback)

void stopCaching ()

void setResourceStateChangeListener (ResourceStateChangeCallback successCallback)

void unsetResourceStateChangeListener ()

ResourcePolicy

Resource

void notify (QosLevel qosLevel, optional long[]? observerIds)

void addResourceTypes (ResourceType[] types)

void addResourceInterface (ResourceInterface interface)

void addChildResource (Resource resource)

void removeChildResource (Resource resource)

void setRequestListener (RequestCallback listener)

void unsetRequestListener ()

Representation

PresenceResponse

Query

IotconOption

Request

Response

void send ()

RemoteResponse

DeviceInfo

PlatformInfo

RequestCallback

void onget (Request request)

void onput (Request request)

void onpost (Request request)

void ondelete (Request request)

void onobserving (Request request, ObserveType observeType, unsigned long observeId)

FoundResourceSuccessCallback

void onfound (RemoteResource remoteResource)

PresenceEventCallback

void onreceived (PresenceResponse presenceResponse)

FoundDeviceInfoSuccessCallback

void onsuccess (DeviceInfo info)

FoundPlatformInfoSuccessCallback

void onsuccess (PlatformInfo info)

RemoteResourceResponseCallback

void onsuccess (RemoteResponse response)

ResourceStateChangeCallback

void onchanged (boolean isAlive)

CacheUpdatedCallback

void onupdated (Representation representation)

GeneratedPinCallback

void onsuccess (DOMString pin)

1. Type Definitions

1.1. ResourceType

A resource type.

    typedef DOMString ResourceType;

Since: 3.0

Remark : The length of resource type should be less than or equal to 61. The resource type must start with a lowercase alphabetic character, followed by a sequence of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.

1.2. QosLevel

Enumeration for quality of service level.

    enum QosLevel{ "HIGH", "LOW" };

Since: 3.0

The following values are supported:

  • HIGH - for a high quality of service. acknowledgments are used to confirm delivery.
  • LOW - for a low quality of service. packet delivery is best effort

1.3. ResponseResult

Enumeration for result of response.

    enum ResponseResult { "SUCCESS", "ERROR", "RESOURCE_CREATED", "RESOURCE_DELETED", "RESOURCE_CHANGED", "SLOW", "FORBIDDEN" };

Since: 3.0

The following values are supported:

  • SUCCESS - result of response for success
  • ERROR - result of response for something error
  • RESOURCE_CREATED - result of response for resource has created
  • RESOURCE_DELETED - result of response for resource has deleted
  • RESOURCE_CHANGED - result of response for resource has changed
  • SLOW - result of response for slow resource
  • FORBIDDEN - result of response for accessing unauthorized resource

1.4. PresenceResponseResultType

Enumeration for result of presence response.

    enum PresenceResponseResultType { "OK", "STOPPED", "TIMEOUT" };

Since: 3.0

The following values are supported:

  • OK - successful action of presence
  • STOPPED - stopped action of presence
  • TIMEOUT - no response of presence for some time

1.5. PresenceTriggerType

Enumeration for trigger type of presence. It is set only if a PresenceResponseResultType is OK.

    enum PresenceTriggerType { "CREATED", "UPDATED", "DESTROYED" };

Since: 3.0

The following values are supported:

  • CREATED - resource creation operation of server
  • UPDATED - resource update operation of server
  • DESTROYED - resource destruction operation of server

1.6. ConnectivityType

Enumeration for connectivities type of connection.

    enum ConnectivityType { "IP", "PREFER_UDP", "PREFER_TCP", "IPV4_ONLY", "IPV6_ONLY", "ALL" };

Since: 3.0

The following values are supported:

  • IP - Internet Protocol connectivity. IP includes all internet connectivity (UDP, TCP, IPV4, IPV6).
  • PREFER_UDP - UDP is preferred
  • PREFER_TCP - TCP is preferred
  • IPV4_ONLY - Internet Protocol version 4 connectivity only
  • IPV6_ONLY - Internet Protocol version 6 connectivity only
  • ALL - All connectivities

1.7. ResourceInterface

Type of interfaces which can be held in a resource.

    typedef DOMString ResourceInterface;

Since: 3.0

The following values are allowed:

  • "oic.if.baseline" - Interface for default. Applicable methods: GET, UPDATE. All resource has this interface automatically.
  • "oic.if.ll" - Interface which is used to list the references to other resources contained in a resource.
  • "oic.if.b" - Interface which is used to manipulate (GET, PUT, POST, DELETE) a collection of sub-resources at the same time.
  • "oic.mi.grp" - Interface which is used to manipulate (GET, PUT, POST) a group of remote resources.
  • "oic.if.r" - Interface which is used to limit the methods that can be applied to a resource to GET only.

1.8. ObservePolicy

Enumeration for policy of observation.

    enum ObservePolicy { "IGNORE_OUT_OF_ORDER", "ACCEPT_OUT_OF_ORDER" };

Since: 3.0

The following values are supported:

  • IGNORE_OUT_OF_ORDER - observation request for most up-to-date notifications only
  • ACCEPT_OUT_OF_ORDER - observation request for all notifications including stale notifications

1.9. ObserveType

Enumeration for type of observation.

    enum ObserveType { "NO_TYPE", "REGISTER",  "DEREGISTER" };

Since: 3.0

The following values are supported:

  • NO_TYPE - no action of observation
  • REGISTER - action of registering observation
  • DEREGISTER - action of unregistering observation

2. Interfaces

2.1. IotconObject

This interface defines what is instantiated by the Tizen object from the Tizen platform.

    [NoInterfaceObject] interface IotconObject {
        readonly attribute Iotcon iotcon;
    };
    Tizen implements IotconObject;

Since: 3.0

There is a tizen.iotcon object that allows access to the Iotcon API.

2.2. Iotcon

This interface provides access to the IotconObject object.

    [NoInterfaceObject] interface Iotcon {
        attribute DOMString deviceName;

        void initialize(DOMString filePath) raises(WebAPIException);

        Client getClient();

        Server getServer();

        long getTimeout();

        void setTimeout(long timeout) raises(WebAPIException);

        long addGeneratedPinListener(GeneratedPinCallback successCallback) raises(WebAPIException);

        void removeGeneratedPinListener(long watchId) raises(WebAPIException);
    };

Since: 3.0

Attributes

  • DOMString deviceName

    The device name of this application.

    Since: 3.0

Methods

initialize

Connects to the iotcon service. Call this function to start Iotcon.

void initialize(DOMString filePath);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Recommends to use application local file for CBOR file path.
If you want to know about iotivity security in detail, See iotivity security.

Parameters:

  • filePath: The CBOR(Concise Binary Object Representation) file path for handling secure virtual resources.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 try {
     var cborPath = "App_installed_fullpath/iotcon-test.dat"
     tizen.iotcon.initialize(cborPath);
     tizen.iotcon.deviceName = "my_test";
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

getClient

Returns object of Client singleton, which provides methods for working with remote resources.

Client getClient();
             

Since: 3.0

Return value:

Client The Client object.

Code example:

 try {
     var cborPath = "App_installed_fullpath/iotcon-test.dat"
     tizen.iotcon.initialize(cborPath);
     tizen.iotcon.deviceName = "my_test";
     var iotClient = tizen.iotcon.getClient();
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

getServer

Returns the Server object, which provides methods for managing resources on current device.

Server getServer();
             

Since: 3.0

Return value:

Server The Server object.

Code example:

 try {
     var cborPath = "App_installed_fullpath/iotcon-test.dat"
     tizen.iotcon.initialize(cborPath);
     tizen.iotcon.deviceName = "my_test";
     var iotServer = tizen.iotcon.getServer();
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

getTimeout

Returns the number of seconds set as the timeout threshold of asynchronous API.

long getTimeout();
             

Since: 3.0

This method returns the common timeout value for methods:
findDeviceInfo
findPlatformInfo
findResource
methodGet
methodPut
methodPost
methodDelete
All asynchronous APIs have the same timeout value, there is no way to have different timeout values at each method. Without a response after the specified time, the mentioned methods would trigger an error callback with TimeoutError.

Return value:

long The timeout value in seconds.

Code example:

 tizen.iotcon.setTimeout(60);
 var timeout  = tizen.iotcon.getTimeout();
 console.log("timeout value is " + timeout);
 

Output example:

timeout value is 60

setTimeout

Sets the timeout value, in seconds, of asynchronous APIs.

void setTimeout(long timeout);
             

Since: 3.0

The timeout value is common for methods:
findDeviceInfo
findPlatformInfo
findResource
methodGet
methodPut
methodPost
methodDelete
All asynchronous APIs have the same timeout value, there is no way to have different timeout values at each method. Without a response after the specified time, the mentioned methods would trigger an error callback with TimeoutError.

Parameters:

  • timeout: Timeout value in seconds (value must range between 1 and 3600 inclusive). The default value is 30.

Exceptions:

  • WebAPIException
    • with error type InvalidValuesError, if any input parameter does not contain a valid value.

Code example:

 tizen.iotcon.setTimeout(60);
 var timeout  = tizen.iotcon.getTimeout();
 console.log("timeout value is " + timeout);
 

Output example:

timeout value is 60

addGeneratedPinListener

Adds a listener to receive generated random pin from provisioning tool .

long addGeneratedPinListener(GeneratedPinCallback successCallback);
             

Since: 3.0

Remark : Listener's callback only be invoked when provisioning tool tries to register this device using random pin based.
If you want to know about provisioning tool and random pin, See iotivity provisioning.

Parameters:

  • successCallback: The method to be invoked when random pin is generated.

Return value:

long The watchID which can be used to remove the listener

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type AbortError, If the operation has been stopped.

Code example:

   var watchId
   function RandomPinSuccess(pin){
       console.log("Pin code : " + pin);
       tizen.iotcon.removeGeneratedPinListener(watchId);
    }

     var cborPath = "App_installed_fullpath/iotcon-test.dat"
     tizen.iotcon.initialize(cborPath);
     watchId =tizen.iotcon.addGeneratedPinListener(RandomPinSuccess);
 

Output example:

Pin code : 73883075

removeGeneratedPinListener

Unregisters the listener and stops receiving generated random pin.

void removeGeneratedPinListener(long watchId);
             

Since: 3.0

Remark : Example of using can be find at addGeneratedPinListener code example.

Parameters:

  • watchId: The watchID identifier returned by the addGeneratedPinListener() method.

Exceptions:

  • WebAPIException
    • with error type AbortError, If the operation has been stopped.

2.3. Client

The Client provides API for client side.

    [NoInterfaceObject] interface Client {

        void findResource(DOMString? hostAddress,
                          Query?  query,
                          ConnectivityType connectivityType,
                          FoundResourceSuccessCallback successCallback,
                          optional ErrorCallback? errorCallback) raises(WebAPIException);

        long addPresenceEventListener(DOMString? hostAddress,
                                      ResourceType? resourceType,
                                      ConnectivityType connectivityType,
                                      PresenceEventCallback successCallback) raises(WebAPIException);

        void removePresenceEventListener(long watchId) raises(WebAPIException);

        void findDeviceInfo(DOMString? hostAddress,
                            Query?  query,
                            ConnectivityType connectivityType,
                            FoundDeviceInfoSuccessCallback successCallback,
                            optional ErrorCallback? errorCallback) raises(WebAPIException);

        void findPlatformInfo(DOMString? hostAddress,
                              Query?  query,
                              ConnectivityType connectivityType,
                              FoundPlatformInfoSuccessCallback successCallback,
                              optional ErrorCallback? errorCallback) raises(WebAPIException);
    };

Since: 3.0

Methods

findResource

Finds resources using host address and resource type.

void findResource(DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundResourceSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: If any system error is invoked

remarks hostAddress should be in the format coap://address:port. For example "coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345" or "coaps://192.168.1.10:12345".

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • hostAddress [nullable]: The address of host, null indicates that this is for all nodes(multicast).
  • query [nullable]: The query specified as a filter for the resource. null means no filter.
  • connectivityType: The connectivity type.
  • successCallback: The method to invoked when a resource is found.
  • errorCallback [optional] [nullable]: The method to invoke on failure of finding resource.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 function onerror(err) {
     console.log("Failed to find resource: " + err.message);
 }

 function foundSuccess(resource) {
     if(resource) {
         console.log("######## Found a resource ########")
         console.log("URI: " + resource.uriPath);
         console.log("Host Address: " + resource.hostAddress);
         console.log("Device ID: " + resource.deviceId);
         var resourceTypes = resource.resourceTypes;
         console.log("Resource Types: ");
         for(var index in resourceTypes) {
             console.log("    " + resourceTypes[index]);
         }
         var resourceInterfaces = resource.resourceInterfaces;
         console.log("Resource interfaces: ");
         for(var index in resourceInterfaces) {
             console.log("    " + resourceInterfaces[index]);
         }
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

######## Found a resource ########
URI: /door
Host Address: coaps://192.168.0.10:12345
Device ID: 3f58ff10-fc23-444c-9e42-e15b295722a7
Resource types:
core.door
Resource interfaces:
oic.if.b

addPresenceEventListener

Adds a listener to receive a presence events from the server. A server sends presence events when starts or stops presence.

long addPresenceEventListener(DOMString? hostAddress, ResourceType? resourceType, ConnectivityType connectivityType, PresenceEventCallback successCallback);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • hostAddress [nullable]: The address of host, null indicates that this is for all nodes(multicast).
  • resourceType [nullable]: The resource type specified as a filter for the resource. The characters should have length less than or equal to 61 and start with a lowercase alphabetic. followed by a sequence of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.
  • connectivityType: The connectivity type.
  • successCallback: The method to invoked when a presence event is received.

Return value:

long The watchID which can be used to remove the listener

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 var client;
 var watchID;
 var connectivityType = "IP";

 function presenceSuccess(presenceResponse) {
     console.log("######## Get a presence response ########");
     if(presenceResponse.resultType != "OK") {
         console.log("the result is not OK")
         return;
     }
     console.log("Trigger type: " + presenceResponse.triggerType);
     console.log("Host address: " + presenceResponse.hostAddress);
     console.log("Connectivity type: " + presenceResponse.connectivityType);
     console.log("Presence resource type: " + presenceResponse.resourceType);

     client.removePresenceEventListener(watchID);
 }

 try {
     client = tizen.iotcon.getClient();
     watchID = client.addPresenceEventListener(null, null, connectivityType, presenceSuccess);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

######## Get a presence response ########
Trigger type: UPDATED
Host address: coaps://192.168.0.10:12345
Connectivity type: IP
Resource type: oic.wk.ad

removePresenceEventListener

Unregisters a presence event listener.

void removePresenceEventListener(long watchId);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Example of using can be find at addPresenceEventListener code example.

Parameters:

  • watchId: The watchID identifier returned by the addPresenceEventListener() method.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

findDeviceInfo

Gets the device information of remote server.

void findDeviceInfo(DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundDeviceInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: If any system error is invoked

remarks hostAddress should be in the format coap://address:port. For example "coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345" or "coaps://192.168.1.10:12345".

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • hostAddress [nullable]: The address of host, null indicates that this is for all nodes(multicast).
  • query [nullable]: The query specified as a filter. null means no filter.
  • connectivityType: The connectivity type.
  • successCallback: The method to invoked when device information is found.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting device information.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 // hostDeviceIpAddress should be a valid IP address
 var hostDeviceIpAddress = "coaps://192.168.0.10:12345";
 var connectivityType = "IP";
 var query = { resourceType: "core.door" };

 function onerror(err) {
     console.log("Failed to find resource: " + err.message);
 }

 function foundSuccess(deviceInfo) {
     if(deviceInfo) {
         console.log("######## Get a device info ########");
         console.log("Name: " + deviceInfo.deviceName);                     // human friendly name for device.
         console.log("Spec version: " + deviceInfo.specVersion);            // spec version of the core specification.
         console.log("ID: " + deviceInfo.oicDeviceId);                      // unique identifier for OIC device.
         console.log("Data model version: " + deviceInfo.dataModelVersion); // version of the specs this device data model is implemented to.
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     client.findDeviceInfo(hostDeviceIpAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

######## Get a device info ########
Name: Tizen
Spec version: core.1.0.0
ID: 3f58ff10-fc23-444c-9e42-e15b295722a7
Data model version: res.1.0.0

findPlatformInfo

Gets the platform information of remote server.

void findPlatformInfo(DOMString? hostAddress, Query? query, ConnectivityType connectivityType, FoundPlatformInfoSuccessCallback successCallback, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: In any system error is invoked

remarks hostAddress should be in the format coap://address:port. For example "coaps://[fe80::ae5a:14ff:fe24:b8fe]:12345" or "coaps://192.168.1.10:12345".

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • hostAddress [nullable]: The address of host, null indicates that this is for all nodes(multicast).
  • query [nullable]: The query specified as a filter. null means no filter.
  • connectivityType: The connectivity type.
  • successCallback: The method to invoked when platform information is found.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting platform information.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 var hostDeviceIpAddress = "coaps://192.168.0.10:12345";
 var connectivityType = "IP";
 var query = { resourceType: "core.door" };

 function onerror(err) {
     console.log("Failed to find resource: " + err.message);
 }

 function foundSuccess(platformInfo) {
     console.log("######## Get a platform info ########");
     console.log("ID: " + platformInfo.platformId);
     console.log("Manufacturer name: " + platformInfo.manufacturerName);
     console.log("Manufacturer URL: " + platformInfo.manufacturerUrl);
     console.log("Model number: " + platformInfo.modelNumber);
     console.log("Date of manufacture: " + platformInfo.manufactureDate);
     console.log("Platform version: " + platformInfo.platformVersion);
     console.log("OS version: " + platformInfo.operatingSystemVersion);
     console.log("Hardware version: " + platformInfo.hardwareVersion);
     console.log("Firmware version: " + platformInfo.firmwareVersion);
     console.log("Support URL: " + platformInfo.supportUrl);
     console.log("System time: " + platformInfo.systemTime);
 }

 try {
     var client = tizen.iotcon.getClient();
     client.findPlatformInfo(hostDeviceIpAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

######## Get a platform info ########
ID: Tizen
Manufacturer name: Tizen
Manufacturer URL:
Model number: tm1
Date of manufacture:
Platform version: 3.0
OS version:
Hardware version:
Firware version: tizen-mobile_20160220.2
Support URL:
System time:

2.4. Server

Provides functions for creating resource, registering a resource, handling request from client .

    [NoInterfaceObject] interface Server {

        Resource[] getResources() raises(WebAPIException);

        Resource createResource(DOMString uriPath, ResourceType[] resourceTypes, ResourceInterface[] resourceInterfaces,
                                RequestCallback listener, optional ResourcePolicy policy) raises(WebAPIException);

        void removeResource(Resource resource) raises(WebAPIException);

        void startPresence(unsigned long timeToLive) raises(WebAPIException);

        void stopPresence() raises(WebAPIException);
    };

Since: 3.0

A Resource is a component in a server that can be viewed and controlled by another client. There are different resource types, for example a temperature sensor, a light controller etc.

Methods

getResources

Returns an array of resources which are registered on the server.

Resource[] getResources();
             

Since: 3.0

Return value:

Array of Resource objects registered on server.

Exceptions:

  • WebAPIException
    • with error type AbortError, if the operation has been stopped.

Code example:

 var server = tizen.iotcon.getServer();
 var resources = server.getResources();
 

createResource

Creates a resource and registers the resource on server.

Resource createResource(DOMString uriPath, ResourceType[] resourceTypes, ResourceInterface[] resourceInterfaces, RequestCallback listener, optional ResourcePolicy policy);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • uriPath: The resource URI.
  • resourceTypes: A list of types in this resource.
  • resourceInterfaces: A list of interfaces in this resource.
  • listener: The request listener, which is called when server receives request from client.
  • policy [optional]: The policy for new Resource object.

Return value:

Instance of Resource object.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 var server = tizen.iotcon.getServer();
 var doorResource;
 var uriPath = "/door";
 var resourceTypes = ["core.door"];
 var resourceInterfaces = ["oic.if.b"];
 var attributes = { openstate : 'open' };
 var policy = {
     isObservable : true,
     isDiscoverable : true
 };

 var requestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           //add request handle code
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           //add request handle code
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving");
           //add request handle code
       }
 }

 doorResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
 

removeResource

Removes the resource and unregisters it from server.

void removeResource(Resource resource);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • resource: The resource object to delete.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 var resource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
 server.removeResource(resource);
 

startPresence

Starts sending presence event of server. Server can send presence event to client when become online for the first time or come back from offline to online.

void startPresence(unsigned long timeToLive);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : If Server doesn't call startPresence(), client can't get presence event with addPresenceEventListener().

Remark : If timeToLive is 0, server will set default value as 60 seconds. If timeToLive is bigger than maximum seconds, server will set maximum value as (60 * 60 * 24) seconds (24 hours).

Parameters:

  • timeToLive: The interval of announcing presence in seconds(value must range between 1 and 60 * 60 * 24 inclusive). default value is 60 seconds.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

Code example:

 var server = tizen.iotcon.getServer();
 server.startPresence(60);

/* Do something */
 server.stopPresence();
 

stopPresence

Stops sending presence announcement of a server.

void stopPresence();
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Example of using can be find at startPresence code example.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, if the operation has been stopped.

2.5. RemoteResource

This interface provides API to manage remote resource for client side.

    interface RemoteResource {

        readonly attribute DOMString uriPath;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute DOMString hostAddress;

        readonly attribute ResourceType[] resourceTypes;

        readonly attribute ResourceInterface[] resourceInterfaces;

        readonly attribute boolean isObservable;

        readonly attribute boolean isDiscoverable;

        readonly attribute boolean isActive;

        readonly attribute boolean isSlow;

        readonly attribute boolean isSecure;

        readonly attribute boolean isExplicitDiscoverable;

        readonly attribute DOMString deviceId;

        readonly attribute DOMString deviceName;

        attribute IotconOption[]? options;

        readonly attribute Representation? cachedRepresentation;

        attribute long timeInterval;

        void methodGet(RemoteResourceResponseCallback responseCallback,
                       optional Query? query,
                       optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodPut(Representation representation,
                       RemoteResourceResponseCallback responseCallback,
                       optional Query? query,
                       optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodPost(Representation representation,
                        RemoteResourceResponseCallback responseCallback,
                        optional Query? query,
                        optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodDelete(RemoteResourceResponseCallback responseCallback,
                          optional ErrorCallback? errorCallback) raises(WebAPIException);

        void startObserving(ObservePolicy observePolicy,
                            RemoteResourceResponseCallback successCallback,
                            optional Query? query) raises(WebAPIException);

        void stopObserving() raises(WebAPIException);

        void startCaching(optional CacheUpdatedCallback? updatedCallback) raises(WebAPIException);

        void stopCaching() raises(WebAPIException);

        void setResourceStateChangeListener(ResourceStateChangeCallback successCallback) raises(WebAPIException);

        void unsetResourceStateChangeListener() raises(WebAPIException);
    };

Since: 3.0

Attributes

  • readonly DOMString uriPath

    The resource URI.

    Since: 3.0

  • readonly ConnectivityType connectivityType

    It is connectivity type.

    Since: 3.0

  • readonly DOMString hostAddress

    The host address

    Since: 3.0

  • readonly ResourceType[] resourceTypes

    A list of types in this resource

    Since: 3.0

  • readonly ResourceInterface[] resourceInterfaces

    A list of interfaces in the resource.

    Since: 3.0

  • readonly boolean isObservable

    Indicates if the resource is observable or not

    Since: 3.0

  • readonly boolean isDiscoverable

    Indicates if the resource is discoverable or not

    Since: 3.0

  • readonly boolean isActive

    Indicates if the resource is initialized and activated or not

    Since: 3.0

  • readonly boolean isSlow

    Indicates if the resource takes some delay to respond or not

    Since: 3.0

  • readonly boolean isSecure

    Indicates if the resource is secure or not

    Since: 3.0

  • readonly boolean isExplicitDiscoverable

    Indicates if the resource is is allowed to be discovered only if discovery request contains an explicit querystring or not

    Since: 3.0

  • readonly DOMString deviceId

    The device unique id. this is unique per-server independent on how it was discovered.

    Since: 3.0

  • readonly DOMString deviceName

    The device name of the remote resource.

    Since: 3.0

  • options [nullable]

    The option for managing vendor specific option of COAP packet.

    Since: 3.0

    Remark : Options can have up to 2 IotconOption.

  • readonly Representation cachedRepresentation [nullable]

    The cached representation of remote resource.

    Since: 3.0

  • long timeInterval

    The time interval in seconds for monitoring state (registered with setResourceStateChangeListener() ) and caching (registered with startCaching() ). Provided value must be in range from 1 to 3600 inclusive. The default value is 10 seconds.

    Since: 3.0

Methods

methodGet

Gets the attributes of a resource.

void methodGet(RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: In any system error is invoked

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • responseCallback: The method to invoked when a client receive get response.
  • query [optional] [nullable]: The query to send to server. The resource request handler should handle this value.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting response.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var query = {};

 function onerror(err) {
     console.log("Error occured: " + err.message);
 }

 function onresponse(remoteResponse) {
     if(remoteResponse.result != "SUCCESS") {
         console.log("the result is not SUCCESS");
         return;
     }
     var repr =  remoteResponse.representation;
     console.log("Resource attributes: ")
     for(var key in repr.attributes) {
         console.log("    key: " + key + ", value: " + repr.attributes[key]);
     }
 }

 function foundSuccess(resource) {
     if(resource){
         query["filter"] =  {openstate: 'open'};
         resource.methodGet(onresponse, query, onerror);
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log (err.name +': ' + err.message);
 }
 

Output example:

Resource attributes:
key: openstate, value: open

methodPut

Puts the representation of a resource for update.

void methodPut(Representation representation, RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: In any system error is invoked

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • Representation: The payload of a request or a response.
  • responseCallback: The method to invoked when a client receive get response.
  • query [optional] [nullable]: The query to send to server. The resource request handler should handle this value.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting response.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var query = {};
 var representation;
 var uriPath = "/door";

 function onerror(err) {
     console.log("Error occured: " + err.message);
 }

 function onresponse(remoteResponse) {
     console.log("result is "+remoteResponse.result );
     var repr =  remoteResponse.representation;
     console.log("representation attributes: ")
     for(var key in repr.attributes) {
         console.log("    key: " + key + ", value: " + repr.attributes[key]);
     }
 }

 function foundSuccess(resource) {
     if(resource){
         query["filter"] =  {openstate: 'open'};
         representation = new tizen.Representation(uriPath);
         representation.resourceTypes = ["core.door"];
         representation.attributes = {openstate : 'closed'};
         resource.methodPut(representation, onresponse, query, onerror);
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

result is RESOURCE_CHANGED
representation attributes:
key: openstate, value: closed

methodPost

Posts the representation of a resource for create.

void methodPost(Representation representation, RemoteResourceResponseCallback responseCallback, optional Query? query, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: In any system error is invoked

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • Representation: The payload of a request or a response.
  • responseCallback: The method to invoked when a client receive get response.
  • query [optional] [nullable]: The query to send to server. The resource request handler should handle this value.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting response.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var representation;
 var uriPath = "/door";

 function onerror(err) {
     console.log("Error occured: " + err.message);
 }

 function onresponse(remoteResponse) {
     console.log("result is "+remoteResponse.result );
     var repr =  remoteResponse.representation;
     console.log("representation attributes: ")
     for(var key in repr.attributes) {
         console.log("    key: " + key + ", value: " + repr.attributes[key]);
     }
 }

 function foundSuccess(resource) {
     if(resource){
         representation = new tizen.Representation(uriPath);
         representation.resourceTypes = ["core.door"];
         representation.attributes = {openstate: 'closed'};
         resource.methodPost(representation, onresponse, null, onerror);
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

result is RESOURCE_CHANGED
representation attributes:
key: openstate, value: closed

methodDelete

Deletes the remote resource.

void methodDelete(RemoteResourceResponseCallback responseCallback, optional ErrorCallback? errorCallback);
             

Since: 3.0

The ErrorCallback is launched with these error types:

  • TimeoutError: If there is no resource or response within timeout value.
  • AbortError: In any system error is invoked

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • responseCallback: The method to invoked when a client receive get response.
  • errorCallback [optional] [nullable]: The method to invoke on failure of getting response.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 function onerror(err) {
     console.log("Error occured: " + err.message);
 }

 function onresponse(remoteResponse) {
     if(remoteResponse.result == "RESOURCE_DELETED" || remoteResponse.result == "SUCCESS") {
         console.log("Successfully deleted");
     }

 function foundSuccess(resource) {
     if(resource){
         resource.methodDelete(onresponse, onerror);
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log (err.name +': ' + err.message);
 }
 

Output example:

Successfully deleted

startObserving

Sets the listener to receive notification about attribute change of remote resource. When server sends notification message, successCallback will be called.

void startObserving(ObservePolicy observePolicy, RemoteResourceResponseCallback successCallback, optional Query? query);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • observePolicy: The policy of observation.
  • successCallback: The method to invoked when the resource receive notification message.
  • query [optional] [nullable]: The query to send to server. The resource request handler should handle this value.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var doorResource;

 function onchanged(remoteResponse) {
     if(remoteResponse.result == "SUCCESS") {
         var attributes = remoteResponse.representation.attributes;
         console.log("start observing, door is " + attributes["openstate"]);
     }
     doorResource.stopObserving();
 }

 function foundSuccess(resource) {
     if(resource) {
         if(resource.uriPath == "/door") {
             doorResource = resource;
             try {
                 doorResource.startObserving("IGNORE_OUT_OF_ORDER", onchanged);
             } catch(err) {
                 console.log(err.name + ': ' + err.message);
             }
         }
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Output example:

start observing, door is open

stopObserving

Unregisters the listener. so stop receiving notification about attribute change of remote resource.

void stopObserving();
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Example of using can be find at startObserving code example.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

startCaching

Starts caching of a remote resource. cached representation is updated when remote resource is changed.

void startCaching(optional CacheUpdatedCallback? updatedCallback);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • updatedCallback [optional] [nullable]: The method to invoked when the remote resource is changed.

Exceptions:

  • WebAPIException
    • with error type InvalidStateError, this error occur when already started.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var resource;

 function onerror(err) {
     console.log("Error occured: " + err.message);
 }

 function onupdated(representation) {
     console.log("######## updated representation ########");
     for(var key in representation.attributes) {
         console.log("key: " + key + ", value: " + representation.attributes[key]);
     }
     resource.stopCaching();
 }

 function foundSuccess(remoteResource) {
     if(remoteResource) {
         resource = remoteResource;
         remoteResource.startCaching(onupdated);   //start caching
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log (err.name +': ' + err.message);
 }
 

Output example:

######## updated representation ########
key: openstate, value: open

stopCaching

Stops caching of a remote resource.

void stopCaching();
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Example of using can be find at startCaching code example.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped

setResourceStateChangeListener

Sets a listener to monitor the state of the remote resource.

void setResourceStateChangeListener(ResourceStateChangeCallback successCallback);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • successCallback: The method to invoked when remote resource's state is changed, registered callbacks will be called in turn. Internally, it checks the state of resource, periodically. Thus, it may not receive the state, immediately.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var doorResource;

 function onchanged(isAlive) {
     if (isAlive == true) {
         console.log("Remote resource is alive");
     } else {
         console.log("Remote resource is lost");
     }
     doorResource.unsetResourceStateChangeListener();
 }

 function foundSuccess(resource) {
     if(resource) {
         if(resource.uriPath == "/door") {
             try {
                 resource.setResourceStateChangeListener(onchanged);
             } catch(err) {
                 console.log(err.name + ': ' + err.message);
             }
         }
     }
 }

 try {
     var client = tizen.iotcon.getClient();
     var hostAddress = null;
     var query = { resourceType: "core.door" };
     var connectivityType = "IP";
     client.findResource(hostAddress, query, connectivityType, foundSuccess, onerror);
 } catch(err) {
     console.log (err.name +': ' + err.message);
 }
 

Output example:

Remote resource is alive

unsetResourceStateChangeListener

Unsets the listener to stop monitoring the state of the remote resource.

void unsetResourceStateChangeListener();
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Remark : Example of using can be find at setResourceStateChangeListener code example.

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

2.6. ResourcePolicy

The ResourcePolicy dictionary specifies resource attributes upon resource creation.

    dictionary ResourcePolicy {
        boolean isObservable;

        boolean isDiscoverable;

        boolean isActive;

        boolean isSlow;

        boolean isSecure;

        boolean isExplicitDiscoverable;
    };

Since: 3.0

This dictionary is used to input parameters when resources are created.

Dictionary members

boolean isObservable

Indicates resource that is allowed to be observed.

The default value is false

Since: 3.0

boolean isDiscoverable

Indicates resource that is allowed to be discovered.

The default value is true

Since: 3.0

boolean isActive

Indicates resource initialized and activated.

The default value is false

Since: 3.0

boolean isSlow

Indicates resource which takes some delay to respond.

The default value is false

Since: 3.0

boolean isSecure

Indicates secure resource.

The default value is false

Since: 3.0

boolean isExplicitDiscoverable

When this value is set true, the resource is allowed to be discovered only if discovery request contains an explicit querystring.

The default value is false

Since: 3.0

2.7. Resource

This interface provides API to manage resource for server side.

    [NoInterfaceObject] interface Resource {

        readonly attribute DOMString uriPath;

        readonly attribute ResourceType[] resourceTypes;

        readonly attribute ResourceInterface[] resourceInterfaces;

        readonly attribute boolean isObservable;

        readonly attribute boolean isDiscoverable;

        readonly attribute boolean isActive;

        readonly attribute boolean isSlow;

        readonly attribute boolean isSecure;

        readonly attribute boolean isExplicitDiscoverable;

        readonly attribute Resource[] resources;

        readonly attribute long[] observerIds;

        attribute object? attributes;

        void notify(QosLevel qosLevel, optional long[]? observerIds) raises(WebAPIException);

        void addResourceTypes(ResourceType[] types) raises(WebAPIException);

        void addResourceInterface(ResourceInterface interface) raises(WebAPIException);

        void addChildResource(Resource resource) raises(WebAPIException);

        void removeChildResource(Resource resource) raises(WebAPIException);

        void setRequestListener(RequestCallback listener) raises(WebAPIException);

        void unsetRequestListener();
    };

Since: 3.0

Attributes

  • readonly DOMString uriPath

    The resource URI.

    Since: 3.0

  • readonly ResourceType[] resourceTypes

    A list of types in this resource.

    Since: 3.0

  • readonly ResourceInterface[] resourceInterfaces

    A list of interfaces in the resource.

    Since: 3.0

  • readonly boolean isObservable

    Indicates if the resource is observable or not

    Since: 3.0

  • readonly boolean isDiscoverable

    Indicates if the resource is discoverable or not

    Since: 3.0

  • readonly boolean isActive

    Indicates if the resource is initialized and activated or not

    Since: 3.0

  • readonly boolean isSlow

    Indicates if the resource takes some delay to respond or not

    Since: 3.0

  • readonly boolean isSecure

    Indicates if the resource is secure or not

    Since: 3.0

  • readonly boolean isExplicitDiscoverable

    Indicates if the resource is is allowed to be discovered only if discovery request contains an explicit querystring or not

    Since: 3.0

readonly Resource[] resources

A list of childs of this resource.

Since: 3.0

readonly long[] observerIds

A list of observation IDs of this resource.

Since: 3.0
  • object attributes [nullable]

    A lists of attributes of this resource.

    Since: 3.0

Methods

notify

Notifies specific clients that resource's attributes have been changed.

void notify(QosLevel qosLevel, optional long[]? observerIds);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • qosLevel: The quality of service level.
  • observerIds [optional] [nullable]: A list of observer id

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type InvalidValuesError, if any input parameter does not contain a valid value.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 resource.attributes = {openstate: 'open'};
 resource.notify("LOW", resource.observerIds);
 

addResourceTypes

Adds resource type to this resource.

void addResourceTypes(ResourceType[] types);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • types: An array of types to be added to resource.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var server = tizen.iotcon.getServer();
 var uriPath = "/door";
 var resourceTypes = ["core.door"];
 var resourceInterfaces = ["oic.if.b"];
 var resource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);

 var types = [ "org.tizen.door"];
 resource.addResourceTypes(types);
 

addResourceInterface

Adds resource interface to this resource.

void addResourceInterface(ResourceInterface interface);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • interface: The interface to be added to resource.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var resource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);

 var interface = "oic.if.ll";
 resource.addResourceInterface(interface);
 

addChildResource

Adds child resource into the parent resource.

void addChildResource(Resource resource);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • resource: The child resource to be added to the parent resource.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var doorResource;
 var lockResource;

 var uriPath = "/door";
 var resourceTypes = ["core.door"];
 var resourceInterfaces : ["oic.if.b"];
 var doorAttributes = { openstate : 'open' };
 var requestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = doorResource.attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           //add request handle code
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           //add request handle code
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving");
           //add request handle code
       }
 }

 doorResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
 doorResource.attributes = doorAttributes;

 uriPath = "/door/lock";
 resourceTypes = ["core.lock"];
 resourceInterfaces : ["oic.if.baseline"];
 var lockAttributes = { lockstate : 'closed' };
 policy = {
     isObservable : true,
     isDiscoverable : true
 };
 var lockRequestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(lockResource.uriPath);
               representation.resourceTypes =lockResource.resourceTypes;
               representation.resourceInterfaces = lockResource.resourceInterfaces;
               representation.attributes = lockResource.attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           //add request handle code
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           //add request handle code
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving");
           //add request handle code
       }
 }

 lockResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, lockRequestListener, policy);
 lockResource.attributes = lockAttributes;

 doorResource.addChildResource(lockResource);
 

removeChildResource

Removes child resource from the parent resource.

void removeChildResource(Resource resource);
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Parameters:

  • resource: The child resource to be removed from the parent resource.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

    • with error type InvalidValuesError, if the resource does not have the input child resource.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 var lockResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
 doorResource.addChildResource(lockResource);
 doorResource.removeChildResource(lockResource);
 

setRequestListener

Sets the listener for request from client.

void setRequestListener(RequestCallback listener);
             

Since: 3.0

Parameters:

  • listener: request listener to set.

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.

Code example:

 var server;
 var doorResource;

 var requestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = doorResource.attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           //add request handle code
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           //add request handle code
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving");
           //add request handle code
       }
 }

 var newRequestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = doorResource.attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           var response = new tizen.Response(request);
           try {
               doorResource.attributes = request.representation.attributes;
               response.representation = request.representation;
               response.result = "RESOURCE_CHANGED";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = doorResource.attributes;
               response.representation = representation;
               response.result = "RESOURCE_DELETED";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
           server.removeResource(doorResource);
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving observeType:" +observeType + ", observeId:" + observeId);
       }
 }

 try {
     server = tizen.iotcon.getServer();
     var uriPath = "/door";
     var resourceTypes = ["core.door"];
     var resourceInterfaces = ["oic.if.b"];
     var attributes = {openstate : 'open' };
     var policy = {
       isObservable : true,
       isDiscoverable : true
     };

     doorResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
     doorResource.attributes =  attributes;
     doorResource.setRequestListener(newRequestListener);
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

unsetRequestListener

Remove the listener.

void unsetRequestListener();
             

Since: 3.0

Remark : Example of using can be find at setRequestListener code example.

2.8. Representation

The Representation Interface contains information of a resource. It can be used to communicate between a client and a server.

    [Constructor(DOMString uriPath)]
    interface Representation {

        attribute DOMString uriPath;

        attribute ResourceType[] resourceTypes;

        attribute ResourceInterface[] resourceInterfaces;

        attribute object? attributes;

        attribute Representation[]? children;
    };

Since: 3.0

Code example:

 var uriPath = "/door";

 // construct an Representation object with uriPath.
 var representation = new tizen.Representation(uriPath);
 

Constructors

Representation(DOMString uriPath);

Attributes

  • DOMString uriPath

    The resource URI.

    Since: 3.0

  • ResourceType[] resourceTypes

    A list of types in this resource

    Since: 3.0

  • ResourceInterface[] resourceInterfaces

    A list of interfaces in the resource.

    Since: 3.0

  • object attributes [nullable]

    A lists of attribute in this resource.

    Since: 3.0

  • Representation[] children [nullable]

    the representations belong to the representation as children.

    Since: 3.0

2.9. PresenceResponse

This interface provides API to manage remote resource for client side.

    [NoInterfaceObject] interface PresenceResponse {

        readonly attribute DOMString hostAddress;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute ResourceType? resourceType;

        readonly attribute PresenceResponseResultType resultType;

        readonly attribute PresenceTriggerType? triggerType;
    };

Since: 3.0

Attributes

  • readonly DOMString hostAddress

    The host address of the presence.

    Since: 3.0

  • readonly ConnectivityType connectivityType

    The connectivity type of the presence.

    Since: 3.0

  • readonly ResourceType resourceType [nullable]

    The resource type of the presence.

    Since: 3.0

  • readonly PresenceResponseResultType resultType

    The results type of presence.

    Since: 3.0

  • readonly PresenceTriggerType triggerType [nullable]

    The trigger type of presence. It is set only if a response result type is "OK".

    Since: 3.0

2.10. Query

The Query dictionary provides a query.

    dictionary Query {

        ResourceType? resourceType;

        ResourceInterface? resourceInterface;

        object? filter;
    };

Since: 3.0

Code example:

 var filter = {"openstate": "open"};
 var query = {
     resourceType: "core.door",
     resourceInterface: "oic.if.b"
 }
 query["filter"] = filter;
 

Dictionary members

ResourceType? resourceType

resourceType The resource type specified as a filter for the resource.

Since: 3.0

ResourceInterface? resourceInterface

resourceInterfaces The resource interface specified as a filter for the resource.

Since: 3.0

object? filter

filter The query filter consists of key and string data.

Since: 3.0

2.11. IotconOption

The IotconOption Interface provides vendor specific options of COAP packet.

    [Constructor(unsigned long id, DOMString data)]
    interface IotconOption {

        attribute unsigned long id;

        attribute DOMString data;
    };

Since: 3.0

Code example:

 var option = new tizen.IotconOption(3000, "12345");
 

Constructors

IotconOption(unsigned long id, DOMString data);

Attributes

  • unsigned longid

    The ID of the option. id is always situated between 2048 and 3000.

    Since: 3.0

  • DOMString data

    The string data to add. Length of data is less than or equal to 15.

    Since: 3.0

2.12. Request

The Request interface represents a details from client.

    [NoInterfaceObject] interface Request {

        readonly attribute DOMString  hostAddress;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute Representation? representation;

        readonly attribute IotconOption[] options;

        readonly attribute Query query;
    };

Since: 3.0

Attributes

  • readonly DOMString hostAddress

    The address of host of the request.

    Since: 3.0

  • readonly ConnectivityType connectivityType

    Connectivities type of connection.

    Since: 3.0

  • readonly Representationrepresentation [nullable]

    The request representation.

    Since: 3.0

  • readonly IotconOption[] options

    The option which was sent from client.

    Since: 3.0

    Remark : Options can have up to 2 IotconOption.

  • readonly Query query

    The query parameters from the request.

    Since: 3.0

2.13. Response

The Response Interface holds response from server for specified request of client. It is server-side object, Response on client-side is hold as RemoteResponse object.

    [Constructor(Request request)]
    interface Response {

        readonly attribute Request request;

        attribute ResponseResult result;

        attribute Representation representation;

        attribute IotconOption[]? options;

        void send() raises(WebAPIException);
    };

Since: 3.0

Code example:

 var server;
 var doorResource;

 var requestListener = {
       onget: function(request) {
           console.log("onget");
           var response = new tizen.Response(request);
           try {
               var representation = new tizen.Representation(doorResource.uriPath);
               representation.resourceTypes =doorResource.resourceTypes;
               representation.resourceInterfaces = doorResource.resourceInterfaces;
               representation.attributes = doorResource.attributes;
               response.representation = representation;
               response.result = "SUCCESS";
           } catch(err) {
               console.log(err.name + ": " + err.message);
               response.result = "ERROR";
           }
           response.send();
       },
       onput: function(request) {
           console.log("onput");
           //add request handle code
       },
       onpost: function(request) {
           console.log("onpost");
           //add request handle code
       },
       ondelete: function(request) {
           console.log("ondelete");
           //add request handle code
       },
       onobserving: function(request, observeType, observeId) {
           console.log("onobserving");
           //add request handle code
       }
 }

 try {
     server = tizen.iotcon.getServer();
     var uriPath = "/door";
     var resourceTypes = ["core.door"];
     var resourceInterfaces = ["oic.if.b"];
     var policy = {
        isObservable : true,
        isDiscoverable : true
     };

     doorResource = server.createResource(uriPath, resourceTypes, resourceInterfaces, requestListener, policy);
     doorResource.attributes = {openstate : 'open' };
 } catch(err) {
     console.log(err.name +': ' + err.message);
 }
 

Constructors

Response(Request request);

Attributes

  • readonly Request request

    the request, that server responded.

    Since: 3.0

    Code example:

     var response = new tizen.Response(request);
     
    
  • ResponseResult result

    the result indicates the detailed information about the result of the response to request.

    Since: 3.0

    Code example:

     var result = "SUCCESS";
     var response = new tizen.Response(request);
     response.result = result;
     
    
  • Representation representation

    the representation indicates the information of the resource.

    Since: 3.0

    Code example:

     var uriPath = "/door";
     var representation = new tizen.Representation(uriPath)
     representation.resourceTypes = ["core.door"];
     representation.resourceInterfaces = ["oic.if.b"];
     representation.attributes = {openstate : "open"};
    
     var response = new tizen.Response(request);
     response.representation = representation;
     
    
  • IotconOption[] options [nullable]

    the options indicates the vendor specific options of COAP packet.

    Since: 3.0

    Remark : Options can have up to 2 IotconOption.

Methods

send

Sends the response.

void send();
             

Since: 3.0

Privilege level: public

Privilege: http://tizen.org/privilege/internet

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type AbortError, If the operation has been stopped.

Code example:

 try {
     var uriPath = "/door";
     var representation = new tizen.Representation(uriPath);
     representation.resourceTypes = ["core.door"];
     representation.resourceInterfaces = ["oic.if.b"];
     representation.attributes = {"openstate": "open"};

     var response = new tizen.Response(request);
     response.representation = representation;
     response.result = "SUCCESS";
 } catch(err) {
     console.log(err.name + ': ' + err.message);
     response.result = "ERROR";
 }
 response.send();
 

2.14. RemoteResponse

The RemoteResponse Interface holds response from server for specified request of client, this is client-side version of Response object.

    [NoInterfaceObject] interface RemoteResponse {

        readonly attribute ResponseResult result;

        readonly attribute Representation representation;

        readonly attribute IotconOption[]? options;
    };

Since: 3.0

Attributes

  • readonly ResponseResult result

    the result indicates the detailed information about the result of the response to request.

    Since: 3.0

  • readonly Representationrepresentation

    the representation indicates the information of the resource.

    Since: 3.0

  • readonly IotconOption[] options [nullable]

    the options indicates the vendor specific options of COAP packet.

    Since: 3.0

2.15. DeviceInfo

The DeviceInfo interface describes device properties.

   [NoInterfaceObject] interface DeviceInfo {

        readonly attribute DOMString? deviceName;

        readonly attribute DOMString? specVersion;

        readonly attribute DOMString? oicDeviceId;

        readonly attribute DOMString? dataModelVersion;
   };

Since: 3.0

Attributes

  • readonly DOMString deviceName [nullable]

    The device name

    Since: 3.0

  • readonly DOMString specVersion [nullable]

    The version of core specification.

    Since: 3.0

  • readonly DOMString oicDeviceId [nullable]

    The unique identifier for OIC device.

    Since: 3.0

  • readonly DOMString dataModelVersion [nullable]

    The version of specification which the device's data model is implemented

    Since: 3.0

2.16. PlatformInfo

The PlatformInfo interface describes platform properties.

    [NoInterfaceObject] interface PlatformInfo {

        readonly attribute DOMString? platformId;

        readonly attribute DOMString? manufacturerName;

        readonly attribute DOMString? manufacturerUrl;

        readonly attribute DOMString? modelNumber;

        readonly attribute DOMString? manufactureDate;

        readonly attribute DOMString? platformVersion;

        readonly attribute DOMString? operatingSystemVersion;

        readonly attribute DOMString? hardwareVersion;

        readonly attribute DOMString? firmwareVersion;

        readonly attribute DOMString? supportUrl;

        readonly attribute DOMString? systemTime;
    };

Since: 3.0

Attributes

  • readonly DOMString platformId [nullable]

    The platform identifier

    Since: 3.0

  • readonly DOMString manufacturerName [nullable]

    The name of manufacturer.

    Since: 3.0

  • readonly DOMString manufacturerUrl [nullable]

    The URL of manufacturer.

    Since: 3.0

  • readonly DOMString modelNumber [nullable]

    The model number is designated by manufacturer.

    Since: 3.0

  • readonly DOMString manufactureDate [nullable]

    The manufacture date of device.

    Since: 3.0

  • readonly DOMString platformVersion [nullable]

    The platform version is defined by manufacturer.

    Since: 3.0

  • readonly DOMString operatingSystemVersion [nullable]

    The operating system version.

    Since: 3.0

  • readonly DOMString hardwareVersion [nullable]

    The hardware version.

    Since: 3.0

  • readonly DOMString firmwareVersion [nullable]

    The firmware version.

    Since: 3.0

  • readonly DOMString supportUrl [nullable]

    The URL that points to support information from manufacturer.

    Since: 3.0

  • readonly DOMString systemTime [nullable]

    The System time.

    Since: 3.0

2.17. RequestCallback

The RequestCallback interface that defines the success method to be invoked when a client request is received.

    [Callback=FunctionOnly, NoInterfaceObject] interface RequestCallback {

        void onget(Request request);

        void onput(Request request);

        void onpost(Request request);

        void ondelete(Request request);

        void onobserving(Request request, ObserveType observeType, unsigned long observeId);
    };

Since: 3.0

Remark : Example of using can be find at setRequestListener code example.

Methods

onget

Called when GET request was received.

void onget(Request request);
             

Since: 3.0

Parameters:

  • request: that is request from server side.

onput

Called when PUT request was received.

void onput(Request request);
             

Since: 3.0

Parameters:

  • request: that is request from server side.

onpost

Called when POST request was received.

void onpost(Request request);
             

Since: 3.0

Parameters:

  • request: that is request from server side.

ondelete

Called when DELETE request was received.

void ondelete(Request request);
             

Since: 3.0

Parameters:

  • request: that is request from server side.

onobserving

Called when OBSERVE request was received.

void onobserving(Request request, ObserveType observeType, unsigned long observeId);
             

Since: 3.0

Parameters:

  • request: that is request from server side.
  • observeType: The observation type of the request.
  • observeId: The observation id of the request.

Return value:

boolean true, if the OBSERVE request is successfully handled.

2.18. FoundResourceSuccessCallback

The FoundResourceSuccessCallback interface that defines the success method for Client.findResource().

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundResourceSuccessCallback {

        void onfound(RemoteResource remoteResource);
    };

Since: 3.0

Remark : Example of using can be find at findResource code example.

Methods

onfound

Called when request was received.

void onfound(RemoteResource remoteResource);
             

Since: 3.0

Parameters:

  • remoteResource: remote resource for client side

2.19. PresenceEventCallback

The PresenceEventCallback interface defines the success method to be invoked when client receive presence events from the server.

    [Callback=FunctionOnly, NoInterfaceObject] interface PresenceEventCallback {

        void onreceived(PresenceResponse presenceResponse);
    };

Since: 3.0

Remark : Example of using can be find at addPresenceEventListener code example.

Methods

onreceived

Called when client receive presence events.

void onreceived(PresenceResponse presenceResponse);
             

Since: 3.0

Parameters:

  • presenceResponse: presence events

2.20. FoundDeviceInfoSuccessCallback

The FoundDeviceInfoSuccessCallback interface defines the success method to be invoked when getting the device information is successful.

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundDeviceInfoSuccessCallback {

        void onsuccess(DeviceInfo info);
    };

Since: 3.0

Remark : Example of using can be find at findDeviceInfo code example.

Methods

onsuccess

Called when the device information is received.

void onsuccess(DeviceInfo info);
             

Since: 3.0

Parameters:

  • info: Device information

2.21. FoundPlatformInfoSuccessCallback

The FoundPlatformInfoSuccessCallback interface defines the success method to be invoked when getting the platform information is successful.

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundPlatformInfoSuccessCallback {

        void onsuccess(PlatformInfo info);
    };

Since: 3.0

Remark : Example of using can be find at findPlatformInfo code example.

Methods

onsuccess

Called when the platform information is received.

void onsuccess(PlatformInfo info);
             

Since: 3.0

Parameters:

  • info: Platform information

2.22. RemoteResourceResponseCallback

The RemoteResourceResponseCallback interface defines the success method to be invoked when a client received response.

    [Callback=FunctionOnly, NoInterfaceObject] interface RemoteResourceResponseCallback {

        void onsuccess(RemoteResponse response);
    };

Since: 3.0

Remark : Example of using can be find at methodGet code example.

Methods

onsuccess

Called when the response is received.

void onsuccess(RemoteResponse response);
             

Since: 3.0

Parameters:

  • response: received for client site

2.23. ResourceStateChangeCallback

The ResourceStateChangeCallback interface defines the success method to be invoked when remote resource's state is changed.

    [Callback=FunctionOnly, NoInterfaceObject] interface ResourceStateChangeCallback {

        void onchanged(boolean isAlive);
    };

Since: 3.0

Remark : Example of using can be find at setResourceStateChangeListener code example.

Methods

onchanged

Called when connection change appeared.

void onchanged(boolean isAlive);
             

Since: 3.0

Parameters:

  • isAlive: - state of the remote resource

2.24. CacheUpdatedCallback

The CacheUpdatedCallback interface defines the success method to be invoked when remote resource is changed.

    [Callback=FunctionOnly, NoInterfaceObject] interface CacheUpdatedCallback {

        void onupdated(Representation representation);
    };

Since: 3.0

Remark : Example of using can be find at startCaching code example.

Methods

onupdated

Called when caching is successfully started.

void onupdated(Representation representation);
             

Since: 3.0

Parameters:

  • Representation: - state of the remote resource

2.25. GeneratedPinCallback

The GeneratedPinCallback interface defines the success method to be invoked when random pin is generated.

    [Callback=FunctionOnly, NoInterfaceObject] interface GeneratedPinCallback {

        void onsuccess(DOMString pin);
    };

Since: 3.0

Remark : Example of using can be find at addGeneratedPinListener code example.

Methods

onsuccess

Called when random pin is successfully generated.

void onsuccess(DOMString pin);
             

Since: 3.0

Parameters:

  • pin: - generated random pin

You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API.

To guarantee this application will run on a device with a iotcon, add the below feature declaration to the config file

  • http://tizen.org/feature/iot.ocf

For more information, see Application Filtering.

4. Full WebIDL

module Iotcon {

    typedef DOMString ResourceType;

    enum QosLevel{ "HIGH", "LOW" };

    enum ResponseResult { "SUCCESS", "ERROR", "RESOURCE_CREATED", "RESOURCE_DELETED", "RESOURCE_CHANGED", "SLOW", "FORBIDDEN" };

    enum PresenceResponseResultType { "OK", "STOPPED", "TIMEOUT" };

    enum PresenceTriggerType { "CREATED", "UPDATED", "DESTROYED" };

    enum ConnectivityType { "IP", "PREFER_UDP", "PREFER_TCP", "IPV4_ONLY", "IPV6_ONLY", "ALL" };

    typedef DOMString ResourceInterface;

    enum ObservePolicy { "IGNORE_OUT_OF_ORDER", "ACCEPT_OUT_OF_ORDER" };

    enum ObserveType { "NO_TYPE", "REGISTER",  "DEREGISTER" };

    [NoInterfaceObject] interface IotconObject {
        readonly attribute Iotcon iotcon;
    };

    Tizen implements IotconObject;

    [NoInterfaceObject] interface Iotcon {
        attribute DOMString deviceName;

        void initialize(DOMString filePath) raises(WebAPIException);

        Client getClient();

        Server getServer();

        long getTimeout();

        void setTimeout(long timeout) raises(WebAPIException);

        long addGeneratedPinListener(GeneratedPinCallback successCallback) raises(WebAPIException);

        void removeGeneratedPinListener(long watchId) raises(WebAPIException);
    };

    [NoInterfaceObject] interface Client {

        void findResource(DOMString? hostAddress,
                          Query?  query,
                          ConnectivityType connectivityType,
                          FoundResourceSuccessCallback successCallback,
                          optional ErrorCallback? errorCallback) raises(WebAPIException);

        long addPresenceEventListener(DOMString? hostAddress,
                                      ResourceType? resourceType,
                                      ConnectivityType connectivityType,
                                      PresenceEventCallback successCallback) raises(WebAPIException);

        void removePresenceEventListener(long watchId) raises(WebAPIException);

        void findDeviceInfo(DOMString? hostAddress,
                            Query?  query,
                            ConnectivityType connectivityType,
                            FoundDeviceInfoSuccessCallback successCallback,
                            optional ErrorCallback? errorCallback) raises(WebAPIException);

        void findPlatformInfo(DOMString? hostAddress,
                              Query?  query,
                              ConnectivityType connectivityType,
                              FoundPlatformInfoSuccessCallback successCallback,
                              optional ErrorCallback? errorCallback) raises(WebAPIException);
    };

    [NoInterfaceObject] interface Server {

        Resource[] getResources() raises(WebAPIException);

        Resource createResource(DOMString uriPath, ResourceType[] resourceTypes, ResourceInterface[] resourceInterfaces,
                                RequestCallback listener, optional ResourcePolicy policy) raises(WebAPIException);

        void removeResource(Resource resource) raises(WebAPIException);

        void startPresence(unsigned long timeToLive) raises(WebAPIException);

        void stopPresence() raises(WebAPIException);
    };

    interface RemoteResource {

        readonly attribute DOMString uriPath;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute DOMString hostAddress;

        readonly attribute ResourceType[] resourceTypes;

        readonly attribute ResourceInterface[] resourceInterfaces;

        readonly attribute boolean isObservable;

        readonly attribute boolean isDiscoverable;

        readonly attribute boolean isActive;

        readonly attribute boolean isSlow;

        readonly attribute boolean isSecure;

        readonly attribute boolean isExplicitDiscoverable;

        readonly attribute DOMString deviceId;

        readonly attribute DOMString deviceName;

        attribute IotconOption[]? options;

        readonly attribute Representation? cachedRepresentation;

        attribute long timeInterval;

        void methodGet(RemoteResourceResponseCallback responseCallback,
                       optional Query? query,
                       optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodPut(Representation representation,
                       RemoteResourceResponseCallback responseCallback,
                       optional Query? query,
                       optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodPost(Representation representation,
                        RemoteResourceResponseCallback responseCallback,
                        optional Query? query,
                        optional ErrorCallback? errorCallback) raises(WebAPIException);

        void methodDelete(RemoteResourceResponseCallback responseCallback,
                          optional ErrorCallback? errorCallback) raises(WebAPIException);

        void startObserving(ObservePolicy observePolicy,
                            RemoteResourceResponseCallback successCallback,
                            optional Query? query) raises(WebAPIException);

        void stopObserving() raises(WebAPIException);

        void startCaching(optional CacheUpdatedCallback? updatedCallback) raises(WebAPIException);

        void stopCaching() raises(WebAPIException);

        void setResourceStateChangeListener(ResourceStateChangeCallback successCallback) raises(WebAPIException);

        void unsetResourceStateChangeListener() raises(WebAPIException);
    };

    dictionary ResourcePolicy {
        boolean isObservable;

        boolean isDiscoverable;

        boolean isActive;

        boolean isSlow;

        boolean isSecure;

        boolean isExplicitDiscoverable;
    };

    [NoInterfaceObject] interface Resource {

        readonly attribute DOMString uriPath;

        readonly attribute ResourceType[] resourceTypes;

        readonly attribute ResourceInterface[] resourceInterfaces;

        readonly attribute boolean isObservable;

        readonly attribute boolean isDiscoverable;

        readonly attribute boolean isActive;

        readonly attribute boolean isSlow;

        readonly attribute boolean isSecure;

        readonly attribute boolean isExplicitDiscoverable;

        readonly attribute Resource[] resources;

        readonly attribute long[] observerIds;

        attribute object? attributes;

        void notify(QosLevel qosLevel, optional long[]? observerIds) raises(WebAPIException);

        void addResourceTypes(ResourceType[] types) raises(WebAPIException);

        void addResourceInterface(ResourceInterface interface) raises(WebAPIException);

        void addChildResource(Resource resource) raises(WebAPIException);

        void removeChildResource(Resource resource) raises(WebAPIException);

        void setRequestListener(RequestCallback listener) raises(WebAPIException);

        void unsetRequestListener();
    };

    [Constructor(DOMString uriPath)]
    interface Representation {

        attribute DOMString uriPath;

        attribute ResourceType[] resourceTypes;

        attribute ResourceInterface[] resourceInterfaces;

        attribute object? attributes;

        attribute Representation[]? children;
    };

    [NoInterfaceObject] interface PresenceResponse {

        readonly attribute DOMString hostAddress;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute ResourceType? resourceType;

        readonly attribute PresenceResponseResultType resultType;

        readonly attribute PresenceTriggerType? triggerType;
    };

    dictionary Query {

        ResourceType? resourceType;

        ResourceInterface? resourceInterface;

        object? filter;
    };

    [Constructor(unsigned long id, DOMString data)]
    interface IotconOption {

        attribute unsigned long id;

        attribute DOMString data;
    };

    [NoInterfaceObject] interface Request {

        readonly attribute DOMString  hostAddress;

        readonly attribute ConnectivityType connectivityType;

        readonly attribute Representation? representation;

        readonly attribute IotconOption[] options;

        readonly attribute Query query;
    };

    [Constructor(Request request)]
    interface Response {

        readonly attribute Request request;

        attribute ResponseResult result;

        attribute Representation representation;

        attribute IotconOption[]? options;

        void send() raises(WebAPIException);
    };

    [NoInterfaceObject] interface RemoteResponse {

        readonly attribute ResponseResult result;

        readonly attribute Representation representation;

        readonly attribute IotconOption[]? options;
    };

   [NoInterfaceObject] interface DeviceInfo {

        readonly attribute DOMString? deviceName;

        readonly attribute DOMString? specVersion;

        readonly attribute DOMString? oicDeviceId;

        readonly attribute DOMString? dataModelVersion;
   };

    [NoInterfaceObject] interface PlatformInfo {

        readonly attribute DOMString? platformId;

        readonly attribute DOMString? manufacturerName;

        readonly attribute DOMString? manufacturerUrl;

        readonly attribute DOMString? modelNumber;

        readonly attribute DOMString? manufactureDate;

        readonly attribute DOMString? platformVersion;

        readonly attribute DOMString? operatingSystemVersion;

        readonly attribute DOMString? hardwareVersion;

        readonly attribute DOMString? firmwareVersion;

        readonly attribute DOMString? supportUrl;

        readonly attribute DOMString? systemTime;
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface RequestCallback {

        void onget(Request request);

        void onput(Request request);

        void onpost(Request request);

        void ondelete(Request request);

        void onobserving(Request request, ObserveType observeType, unsigned long observeId);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundResourceSuccessCallback {

        void onfound(RemoteResource remoteResource);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface PresenceEventCallback {

        void onreceived(PresenceResponse presenceResponse);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundDeviceInfoSuccessCallback {

        void onsuccess(DeviceInfo info);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface FoundPlatformInfoSuccessCallback {

        void onsuccess(PlatformInfo info);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface RemoteResourceResponseCallback {

        void onsuccess(RemoteResponse response);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface ResourceStateChangeCallback {

        void onchanged(boolean isAlive);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface CacheUpdatedCallback {

        void onupdated(Representation representation);
    };

    [Callback=FunctionOnly, NoInterfaceObject] interface GeneratedPinCallback {

        void onsuccess(DOMString pin);
    };
};