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("connectivity_abstraction");
42 System.loadLibrary("oc");
43 System.loadLibrary("ocprovision");
44 System.loadLibrary("ocstack-jni");
50 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
53 * Used in discovering (GET) links to other resources of a collection
55 public static final String LINK_INTERFACE = "oic.if.ll";
58 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
60 public static final String BATCH_INTERFACE = "oic.if.b";
63 * Used in GET, PUT, POST methods on links to other remote resources of a group
65 public static final String GROUP_INTERFACE = "oic.mi.grp";
67 public static final String WELL_KNOWN_QUERY = "/oic/res";
68 public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
69 public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
70 public static final int DEFAULT_PRESENCE_TTL = 60;
71 public static final String PRESENCE_URI = "/oic/ad";
73 private static volatile boolean sIsPlatformInitialized = false;
74 private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
76 private OcPlatform() {
80 * API for setting the configuration of the OcPlatform.
82 * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
85 * @param platformConfig platform configuration
87 public synchronized static void Configure(PlatformConfig platformConfig) {
88 if (!sIsPlatformInitialized) {
89 CaInterface.initialize(platformConfig.getActivity(), platformConfig.getContext());
91 sPlatformQualityOfService = platformConfig.getQualityOfService();
94 platformConfig.getServiceType().getValue(),
95 platformConfig.getModeType().getValue(),
96 platformConfig.getIpAddress(),
97 platformConfig.getPort(),
98 platformConfig.getQualityOfService().getValue(),
99 platformConfig.getSvrDbPath()
102 sIsPlatformInitialized = true;
106 private static native void configure(int serviceType,
110 int qualityOfService,
114 * API for notifying base that resource's attributes have changed.
116 * Note: This API is for server side only.
119 * @param ocResourceHandle resource handle of the resource
120 * @throws OcException if failure
122 public static void notifyAllObservers(
123 OcResourceHandle ocResourceHandle) throws OcException {
124 OcPlatform.initCheck();
125 OcPlatform.notifyAllObservers0(ocResourceHandle);
128 private static native void notifyAllObservers0(
129 OcResourceHandle ocResourceHandle) throws OcException;
132 * API for notifying base that resource's attributes have changed.
134 * Note: This API is for server side only.
137 * @param ocResourceHandle resource handle of the resource
138 * @param qualityOfService the quality of communication
139 * @throws OcException if failure
141 public static void notifyAllObservers(
142 OcResourceHandle ocResourceHandle,
143 QualityOfService qualityOfService) throws OcException {
144 OcPlatform.initCheck();
145 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
148 private static native void notifyAllObservers1(
149 OcResourceHandle ocResourceHandle,
150 int qualityOfService) throws OcException;
153 * API for notifying only specific clients that resource's attributes have changed.
155 * Note: This API is for server side only.
158 * @param ocResourceHandle resource handle of the resource
159 * @param ocObservationIdList These set of ids are ones which which will be notified upon
161 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
162 * this resource change
163 * @throws OcException if failure
165 public static void notifyListOfObservers(
166 OcResourceHandle ocResourceHandle,
167 List<Byte> ocObservationIdList,
168 OcResourceResponse ocResourceResponse) throws OcException {
169 OcPlatform.initCheck();
171 byte[] idArr = new byte[ocObservationIdList.size()];
172 Iterator<Byte> it = ocObservationIdList.iterator();
174 while (it.hasNext()) {
175 idArr[i++] = (byte) it.next();
178 OcPlatform.notifyListOfObservers2(
184 private static native void notifyListOfObservers2(
185 OcResourceHandle ocResourceHandle,
186 byte[] ocObservationIdArray,
187 OcResourceResponse ocResourceResponse) throws OcException;
190 * API for notifying only specific clients that resource's attributes have changed.
192 * Note: This API is for server side only.
195 * @param ocResourceHandle resource handle of the resource
196 * @param ocObservationIdList These set of ids are ones which which will be notified upon
198 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
199 * this resource change
200 * @param qualityOfService the quality of communication
201 * @throws OcException if failure
203 public static void notifyListOfObservers(
204 OcResourceHandle ocResourceHandle,
205 List<Byte> ocObservationIdList,
206 OcResourceResponse ocResourceResponse,
207 QualityOfService qualityOfService) throws OcException {
208 OcPlatform.initCheck();
210 byte[] idArr = new byte[ocObservationIdList.size()];
211 Iterator<Byte> it = ocObservationIdList.iterator();
213 while (it.hasNext()) {
214 idArr[i++] = (byte) it.next();
217 OcPlatform.notifyListOfObservers3(
221 qualityOfService.getValue()
225 private static native void notifyListOfObservers3(
226 OcResourceHandle ocResourceHandle,
227 byte[] ocObservationIdArray,
228 OcResourceResponse ocResourceResponse,
229 int qualityOfService) throws OcException;
232 * API for Service and Resource Discovery
234 * Note: This API is for client side only.
237 * @param host Host Address of a service to direct resource discovery query.
238 * If empty, performs multicast resource discovery query
239 * @param resourceUri name of the resource. If null or empty, performs search for all
241 * @param connectivityTypeSet Set of types of connectivity. Example: IP
242 * @param onResourceFoundListener Handles events, success states and failure states.
243 * @throws OcException if failure
245 public static void findResource(
248 EnumSet<OcConnectivityType> connectivityTypeSet,
249 OnResourceFoundListener onResourceFoundListener) throws OcException {
250 OcPlatform.initCheck();
254 for (OcConnectivityType connType : OcConnectivityType.values()) {
255 if (connectivityTypeSet.contains(connType))
256 connTypeInt |= connType.getValue();
259 OcPlatform.findResource0(
263 onResourceFoundListener
267 private static native void findResource0(
270 int connectivityType,
271 OnResourceFoundListener onResourceFoundListener) throws OcException;
274 * API for Service and Resource Discovery.
276 * Note: This API is for client side only.
279 * @param host Host IP Address of a service to direct resource discovery query.
280 * If empty, performs multicast resource discovery query
281 * @param resourceUri name of the resource. If null or empty, performs search for all
283 * @param connectivityTypeSet Set of types of connectivity. Example: IP
284 * @param onResourceFoundListener Handles events, success states and failure states.
285 * @param qualityOfService the quality of communication
286 * @throws OcException if failure
288 public static void findResource(
291 EnumSet<OcConnectivityType> connectivityTypeSet,
292 OnResourceFoundListener onResourceFoundListener,
293 QualityOfService qualityOfService) throws OcException {
294 OcPlatform.initCheck();
298 for (OcConnectivityType connType : OcConnectivityType.values()) {
299 if (connectivityTypeSet.contains(connType))
300 connTypeInt |= connType.getValue();
303 OcPlatform.findResource1(host,
306 onResourceFoundListener,
307 qualityOfService.getValue()
311 private static native void findResource1(
314 int connectivityType,
315 OnResourceFoundListener onResourceFoundListener,
316 int qualityOfService) throws OcException;
319 * API for Device Discovery
321 * @param host Host IP Address. If null or empty, Multicast is performed.
322 * @param deviceUri Uri containing address to the virtual device
323 * @param connectivityTypeSet Set of types of connectivity. Example: IP
324 * @param onDeviceFoundListener Handles events, success states and failure states.
325 * @throws OcException if failure
327 public static void getDeviceInfo(
330 EnumSet<OcConnectivityType> connectivityTypeSet,
331 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
332 OcPlatform.initCheck();
335 for (OcConnectivityType connType : OcConnectivityType.values()) {
336 if (connectivityTypeSet.contains(connType))
337 connTypeInt |= connType.getValue();
339 OcPlatform.getDeviceInfo0(
343 onDeviceFoundListener
347 private static native void getDeviceInfo0(
350 int connectivityType,
351 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
354 * API for Device Discovery
356 * @param host Host IP Address. If null or empty, Multicast is performed.
357 * @param deviceUri Uri containing address to the virtual device
358 * @param connectivityTypeSet Set of types of connectivity. Example: IP
359 * @param onDeviceFoundListener Handles events, success states and failure states.
360 * @param qualityOfService the quality of communication
361 * @throws OcException if failure
363 public static void getDeviceInfo(
366 EnumSet<OcConnectivityType> connectivityTypeSet,
367 OnDeviceFoundListener onDeviceFoundListener,
368 QualityOfService qualityOfService) throws OcException {
369 OcPlatform.initCheck();
372 for (OcConnectivityType connType : OcConnectivityType.values()) {
373 if (connectivityTypeSet.contains(connType))
374 connTypeInt |= connType.getValue();
376 OcPlatform.getDeviceInfo1(
380 onDeviceFoundListener,
381 qualityOfService.getValue()
385 private static native void getDeviceInfo1(
388 int connectivityType,
389 OnDeviceFoundListener onDeviceFoundListener,
390 int qualityOfService) throws OcException;
393 * API for Platform Discovery
395 * @param host Host IP Address. If null or empty, Multicast is performed.
396 * @param platformUri Uri containing address to the platform
397 * @param connectivityTypeSet Set of types of connectivity. Example: IP
398 * @param onPlatformFoundListener Handles events, success states and failure states.
399 * @throws OcException if failure
402 public static void getPlatformInfo(
405 EnumSet<OcConnectivityType> connectivityTypeSet,
406 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
407 OcPlatform.initCheck();
410 for (OcConnectivityType connType : OcConnectivityType.values()) {
411 if (connectivityTypeSet.contains(connType))
412 connTypeInt |= connType.getValue();
414 OcPlatform.getPlatformInfo0(
418 onPlatformFoundListener
422 private static native void getPlatformInfo0(
425 int connectivityType,
426 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
429 * API for Platform Discovery
431 * @param host Host IP Address. If null or empty, Multicast is performed.
432 * @param platformUri Uri containing address to the platform
433 * @param connectivityTypeSet Set of types of connectivity. Example: IP
434 * @param onPlatformFoundListener Handles events, success states and failure states.
435 * @param qualityOfService the quality of communication
436 * @throws OcException if failure
439 public static void getPlatformInfo(
442 EnumSet<OcConnectivityType> connectivityTypeSet,
443 OnPlatformFoundListener onPlatformFoundListener,
444 QualityOfService qualityOfService) throws OcException {
445 OcPlatform.initCheck();
448 for (OcConnectivityType connType : OcConnectivityType.values()) {
449 if (connectivityTypeSet.contains(connType))
450 connTypeInt |= connType.getValue();
452 OcPlatform.getPlatformInfo1(
456 onPlatformFoundListener,
457 qualityOfService.getValue()
461 private static native void getPlatformInfo1(
464 int connectivityType,
465 OnPlatformFoundListener onPlatformFoundListener,
466 int qualityOfService) throws OcException;
469 * This API registers a resource with the server
471 * Note: This API applies to server & client side.
474 * @param ocResource The instance of OcResource with all data filled
475 * @return resource handle
476 * @throws OcException if failure
478 public static OcResourceHandle registerResource(
479 OcResource ocResource) throws OcException {
480 OcPlatform.initCheck();
481 return OcPlatform.registerResource0(ocResource);
484 private static native OcResourceHandle registerResource0(
485 OcResource ocResource) throws OcException;
488 * This API registers a resource with the server NOTE: This API applies to server side only.
490 * Note: This API applies to server side only.
493 * @param resourceUri The URI of the resource. Example: "a/light"
494 * @param resourceTypeName The resource type. Example: "light"
495 * @param resourceInterface The resource interface (whether it is collection etc).
496 * @param entityHandler entity handler.
497 * @param resourcePropertySet indicates the property of the resource
498 * @return resource handle
499 * @throws OcException if failure
501 public static OcResourceHandle registerResource(
503 String resourceTypeName,
504 String resourceInterface,
505 EntityHandler entityHandler,
506 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
507 OcPlatform.initCheck();
511 for (ResourceProperty prop : ResourceProperty.values()) {
512 if (resourcePropertySet.contains(prop))
513 resProperty |= prop.getValue();
516 return OcPlatform.registerResource1(resourceUri,
523 private static native OcResourceHandle registerResource1(
525 String resourceTypeName,
526 String resourceInterface,
527 EntityHandler entityHandler,
528 int resourceProperty) throws OcException;
531 * Register Device Info
533 * @param ocDeviceInfo object containing all the device specific information
534 * @throws OcException if failure
536 public static void registerDeviceInfo(
537 OcDeviceInfo ocDeviceInfo) throws OcException {
538 OcPlatform.initCheck();
539 OcPlatform.registerDeviceInfo0(
540 ocDeviceInfo.getDeviceName()
544 private static native void registerDeviceInfo0(
546 ) throws OcException;
549 * Register Platform Info
551 * @param ocPlatformInfo object containing all the platform specific information
552 * @throws OcException if failure
554 public static void registerPlatformInfo(
555 OcPlatformInfo ocPlatformInfo) throws OcException {
556 OcPlatform.initCheck();
557 OcPlatform.registerPlatformInfo0(
558 ocPlatformInfo.getPlatformId(),
559 ocPlatformInfo.getManufacturerName(),
560 ocPlatformInfo.getManufacturerUrl(),
561 ocPlatformInfo.getModelNumber(),
562 ocPlatformInfo.getDateOfManufacture(),
563 ocPlatformInfo.getPlatformVersion(),
564 ocPlatformInfo.getOperatingSystemVersion(),
565 ocPlatformInfo.getHardwareVersion(),
566 ocPlatformInfo.getFirmwareVersion(),
567 ocPlatformInfo.getSupportUrl(),
568 ocPlatformInfo.getSystemTime()
572 private static native void registerPlatformInfo0(
573 String platformId, String manufacturerName, String manufacturerUrl,
574 String modelNumber, String dateOfManufacture, String platformVersion,
575 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
576 String supportUrl, String systemTime
577 ) throws OcException;
580 * This API unregisters a resource with the server NOTE: This API applies to server side only.
582 * @param ocResourceHandle This is the resource handle which we which to unregister from the
584 * @throws OcException if failure
586 public static void unregisterResource(
587 OcResourceHandle ocResourceHandle) throws OcException {
588 OcPlatform.initCheck();
589 OcPlatform.unregisterResource0(ocResourceHandle);
592 private static native void unregisterResource0(
593 OcResourceHandle ocResourceHandle) throws OcException;
597 * Add a resource to a collection resource
599 * @param ocResourceCollectionHandle handle to the collection resource
600 * @param ocResourceHandle handle to resource to be added to the collection resource
601 * @throws OcException if failure
603 public static void bindResource(
604 OcResourceHandle ocResourceCollectionHandle,
605 OcResourceHandle ocResourceHandle) throws OcException {
606 OcPlatform.initCheck();
607 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
610 private static native void bindResource0(
611 OcResourceHandle ocResourceCollectionHandle,
612 OcResourceHandle ocResourceHandle) throws OcException;
615 * Add multiple resources to a collection resource.
617 * @param ocResourceCollectionHandle handle to the collection resource
618 * @param ocResourceHandleList reference to list of resource handles to be added to the
619 * collection resource
620 * @throws OcException if failure
622 public static void bindResources(
623 OcResourceHandle ocResourceCollectionHandle,
624 List<OcResourceHandle> ocResourceHandleList) throws OcException {
625 OcPlatform.initCheck();
626 OcPlatform.bindResources0(
627 ocResourceCollectionHandle,
628 ocResourceHandleList.toArray(
629 new OcResourceHandle[ocResourceHandleList.size()])
633 private static native void bindResources0(
634 OcResourceHandle ocResourceCollectionHandle,
635 OcResourceHandle[] ocResourceHandleArray) throws OcException;
638 * Unbind a resource from a collection resource.
640 * @param ocResourceCollectionHandle handle to the collection resource
641 * @param ocResourceHandle resource handle to be unbound from the collection resource
642 * @throws OcException if failure
644 public static void unbindResource(
645 OcResourceHandle ocResourceCollectionHandle,
646 OcResourceHandle ocResourceHandle) throws OcException {
647 OcPlatform.initCheck();
648 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
651 private static native void unbindResource0(
652 OcResourceHandle ocResourceCollectionHandle,
653 OcResourceHandle ocResourceHandle) throws OcException;
656 * Unbind resources from a collection resource.
658 * @param ocResourceCollectionHandle Handle to the collection resource
659 * @param ocResourceHandleList List of resource handles to be unbound from the collection
661 * @throws OcException if failure
663 public static void unbindResources(
664 OcResourceHandle ocResourceCollectionHandle,
665 List<OcResourceHandle> ocResourceHandleList) throws OcException {
666 OcPlatform.initCheck();
667 OcPlatform.unbindResources0(
668 ocResourceCollectionHandle,
669 ocResourceHandleList.toArray(
670 new OcResourceHandle[ocResourceHandleList.size()])
674 private static native void unbindResources0(
675 OcResourceHandle ocResourceCollectionHandle,
676 OcResourceHandle[] ocResourceHandleArray) throws OcException;
679 * Binds a type to a particular resource
681 * @param ocResourceHandle handle to the resource
682 * @param resourceTypeName new typename to bind to the resource
683 * @throws OcException if failure
685 public static void bindTypeToResource(
686 OcResourceHandle ocResourceHandle,
687 String resourceTypeName) throws OcException {
688 OcPlatform.initCheck();
689 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
692 private static native void bindTypeToResource0(
693 OcResourceHandle ocResourceHandle,
694 String resourceTypeName) throws OcException;
697 * Binds an interface to a particular resource
699 * @param ocResourceHandle handle to the resource
700 * @param resourceInterfaceName new interface to bind to the resource
701 * @throws OcException if failure
703 public static void bindInterfaceToResource(
704 OcResourceHandle ocResourceHandle,
705 String resourceInterfaceName) throws OcException {
706 OcPlatform.initCheck();
707 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
710 private static native void bindInterfaceToResource0(
711 OcResourceHandle ocResourceHandle,
712 String resourceInterfaceName) throws OcException;
715 * Start Presence announcements.
717 * @param ttl time to live in seconds
718 * @throws OcException if failure
720 public static void startPresence(int ttl) throws OcException {
721 OcPlatform.initCheck();
722 OcPlatform.startPresence0(ttl);
725 private static native void startPresence0(int ttl) throws OcException;
728 * Stop Presence announcements.
730 * @throws OcException if failure
732 public static void stopPresence() throws OcException {
733 OcPlatform.initCheck();
734 OcPlatform.stopPresence0();
737 private static native void stopPresence0() throws OcException;
740 * Subscribes to a server's presence change events. By making this subscription, every time a
741 * server adds/removes/alters a resource, starts or is intentionally stopped
743 * @param host The IP address/addressable name of the server to subscribe to
744 * @param connectivityTypeSet Set of types of connectivity. Example: IP
745 * @param onPresenceListener listener that will receive notifications/subscription events
746 * @return a handle object that can be used to identify this subscription request. It can be
747 * used to unsubscribe from these events in the future
748 * @throws OcException if failure
750 public static OcPresenceHandle subscribePresence(
752 EnumSet<OcConnectivityType> connectivityTypeSet,
753 OnPresenceListener onPresenceListener) throws OcException {
754 OcPlatform.initCheck();
757 for (OcConnectivityType connType : OcConnectivityType.values()) {
758 if (connectivityTypeSet.contains(connType))
759 connTypeInt |= connType.getValue();
761 return OcPlatform.subscribePresence0(
768 private static native OcPresenceHandle subscribePresence0(
770 int connectivityType,
771 OnPresenceListener onPresenceListener) throws OcException;
774 * Subscribes to a server's presence change events. By making this subscription, every time a
775 * server adds/removes/alters a resource, starts or is intentionally stopped
777 * @param host The IP address/addressable name of the server to subscribe to
778 * @param resourceType a resource type specified as a filter for subscription events.
779 * @param connectivityTypeSet Set of types of connectivity. Example: IP
780 * @param onPresenceListener listener that will receive notifications/subscription events
781 * @return a handle object that can be used to identify this subscription request. It can be
782 * used to unsubscribe from these events in the future
783 * @throws OcException if failure
785 public static OcPresenceHandle subscribePresence(
788 EnumSet<OcConnectivityType> connectivityTypeSet,
789 OnPresenceListener onPresenceListener) throws OcException {
790 OcPlatform.initCheck();
793 for (OcConnectivityType connType : OcConnectivityType.values()) {
794 if (connectivityTypeSet.contains(connType))
795 connTypeInt |= connType.getValue();
797 return OcPlatform.subscribePresence1(
804 private static native OcPresenceHandle subscribePresence1(
807 int connectivityType,
808 OnPresenceListener onPresenceListener) throws OcException;
811 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
812 * a short time still receive events from the server since it may take time for the
813 * unsubscribe to take effect.
815 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
816 * identifies this subscription
817 * @throws OcException if failure
819 public static void unsubscribePresence(
820 OcPresenceHandle ocPresenceHandle) throws OcException {
821 OcPlatform.initCheck();
822 OcPlatform.unsubscribePresence0(ocPresenceHandle);
825 private static native void unsubscribePresence0(
826 OcPresenceHandle ocPresenceHandle) throws OcException;
829 * Creates a resource proxy object so that get/put/observe functionality can be used without
830 * discovering the object in advance. Note that the consumer of this method needs to provide
831 * all of the details required to correctly contact and observe the object. If the consumer
832 * lacks any of this information, they should discover the resource object normally.
833 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
836 * @param host a string containing a resolvable host address of the server holding
838 * @param uri the rest of the resource's URI that will permit messages to be
841 * @param connectivityTypeSet Set of types of connectivity. Example: IP
842 * @param isObservable a boolean containing whether the resource supports observation
843 * @param resourceTypeList a collection of resource types implemented by the resource
844 * @param interfaceList a collection of interfaces that the resource supports/implements
845 * @return new resource object
846 * @throws OcException if failure
848 public static OcResource constructResourceObject(
851 EnumSet<OcConnectivityType> connectivityTypeSet,
852 boolean isObservable,
853 List<String> resourceTypeList,
854 List<String> interfaceList) throws OcException {
855 OcPlatform.initCheck();
858 for (OcConnectivityType connType : OcConnectivityType.values()) {
859 if (connectivityTypeSet.contains(connType))
860 connTypeInt |= connType.getValue();
862 return OcPlatform.constructResourceObject0(
867 resourceTypeList.toArray(new String[resourceTypeList.size()]),
868 interfaceList.toArray(new String[interfaceList.size()])
872 private static native OcResource constructResourceObject0(
875 int connectivityType,
876 boolean isObservable,
877 String[] resourceTypes,
878 String[] interfaces) throws OcException;
881 * Allows application entity handler to send response to an incoming request.
883 * @param ocResourceResponse resource response
884 * @throws OcException if failure
886 public static void sendResponse(OcResourceResponse ocResourceResponse)
888 OcPlatform.initCheck();
889 OcPlatform.sendResponse0(ocResourceResponse);
892 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
896 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
897 * Event listeners are notified asynchronously
899 public interface OnResourceFoundListener {
900 public void onResourceFound(OcResource resource);
904 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
905 * Event listeners are notified asynchronously
907 public interface OnDeviceFoundListener {
908 public void onDeviceFound(OcRepresentation ocRepresentation);
912 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
913 * Event listeners are notified asynchronously
915 public interface OnPlatformFoundListener {
916 public void onPlatformFound(OcRepresentation ocRepresentation);
920 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
921 * Event listeners are notified asynchronously
923 public interface OnPresenceListener {
924 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
928 * An EntityHandler can be registered via the OcPlatform.registerResource call.
929 * Event listeners are notified asynchronously
931 public interface EntityHandler {
932 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
935 private static void initCheck() {
936 if (!sIsPlatformInitialized) {
937 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
938 "OcPlatform.Configure before any other API calls are permitted");
943 * Gets platform quality of service
945 * @return quality of service
947 public static QualityOfService getPlatformQualityOfService() {
948 OcPlatform.initCheck();
949 return sPlatformQualityOfService;