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.
public abstract class Resource : IDisposable
- Inheritance
-
objectResource
- Derived
- Implements
-
System.IDisposable
Constructors
View SourceResource(string, ResourceTypes, ResourceInterfaces, ResourcePolicy)
The constructor.
Declaration
protected 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
// 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. |
See Also
Properties
View SourceChildren
List of Child resources.
Declaration
public ICollection<Resource> Children { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<T><Resource> | List of Child resources. |
Interfaces
Interface details of the resource.
Declaration
public ResourceInterfaces Interfaces { get; }
Property Value
Type | Description |
---|---|
ResourceInterfaces | Interface details of the resource. |
Policy
The policies of the resource.
Declaration
public ResourcePolicy Policy { get; }
Property Value
Type | Description |
---|---|
ResourcePolicy | The policies of the resource. |
Types
Type details of the resource.
Declaration
public ResourceTypes Types { get; }
Property Value
Type | Description |
---|---|
ResourceTypes | Type details of the resource. |
UriPath
URI path of the resource.
Declaration
public string UriPath { get; }
Property Value
Type | Description |
---|---|
string | URI path of the resource. |
Methods
View SourceDispose()
Releases any unmanaged resources used by this object.
Declaration
public void Dispose()
Dispose(bool)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
~Resource()
Destructor of the Resource class.
Declaration
protected ~Resource()
Notify(Representation, QualityOfService)
Notify the specified representation and qos.
Declaration
public void Notify(Representation representation, QualityOfService qos)
Parameters
Type | Name | Description |
---|---|---|
Representation | representation | Representation. |
QualityOfService | qos | The quality of service for message transfer. |
Examples
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. |
System.UnauthorizedAccessException | Thrown when an application does not have privilege to access. |
System.InvalidOperationException | Thrown when the operation is invalid. |
See Also
View SourceOnDelete(Request)
This is called when the client performs delete operation on this resource.
Declaration
protected abstract Response OnDelete(Request request)
Parameters
Type | Name | Description |
---|---|---|
Request | request | A request from client. |
Returns
Type | Description |
---|---|
Response | A response. |
OnGet(Request)
This is called when the client performs get operation on this resource.
Declaration
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. |
OnObserving(Request, ObserveType, int)
Called on the observing event.
Declaration
protected 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
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. |
OnPut(Request)
This is called when the client performs put operation on this resource.
Declaration
protected abstract Response OnPut(Request request)
Parameters
Type | Name | Description |
---|---|---|
Request | request | A request from client. |
Returns
Type | Description |
---|---|
Response | A response. |