Skip to content

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

OCF Common

OCFAPI.getAdapter()

  • 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

OCFAdapter.initialize()

  • void OCFAdapter.initialize(void)
    • Initialize the OCF adapter. It sets the internal data structures managed by OCF thread.

OCFAdapter.deinitialize()

  • void OCFAdapter.deinitialize(void)
    • Deinitialize the OCF adapter. It resets the internal data structures managed by OCF thread.

OCFAdapter.onPrepareEventLoop()

  • 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');
});

OCFAdapter.start()

  • void OCFAdapter.start()
    • Start the OCF adapter and launch the OCF thread.

OCFAdapter.stop()

  • void OCFAdapter.stop()
    • Stop the OCF adapter and terminate the OCF thread.

OCFAdapter.setPlatform()

  • void OCFAdapter.setPlatform(String mfgName)
    • Set this device's platform type

OCFAdapter.getPlatform()

  • String OCFAdapter.getPlatform()
    • Get this device's platform type

OCFAdapter.addDevice()

  • void OCFAdapter.addDevice(String URI, String resourceType, String name, String specVersion, String dataModelVersion)
    • Add a device resource that this OCF adapter serves

OCFAdapter.getDevices()

  • Array OCFAdapter.getDevices()
    • Get the device resources that this OCF adapter is or will be serving

OCFAdapter.getDevice()

  • OCFDevice OCFAdapter.getDevice(Integer index)
    • Get a specific device resource that this OCF adapter is or will be serving

OCF Representation

OCFAdapter.repStartRootObject()

  • void OCFAdapter.repStartRootObject(void)

OCFAdapter.repSet()

  • void OCFAdapter.repSet(String key, [Boolean, Number, String] value)
    • Argument 1: String key
    • Argument 2: [Boolean, Number, String] value

OCFAdapter.repEndRootObject()

  • void OCFAdapter.repEndRootObject(void)

OCF Server

OCFAdapter.onPrepareServer()

  • 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);
});

OCFAPI.createResource()

  • OCFResource OCFAdapter.createResource(String device, String name, String uri, Array types, Array interfaceMasks)

OCFAdapter.addResource()

  • void OCFAdapter.addResource(OCFResource resource)

OCFAdapter.deleteResource()

  • void OCFAdapter.deleteResource(OCFResource resource)

OCFAdapter.getResources()

  • OCFResource OCFAdapter.getResources()

OCFAdapter.sendResponse()

  • void OCFAdapter.sendResponse(OCFRequest request, Integer statusCode)

OCF Client

OCFAdapter.onPrepareClient()

  • void OCFAdapter.onPrepareClient(Function handler)
    • Example
oa.onPrepareClient(function () {
  oa.discovery('oic.r.light', onDiscovery);
});

OCFAdapter.discovery()

  • Boolean OCFAdapter.discovery(String resourceType, Function handler)

OCFAdapter.discoveryAll()

  • Boolean OCFAdapter.discoveryAll(Function handler)

OCFAdapter.stopDiscovery()

  • Boolean OCFAdapter.stopDiscovery(void)

OCFAdapter.isDiscovering()

  • Boolean OCFAdapter.isDiscovering()

OCFAdapter.observe()

  • Boolean OCFAdapter.observe(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)

OCFAdapter.stopObserve()

  • Boolean OCFAdapter.stopObserve(OCFEndpoint endpoint, String uri)

OCFAdapter.get()

  • Boolean OCFAdapter.get(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)

OCFAdapter.delete()

  • Boolean OCFAdapter.delete(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)

OCFAdapter.initPost()

  • Boolean OCFAdapter.initPost(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)

OCFAdapter.post()

  • Boolean OCFAdapter.post(void)

OCFAdapter.initPut()

  • Boolean OCFAdapter.initPut(OCFEndpoint endpoint, String uri, Function handler, String query, String qos)

OCFAdapter.put()

  • Boolean OCFAdapter.put(void)
Clone this wiki locally