-
Notifications
You must be signed in to change notification settings - Fork 28
Lite API: OCF
Gyeonghwan Hong edited this page Dec 21, 2020
·
7 revisions
Parent Document: ANT APIs
OCF API takes charge of supporting OCF (Open Connectivity Foundation) standard-based communication.
The OCF API is composed of OCF-server functions and OCF-client functions.
You need to load OCF API module before you use its API as following.
var ocfAPI = require('ocf');
There is example applications to implement a OCF server or a OCF client.
apps/ocf_client.js
apps/ocf_server.js
apps/ocf_client_multi.js
apps/ocf_server_multi.js
- OCFAdapter OCFAPI.getAdapter(void)
- Get the singleton OCF adapter. OCF adapter manages the event loop of a OCF client and a OCF server.
-
Return: OCFAdapter
- Resulting OCFAdapter object
- void OCFAdapter.initialize(void)
- Initialize the OCF adapter. It sets the internal data structures managed by OCF thread.
- void OCFAdapter.deinitialize(void)
- Deinitialize the OCF adapter. It resets the internal data structures managed by OCF thread.
- void OCFAdapter.onPrepareEventLoop(Function handler)
- Set the event handler called when the OCF thread's event loop becomes ready. The handler usually sets the platform or devices provided by this OCF adapter.
- Example:
var oa = OCFAPI.getAdapter();
oa.onPrepareEventLoop(function () {
oa.setPlatform('ant');
oa.addDevice('/oic/d', 'oic.wk.d', 'Client', 'ocf.1.0.0', 'ocf.res.1.0.0');
});
- void OCFAdapter.start()
- Start the OCF adapter and launch the OCF thread.
- void OCFAdapter.stop()
- Stop the OCF adapter and terminate the OCF thread.
- void OCFAdapter.setPlatform(String mfgName)
- Set this device's platform type
- String OCFAdapter.getPlatform()
- Get this device's platform type
- void OCFAdapter.addDevice(String URI, String resourceType, String name, String specVersion, String dataModelVersion)
- Add a device resource that this OCF adapter serves
- Array OCFAdapter.getDevices()
- Get the device resources that this OCF adapter is or will be serving
- OCFDevice OCFAdapter.getDevice(Integer index)
- Get a specific device resource that this OCF adapter is or will be serving
- void OCFAdapter.repStartRootObject(void)
- void OCFAdapter.repSet(String key, [Boolean, Number, String] value)
- Argument 1: String key
- Argument 2: [Boolean, Number, String] value
- void OCFAdapter.repEndRootObject(void)
- void OCFAdapter.onPrepareServer(Function handler)
- Example
oa.onPrepareServer(function () {
console.log('onPrepareServer()');
device = oa.getDevice(0);
var lightRes = ocf.createResource(
device,
'lightbulb',
'/light/1',
['oic.r.light'],
[ocf.OC_IF_RW]
);
lightRes.setDiscoverable(true);
lightRes.setPeriodicObservable(1);
lightRes.setHandler(ocf.OC_GET, getLightHandler);
lightRes.setHandler(ocf.OC_POST, postLightHandler);
oa.addResource(lightRes);
});
- OCFResource OCFAdapter.createResource(String device, String name, String uri, Array types, Array interfaceMasks)
- void OCFAdapter.addResource(OCFResource resource)
- void OCFAdapter.deleteResource(OCFResource resource)
- OCFResource OCFAdapter.getResources()
- void OCFAdapter.sendResponse(OCFRequest request, Integer statusCode)
- void OCFAdapter.onPrepareClient(Function handler)
- Example
oa.onPrepareClient(function () {
oa.discovery('oic.r.light', onDiscovery);
});
- Boolean OCFAdapter.discovery(String resourceType, Function handler)
- Boolean OCFAdapter.discoveryAll(Function handler)
- Boolean OCFAdapter.stopDiscovery(void)
- Boolean OCFAdapter.isDiscovering()
- Boolean OCFAdapter.observe(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)
- Boolean OCFAdapter.stopObserve(OCFEndpoint endpoint, String uri)
- Boolean OCFAdapter.get(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)
- Boolean OCFAdapter.delete(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)
- Boolean OCFAdapter.initPost(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)
- Boolean OCFAdapter.post(void)
- Boolean OCFAdapter.initPut(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)
- Boolean OCFAdapter.put(void)
- Home
- About
- Getting Started
-
ANT APIs
- ANT Classic API
- ANT Lite API
- Getting Involved