Class Resource
Definition
- Namespace:
- Tizen.Network.IoTConnectivity
- Assembly:
- Tizen.Network.IoTConnectivity.dll
Abstract class respresenting a resource. All resources need to inherit from this class.
C#Copypublic abstract class Resource : IDisposable
- Inheritance
-
objectResource
- Derived
- Implements
-
System.IDisposable
Constructors
Declaration
C#Copyprotected Resource(string uri, ResourceTypes types, ResourceInterfaces interfaces, ResourcePolicy policy)
Parameters
| Type | Name | Description |
|---|---|---|
| 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. |
| System.OutOfMemoryException | Thrown when there is not enough memory. |
Properties
Declaration
C#Copypublic ICollection<Resource> Children { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.ICollection<T><Resource> | List of Child resources. |
Declaration
C#Copypublic ResourceInterfaces Interfaces { get; }
Property Value
| Type | Description |
|---|---|
| ResourceInterfaces | Interface details of the resource. |
Declaration
C#Copypublic ResourcePolicy Policy { get; }
Property Value
| Type | Description |
|---|---|
| ResourcePolicy | The policies of the resource. |
Declaration
C#Copypublic ResourceTypes Types { get; }
Property Value
| Type | Description |
|---|---|
| ResourceTypes | Type details of the resource. |
Declaration
C#Copypublic string UriPath { get; }
Property Value
| Type | Description |
|---|---|
| string | URI path of the resource. |
Methods
Declaration
C#Copypublic void Dispose()
Dispose(bool)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
C#Copyprotected virtual void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
Declaration
C#Copyprotected ~Resource()
Declaration
C#Copypublic void Notify(Representation representation, QualityOfService qos)
Parameters
| Type | Name | Description |
|---|---|---|
| Representation | representation | Representation. |
| QualityOfService | qos | The quality of service for message transfer. |
Examples
CopyResourceInterfaces 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. |
| System.UnauthorizedAccessException | Thrown when an application does not have privilege to access. |
| System.InvalidOperationException | Thrown when the operation is invalid. |
OnDelete(Request)
This is called when the client performs delete operation on this resource.
Declaration
C#Copyprotected abstract Response OnDelete(Request request)
Parameters
| Type | Name | Description |
|---|---|---|
| Request | request | A request from client. |
Returns
| Type | Description |
|---|---|
| Response | A response. |
Declaration
C#Copyprotected 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. |
Declaration
C#Copyprotected abstract bool OnObserving(Request request, ObserveType type, int observeId)
Parameters
| Type | Name | Description |
|---|---|---|
| Request | request | A request from client. |
| ObserveType | type | Observer type. |
| int | observeId | Observe identifier. |
Returns
| Type | Description |
|---|---|
| bool | Returns true if it wants to be observed, else false. |
OnPost(Request)
This is called when the client performs post operation on this resource.
Declaration
C#Copyprotected 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. |
Declaration
C#Copyprotected abstract Response OnPut(Request request)
Parameters
| Type | Name | Description |
|---|---|---|
| Request | request | A request from client. |
Returns
| Type | Description |
|---|---|
| Response | A response. |