You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: api/ocf/README.md
+49-21Lines changed: 49 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
OCF Web API
2
2
===========
3
3
4
-
*[OCF API object](#api-entry-point)
5
-
-[OCF Client API](./client.md)
6
-
-[OCF Server API](./server.md)
4
+
*[OCF API object](#api-object)
5
+
-[OCF Client API](./client.md) to access remote resources
6
+
-[OCF Server API](./server.md) to implement local resources
7
7
* The [OcfDevice](#ocfdevice) dictionary
8
8
* The [OcfPlatform](#ocfplatform) dictionary
9
9
* The [OcfError](#ocferror) interface
@@ -32,31 +32,59 @@ This version of the API supports OCF Resource, Device, and Platform related func
32
32
33
33
Since implementations may run on constrained hardware, examples use [ECMAScript 5.1](http://www.ecma-international.org/ecma-262/5.1/).
34
34
35
+
<aname="api-object"></a>
35
36
The API object
36
37
--------------
37
-
The API object is exposed in a platform-specific manner. As an example, on Node.js it can be obtained by requiring the package that implements this API. On other platforms, it can be exposed as a property of a global object.
38
+
The API object represents an OCF stack (device) and is exposed in a platform-specific manner. As an example, on Node.js it can be obtained by requiring the package that implements this API. On other platforms, it can be exposed as a property of a global object.
38
39
39
40
```javascript
40
41
letmodule='ocf'; // use your own implementation's name
41
42
var ocf =require(module);
42
43
```
43
44
If the functionality is not supported by the platform, `require` should throw `NotSupportedError`. If there is no permission for using the functionality, `require` should throw `SecurityError`.
44
45
45
-
When `require` is successful, it MUST return an object with the following read-only properties:
46
-
-`client` is an object that implements the [OCF Client API](./client.md), i.e. CRUDN (Create, Retrieve, Update, Delete, Notify) functionality:
47
-
* remote access to resources on the network,
48
-
* listening to presence notifications in the OCF network, and
49
-
* discovery for platforms, devices and resources on the OCF network.
50
-
-`server` is an object that implements the [OCF Server API](./server.md), i.e. the functionality to serve CRUDN requests on a device, to register and unregister resources, to notify of resource changes, and to enable and disable presence functionality on the device.
51
-
-`device` is an [`OcfDevice`](#ocfdevice) object that represents properties of the current device.
52
-
-`platform` is an [`OcfPlatform`](#ocfplatform) object that represents properties of the platform that hosts the current device.
53
-
54
-
|Property |Type |Optional |Default value |
55
-
| --- | --- | --- | --- |
56
-
|`client`|[OcfClient](./client.md#ocfclient) object | no | platform provided |
57
-
|`server`|[OcfServer](./server.md#ocfserver) object | no | platform provided |
58
-
|`device`|[OcfDevice](#ocfdevice) object | no | platform provided |
59
-
|`platform`|[OcfPlatform](#ocfplatform) object | no | platform provided |
46
+
When `require` is successful, it MUST return an object with the following methods.
47
+
48
+
| Method signature | Description |
49
+
| --- | --- |
50
+
|[`start(mode, options)`](#ocfstart)| start the OCF stack |
51
+
|[`stop()`](#ocfstop)| stop the OCF stack |
52
+
53
+
<aname="ocfstart"></a>
54
+
The `start(options)` method initializes the underlying platform and resolves with an API object providing OCF client, or server, or both client-server functionality.
55
+
56
+
The `mode` optional parameter is a string that can be `"client-server"` (by default), or `"client"`, or `"server"`.
57
+
58
+
The `options` optional parameter is an object that may contain the following properties:
- Return a [`Promise`](../README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
67
+
- Let `ocf` denote the API object (equal to the `this` property of `start()`).
68
+
- If the `mode` argument is `undefined`, let `mode` be `"client-server"`.
69
+
- Otherwise if the `mode` argument is not `"client"`, or `"server"`, or `"client-server"`, reject `promise` with a `TypeError` and abort these steps.
70
+
- If the `mode` parameter is `"client"`, then run the following sub-steps:
71
+
* If `options` or `options.device` or `options.platform` are not `undefined`, reject `promise` with `NotSupportedError` and abort these steps. (Client-only device has no `platform` property, and its `device` property cannot be configured).
72
+
* Initialize the underlying OCF stack in client mode.
73
+
* If there is an error, reject `promise` with `OcfDeviceError` and abort these steps.
74
+
* Let `result` be an object that implements [`OcfClient`](./client.md#ocfclient). Let `result.device` be an [`OcfDevice`](#ocfdevice) object initialized from the underlying platform.
75
+
- Otherwise if the `mode` parameter is `"server"`, then run the following sub-steps.
76
+
* Initialize the underlying OCF stack in server mode. If `options.device` is defined, use the defined properties for initializing the OCF stack. If `options.platform` is defined, use the defined properties for initializing the OCF stack.
77
+
* If there is an error, reject `promise` with `OcfDeviceError` and abort these steps.
78
+
* Let `result` be a new object that implements [`OcfServer`](./server.md#ocfserver). Initialize the `result.device` and `result.platform` properties from the underlying OCF stack.
79
+
- Otherwise if the `mode` parameter is `client-server`, then run the following sub-steps.
80
+
* Initialize the underlying OCF stack in client-server mode. If `options.device` is defined, use the defined properties for initializing the OCF stack. If `options.platform` is defined, use the defined properties for initializing the OCF stack.
81
+
* If there is an error, reject `promise` with `OcfDeviceError` and abort these steps.
82
+
* Let `result` be a new object that implements both [`OcfServer`](./server.md#ocfserver) and [`OcfClient`](./client.md#ocfclient).
83
+
* Initialize the `result.device` and `result.platform` properties from the underlying OCF stack.
84
+
- Resolve `promise` with `result`.
85
+
86
+
<aname="ocfstop"></a>
87
+
The `stop()` method frees resources in the underlying platform, so that a next invocation to `start()` is able to start the device from a clean state. After the `stop()` method returns, all properties of `ocf` should be `undefined`.
60
88
61
89
<aname="ocfdevice"></a>
62
90
### The `OcfDevice` object
@@ -71,7 +99,7 @@ Exposes information about the OCF device that runs the current OCF stack instanc
71
99
|`dataModels`| array of strings | no |`[]`| List of supported OCF data models |
72
100
|`coreSpecVersion`| string | no |`undefined`| OCF Core Specification version |
73
101
74
-
The `types` property is a list of the OCF Device types that are supported. It comforms to the same syntax constraints as [resource](./client.md/#resource) types. OCF mandates that every device supports at least the properties defined in the `"oic.wk.d"` resource type, that represents a resource for a "basic device". Other specifications, such as the OCF Smart Home Device Specification can define more device types, for instance `"oic.d.fan"`, `"oic.d.thermostat"`, `"oic.d.light"`, `"oic.d.airconditioner"`, etc. The properties exposed by these device types are defined in [oneiota.org](http://wwww.oneiota.org). [Device discovery](./client.md/#finddevices)may use filters based upon device types.
102
+
The `types` property is a list of the OCF Device types that are supported. It comforms to the same syntax constraints as [resource](./client.md/#resource) types. OCF mandates that every device supports at least the properties defined in the `"oic.wk.d"` resource type, that represents a resource for a "basic device". Other specifications, such as the OCF Smart Home Device Specification can define more device types, for instance `"oic.d.fan"`, `"oic.d.thermostat"`, `"oic.d.light"`, `"oic.d.airconditioner"`, etc. The properties exposed by these device types are defined in [oneiota.org](http://www.oneiota.org). The values in `types` may be used in [device discovery](./client.md/#finddevices) filters. For a client-only device `types` is an empty array.
75
103
76
104
The `dataModels` property is in the following format: `vertical.major.minor` where `major` and `minor` are numbers and `vertical` is a string such as `"Smart Home"`.
77
105
@@ -96,7 +124,7 @@ Exposes information about the OCF platform that hosts the current device.
96
124
97
125
Errors during OCF network operations are exposed via `onerror` events and `Promise` rejections.
98
126
99
-
OCF errors (see also [these notes](../README.md#errors)) are represented as augmented instances of [`Error`](https://nodejs.org/api/errors.html#errors_class_error) objects.
127
+
[OCF errors](../README.md#error) are represented as augmented instances of [`Error`](https://nodejs.org/api/errors.html#errors_class_error) objects.
100
128
101
129
The following [`Error` names](https://nodejs.org/api/errors.html) are used for signaling OCF issues:
102
130
-`OcfResourceNotFound` used if the resource cannot be located in the OCF network, or when an observed resource is deleted from the network.
Copy file name to clipboardExpand all lines: api/ocf/client.md
+24-3Lines changed: 24 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,10 @@ Introduction
10
10
------------
11
11
<aname="ocfclient"></a>
12
12
The OCF Client API implements CRUDN (Create, Retrieve, Update, Delete, Notify) functionality that enables remote access to resources on the network, as well as OCF discovery.
13
-
The Client API object does not expose its own properties, only events and methods.
13
+
14
+
|Property |Type |Optional |Default value |
15
+
| --- | --- | --- | --- |
16
+
|`device`|[`OcfDevice`](./README.md/#ocfdevice) object | no | implementation provided |
14
17
15
18
| Event name | Event callback argument |
16
19
| --- | --- |
@@ -34,7 +37,7 @@ The Client API object does not expose its own properties, only events and method
34
37
|[`retrieve(resourceId, options, listener)`](#retrieve)| retrieve/observe a resource |
35
38
|[`update(resource)`](#update)| update a resource |
36
39
|[`delete(resourceId)`](#delete)| delete a resource |
37
-
40
+
|[`configure(deviceId, options)`](#configure)| configure a remote device |
38
41
39
42
## Structures
40
43
<aname="resourceid"></a>
@@ -102,7 +105,7 @@ Note that applications should not create `ClientResource` objects, as they are c
102
105
<aname="onresourceupdate"></a>
103
106
The `update` event is fired on a `ClientResource` object when the implementation receives an OCF resource update notification because the resource representation has changed. The event listener receives a dictionary object that contains the resource properties that have changed. In addition, the resource property values are already updated to the new values when the event is fired.
104
107
105
-
The recommended way to observe and unobserve resources from applications is by using the [`retrieve()`](#retrieve) method, in order to be able to specify OCF retrieve options. However, for convenience, when the first listener function `listener` is added to the `update` event of `resource`, implementations SHOULD call [`retrieve(resource, null, listener)](#retrieve). When the last listener is removed, the implementations SHOULD call [`retrieve(resource)`](#retrieve), i.e. make an OCF retrieve request with the observe flag off.
108
+
The recommended way to observe and unobserve resources from applications is by using the [`retrieve()`](#retrieve) method, in order to be able to specify OCF retrieve options. However, for convenience, when the first listener function `listener` is added to the `update` event of `resource`, implementations SHOULD call [`retrieve(resource, null, listener)`](#retrieve). When the last listener is removed, the implementations SHOULD call [`retrieve(resource)`](#retrieve), i.e. make an OCF retrieve request with the observe flag off.
106
109
107
110
<aname="onresourcelost"></a>
108
111
The `delete` event is fired on a `ClientResource` object when the implementation gets notified about the resource being deleted or unregistered from the OCF network. The event listener receives a dictionary object that contains the `deviceId` and `resourcePath` of the deleted resource.
@@ -313,3 +316,21 @@ The method runs the following steps:
313
316
- Return a [`Promise`](./README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
314
317
- Send a request to delete the resource specified by `resourceId`, and wait for the answer.
315
318
- If there is an error during the request, reject `promise` with that error, otherwise resolve `promise`.
319
+
320
+
<aname="configure"></a>
321
+
##### 4.4. The `configure(deviceId, options)` method
322
+
Configures a remote device using its `/oic/con` resource with the properties defined by the `options` argument. The following properties are supported:
323
+
324
+
|Property |Type |Optional |Default value |Represents |
325
+
| --- | --- | --- | --- | --- |
326
+
|`deviceName`| string | no |`undefined`| User provided device name |
327
+
|`location`| a [`Coordinates`](https://www.w3.org/TR/geolocation-API/#coordinates_interface) object | yes |`undefined`| Device coordinates |
328
+
|`locationName`| string | yes |`undefined`| User provided location name |
329
+
|`region`| string | yes |`undefined`| User provided region name |
330
+
|`currency`| string | yes |`undefined`| User provided currency name |
331
+
332
+
The method runs the following steps:
333
+
- Return a [`Promise`](./README.md/#promise) object `promise` and continue [in parallel](https://html.spec.whatwg.org/#in-parallel).
334
+
- If `options` is not a dictionary, or `options.deviceName` is not a string, reject `promise` with `TypeError` and abort these steps.
335
+
- Send a request to update the `/oic/con` resource on the device specified by the `deviceId` argument with the dictionary specified by `options` argument, and wait for the answer.
336
+
- If there is an error during the request, reject `promise` with that error, otherwise resolve `promise`.
0 commit comments