Class Resource

Definition

Namespace:
Tizen.Network.IoTConnectivity
Assembly:
Tizen.Network.IoTConnectivity.dll
API Level:
3

Abstract class respresenting a resource. All resources need to inherit from this class.

C#
Copy
public abstract class Resource : IDisposable
Inheritance
Resource
Derived
Implements
System.IDisposable

Constructors

View Source

Resource(String, ResourceTypes, ResourceInterfaces, ResourcePolicy)

The constructor.

Declaration
C#
Copy
protected Resource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy)
Parameters
Type Name Description
System.String uri

The URI path of the resource.

ResourceTypes types

Resource types.

ResourceInterfaces interfaces

Resource interfaces.

ResourcePolicy policy

The policies of the resoruce.

Remarks

uri format would be relative URI path like '/a/light' and its length must be less than 128.

Examples
Copy
// Create a class which inherits from Resource public class DoorResource : Resource { public DoorResource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy) : base(uri, types, interfaces, policy) { } protected override Response OnDelete(Request request) { // Do something } protected override Response OnGet(Request request) { // Do something } // Override other abstract methods of Resource class } // Use it like below ResourceInterfaces ifaces = new ResourceInterfaces(new List<string>(){ ResourceInterfaces.DefaultInterface }); ResourceTypes types = new ResourceTypes(new List<string>(){ "oic.iot.door.new" }); Resource resource = new DoorResource("/door/uri1", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable);
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

OutOfMemoryException

Thrown when there is not enough memory.

API Level: 3
Privilege Level: public
Privilege: http://tizen.org/privilege/internet
Feature: http://tizen.org/feature/iot.ocf
Precondition: IoTConnectivityServerManager.Initialize() should be called to initialize.

Properties

View Source

Children

List of Child resources.

Declaration
C#
Copy
public ICollection<Resource> Children { get; }
Property Value
Type Description
ICollection<Resource>

List of Child resources.

API Level: 3
View Source

Interfaces

Interface details of the resource.

Declaration
C#
Copy
public ResourceInterfaces Interfaces { get; }
Property Value
Type Description
ResourceInterfaces

Interface details of the resource.

API Level: 3
View Source

Policy

The policies of the resource.

Declaration
C#
Copy
public ResourcePolicy Policy { get; }
Property Value
Type Description
ResourcePolicy

The policies of the resource.

API Level: 3
View Source

Types

Type details of the resource.

Declaration
C#
Copy
public ResourceTypes Types { get; }
Property Value
Type Description
ResourceTypes

Type details of the resource.

API Level: 3
View Source

UriPath

URI path of the resource.

Declaration
C#
Copy
public string UriPath { get; }
Property Value
Type Description
System.String

URI path of the resource.

API Level: 3

Methods

View Source

Dispose()

Releases any unmanaged resources used by this object.

Declaration
C#
Copy
public void Dispose()
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Dispose(Boolean)

Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.

Declaration
C#
Copy
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
Boolean disposing

If true, disposes any disposable objects. If false, does not dispose disposable objects.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Finalize()

Destructor of the Resource class.

Declaration
C#
Copy
protected void Finalize()
View Source

Notify(Representation, QualityOfService)

Notify the specified representation and qos.

Declaration
C#
Copy
public void Notify(Representation representation, QualityOfService qos)
Parameters
Type Name Description
Representation representation

Representation.

QualityOfService qos

The quality of service for message transfer.

Examples
Copy
ResourceInterfaces ifaces = new ResourceInterfaces(new List<string>(){ ResourceInterfaces.DefaultInterface }); ResourceTypes types = new ResourceTypes(new List<string>(){ "oic.iot.door.new.notify" }); Resource resource = new DoorResource("/door/uri/new/notify", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable); IoTConnectivityServerManager.RegisterResource(resource); Representation repr = new Representation(); repr.UriPath = "/door/uri/new/notify"; repr.Type = new ResourceTypes(new List<string>(){ "oic.iot.door.new.notify" }); repr.Attributes = new Attributes() { _attribute, 1 } }; resource.Notify(repr, QualityOfService.High);
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

UnauthorizedAccessException

Thrown when an application does not have privilege to access.

InvalidOperationException

Thrown when the operation is invalid.

API Level: 3
Privilege Level: public
Privilege: http://tizen.org/privilege/internet
Feature: http://tizen.org/feature/iot.ocf
Precondition: IoTConnectivityServerManager.Initialize() should be called to initialize.
View Source

OnDelete(Request)

This is called when the client performs delete operation on this resource.

Declaration
C#
Copy
protected abstract Response OnDelete(Request request)
Parameters
Type Name Description
Request request

A request from client.

Returns
Type Description
Response

A response.

API Level: 3
View Source

OnGet(Request)

This is called when the client performs get operation on this resource.

Declaration
C#
Copy
protected abstract Response OnGet(Request request)
Parameters
Type Name Description
Request request

A request from client.

Returns
Type Description
Response

A response having the representation and the result.

API Level: 3
View Source

OnObserving(Request, ObserveType, Int32)

Called on the observing event.

Declaration
C#
Copy
protected abstract bool OnObserving(Request request, ObserveType type, int observeId)
Parameters
Type Name Description
Request request

A request from client.

ObserveType type

Observer type.

System.Int32 observeId

Observe identifier.

Returns
Type Description
Boolean

Returns true if it wants to be observed, else false.

API Level: 3
View Source

OnPost(Request)

This is called when the client performs post operation on this resource.

Declaration
C#
Copy
protected abstract Response OnPost(Request request)
Parameters
Type Name Description
Request request

A request from client.

Returns
Type Description
Response

A response having the representation and the result.

API Level: 3
View Source

OnPut(Request)

This is called when the client performs put operation on this resource.

Declaration
C#
Copy
protected abstract Response OnPut(Request request)
Parameters
Type Name Description
Request request

A request from client.

Returns
Type Description
Response

A response.

API Level: 3

Implements

System.IDisposable