2 * //******************************************************************
4 * // Copyright 2015 Intel Corporation.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base;
25 import org.iotivity.ca.CaInterface;
27 import java.util.EnumSet;
28 import java.util.Iterator;
29 import java.util.List;
32 * Contains the main entrance/functionality of the product. To set a custom configuration, the
33 * implementer must make a call to OcPlatform.Configure before the first usage of a function in this
36 public final class OcPlatform {
39 System.loadLibrary("oc_logger");
40 System.loadLibrary("octbstack");
41 System.loadLibrary("connectivity_abstraction");
42 System.loadLibrary("oc");
43 System.loadLibrary("ocstack-jni");
49 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
52 * Used in discovering (GET) links to other resources of a collection
54 public static final String LINK_INTERFACE = "oic.if.ll";
57 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
59 public static final String BATCH_INTERFACE = "oic.if.b";
62 * Used in GET, PUT, POST methods on links to other remote resources of a group
64 public static final String GROUP_INTERFACE = "oic.mi.grp";
66 public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res";
67 public static final String MULTICAST_PREFIX = "224.0.1.187:5683";
68 public static final String MULTICAST_IP = "224.0.1.187";
69 public static final int MULTICAST_PORT = 5683;
70 public static final int DEFAULT_PRESENCE_TTL = 60;
71 public static final String DEVICE_URI = "/oic/d";
72 public static final String PRESENCE_URI = "/oic/ad";
74 private static volatile boolean sIsPlatformInitialized = false;
76 private OcPlatform() {
80 * API for setting the configuration of the OcPlatform.
81 * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
83 * @param platformConfig platform configuration
85 public synchronized static void Configure(PlatformConfig platformConfig) {
86 if (!sIsPlatformInitialized) {
87 CaInterface.initialize(platformConfig.getContext());
90 platformConfig.getServiceType().getValue(),
91 platformConfig.getModeType().getValue(),
92 platformConfig.getIpAddress(),
93 platformConfig.getPort(),
94 platformConfig.getQualityOfService().getValue(),
95 platformConfig.getSvrDbPath()
98 sIsPlatformInitialized = true;
102 private static native void configure(int serviceType,
106 int qualityOfService,
110 * API for notifying base that resource's attributes have changed.
112 * @param ocResourceHandle resource handle of the resource
113 * @throws OcException
115 public static void notifyAllObservers(
116 OcResourceHandle ocResourceHandle) throws OcException {
117 OcPlatform.initCheck();
118 OcPlatform.notifyAllObservers0(ocResourceHandle);
121 private static native void notifyAllObservers0(
122 OcResourceHandle ocResourceHandle) throws OcException;
125 * API for notifying base that resource's attributes have changed.
127 * @param ocResourceHandle resource handle of the resource
128 * @param qualityOfService the quality of communication
129 * @throws OcException
131 public static void notifyAllObservers(
132 OcResourceHandle ocResourceHandle,
133 QualityOfService qualityOfService) throws OcException {
134 OcPlatform.initCheck();
135 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
138 private static native void notifyAllObservers1(
139 OcResourceHandle ocResourceHandle,
140 int qualityOfService) throws OcException;
143 * API for notifying only specific clients that resource's attributes have changed.
145 * @param ocResourceHandle resource handle of the resource
146 * @param ocObservationIdList These set of ids are ones which which will be notified upon
148 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
149 * this resource change
150 * @throws OcException
152 public static void notifyListOfObservers(
153 OcResourceHandle ocResourceHandle,
154 List<Byte> ocObservationIdList,
155 OcResourceResponse ocResourceResponse) throws OcException {
156 OcPlatform.initCheck();
158 byte[] idArr = new byte[ocObservationIdList.size()];
159 Iterator<Byte> it = ocObservationIdList.iterator();
161 while (it.hasNext()) {
162 idArr[i++] = (byte) it.next();
165 OcPlatform.notifyListOfObservers2(
171 private static native void notifyListOfObservers2(
172 OcResourceHandle ocResourceHandle,
173 byte[] ocObservationIdArray,
174 OcResourceResponse ocResourceResponse) throws OcException;
177 * API for notifying only specific clients that resource's attributes have changed.
179 * @param ocResourceHandle resource handle of the resource
180 * @param ocObservationIdList These set of ids are ones which which will be notified upon
182 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
183 * this resource change
184 * @param qualityOfService the quality of communication
185 * @throws OcException
187 public static void notifyListOfObservers(
188 OcResourceHandle ocResourceHandle,
189 List<Byte> ocObservationIdList,
190 OcResourceResponse ocResourceResponse,
191 QualityOfService qualityOfService) throws OcException {
192 OcPlatform.initCheck();
194 byte[] idArr = new byte[ocObservationIdList.size()];
195 Iterator<Byte> it = ocObservationIdList.iterator();
197 while (it.hasNext()) {
198 idArr[i++] = (byte) it.next();
201 OcPlatform.notifyListOfObservers3(
205 qualityOfService.getValue()
209 private static native void notifyListOfObservers3(
210 OcResourceHandle ocResourceHandle,
211 byte[] ocObservationIdArray,
212 OcResourceResponse ocResourceResponse,
213 int qualityOfService) throws OcException;
216 * API for Service and Resource Discovery. NOTE: This API applies to client side only
218 * @param host Host IP Address of a service to direct resource discovery query.
219 * If empty, performs multicast resource discovery query
220 * @param resourceUri name of the resource. If null or empty, performs search for all
222 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
224 * @param onResourceFoundListener Handles events, success states and failure states.
225 * @throws OcException
227 public static void findResource(
230 EnumSet<OcConnectivityType> connectivityTypeSet,
231 OnResourceFoundListener onResourceFoundListener) throws OcException {
232 OcPlatform.initCheck();
236 for (OcConnectivityType connType : OcConnectivityType.values()) {
237 if (connectivityTypeSet.contains(connType))
238 connTypeInt |= connType.getValue();
241 OcPlatform.findResource0(
245 onResourceFoundListener
249 private static native void findResource0(
252 int connectivityType,
253 OnResourceFoundListener onResourceFoundListener) throws OcException;
256 * API for Service and Resource Discovery. NOTE: This API applies to client side only
258 * @param host Host IP Address of a service to direct resource discovery query.
259 * If empty, performs multicast resource discovery query
260 * @param resourceUri name of the resource. If null or empty, performs search for all
262 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
264 * @param onResourceFoundListener Handles events, success states and failure states.
265 * @param qualityOfService the quality of communication
266 * @throws OcException
268 public static void findResource(
271 EnumSet<OcConnectivityType> connectivityTypeSet,
272 OnResourceFoundListener onResourceFoundListener,
273 QualityOfService qualityOfService) throws OcException {
274 OcPlatform.initCheck();
278 for (OcConnectivityType connType : OcConnectivityType.values()) {
279 if (connectivityTypeSet.contains(connType))
280 connTypeInt |= connType.getValue();
283 OcPlatform.findResource1(host,
286 onResourceFoundListener,
287 qualityOfService.getValue()
291 private static native void findResource1(
294 int connectivityType,
295 OnResourceFoundListener onResourceFoundListener,
296 int qualityOfService) throws OcException;
299 * API for Device Discovery
301 * @param host Host IP Address. If null or empty, Multicast is performed.
302 * @param deviceUri Uri containing address to the virtual device
303 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
305 * @param onDeviceFoundListener Handles events, success states and failure states.
306 * @throws OcException
308 public static void getDeviceInfo(
311 EnumSet<OcConnectivityType> connectivityTypeSet,
312 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
313 OcPlatform.initCheck();
316 for (OcConnectivityType connType : OcConnectivityType.values()) {
317 if (connectivityTypeSet.contains(connType))
318 connTypeInt |= connType.getValue();
320 OcPlatform.getDeviceInfo0(
324 onDeviceFoundListener
328 private static native void getDeviceInfo0(
331 int connectivityType,
332 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
335 * API for Device Discovery
337 * @param host Host IP Address. If null or empty, Multicast is performed.
338 * @param deviceUri Uri containing address to the virtual device
339 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
341 * @param onDeviceFoundListener Handles events, success states and failure states.
342 * @param qualityOfService the quality of communication
343 * @throws OcException
345 public static void getDeviceInfo(
348 EnumSet<OcConnectivityType> connectivityTypeSet,
349 OnDeviceFoundListener onDeviceFoundListener,
350 QualityOfService qualityOfService) throws OcException {
351 OcPlatform.initCheck();
354 for (OcConnectivityType connType : OcConnectivityType.values()) {
355 if (connectivityTypeSet.contains(connType))
356 connTypeInt |= connType.getValue();
358 OcPlatform.getDeviceInfo1(
362 onDeviceFoundListener,
363 qualityOfService.getValue()
367 private static native void getDeviceInfo1(
370 int connectivityType,
371 OnDeviceFoundListener onDeviceFoundListener,
372 int qualityOfService) throws OcException;
375 * API for Platform Discovery
377 * @param host Host IP Address. If null or empty, Multicast is performed.
378 * @param platformUri Uri containing address to the platform
379 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
381 * @param onPlatformFoundListener Handles events, success states and failure states.
382 * @throws OcException
385 public static void getPlatformInfo(
388 EnumSet<OcConnectivityType> connectivityTypeSet,
389 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
390 OcPlatform.initCheck();
393 for (OcConnectivityType connType : OcConnectivityType.values()) {
394 if (connectivityTypeSet.contains(connType))
395 connTypeInt |= connType.getValue();
397 OcPlatform.getPlatformInfo0(
401 onPlatformFoundListener
405 private static native void getPlatformInfo0(
408 int connectivityType,
409 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
412 * API for Platform Discovery
414 * @param host Host IP Address. If null or empty, Multicast is performed.
415 * @param platformUri Uri containing address to the platform
416 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
418 * @param onPlatformFoundListener Handles events, success states and failure states.
419 * @param qualityOfService the quality of communication
420 * @throws OcException
423 public static void getPlatformInfo(
426 EnumSet<OcConnectivityType> connectivityTypeSet,
427 OnPlatformFoundListener onPlatformFoundListener,
428 QualityOfService qualityOfService) throws OcException {
429 OcPlatform.initCheck();
432 for (OcConnectivityType connType : OcConnectivityType.values()) {
433 if (connectivityTypeSet.contains(connType))
434 connTypeInt |= connType.getValue();
436 OcPlatform.getPlatformInfo1(
440 onPlatformFoundListener,
441 qualityOfService.getValue()
445 private static native void getPlatformInfo1(
448 int connectivityType,
449 OnPlatformFoundListener onPlatformFoundListener,
450 int qualityOfService) throws OcException;
453 * This API registers a resource with the server NOTE: This API applies to server side only.
455 * @param ocResource The instance of OcResource with all data filled
456 * @return resource handle
457 * @throws OcException
459 public static OcResourceHandle registerResource(
460 OcResource ocResource) throws OcException {
461 OcPlatform.initCheck();
462 return OcPlatform.registerResource0(ocResource);
465 private static native OcResourceHandle registerResource0(
466 OcResource ocResource) throws OcException;
469 * This API registers a resource with the server NOTE: This API applies to server side only.
471 * @param resourceUri The URI of the resource. Example: "a/light"
472 * @param resourceTypeName The resource type. Example: "light"
473 * @param resourceInterface The resource interface (whether it is collection etc).
474 * @param entityHandler entity handler.
475 * @param resourcePropertySet indicates the property of the resource
476 * @return resource handle
477 * @throws OcException
479 public static OcResourceHandle registerResource(
481 String resourceTypeName,
482 String resourceInterface,
483 EntityHandler entityHandler,
484 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
485 OcPlatform.initCheck();
489 for (ResourceProperty prop : ResourceProperty.values()) {
490 if (resourcePropertySet.contains(prop))
491 resProperty |= prop.getValue();
494 return OcPlatform.registerResource1(resourceUri,
501 private static native OcResourceHandle registerResource1(
503 String resourceTypeName,
504 String resourceInterface,
505 EntityHandler entityHandler,
506 int resourceProperty) throws OcException;
509 * Register Device Info
511 * @param ocDeviceInfo object containing all the device specific information
512 * @throws OcException
514 public static void registerDeviceInfo(
515 OcDeviceInfo ocDeviceInfo) throws OcException {
516 OcPlatform.initCheck();
517 OcPlatform.registerDeviceInfo0(
518 ocDeviceInfo.getDeviceName()
522 private static native void registerDeviceInfo0(
524 ) throws OcException;
527 * Register Platform Info
529 * @param ocPlatformInfo object containing all the platform specific information
530 * @throws OcException
532 public static void registerPlatformInfo(
533 OcPlatformInfo ocPlatformInfo) throws OcException {
534 OcPlatform.initCheck();
535 OcPlatform.registerPlatformInfo0(
536 ocPlatformInfo.getPlatformID(),
537 ocPlatformInfo.getManufacturerName(),
538 ocPlatformInfo.getManufacturerUrl(),
539 ocPlatformInfo.getModelNumber(),
540 ocPlatformInfo.getDateOfManufacture(),
541 ocPlatformInfo.getPlatformVersion(),
542 ocPlatformInfo.getOperatingSystemVersion(),
543 ocPlatformInfo.getHardwareVersion(),
544 ocPlatformInfo.getFirmwareVersion(),
545 ocPlatformInfo.getSupportUrl(),
546 ocPlatformInfo.getSystemTime()
550 private static native void registerPlatformInfo0(
551 String platformId, String manufacturerName, String manufacturerUrl,
552 String modelNumber, String dateOfManufacture, String platformVersion,
553 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
554 String supportUrl, String systemTime
555 ) throws OcException;
558 * This API unregisters a resource with the server NOTE: This API applies to server side only.
560 * @param ocResourceHandle This is the resource handle which we which to unregister from the
562 * @throws OcException
564 public static void unregisterResource(
565 OcResourceHandle ocResourceHandle) throws OcException {
566 OcPlatform.initCheck();
567 OcPlatform.unregisterResource0(ocResourceHandle);
570 private static native void unregisterResource0(
571 OcResourceHandle ocResourceHandle) throws OcException;
575 * Add a resource to a collection resource
577 * @param ocResourceCollectionHandle handle to the collection resource
578 * @param ocResourceHandle handle to resource to be added to the collection resource
579 * @throws OcException
581 public static void bindResource(
582 OcResourceHandle ocResourceCollectionHandle,
583 OcResourceHandle ocResourceHandle) throws OcException {
584 OcPlatform.initCheck();
585 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
588 private static native void bindResource0(
589 OcResourceHandle ocResourceCollectionHandle,
590 OcResourceHandle ocResourceHandle) throws OcException;
593 * Add multiple resources to a collection resource.
595 * @param ocResourceCollectionHandle handle to the collection resource
596 * @param ocResourceHandleList reference to list of resource handles to be added to the
597 * collection resource
598 * @throws OcException
600 public static void bindResources(
601 OcResourceHandle ocResourceCollectionHandle,
602 List<OcResourceHandle> ocResourceHandleList) throws OcException {
603 OcPlatform.initCheck();
604 OcPlatform.bindResources0(
605 ocResourceCollectionHandle,
606 ocResourceHandleList.toArray(
607 new OcResourceHandle[ocResourceHandleList.size()])
611 private static native void bindResources0(
612 OcResourceHandle ocResourceCollectionHandle,
613 OcResourceHandle[] ocResourceHandleArray) throws OcException;
616 * Unbind a resource from a collection resource.
618 * @param ocResourceCollectionHandle handle to the collection resource
619 * @param ocResourceHandle resource handle to be unbound from the collection resource
620 * @throws OcException
622 public static void unbindResource(
623 OcResourceHandle ocResourceCollectionHandle,
624 OcResourceHandle ocResourceHandle) throws OcException {
625 OcPlatform.initCheck();
626 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
629 private static native void unbindResource0(
630 OcResourceHandle ocResourceCollectionHandle,
631 OcResourceHandle ocResourceHandle) throws OcException;
634 * Unbind resources from a collection resource.
636 * @param ocResourceCollectionHandle Handle to the collection resource
637 * @param ocResourceHandleList List of resource handles to be unbound from the collection
639 * @throws OcException
641 public static void unbindResources(
642 OcResourceHandle ocResourceCollectionHandle,
643 List<OcResourceHandle> ocResourceHandleList) throws OcException {
644 OcPlatform.initCheck();
645 OcPlatform.unbindResources0(
646 ocResourceCollectionHandle,
647 ocResourceHandleList.toArray(
648 new OcResourceHandle[ocResourceHandleList.size()])
652 private static native void unbindResources0(
653 OcResourceHandle ocResourceCollectionHandle,
654 OcResourceHandle[] ocResourceHandleArray) throws OcException;
657 * Binds a type to a particular resource
659 * @param ocResourceHandle handle to the resource
660 * @param resourceTypeName new typename to bind to the resource
661 * @throws OcException
663 public static void bindTypeToResource(
664 OcResourceHandle ocResourceHandle,
665 String resourceTypeName) throws OcException {
666 OcPlatform.initCheck();
667 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
670 private static native void bindTypeToResource0(
671 OcResourceHandle ocResourceHandle,
672 String resourceTypeName) throws OcException;
675 * Binds an interface to a particular resource
677 * @param ocResourceHandle handle to the resource
678 * @param resourceInterfaceName new interface to bind to the resource
679 * @throws OcException
681 public static void bindInterfaceToResource(
682 OcResourceHandle ocResourceHandle,
683 String resourceInterfaceName) throws OcException {
684 OcPlatform.initCheck();
685 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
688 private static native void bindInterfaceToResource0(
689 OcResourceHandle ocResourceHandle,
690 String resourceInterfaceName) throws OcException;
693 * Start Presence announcements.
695 * @param ttl time to live in seconds
696 * @throws OcException
698 public static void startPresence(int ttl) throws OcException {
699 OcPlatform.initCheck();
700 OcPlatform.startPresence0(ttl);
703 private static native void startPresence0(int ttl) throws OcException;
706 * Stop Presence announcements.
708 * @throws OcException
710 public static void stopPresence() throws OcException {
711 OcPlatform.initCheck();
712 OcPlatform.stopPresence0();
715 private static native void stopPresence0() throws OcException;
718 * Subscribes to a server's presence change events. By making this subscription, every time a
719 * server adds/removes/alters a resource, starts or is intentionally stopped
721 * @param host The IP address/addressable name of the server to subscribe to
722 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
724 * @param onPresenceListener listener that will receive notifications/subscription events
725 * @return a handle object that can be used to identify this subscription request. It can be
726 * used to unsubscribe from these events in the future
727 * @throws OcException
729 public static OcPresenceHandle subscribePresence(
731 EnumSet<OcConnectivityType> connectivityTypeSet,
732 OnPresenceListener onPresenceListener) throws OcException {
733 OcPlatform.initCheck();
736 for (OcConnectivityType connType : OcConnectivityType.values()) {
737 if (connectivityTypeSet.contains(connType))
738 connTypeInt |= connType.getValue();
740 return OcPlatform.subscribePresence0(
747 private static native OcPresenceHandle subscribePresence0(
749 int connectivityType,
750 OnPresenceListener onPresenceListener) throws OcException;
753 * Subscribes to a server's presence change events. By making this subscription, every time a
754 * server adds/removes/alters a resource, starts or is intentionally stopped
756 * @param host The IP address/addressable name of the server to subscribe to
757 * @param resourceType a resource type specified as a filter for subscription events.
758 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
760 * @param onPresenceListener listener that will receive notifications/subscription events
761 * @return a handle object that can be used to identify this subscription request. It can be
762 * used to unsubscribe from these events in the future
763 * @throws OcException
765 public static OcPresenceHandle subscribePresence(
768 EnumSet<OcConnectivityType> connectivityTypeSet,
769 OnPresenceListener onPresenceListener) throws OcException {
770 OcPlatform.initCheck();
773 for (OcConnectivityType connType : OcConnectivityType.values()) {
774 if (connectivityTypeSet.contains(connType))
775 connTypeInt |= connType.getValue();
777 return OcPlatform.subscribePresence1(
784 private static native OcPresenceHandle subscribePresence1(
787 int connectivityType,
788 OnPresenceListener onPresenceListener) throws OcException;
791 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
792 * a short time still receive events from the server since it may take time for the
793 * unsubscribe to take effect.
795 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
796 * identifies this subscription
797 * @throws OcException
799 public static void unsubscribePresence(
800 OcPresenceHandle ocPresenceHandle) throws OcException {
801 OcPlatform.initCheck();
802 OcPlatform.unsubscribePresence0(ocPresenceHandle);
805 private static native void unsubscribePresence0(
806 OcPresenceHandle ocPresenceHandle) throws OcException;
809 * Creates a resource proxy object so that get/put/observe functionality can be used without
810 * discovering the object in advance. Note that the consumer of this method needs to provide
811 * all of the details required to correctly contact and observe the object. If the consumer
812 * lacks any of this information, they should discover the resource object normally.
813 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
816 * @param host a string containing a resolvable host address of the server holding
818 * @param uri the rest of the resource's URI that will permit messages to be
821 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
823 * @param isObservable a boolean containing whether the resource supports observation
824 * @param resourceTypeList a collection of resource types implemented by the resource
825 * @param interfaceList a collection of interfaces that the resource supports/implements
826 * @return new resource object
827 * @throws OcException
829 public static OcResource constructResourceObject(
832 EnumSet<OcConnectivityType> connectivityTypeSet,
833 boolean isObservable,
834 List<String> resourceTypeList,
835 List<String> interfaceList) throws OcException {
836 OcPlatform.initCheck();
839 for (OcConnectivityType connType : OcConnectivityType.values()) {
840 if (connectivityTypeSet.contains(connType))
841 connTypeInt |= connType.getValue();
843 return OcPlatform.constructResourceObject0(
848 resourceTypeList.toArray(new String[resourceTypeList.size()]),
849 interfaceList.toArray(new String[interfaceList.size()])
853 private static native OcResource constructResourceObject0(
856 int connectivityType,
857 boolean isObservable,
858 String[] resourceTypes,
859 String[] interfaces) throws OcException;
862 * Allows application entity handler to send response to an incoming request.
864 * @param ocResourceResponse resource response
865 * @throws OcException
867 public static void sendResponse(OcResourceResponse ocResourceResponse)
869 OcPlatform.initCheck();
870 OcPlatform.sendResponse0(ocResourceResponse);
873 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
877 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
878 * Event listeners are notified asynchronously
880 public interface OnResourceFoundListener {
881 public void onResourceFound(OcResource resource);
885 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
886 * Event listeners are notified asynchronously
888 public interface OnDeviceFoundListener {
889 public void onDeviceFound(OcRepresentation ocRepresentation);
893 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
894 * Event listeners are notified asynchronously
896 public interface OnPlatformFoundListener {
897 public void onPlatformFound(OcRepresentation ocRepresentation);
901 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
902 * Event listeners are notified asynchronously
904 public interface OnPresenceListener {
905 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
909 * An EntityHandler can be registered via the OcPlatform.registerResource call.
910 * Event listeners are notified asynchronously
912 public interface EntityHandler {
913 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
916 private static void initCheck() {
917 if (!sIsPlatformInitialized) {
918 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
919 "OcPlatform.Configure before any other API calls are permitted");