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;
26 import org.iotivity.base.BuildConfig;
28 import java.util.EnumSet;
29 import java.util.Iterator;
30 import java.util.List;
33 * This class contains the main entrance/functionality of the product. To set a custom
34 * configuration, the implementer must make a call to OcPlatform.Configure before the first usage
35 * of a method in this class.
37 public final class OcPlatform {
40 System.loadLibrary("oc_logger");
41 System.loadLibrary("octbstack");
42 System.loadLibrary("connectivity_abstraction");
43 System.loadLibrary("oc");
44 if (0 != BuildConfig.SECURED)
46 System.loadLibrary("ocprovision");
48 System.loadLibrary("ocstack-jni");
54 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
57 * Used in discovering (GET) links to other resources of a collection
59 public static final String LINK_INTERFACE = "oic.if.ll";
62 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
64 public static final String BATCH_INTERFACE = "oic.if.b";
67 * Used in GET, PUT, POST methods on links to other remote resources of a group
69 public static final String GROUP_INTERFACE = "oic.mi.grp";
71 public static final String WELL_KNOWN_QUERY = "/oic/res";
72 public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
73 public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
74 public static final int DEFAULT_PRESENCE_TTL = 60;
75 public static final String PRESENCE_URI = "/oic/ad";
77 private static volatile boolean sIsPlatformInitialized = false;
78 private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
80 private OcPlatform() {
84 * API for setting the configuration of the OcPlatform.
86 * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
89 * @param platformConfig platform configuration
91 public synchronized static void Configure(PlatformConfig platformConfig) {
92 if (!sIsPlatformInitialized) {
93 CaInterface.initialize(platformConfig.getActivity(), platformConfig.getContext());
95 sPlatformQualityOfService = platformConfig.getQualityOfService();
98 platformConfig.getServiceType().getValue(),
99 platformConfig.getModeType().getValue(),
100 platformConfig.getIpAddress(),
101 platformConfig.getPort(),
102 platformConfig.getQualityOfService().getValue(),
103 platformConfig.getSvrDbPath()
106 sIsPlatformInitialized = true;
110 private static native void configure(int serviceType,
114 int qualityOfService,
118 * API for notifying base that resource's attributes have changed.
120 * Note: This API is for server side only.
123 * @param ocResourceHandle resource handle of the resource
124 * @throws OcException if failure
126 public static void notifyAllObservers(
127 OcResourceHandle ocResourceHandle) throws OcException {
128 OcPlatform.initCheck();
129 OcPlatform.notifyAllObservers0(ocResourceHandle);
132 private static native void notifyAllObservers0(
133 OcResourceHandle ocResourceHandle) throws OcException;
136 * API for notifying base that resource's attributes have changed.
138 * Note: This API is for server side only.
141 * @param ocResourceHandle resource handle of the resource
142 * @param qualityOfService the quality of communication
143 * @throws OcException if failure
145 public static void notifyAllObservers(
146 OcResourceHandle ocResourceHandle,
147 QualityOfService qualityOfService) throws OcException {
148 OcPlatform.initCheck();
149 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
152 private static native void notifyAllObservers1(
153 OcResourceHandle ocResourceHandle,
154 int qualityOfService) throws OcException;
157 * API for notifying only specific clients that resource's attributes have changed.
159 * Note: This API is for server side only.
162 * @param ocResourceHandle resource handle of the resource
163 * @param ocObservationIdList These set of ids are ones which which will be notified upon
165 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
166 * this resource change
167 * @throws OcException if failure
169 public static void notifyListOfObservers(
170 OcResourceHandle ocResourceHandle,
171 List<Byte> ocObservationIdList,
172 OcResourceResponse ocResourceResponse) throws OcException {
173 OcPlatform.initCheck();
175 byte[] idArr = new byte[ocObservationIdList.size()];
176 Iterator<Byte> it = ocObservationIdList.iterator();
178 while (it.hasNext()) {
179 idArr[i++] = (byte) it.next();
182 OcPlatform.notifyListOfObservers2(
188 private static native void notifyListOfObservers2(
189 OcResourceHandle ocResourceHandle,
190 byte[] ocObservationIdArray,
191 OcResourceResponse ocResourceResponse) throws OcException;
194 * API for notifying only specific clients that resource's attributes have changed.
196 * Note: This API is for server side only.
199 * @param ocResourceHandle resource handle of the resource
200 * @param ocObservationIdList These set of ids are ones which which will be notified upon
202 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
203 * this resource change
204 * @param qualityOfService the quality of communication
205 * @throws OcException if failure
207 public static void notifyListOfObservers(
208 OcResourceHandle ocResourceHandle,
209 List<Byte> ocObservationIdList,
210 OcResourceResponse ocResourceResponse,
211 QualityOfService qualityOfService) throws OcException {
212 OcPlatform.initCheck();
214 byte[] idArr = new byte[ocObservationIdList.size()];
215 Iterator<Byte> it = ocObservationIdList.iterator();
217 while (it.hasNext()) {
218 idArr[i++] = (byte) it.next();
221 OcPlatform.notifyListOfObservers3(
225 qualityOfService.getValue()
229 private static native void notifyListOfObservers3(
230 OcResourceHandle ocResourceHandle,
231 byte[] ocObservationIdArray,
232 OcResourceResponse ocResourceResponse,
233 int qualityOfService) throws OcException;
236 * API for Service and Resource Discovery
238 * Note: This API is for client side only.
241 * @param host Host Address of a service to direct resource discovery query.
242 * If empty, performs multicast resource discovery query
243 * @param resourceUri name of the resource. If null or empty, performs search for all
245 * @param connectivityTypeSet Set of types of connectivity. Example: IP
246 * @param onResourceFoundListener Handles events, success states and failure states.
247 * @throws OcException if failure
249 public static void findResource(
252 EnumSet<OcConnectivityType> connectivityTypeSet,
253 OnResourceFoundListener onResourceFoundListener) throws OcException {
254 OcPlatform.initCheck();
258 for (OcConnectivityType connType : OcConnectivityType.values()) {
259 if (connectivityTypeSet.contains(connType))
260 connTypeInt |= connType.getValue();
263 OcPlatform.findResource0(
267 onResourceFoundListener
271 private static native void findResource0(
274 int connectivityType,
275 OnResourceFoundListener onResourceFoundListener) throws OcException;
278 * API for Service and Resource Discovery.
280 * Note: This API is for client side only.
283 * @param host Host IP Address of a service to direct resource discovery query.
284 * If empty, performs multicast resource discovery query
285 * @param resourceUri name of the resource. If null or empty, performs search for all
287 * @param connectivityTypeSet Set of types of connectivity. Example: IP
288 * @param onResourceFoundListener Handles events, success states and failure states.
289 * @param qualityOfService the quality of communication
290 * @throws OcException if failure
292 public static void findResource(
295 EnumSet<OcConnectivityType> connectivityTypeSet,
296 OnResourceFoundListener onResourceFoundListener,
297 QualityOfService qualityOfService) throws OcException {
298 OcPlatform.initCheck();
302 for (OcConnectivityType connType : OcConnectivityType.values()) {
303 if (connectivityTypeSet.contains(connType))
304 connTypeInt |= connType.getValue();
307 OcPlatform.findResource1(host,
310 onResourceFoundListener,
311 qualityOfService.getValue()
315 private static native void findResource1(
318 int connectivityType,
319 OnResourceFoundListener onResourceFoundListener,
320 int qualityOfService) throws OcException;
323 * API for Device Discovery
325 * @param host Host IP Address. If null or empty, Multicast is performed.
326 * @param deviceUri Uri containing address to the virtual device
327 * @param connectivityTypeSet Set of types of connectivity. Example: IP
328 * @param onDeviceFoundListener Handles events, success states and failure states.
329 * @throws OcException if failure
331 public static void getDeviceInfo(
334 EnumSet<OcConnectivityType> connectivityTypeSet,
335 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
336 OcPlatform.initCheck();
339 for (OcConnectivityType connType : OcConnectivityType.values()) {
340 if (connectivityTypeSet.contains(connType))
341 connTypeInt |= connType.getValue();
343 OcPlatform.getDeviceInfo0(
347 onDeviceFoundListener
351 private static native void getDeviceInfo0(
354 int connectivityType,
355 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
358 * API for Device Discovery
360 * @param host Host IP Address. If null or empty, Multicast is performed.
361 * @param deviceUri Uri containing address to the virtual device
362 * @param connectivityTypeSet Set of types of connectivity. Example: IP
363 * @param onDeviceFoundListener Handles events, success states and failure states.
364 * @param qualityOfService the quality of communication
365 * @throws OcException if failure
367 public static void getDeviceInfo(
370 EnumSet<OcConnectivityType> connectivityTypeSet,
371 OnDeviceFoundListener onDeviceFoundListener,
372 QualityOfService qualityOfService) throws OcException {
373 OcPlatform.initCheck();
376 for (OcConnectivityType connType : OcConnectivityType.values()) {
377 if (connectivityTypeSet.contains(connType))
378 connTypeInt |= connType.getValue();
380 OcPlatform.getDeviceInfo1(
384 onDeviceFoundListener,
385 qualityOfService.getValue()
389 private static native void getDeviceInfo1(
392 int connectivityType,
393 OnDeviceFoundListener onDeviceFoundListener,
394 int qualityOfService) throws OcException;
397 * API for Platform Discovery
399 * @param host Host IP Address. If null or empty, Multicast is performed.
400 * @param platformUri Uri containing address to the platform
401 * @param connectivityTypeSet Set of types of connectivity. Example: IP
402 * @param onPlatformFoundListener Handles events, success states and failure states.
403 * @throws OcException if failure
406 public static void getPlatformInfo(
409 EnumSet<OcConnectivityType> connectivityTypeSet,
410 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
411 OcPlatform.initCheck();
414 for (OcConnectivityType connType : OcConnectivityType.values()) {
415 if (connectivityTypeSet.contains(connType))
416 connTypeInt |= connType.getValue();
418 OcPlatform.getPlatformInfo0(
422 onPlatformFoundListener
426 private static native void getPlatformInfo0(
429 int connectivityType,
430 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
433 * API for Platform Discovery
435 * @param host Host IP Address. If null or empty, Multicast is performed.
436 * @param platformUri Uri containing address to the platform
437 * @param connectivityTypeSet Set of types of connectivity. Example: IP
438 * @param onPlatformFoundListener Handles events, success states and failure states.
439 * @param qualityOfService the quality of communication
440 * @throws OcException if failure
443 public static void getPlatformInfo(
446 EnumSet<OcConnectivityType> connectivityTypeSet,
447 OnPlatformFoundListener onPlatformFoundListener,
448 QualityOfService qualityOfService) throws OcException {
449 OcPlatform.initCheck();
452 for (OcConnectivityType connType : OcConnectivityType.values()) {
453 if (connectivityTypeSet.contains(connType))
454 connTypeInt |= connType.getValue();
456 OcPlatform.getPlatformInfo1(
460 onPlatformFoundListener,
461 qualityOfService.getValue()
465 private static native void getPlatformInfo1(
468 int connectivityType,
469 OnPlatformFoundListener onPlatformFoundListener,
470 int qualityOfService) throws OcException;
473 * This API registers a resource with the server
475 * Note: This API applies to server & client side.
478 * @param ocResource The instance of OcResource with all data filled
479 * @return resource handle
480 * @throws OcException if failure
482 public static OcResourceHandle registerResource(
483 OcResource ocResource) throws OcException {
484 OcPlatform.initCheck();
485 return OcPlatform.registerResource0(ocResource);
488 private static native OcResourceHandle registerResource0(
489 OcResource ocResource) throws OcException;
492 * This API registers a resource with the server NOTE: This API applies to server side only.
494 * Note: This API applies to server side only.
497 * @param resourceUri The URI of the resource. Example: "a/light"
498 * @param resourceTypeName The resource type. Example: "light"
499 * @param resourceInterface The resource interface (whether it is collection etc).
500 * @param entityHandler entity handler.
501 * @param resourcePropertySet indicates the property of the resource
502 * @return resource handle
503 * @throws OcException if failure
505 public static OcResourceHandle registerResource(
507 String resourceTypeName,
508 String resourceInterface,
509 EntityHandler entityHandler,
510 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
511 OcPlatform.initCheck();
515 for (ResourceProperty prop : ResourceProperty.values()) {
516 if (resourcePropertySet.contains(prop))
517 resProperty |= prop.getValue();
520 return OcPlatform.registerResource1(resourceUri,
527 private static native OcResourceHandle registerResource1(
529 String resourceTypeName,
530 String resourceInterface,
531 EntityHandler entityHandler,
532 int resourceProperty) throws OcException;
535 * Register Device Info
537 * @param ocDeviceInfo object containing all the device specific information
538 * @throws OcException if failure
540 public static void registerDeviceInfo(
541 OcDeviceInfo ocDeviceInfo) throws OcException {
542 OcPlatform.initCheck();
543 OcPlatform.registerDeviceInfo0(
544 ocDeviceInfo.getDeviceName(),
545 ocDeviceInfo.getDeviceTypes().toArray(
546 new String[ocDeviceInfo.getDeviceTypes().size()]
551 private static native void registerDeviceInfo0(
554 ) throws OcException;
557 * Register Platform Info
559 * @param ocPlatformInfo object containing all the platform specific information
560 * @throws OcException if failure
562 public static void registerPlatformInfo(
563 OcPlatformInfo ocPlatformInfo) throws OcException {
564 OcPlatform.initCheck();
565 OcPlatform.registerPlatformInfo0(
566 ocPlatformInfo.getPlatformId(),
567 ocPlatformInfo.getManufacturerName(),
568 ocPlatformInfo.getManufacturerUrl(),
569 ocPlatformInfo.getModelNumber(),
570 ocPlatformInfo.getDateOfManufacture(),
571 ocPlatformInfo.getPlatformVersion(),
572 ocPlatformInfo.getOperatingSystemVersion(),
573 ocPlatformInfo.getHardwareVersion(),
574 ocPlatformInfo.getFirmwareVersion(),
575 ocPlatformInfo.getSupportUrl(),
576 ocPlatformInfo.getSystemTime()
580 private static native void registerPlatformInfo0(
581 String platformId, String manufacturerName, String manufacturerUrl,
582 String modelNumber, String dateOfManufacture, String platformVersion,
583 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
584 String supportUrl, String systemTime
585 ) throws OcException;
588 * This API unregisters a resource with the server NOTE: This API applies to server side only.
590 * @param ocResourceHandle This is the resource handle which we which to unregister from the
592 * @throws OcException if failure
594 public static void unregisterResource(
595 OcResourceHandle ocResourceHandle) throws OcException {
596 OcPlatform.initCheck();
597 OcPlatform.unregisterResource0(ocResourceHandle);
600 private static native void unregisterResource0(
601 OcResourceHandle ocResourceHandle) throws OcException;
605 * Add a resource to a collection resource
607 * @param ocResourceCollectionHandle handle to the collection resource
608 * @param ocResourceHandle handle to resource to be added to the collection resource
609 * @throws OcException if failure
611 public static void bindResource(
612 OcResourceHandle ocResourceCollectionHandle,
613 OcResourceHandle ocResourceHandle) throws OcException {
614 OcPlatform.initCheck();
615 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
618 private static native void bindResource0(
619 OcResourceHandle ocResourceCollectionHandle,
620 OcResourceHandle ocResourceHandle) throws OcException;
623 * Add multiple resources to a collection resource.
625 * @param ocResourceCollectionHandle handle to the collection resource
626 * @param ocResourceHandleList reference to list of resource handles to be added to the
627 * collection resource
628 * @throws OcException if failure
630 public static void bindResources(
631 OcResourceHandle ocResourceCollectionHandle,
632 List<OcResourceHandle> ocResourceHandleList) throws OcException {
633 OcPlatform.initCheck();
634 OcPlatform.bindResources0(
635 ocResourceCollectionHandle,
636 ocResourceHandleList.toArray(
637 new OcResourceHandle[ocResourceHandleList.size()])
641 private static native void bindResources0(
642 OcResourceHandle ocResourceCollectionHandle,
643 OcResourceHandle[] ocResourceHandleArray) throws OcException;
646 * Unbind a resource from a collection resource.
648 * @param ocResourceCollectionHandle handle to the collection resource
649 * @param ocResourceHandle resource handle to be unbound from the collection resource
650 * @throws OcException if failure
652 public static void unbindResource(
653 OcResourceHandle ocResourceCollectionHandle,
654 OcResourceHandle ocResourceHandle) throws OcException {
655 OcPlatform.initCheck();
656 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
659 private static native void unbindResource0(
660 OcResourceHandle ocResourceCollectionHandle,
661 OcResourceHandle ocResourceHandle) throws OcException;
664 * Unbind resources from a collection resource.
666 * @param ocResourceCollectionHandle Handle to the collection resource
667 * @param ocResourceHandleList List of resource handles to be unbound from the collection
669 * @throws OcException if failure
671 public static void unbindResources(
672 OcResourceHandle ocResourceCollectionHandle,
673 List<OcResourceHandle> ocResourceHandleList) throws OcException {
674 OcPlatform.initCheck();
675 OcPlatform.unbindResources0(
676 ocResourceCollectionHandle,
677 ocResourceHandleList.toArray(
678 new OcResourceHandle[ocResourceHandleList.size()])
682 private static native void unbindResources0(
683 OcResourceHandle ocResourceCollectionHandle,
684 OcResourceHandle[] ocResourceHandleArray) throws OcException;
687 * Binds a type to a particular resource
689 * @param ocResourceHandle handle to the resource
690 * @param resourceTypeName new typename to bind to the resource
691 * @throws OcException if failure
693 public static void bindTypeToResource(
694 OcResourceHandle ocResourceHandle,
695 String resourceTypeName) throws OcException {
696 OcPlatform.initCheck();
697 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
700 private static native void bindTypeToResource0(
701 OcResourceHandle ocResourceHandle,
702 String resourceTypeName) throws OcException;
705 * Binds an interface to a particular resource
707 * @param ocResourceHandle handle to the resource
708 * @param resourceInterfaceName new interface to bind to the resource
709 * @throws OcException if failure
711 public static void bindInterfaceToResource(
712 OcResourceHandle ocResourceHandle,
713 String resourceInterfaceName) throws OcException {
714 OcPlatform.initCheck();
715 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
718 private static native void bindInterfaceToResource0(
719 OcResourceHandle ocResourceHandle,
720 String resourceInterfaceName) throws OcException;
723 * Start Presence announcements.
725 * @param ttl time to live in seconds
726 * @throws OcException if failure
728 public static void startPresence(int ttl) throws OcException {
729 OcPlatform.initCheck();
730 OcPlatform.startPresence0(ttl);
733 private static native void startPresence0(int ttl) throws OcException;
736 * Stop Presence announcements.
738 * @throws OcException if failure
740 public static void stopPresence() throws OcException {
741 OcPlatform.initCheck();
742 OcPlatform.stopPresence0();
745 private static native void stopPresence0() throws OcException;
748 * Subscribes to a server's presence change events. By making this subscription, every time a
749 * server adds/removes/alters a resource, starts or is intentionally stopped
751 * @param host The IP address/addressable name of the server to subscribe to
752 * @param connectivityTypeSet Set of types of connectivity. Example: IP
753 * @param onPresenceListener listener that will receive notifications/subscription events
754 * @return a handle object that can be used to identify this subscription request. It can be
755 * used to unsubscribe from these events in the future
756 * @throws OcException if failure
758 public static OcPresenceHandle subscribePresence(
760 EnumSet<OcConnectivityType> connectivityTypeSet,
761 OnPresenceListener onPresenceListener) throws OcException {
762 OcPlatform.initCheck();
765 for (OcConnectivityType connType : OcConnectivityType.values()) {
766 if (connectivityTypeSet.contains(connType))
767 connTypeInt |= connType.getValue();
769 return OcPlatform.subscribePresence0(
776 private static native OcPresenceHandle subscribePresence0(
778 int connectivityType,
779 OnPresenceListener onPresenceListener) throws OcException;
782 * Subscribes to a server's presence change events. By making this subscription, every time a
783 * server adds/removes/alters a resource, starts or is intentionally stopped
785 * @param host The IP address/addressable name of the server to subscribe to
786 * @param resourceType a resource type specified as a filter for subscription events.
787 * @param connectivityTypeSet Set of types of connectivity. Example: IP
788 * @param onPresenceListener listener that will receive notifications/subscription events
789 * @return a handle object that can be used to identify this subscription request. It can be
790 * used to unsubscribe from these events in the future
791 * @throws OcException if failure
793 public static OcPresenceHandle subscribePresence(
796 EnumSet<OcConnectivityType> connectivityTypeSet,
797 OnPresenceListener onPresenceListener) throws OcException {
798 OcPlatform.initCheck();
801 for (OcConnectivityType connType : OcConnectivityType.values()) {
802 if (connectivityTypeSet.contains(connType))
803 connTypeInt |= connType.getValue();
805 return OcPlatform.subscribePresence1(
812 private static native OcPresenceHandle subscribePresence1(
815 int connectivityType,
816 OnPresenceListener onPresenceListener) throws OcException;
819 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
820 * a short time still receive events from the server since it may take time for the
821 * unsubscribe to take effect.
823 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
824 * identifies this subscription
825 * @throws OcException if failure
827 public static void unsubscribePresence(
828 OcPresenceHandle ocPresenceHandle) throws OcException {
829 OcPlatform.initCheck();
830 OcPlatform.unsubscribePresence0(ocPresenceHandle);
833 private static native void unsubscribePresence0(
834 OcPresenceHandle ocPresenceHandle) throws OcException;
837 * Creates a resource proxy object so that get/put/observe functionality can be used without
838 * discovering the object in advance. Note that the consumer of this method needs to provide
839 * all of the details required to correctly contact and observe the object. If the consumer
840 * lacks any of this information, they should discover the resource object normally.
841 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
844 * @param host a string containing a resolvable host address of the server holding
846 * @param uri the rest of the resource's URI that will permit messages to be
849 * @param connectivityTypeSet Set of types of connectivity. Example: IP
850 * @param isObservable a boolean containing whether the resource supports observation
851 * @param resourceTypeList a collection of resource types implemented by the resource
852 * @param interfaceList a collection of interfaces that the resource supports/implements
853 * @return new resource object
854 * @throws OcException if failure
856 public static OcResource constructResourceObject(
859 EnumSet<OcConnectivityType> connectivityTypeSet,
860 boolean isObservable,
861 List<String> resourceTypeList,
862 List<String> interfaceList) throws OcException {
863 OcPlatform.initCheck();
866 for (OcConnectivityType connType : OcConnectivityType.values()) {
867 if (connectivityTypeSet.contains(connType))
868 connTypeInt |= connType.getValue();
870 return OcPlatform.constructResourceObject0(
875 resourceTypeList.toArray(new String[resourceTypeList.size()]),
876 interfaceList.toArray(new String[interfaceList.size()])
880 private static native OcResource constructResourceObject0(
883 int connectivityType,
884 boolean isObservable,
885 String[] resourceTypes,
886 String[] interfaces) throws OcException;
889 * Allows application entity handler to send response to an incoming request.
891 * @param ocResourceResponse resource response
892 * @throws OcException if failure
894 public static void sendResponse(OcResourceResponse ocResourceResponse)
896 OcPlatform.initCheck();
897 OcPlatform.sendResponse0(ocResourceResponse);
900 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
904 * Method to find all devices which are eligible for direct pairing and return the list.
906 * @param timeout timeout for discovering direct pair devices.
907 * @param FindDirectPairingListener Callback function, which will receive the list of direct
909 * @throws OcException
911 public static native void findDirectPairingDevices(int timeout,
912 FindDirectPairingListener onFindDirectPairingListener) throws OcException;
915 * Method to get list of all paired devices for a given device.
917 * @param GetDirectPairedListener Callback function, which will receive the list of direct
919 * @throws OcException
921 public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
925 * Method to perform direct pairing between two devices.
927 * @param peer Target peer
928 * @param prmType Pairing Method to be used for Pairing
930 * @param DirectPairingListener Callback function, which will be called after
931 * completion of direct pairing.
932 * @throws OcException
934 public static void doDirectPairing(
935 OcDirectPairDevice peer,
938 DirectPairingListener onDirectPairingListener) throws OcException {
940 OcPlatform.doDirectPairing0(
944 onDirectPairingListener
948 private static native void doDirectPairing0(OcDirectPairDevice peer,
949 int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
953 * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
954 * Event listeners are notified asynchronously
956 public interface FindDirectPairingListener {
957 public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
961 * Listerner to Get List of already Direct Paired devices.
962 * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
963 * Event listeners are notified asynchronously
965 public interface GetDirectPairedListener {
966 public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
970 * Listner to get result of doDirectPairing.
971 * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
972 * Event listeners are notified asynchronously
974 public interface DirectPairingListener {
975 public void onDirectPairingListener(String devId, int result);
979 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
980 * Event listeners are notified asynchronously
982 public interface OnResourceFoundListener {
983 public void onResourceFound(OcResource resource);
987 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
988 * Event listeners are notified asynchronously
990 public interface OnDeviceFoundListener {
991 public void onDeviceFound(OcRepresentation ocRepresentation);
995 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
996 * Event listeners are notified asynchronously
998 public interface OnPlatformFoundListener {
999 public void onPlatformFound(OcRepresentation ocRepresentation);
1003 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
1004 * Event listeners are notified asynchronously
1006 public interface OnPresenceListener {
1007 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
1011 * An EntityHandler can be registered via the OcPlatform.registerResource call.
1012 * Event listeners are notified asynchronously
1014 public interface EntityHandler {
1015 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
1018 private static void initCheck() {
1019 if (!sIsPlatformInitialized) {
1020 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
1021 "OcPlatform.Configure before any other API calls are permitted");
1026 * Gets platform quality of service
1028 * @return quality of service
1030 public static QualityOfService getPlatformQualityOfService() {
1031 OcPlatform.initCheck();
1032 return sPlatformQualityOfService;