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 * This class contains the main entrance/functionality of the product. To set a custom
33 * configuration, the implementer must make a call to OcPlatform.Configure before the first usage
34 * of a method in this class.
36 public final class OcPlatform {
39 System.loadLibrary("oc_logger");
40 System.loadLibrary("octbstack");
41 System.loadLibrary("oc");
42 System.loadLibrary("ocstack-jni");
48 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
51 * Used in discovering (GET) links to other resources of a collection
53 public static final String LINK_INTERFACE = "oic.if.ll";
56 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
58 public static final String BATCH_INTERFACE = "oic.if.b";
61 * Used in GET, PUT, POST methods on links to other remote resources of a group
63 public static final String GROUP_INTERFACE = "oic.mi.grp";
65 public static final String WELL_KNOWN_QUERY = "/oic/res";
66 public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
67 public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
68 public static final int DEFAULT_PRESENCE_TTL = 60;
69 public static final String PRESENCE_URI = "/oic/ad";
71 private static volatile boolean sIsPlatformInitialized = false;
72 private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
74 private OcPlatform() {
78 * API for setting the configuration of the OcPlatform.
80 * 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();
89 sPlatformQualityOfService = platformConfig.getQualityOfService();
92 platformConfig.getServiceType().getValue(),
93 platformConfig.getModeType().getValue(),
94 platformConfig.getIpAddress(),
95 platformConfig.getPort(),
96 platformConfig.getQualityOfService().getValue(),
97 platformConfig.getSvrDbPath()
100 sIsPlatformInitialized = true;
104 private static native void configure(int serviceType,
108 int qualityOfService,
112 * API for notifying base that resource's attributes have changed.
114 * Note: This API is for server side only.
117 * @param ocResourceHandle resource handle of the resource
118 * @throws OcException if failure
120 public static void notifyAllObservers(
121 OcResourceHandle ocResourceHandle) throws OcException {
122 OcPlatform.initCheck();
123 OcPlatform.notifyAllObservers0(ocResourceHandle);
126 private static native void notifyAllObservers0(
127 OcResourceHandle ocResourceHandle) throws OcException;
130 * API for notifying base that resource's attributes have changed.
132 * Note: This API is for server side only.
135 * @param ocResourceHandle resource handle of the resource
136 * @param qualityOfService the quality of communication
137 * @throws OcException if failure
139 public static void notifyAllObservers(
140 OcResourceHandle ocResourceHandle,
141 QualityOfService qualityOfService) throws OcException {
142 OcPlatform.initCheck();
143 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
146 private static native void notifyAllObservers1(
147 OcResourceHandle ocResourceHandle,
148 int qualityOfService) throws OcException;
151 * API for notifying only specific clients that resource's attributes have changed.
153 * Note: This API is for server side only.
156 * @param ocResourceHandle resource handle of the resource
157 * @param ocObservationIdList These set of ids are ones which which will be notified upon
159 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
160 * this resource change
161 * @throws OcException if failure
163 public static void notifyListOfObservers(
164 OcResourceHandle ocResourceHandle,
165 List<Byte> ocObservationIdList,
166 OcResourceResponse ocResourceResponse) throws OcException {
167 OcPlatform.initCheck();
169 byte[] idArr = new byte[ocObservationIdList.size()];
170 Iterator<Byte> it = ocObservationIdList.iterator();
172 while (it.hasNext()) {
173 idArr[i++] = (byte) it.next();
176 OcPlatform.notifyListOfObservers2(
182 private static native void notifyListOfObservers2(
183 OcResourceHandle ocResourceHandle,
184 byte[] ocObservationIdArray,
185 OcResourceResponse ocResourceResponse) throws OcException;
188 * API for notifying only specific clients that resource's attributes have changed.
190 * Note: This API is for server side only.
193 * @param ocResourceHandle resource handle of the resource
194 * @param ocObservationIdList These set of ids are ones which which will be notified upon
196 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
197 * this resource change
198 * @param qualityOfService the quality of communication
199 * @throws OcException if failure
201 public static void notifyListOfObservers(
202 OcResourceHandle ocResourceHandle,
203 List<Byte> ocObservationIdList,
204 OcResourceResponse ocResourceResponse,
205 QualityOfService qualityOfService) throws OcException {
206 OcPlatform.initCheck();
208 byte[] idArr = new byte[ocObservationIdList.size()];
209 Iterator<Byte> it = ocObservationIdList.iterator();
211 while (it.hasNext()) {
212 idArr[i++] = (byte) it.next();
215 OcPlatform.notifyListOfObservers3(
219 qualityOfService.getValue()
223 private static native void notifyListOfObservers3(
224 OcResourceHandle ocResourceHandle,
225 byte[] ocObservationIdArray,
226 OcResourceResponse ocResourceResponse,
227 int qualityOfService) throws OcException;
230 * API for Service and Resource Discovery
232 * Note: This API is for client side only.
235 * @param host Host Address of a service to direct resource discovery query.
236 * If empty, performs multicast resource discovery query
237 * @param resourceUri name of the resource. If null or empty, performs search for all
239 * @param connectivityTypeSet Set of types of connectivity. Example: IP
240 * @param onResourceFoundListener Handles events, success states and failure states.
241 * @throws OcException if failure
243 public static void findResource(
246 EnumSet<OcConnectivityType> connectivityTypeSet,
247 OnResourceFoundListener onResourceFoundListener) throws OcException {
248 OcPlatform.initCheck();
252 for (OcConnectivityType connType : OcConnectivityType.values()) {
253 if (connectivityTypeSet.contains(connType))
254 connTypeInt |= connType.getValue();
257 OcPlatform.findResource0(
261 onResourceFoundListener
265 private static native void findResource0(
268 int connectivityType,
269 OnResourceFoundListener onResourceFoundListener) throws OcException;
272 * API for Service and Resource Discovery.
274 * Note: This API is for client side only.
277 * @param host Host IP Address of a service to direct resource discovery query.
278 * If empty, performs multicast resource discovery query
279 * @param resourceUri name of the resource. If null or empty, performs search for all
281 * @param connectivityTypeSet Set of types of connectivity. Example: IP
282 * @param onResourceFoundListener Handles events, success states and failure states.
283 * @param qualityOfService the quality of communication
284 * @throws OcException if failure
286 public static void findResource(
289 EnumSet<OcConnectivityType> connectivityTypeSet,
290 OnResourceFoundListener onResourceFoundListener,
291 QualityOfService qualityOfService) throws OcException {
292 OcPlatform.initCheck();
296 for (OcConnectivityType connType : OcConnectivityType.values()) {
297 if (connectivityTypeSet.contains(connType))
298 connTypeInt |= connType.getValue();
301 OcPlatform.findResource1(host,
304 onResourceFoundListener,
305 qualityOfService.getValue()
309 private static native void findResource1(
312 int connectivityType,
313 OnResourceFoundListener onResourceFoundListener,
314 int qualityOfService) throws OcException;
317 * API for Device Discovery
319 * @param host Host IP Address. If null or empty, Multicast is performed.
320 * @param deviceUri Uri containing address to the virtual device
321 * @param connectivityTypeSet Set of types of connectivity. Example: IP
322 * @param onDeviceFoundListener Handles events, success states and failure states.
323 * @throws OcException if failure
325 public static void getDeviceInfo(
328 EnumSet<OcConnectivityType> connectivityTypeSet,
329 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
330 OcPlatform.initCheck();
333 for (OcConnectivityType connType : OcConnectivityType.values()) {
334 if (connectivityTypeSet.contains(connType))
335 connTypeInt |= connType.getValue();
337 OcPlatform.getDeviceInfo0(
341 onDeviceFoundListener
345 private static native void getDeviceInfo0(
348 int connectivityType,
349 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
352 * API for Device Discovery
354 * @param host Host IP Address. If null or empty, Multicast is performed.
355 * @param deviceUri Uri containing address to the virtual device
356 * @param connectivityTypeSet Set of types of connectivity. Example: IP
357 * @param onDeviceFoundListener Handles events, success states and failure states.
358 * @param qualityOfService the quality of communication
359 * @throws OcException if failure
361 public static void getDeviceInfo(
364 EnumSet<OcConnectivityType> connectivityTypeSet,
365 OnDeviceFoundListener onDeviceFoundListener,
366 QualityOfService qualityOfService) throws OcException {
367 OcPlatform.initCheck();
370 for (OcConnectivityType connType : OcConnectivityType.values()) {
371 if (connectivityTypeSet.contains(connType))
372 connTypeInt |= connType.getValue();
374 OcPlatform.getDeviceInfo1(
378 onDeviceFoundListener,
379 qualityOfService.getValue()
383 private static native void getDeviceInfo1(
386 int connectivityType,
387 OnDeviceFoundListener onDeviceFoundListener,
388 int qualityOfService) throws OcException;
391 * API for Platform Discovery
393 * @param host Host IP Address. If null or empty, Multicast is performed.
394 * @param platformUri Uri containing address to the platform
395 * @param connectivityTypeSet Set of types of connectivity. Example: IP
396 * @param onPlatformFoundListener Handles events, success states and failure states.
397 * @throws OcException if failure
400 public static void getPlatformInfo(
403 EnumSet<OcConnectivityType> connectivityTypeSet,
404 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
405 OcPlatform.initCheck();
408 for (OcConnectivityType connType : OcConnectivityType.values()) {
409 if (connectivityTypeSet.contains(connType))
410 connTypeInt |= connType.getValue();
412 OcPlatform.getPlatformInfo0(
416 onPlatformFoundListener
420 private static native void getPlatformInfo0(
423 int connectivityType,
424 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
427 * API for Platform Discovery
429 * @param host Host IP Address. If null or empty, Multicast is performed.
430 * @param platformUri Uri containing address to the platform
431 * @param connectivityTypeSet Set of types of connectivity. Example: IP
432 * @param onPlatformFoundListener Handles events, success states and failure states.
433 * @param qualityOfService the quality of communication
434 * @throws OcException if failure
437 public static void getPlatformInfo(
440 EnumSet<OcConnectivityType> connectivityTypeSet,
441 OnPlatformFoundListener onPlatformFoundListener,
442 QualityOfService qualityOfService) throws OcException {
443 OcPlatform.initCheck();
446 for (OcConnectivityType connType : OcConnectivityType.values()) {
447 if (connectivityTypeSet.contains(connType))
448 connTypeInt |= connType.getValue();
450 OcPlatform.getPlatformInfo1(
454 onPlatformFoundListener,
455 qualityOfService.getValue()
459 private static native void getPlatformInfo1(
462 int connectivityType,
463 OnPlatformFoundListener onPlatformFoundListener,
464 int qualityOfService) throws OcException;
467 * This API registers a resource with the server
469 * Note: This API applies to server & client side.
472 * @param ocResource The instance of OcResource with all data filled
473 * @return resource handle
474 * @throws OcException if failure
476 public static OcResourceHandle registerResource(
477 OcResource ocResource) throws OcException {
478 OcPlatform.initCheck();
479 return OcPlatform.registerResource0(ocResource);
482 private static native OcResourceHandle registerResource0(
483 OcResource ocResource) throws OcException;
486 * This API registers a resource with the server NOTE: This API applies to server side only.
488 * Note: This API applies to server side only.
491 * @param resourceUri The URI of the resource. Example: "a/light"
492 * @param resourceTypeName The resource type. Example: "light"
493 * @param resourceInterface The resource interface (whether it is collection etc).
494 * @param entityHandler entity handler.
495 * @param resourcePropertySet indicates the property of the resource
496 * @return resource handle
497 * @throws OcException if failure
499 public static OcResourceHandle registerResource(
501 String resourceTypeName,
502 String resourceInterface,
503 EntityHandler entityHandler,
504 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
505 OcPlatform.initCheck();
509 for (ResourceProperty prop : ResourceProperty.values()) {
510 if (resourcePropertySet.contains(prop))
511 resProperty |= prop.getValue();
514 return OcPlatform.registerResource1(resourceUri,
521 private static native OcResourceHandle registerResource1(
523 String resourceTypeName,
524 String resourceInterface,
525 EntityHandler entityHandler,
526 int resourceProperty) throws OcException;
529 * Register Device Info
531 * @param ocDeviceInfo object containing all the device specific information
532 * @throws OcException if failure
534 public static void registerDeviceInfo(
535 OcDeviceInfo ocDeviceInfo) throws OcException {
536 OcPlatform.initCheck();
537 OcPlatform.registerDeviceInfo0(
538 ocDeviceInfo.getDeviceName()
542 private static native void registerDeviceInfo0(
544 ) throws OcException;
547 * Register Platform Info
549 * @param ocPlatformInfo object containing all the platform specific information
550 * @throws OcException if failure
552 public static void registerPlatformInfo(
553 OcPlatformInfo ocPlatformInfo) throws OcException {
554 OcPlatform.initCheck();
555 OcPlatform.registerPlatformInfo0(
556 ocPlatformInfo.getPlatformId(),
557 ocPlatformInfo.getManufacturerName(),
558 ocPlatformInfo.getManufacturerUrl(),
559 ocPlatformInfo.getModelNumber(),
560 ocPlatformInfo.getDateOfManufacture(),
561 ocPlatformInfo.getPlatformVersion(),
562 ocPlatformInfo.getOperatingSystemVersion(),
563 ocPlatformInfo.getHardwareVersion(),
564 ocPlatformInfo.getFirmwareVersion(),
565 ocPlatformInfo.getSupportUrl(),
566 ocPlatformInfo.getSystemTime()
570 private static native void registerPlatformInfo0(
571 String platformId, String manufacturerName, String manufacturerUrl,
572 String modelNumber, String dateOfManufacture, String platformVersion,
573 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
574 String supportUrl, String systemTime
575 ) throws OcException;
578 * This API unregisters a resource with the server NOTE: This API applies to server side only.
580 * @param ocResourceHandle This is the resource handle which we which to unregister from the
582 * @throws OcException if failure
584 public static void unregisterResource(
585 OcResourceHandle ocResourceHandle) throws OcException {
586 OcPlatform.initCheck();
587 OcPlatform.unregisterResource0(ocResourceHandle);
590 private static native void unregisterResource0(
591 OcResourceHandle ocResourceHandle) throws OcException;
595 * Add a resource to a collection resource
597 * @param ocResourceCollectionHandle handle to the collection resource
598 * @param ocResourceHandle handle to resource to be added to the collection resource
599 * @throws OcException if failure
601 public static void bindResource(
602 OcResourceHandle ocResourceCollectionHandle,
603 OcResourceHandle ocResourceHandle) throws OcException {
604 OcPlatform.initCheck();
605 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
608 private static native void bindResource0(
609 OcResourceHandle ocResourceCollectionHandle,
610 OcResourceHandle ocResourceHandle) throws OcException;
613 * Add multiple resources to a collection resource.
615 * @param ocResourceCollectionHandle handle to the collection resource
616 * @param ocResourceHandleList reference to list of resource handles to be added to the
617 * collection resource
618 * @throws OcException if failure
620 public static void bindResources(
621 OcResourceHandle ocResourceCollectionHandle,
622 List<OcResourceHandle> ocResourceHandleList) throws OcException {
623 OcPlatform.initCheck();
624 OcPlatform.bindResources0(
625 ocResourceCollectionHandle,
626 ocResourceHandleList.toArray(
627 new OcResourceHandle[ocResourceHandleList.size()])
631 private static native void bindResources0(
632 OcResourceHandle ocResourceCollectionHandle,
633 OcResourceHandle[] ocResourceHandleArray) throws OcException;
636 * Unbind a resource from a collection resource.
638 * @param ocResourceCollectionHandle handle to the collection resource
639 * @param ocResourceHandle resource handle to be unbound from the collection resource
640 * @throws OcException if failure
642 public static void unbindResource(
643 OcResourceHandle ocResourceCollectionHandle,
644 OcResourceHandle ocResourceHandle) throws OcException {
645 OcPlatform.initCheck();
646 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
649 private static native void unbindResource0(
650 OcResourceHandle ocResourceCollectionHandle,
651 OcResourceHandle ocResourceHandle) throws OcException;
654 * Unbind resources from a collection resource.
656 * @param ocResourceCollectionHandle Handle to the collection resource
657 * @param ocResourceHandleList List of resource handles to be unbound from the collection
659 * @throws OcException if failure
661 public static void unbindResources(
662 OcResourceHandle ocResourceCollectionHandle,
663 List<OcResourceHandle> ocResourceHandleList) throws OcException {
664 OcPlatform.initCheck();
665 OcPlatform.unbindResources0(
666 ocResourceCollectionHandle,
667 ocResourceHandleList.toArray(
668 new OcResourceHandle[ocResourceHandleList.size()])
672 private static native void unbindResources0(
673 OcResourceHandle ocResourceCollectionHandle,
674 OcResourceHandle[] ocResourceHandleArray) throws OcException;
677 * Binds a type to a particular resource
679 * @param ocResourceHandle handle to the resource
680 * @param resourceTypeName new typename to bind to the resource
681 * @throws OcException if failure
683 public static void bindTypeToResource(
684 OcResourceHandle ocResourceHandle,
685 String resourceTypeName) throws OcException {
686 OcPlatform.initCheck();
687 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
690 private static native void bindTypeToResource0(
691 OcResourceHandle ocResourceHandle,
692 String resourceTypeName) throws OcException;
695 * Binds an interface to a particular resource
697 * @param ocResourceHandle handle to the resource
698 * @param resourceInterfaceName new interface to bind to the resource
699 * @throws OcException if failure
701 public static void bindInterfaceToResource(
702 OcResourceHandle ocResourceHandle,
703 String resourceInterfaceName) throws OcException {
704 OcPlatform.initCheck();
705 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
708 private static native void bindInterfaceToResource0(
709 OcResourceHandle ocResourceHandle,
710 String resourceInterfaceName) throws OcException;
713 * Start Presence announcements.
715 * @param ttl time to live in seconds
716 * @throws OcException if failure
718 public static void startPresence(int ttl) throws OcException {
719 OcPlatform.initCheck();
720 OcPlatform.startPresence0(ttl);
723 private static native void startPresence0(int ttl) throws OcException;
726 * Stop Presence announcements.
728 * @throws OcException if failure
730 public static void stopPresence() throws OcException {
731 OcPlatform.initCheck();
732 OcPlatform.stopPresence0();
735 private static native void stopPresence0() throws OcException;
738 * Subscribes to a server's presence change events. By making this subscription, every time a
739 * server adds/removes/alters a resource, starts or is intentionally stopped
741 * @param host The IP address/addressable name of the server to subscribe to
742 * @param connectivityTypeSet Set of types of connectivity. Example: IP
743 * @param onPresenceListener listener that will receive notifications/subscription events
744 * @return a handle object that can be used to identify this subscription request. It can be
745 * used to unsubscribe from these events in the future
746 * @throws OcException if failure
748 public static OcPresenceHandle subscribePresence(
750 EnumSet<OcConnectivityType> connectivityTypeSet,
751 OnPresenceListener onPresenceListener) throws OcException {
752 OcPlatform.initCheck();
755 for (OcConnectivityType connType : OcConnectivityType.values()) {
756 if (connectivityTypeSet.contains(connType))
757 connTypeInt |= connType.getValue();
759 return OcPlatform.subscribePresence0(
766 private static native OcPresenceHandle subscribePresence0(
768 int connectivityType,
769 OnPresenceListener onPresenceListener) throws OcException;
772 * Subscribes to a server's presence change events. By making this subscription, every time a
773 * server adds/removes/alters a resource, starts or is intentionally stopped
775 * @param host The IP address/addressable name of the server to subscribe to
776 * @param resourceType a resource type specified as a filter for subscription events.
777 * @param connectivityTypeSet Set of types of connectivity. Example: IP
778 * @param onPresenceListener listener that will receive notifications/subscription events
779 * @return a handle object that can be used to identify this subscription request. It can be
780 * used to unsubscribe from these events in the future
781 * @throws OcException if failure
783 public static OcPresenceHandle subscribePresence(
786 EnumSet<OcConnectivityType> connectivityTypeSet,
787 OnPresenceListener onPresenceListener) throws OcException {
788 OcPlatform.initCheck();
791 for (OcConnectivityType connType : OcConnectivityType.values()) {
792 if (connectivityTypeSet.contains(connType))
793 connTypeInt |= connType.getValue();
795 return OcPlatform.subscribePresence1(
802 private static native OcPresenceHandle subscribePresence1(
805 int connectivityType,
806 OnPresenceListener onPresenceListener) throws OcException;
809 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
810 * a short time still receive events from the server since it may take time for the
811 * unsubscribe to take effect.
813 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
814 * identifies this subscription
815 * @throws OcException if failure
817 public static void unsubscribePresence(
818 OcPresenceHandle ocPresenceHandle) throws OcException {
819 OcPlatform.initCheck();
820 OcPlatform.unsubscribePresence0(ocPresenceHandle);
823 private static native void unsubscribePresence0(
824 OcPresenceHandle ocPresenceHandle) throws OcException;
827 * Creates a resource proxy object so that get/put/observe functionality can be used without
828 * discovering the object in advance. Note that the consumer of this method needs to provide
829 * all of the details required to correctly contact and observe the object. If the consumer
830 * lacks any of this information, they should discover the resource object normally.
831 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
834 * @param host a string containing a resolvable host address of the server holding
836 * @param uri the rest of the resource's URI that will permit messages to be
839 * @param connectivityTypeSet Set of types of connectivity. Example: IP
840 * @param isObservable a boolean containing whether the resource supports observation
841 * @param resourceTypeList a collection of resource types implemented by the resource
842 * @param interfaceList a collection of interfaces that the resource supports/implements
843 * @return new resource object
844 * @throws OcException if failure
846 public static OcResource constructResourceObject(
849 EnumSet<OcConnectivityType> connectivityTypeSet,
850 boolean isObservable,
851 List<String> resourceTypeList,
852 List<String> interfaceList) throws OcException {
853 OcPlatform.initCheck();
856 for (OcConnectivityType connType : OcConnectivityType.values()) {
857 if (connectivityTypeSet.contains(connType))
858 connTypeInt |= connType.getValue();
860 return OcPlatform.constructResourceObject0(
865 resourceTypeList.toArray(new String[resourceTypeList.size()]),
866 interfaceList.toArray(new String[interfaceList.size()])
870 private static native OcResource constructResourceObject0(
873 int connectivityType,
874 boolean isObservable,
875 String[] resourceTypes,
876 String[] interfaces) throws OcException;
879 * Allows application entity handler to send response to an incoming request.
881 * @param ocResourceResponse resource response
882 * @throws OcException if failure
884 public static void sendResponse(OcResourceResponse ocResourceResponse)
886 OcPlatform.initCheck();
887 OcPlatform.sendResponse0(ocResourceResponse);
890 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
894 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
895 * Event listeners are notified asynchronously
897 public interface OnResourceFoundListener {
898 public void onResourceFound(OcResource resource);
902 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
903 * Event listeners are notified asynchronously
905 public interface OnDeviceFoundListener {
906 public void onDeviceFound(OcRepresentation ocRepresentation);
910 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
911 * Event listeners are notified asynchronously
913 public interface OnPlatformFoundListener {
914 public void onPlatformFound(OcRepresentation ocRepresentation);
918 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
919 * Event listeners are notified asynchronously
921 public interface OnPresenceListener {
922 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
926 * An EntityHandler can be registered via the OcPlatform.registerResource call.
927 * Event listeners are notified asynchronously
929 public interface EntityHandler {
930 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
933 private static void initCheck() {
934 if (!sIsPlatformInitialized) {
935 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
936 "OcPlatform.Configure before any other API calls are permitted");
941 * Gets platform quality of service
943 * @return quality of service
945 public static QualityOfService getPlatformQualityOfService() {
946 OcPlatform.initCheck();
947 return sPlatformQualityOfService;