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#Copypublic abstract class Resource : IDisposable
- Inheritance
-
Resource
- Derived
- Implements
-
System.IDisposable
Constructors
Declaration
C#Copyprotected 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
Declaration
C#Copypublic ICollection<Resource> Children { get; }
Property Value
Type | Description |
---|---|
ICollection<Resource> | List of Child resources. |
API Level: 3
Declaration
C#Copypublic ResourceInterfaces Interfaces { get; }
Property Value
Type | Description |
---|---|
ResourceInterfaces | Interface details of the resource. |
API Level: 3
Declaration
C#Copypublic ResourcePolicy Policy { get; }
Property Value
Type | Description |
---|---|
ResourcePolicy | The policies of the resource. |
API Level: 3
Declaration
C#Copypublic ResourceTypes Types { get; }
Property Value
Type | Description |
---|---|
ResourceTypes | Type details of the resource. |
API Level: 3
Declaration
C#Copypublic string UriPath { get; }
Property Value
Type | Description |
---|---|
System.String | URI path of the resource. |
API Level: 3
Methods
Declaration
C#Copypublic void Dispose()
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Dispose(Boolean)
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 |
---|---|---|
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
Declaration
C#Copyprotected void Finalize()
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. |
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.
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. |
API Level: 3
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. |
API Level: 3
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. |
System.Int32 | observeId | Observe identifier. |
Returns
Type | Description |
---|---|
Boolean | Returns true if it wants to be observed, else false. |
API Level: 3
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. |
API Level: 3
Declaration
C#Copyprotected abstract Response OnPut(Request request)
Parameters
Type | Name | Description |
---|---|---|
Request | request | A request from client. |
Returns
Type | Description |
---|---|
Response | A response. |