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 if (ocObservationIdList == null) {
176 throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null");
179 byte[] idArr = new byte[ocObservationIdList.size()];
180 Iterator<Byte> it = ocObservationIdList.iterator();
182 while (it.hasNext()) {
183 idArr[i++] = (byte) it.next();
186 OcPlatform.notifyListOfObservers2(
192 private static native void notifyListOfObservers2(
193 OcResourceHandle ocResourceHandle,
194 byte[] ocObservationIdArray,
195 OcResourceResponse ocResourceResponse) throws OcException;
198 * API for notifying only specific clients that resource's attributes have changed.
200 * Note: This API is for server side only.
203 * @param ocResourceHandle resource handle of the resource
204 * @param ocObservationIdList These set of ids are ones which which will be notified upon
206 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
207 * this resource change
208 * @param qualityOfService the quality of communication
209 * @throws OcException if failure
211 public static void notifyListOfObservers(
212 OcResourceHandle ocResourceHandle,
213 List<Byte> ocObservationIdList,
214 OcResourceResponse ocResourceResponse,
215 QualityOfService qualityOfService) throws OcException {
216 OcPlatform.initCheck();
218 if (ocObservationIdList == null) {
219 throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null");
222 byte[] idArr = new byte[ocObservationIdList.size()];
223 Iterator<Byte> it = ocObservationIdList.iterator();
225 while (it.hasNext()) {
226 idArr[i++] = (byte) it.next();
229 OcPlatform.notifyListOfObservers3(
233 qualityOfService.getValue()
237 private static native void notifyListOfObservers3(
238 OcResourceHandle ocResourceHandle,
239 byte[] ocObservationIdArray,
240 OcResourceResponse ocResourceResponse,
241 int qualityOfService) throws OcException;
244 * API for Service and Resource Discovery
246 * Note: This API is for client side only.
249 * @param host Host Address of a service to direct resource discovery query.
250 * If empty, performs multicast resource discovery query
251 * @param resourceUri name of the resource. If null or empty, performs search for all
253 * @param connectivityTypeSet Set of types of connectivity. Example: IP
254 * @param onResourceFoundListener Handles events, success states and failure states.
255 * @throws OcException if failure
257 public static void findResource(
260 EnumSet<OcConnectivityType> connectivityTypeSet,
261 OnResourceFoundListener onResourceFoundListener) throws OcException {
262 OcPlatform.initCheck();
266 for (OcConnectivityType connType : OcConnectivityType.values()) {
267 if (connectivityTypeSet.contains(connType))
268 connTypeInt |= connType.getValue();
271 OcPlatform.findResource0(
275 onResourceFoundListener
279 private static native void findResource0(
282 int connectivityType,
283 OnResourceFoundListener onResourceFoundListener) throws OcException;
286 * API for Service and Resource Discovery.
288 * Note: This API is for client side only.
291 * @param host Host IP Address of a service to direct resource discovery query.
292 * If empty, performs multicast resource discovery query
293 * @param resourceUri name of the resource. If null or empty, performs search for all
295 * @param connectivityTypeSet Set of types of connectivity. Example: IP
296 * @param onResourceFoundListener Handles events, success states and failure states.
297 * @param qualityOfService the quality of communication
298 * @throws OcException if failure
300 public static void findResource(
303 EnumSet<OcConnectivityType> connectivityTypeSet,
304 OnResourceFoundListener onResourceFoundListener,
305 QualityOfService qualityOfService) throws OcException {
306 OcPlatform.initCheck();
310 for (OcConnectivityType connType : OcConnectivityType.values()) {
311 if (connectivityTypeSet.contains(connType))
312 connTypeInt |= connType.getValue();
315 OcPlatform.findResource1(host,
318 onResourceFoundListener,
319 qualityOfService.getValue()
323 private static native void findResource1(
326 int connectivityType,
327 OnResourceFoundListener onResourceFoundListener,
328 int qualityOfService) throws OcException;
331 * API for Device Discovery
333 * @param host Host IP Address. If null or empty, Multicast is performed.
334 * @param deviceUri Uri containing address to the virtual device
335 * @param connectivityTypeSet Set of types of connectivity. Example: IP
336 * @param onDeviceFoundListener Handles events, success states and failure states.
337 * @throws OcException if failure
339 public static void getDeviceInfo(
342 EnumSet<OcConnectivityType> connectivityTypeSet,
343 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
344 OcPlatform.initCheck();
347 for (OcConnectivityType connType : OcConnectivityType.values()) {
348 if (connectivityTypeSet.contains(connType))
349 connTypeInt |= connType.getValue();
351 OcPlatform.getDeviceInfo0(
355 onDeviceFoundListener
359 private static native void getDeviceInfo0(
362 int connectivityType,
363 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
366 * API for Device Discovery
368 * @param host Host IP Address. If null or empty, Multicast is performed.
369 * @param deviceUri Uri containing address to the virtual device
370 * @param connectivityTypeSet Set of types of connectivity. Example: IP
371 * @param onDeviceFoundListener Handles events, success states and failure states.
372 * @param qualityOfService the quality of communication
373 * @throws OcException if failure
375 public static void getDeviceInfo(
378 EnumSet<OcConnectivityType> connectivityTypeSet,
379 OnDeviceFoundListener onDeviceFoundListener,
380 QualityOfService qualityOfService) throws OcException {
381 OcPlatform.initCheck();
384 for (OcConnectivityType connType : OcConnectivityType.values()) {
385 if (connectivityTypeSet.contains(connType))
386 connTypeInt |= connType.getValue();
388 OcPlatform.getDeviceInfo1(
392 onDeviceFoundListener,
393 qualityOfService.getValue()
397 private static native void getDeviceInfo1(
400 int connectivityType,
401 OnDeviceFoundListener onDeviceFoundListener,
402 int qualityOfService) throws OcException;
405 * API for Platform Discovery
407 * @param host Host IP Address. If null or empty, Multicast is performed.
408 * @param platformUri Uri containing address to the platform
409 * @param connectivityTypeSet Set of types of connectivity. Example: IP
410 * @param onPlatformFoundListener Handles events, success states and failure states.
411 * @throws OcException if failure
414 public static void getPlatformInfo(
417 EnumSet<OcConnectivityType> connectivityTypeSet,
418 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
419 OcPlatform.initCheck();
422 for (OcConnectivityType connType : OcConnectivityType.values()) {
423 if (connectivityTypeSet.contains(connType))
424 connTypeInt |= connType.getValue();
426 OcPlatform.getPlatformInfo0(
430 onPlatformFoundListener
434 private static native void getPlatformInfo0(
437 int connectivityType,
438 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
441 * API for Platform Discovery
443 * @param host Host IP Address. If null or empty, Multicast is performed.
444 * @param platformUri Uri containing address to the platform
445 * @param connectivityTypeSet Set of types of connectivity. Example: IP
446 * @param onPlatformFoundListener Handles events, success states and failure states.
447 * @param qualityOfService the quality of communication
448 * @throws OcException if failure
451 public static void getPlatformInfo(
454 EnumSet<OcConnectivityType> connectivityTypeSet,
455 OnPlatformFoundListener onPlatformFoundListener,
456 QualityOfService qualityOfService) throws OcException {
457 OcPlatform.initCheck();
460 for (OcConnectivityType connType : OcConnectivityType.values()) {
461 if (connectivityTypeSet.contains(connType))
462 connTypeInt |= connType.getValue();
464 OcPlatform.getPlatformInfo1(
468 onPlatformFoundListener,
469 qualityOfService.getValue()
473 private static native void getPlatformInfo1(
476 int connectivityType,
477 OnPlatformFoundListener onPlatformFoundListener,
478 int qualityOfService) throws OcException;
481 * This API registers a resource with the server
483 * Note: This API applies to server & client side.
486 * @param ocResource The instance of OcResource with all data filled
487 * @return resource handle
488 * @throws OcException if failure
490 public static OcResourceHandle registerResource(
491 OcResource ocResource) throws OcException {
492 OcPlatform.initCheck();
493 return OcPlatform.registerResource0(ocResource);
496 private static native OcResourceHandle registerResource0(
497 OcResource ocResource) throws OcException;
500 * This API registers a resource with the server NOTE: This API applies to server side only.
502 * Note: This API applies to server side only.
505 * @param resourceUri The URI of the resource. Example: "a/light"
506 * @param resourceTypeName The resource type. Example: "light"
507 * @param resourceInterface The resource interface (whether it is collection etc).
508 * @param entityHandler entity handler.
509 * @param resourcePropertySet indicates the property of the resource
510 * @return resource handle
511 * @throws OcException if failure
513 public static OcResourceHandle registerResource(
515 String resourceTypeName,
516 String resourceInterface,
517 EntityHandler entityHandler,
518 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
519 OcPlatform.initCheck();
523 for (ResourceProperty prop : ResourceProperty.values()) {
524 if (resourcePropertySet.contains(prop))
525 resProperty |= prop.getValue();
528 return OcPlatform.registerResource1(resourceUri,
535 private static native OcResourceHandle registerResource1(
537 String resourceTypeName,
538 String resourceInterface,
539 EntityHandler entityHandler,
540 int resourceProperty) throws OcException;
543 * Register Device Info
545 * @param ocDeviceInfo object containing all the device specific information
546 * @throws OcException if failure
548 public static void registerDeviceInfo(
549 OcDeviceInfo ocDeviceInfo) throws OcException {
550 OcPlatform.initCheck();
551 OcPlatform.registerDeviceInfo0(
552 ocDeviceInfo.getDeviceName(),
553 ocDeviceInfo.getDeviceTypes().toArray(
554 new String[ocDeviceInfo.getDeviceTypes().size()]
559 private static native void registerDeviceInfo0(
562 ) throws OcException;
567 * @param ocDeviceInfo object containing all the device specific information
568 * @throws OcException if failure
570 public static void setPropertyValue(
571 int path, String propName, String propValue) throws OcException {
572 OcPlatform.initCheck();
573 OcPlatform.setPropertyValue0(path, propName, propValue);
576 public static void setPropertyValue(
577 int path, String propName, List<String> propValue) throws OcException {
578 OcPlatform.initCheck();
579 OcPlatform.setPropertyValue1(path, propName, propValue.toArray(new String[propValue.size()]));
582 public static void getPropertyValue(
583 int path, String propName, String propValue) throws OcException {
584 OcPlatform.initCheck();
585 OcPlatform.getPropertyValue0(path, propName, propValue);
588 private static native void setPropertyValue0(
592 ) throws OcException;
595 private static native void setPropertyValue1(
599 ) throws OcException;
601 private static native void getPropertyValue0(
605 ) throws OcException;
608 * Register Platform Info
610 * @param ocPlatformInfo object containing all the platform specific information
611 * @throws OcException if failure
613 public static void registerPlatformInfo(
614 OcPlatformInfo ocPlatformInfo) throws OcException {
615 OcPlatform.initCheck();
616 OcPlatform.registerPlatformInfo0(
617 ocPlatformInfo.getPlatformId(),
618 ocPlatformInfo.getManufacturerName(),
619 ocPlatformInfo.getManufacturerUrl(),
620 ocPlatformInfo.getModelNumber(),
621 ocPlatformInfo.getDateOfManufacture(),
622 ocPlatformInfo.getPlatformVersion(),
623 ocPlatformInfo.getOperatingSystemVersion(),
624 ocPlatformInfo.getHardwareVersion(),
625 ocPlatformInfo.getFirmwareVersion(),
626 ocPlatformInfo.getSupportUrl(),
627 ocPlatformInfo.getSystemTime()
631 private static native void registerPlatformInfo0(
632 String platformId, String manufacturerName, String manufacturerUrl,
633 String modelNumber, String dateOfManufacture, String platformVersion,
634 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
635 String supportUrl, String systemTime
636 ) throws OcException;
639 * This API unregisters a resource with the server NOTE: This API applies to server side only.
641 * @param ocResourceHandle This is the resource handle which we which to unregister from the
643 * @throws OcException if failure
645 public static void unregisterResource(
646 OcResourceHandle ocResourceHandle) throws OcException {
647 OcPlatform.initCheck();
648 OcPlatform.unregisterResource0(ocResourceHandle);
651 private static native void unregisterResource0(
652 OcResourceHandle ocResourceHandle) throws OcException;
656 * Add a resource to a collection resource
658 * @param ocResourceCollectionHandle handle to the collection resource
659 * @param ocResourceHandle handle to resource to be added to the collection resource
660 * @throws OcException if failure
662 public static void bindResource(
663 OcResourceHandle ocResourceCollectionHandle,
664 OcResourceHandle ocResourceHandle) throws OcException {
665 OcPlatform.initCheck();
666 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
669 private static native void bindResource0(
670 OcResourceHandle ocResourceCollectionHandle,
671 OcResourceHandle ocResourceHandle) throws OcException;
674 * Add multiple resources to a collection resource.
676 * @param ocResourceCollectionHandle handle to the collection resource
677 * @param ocResourceHandleList reference to list of resource handles to be added to the
678 * collection resource
679 * @throws OcException if failure
681 public static void bindResources(
682 OcResourceHandle ocResourceCollectionHandle,
683 List<OcResourceHandle> ocResourceHandleList) throws OcException {
684 OcPlatform.initCheck();
686 if (ocResourceHandleList == null) {
687 throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
690 OcPlatform.bindResources0(
691 ocResourceCollectionHandle,
692 ocResourceHandleList.toArray(
693 new OcResourceHandle[ocResourceHandleList.size()])
697 private static native void bindResources0(
698 OcResourceHandle ocResourceCollectionHandle,
699 OcResourceHandle[] ocResourceHandleArray) throws OcException;
702 * Unbind a resource from a collection resource.
704 * @param ocResourceCollectionHandle handle to the collection resource
705 * @param ocResourceHandle resource handle to be unbound from the collection resource
706 * @throws OcException if failure
708 public static void unbindResource(
709 OcResourceHandle ocResourceCollectionHandle,
710 OcResourceHandle ocResourceHandle) throws OcException {
711 OcPlatform.initCheck();
712 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
715 private static native void unbindResource0(
716 OcResourceHandle ocResourceCollectionHandle,
717 OcResourceHandle ocResourceHandle) throws OcException;
720 * Unbind resources from a collection resource.
722 * @param ocResourceCollectionHandle Handle to the collection resource
723 * @param ocResourceHandleList List of resource handles to be unbound from the collection
725 * @throws OcException if failure
727 public static void unbindResources(
728 OcResourceHandle ocResourceCollectionHandle,
729 List<OcResourceHandle> ocResourceHandleList) throws OcException {
730 OcPlatform.initCheck();
732 if (ocResourceHandleList == null) {
733 throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
736 OcPlatform.unbindResources0(
737 ocResourceCollectionHandle,
738 ocResourceHandleList.toArray(
739 new OcResourceHandle[ocResourceHandleList.size()])
743 private static native void unbindResources0(
744 OcResourceHandle ocResourceCollectionHandle,
745 OcResourceHandle[] ocResourceHandleArray) throws OcException;
748 * Binds a type to a particular resource
750 * @param ocResourceHandle handle to the resource
751 * @param resourceTypeName new typename to bind to the resource
752 * @throws OcException if failure
754 public static void bindTypeToResource(
755 OcResourceHandle ocResourceHandle,
756 String resourceTypeName) throws OcException {
757 OcPlatform.initCheck();
758 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
761 private static native void bindTypeToResource0(
762 OcResourceHandle ocResourceHandle,
763 String resourceTypeName) throws OcException;
766 * Binds an interface to a particular resource
768 * @param ocResourceHandle handle to the resource
769 * @param resourceInterfaceName new interface to bind to the resource
770 * @throws OcException if failure
772 public static void bindInterfaceToResource(
773 OcResourceHandle ocResourceHandle,
774 String resourceInterfaceName) throws OcException {
775 OcPlatform.initCheck();
776 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
779 private static native void bindInterfaceToResource0(
780 OcResourceHandle ocResourceHandle,
781 String resourceInterfaceName) throws OcException;
784 * Start Presence announcements.
786 * @param ttl time to live in seconds
787 * @throws OcException if failure
789 public static void startPresence(int ttl) throws OcException {
790 OcPlatform.initCheck();
791 OcPlatform.startPresence0(ttl);
794 private static native void startPresence0(int ttl) throws OcException;
797 * Stop Presence announcements.
799 * @throws OcException if failure
801 public static void stopPresence() throws OcException {
802 OcPlatform.initCheck();
803 OcPlatform.stopPresence0();
806 private static native void stopPresence0() throws OcException;
809 * Subscribes to a server's presence change events. By making this subscription, every time a
810 * server adds/removes/alters a resource, starts or is intentionally stopped
812 * @param host The IP address/addressable name of the server to subscribe to
813 * @param connectivityTypeSet Set of types of connectivity. Example: IP
814 * @param onPresenceListener listener that will receive notifications/subscription events
815 * @return a handle object that can be used to identify this subscription request. It can be
816 * used to unsubscribe from these events in the future
817 * @throws OcException if failure
819 public static OcPresenceHandle subscribePresence(
821 EnumSet<OcConnectivityType> connectivityTypeSet,
822 OnPresenceListener onPresenceListener) throws OcException {
823 OcPlatform.initCheck();
826 for (OcConnectivityType connType : OcConnectivityType.values()) {
827 if (connectivityTypeSet.contains(connType))
828 connTypeInt |= connType.getValue();
830 return OcPlatform.subscribePresence0(
837 private static native OcPresenceHandle subscribePresence0(
839 int connectivityType,
840 OnPresenceListener onPresenceListener) throws OcException;
843 * Subscribes to a server's presence change events. By making this subscription, every time a
844 * server adds/removes/alters a resource, starts or is intentionally stopped
846 * @param host The IP address/addressable name of the server to subscribe to
847 * @param resourceType a resource type specified as a filter for subscription events.
848 * @param connectivityTypeSet Set of types of connectivity. Example: IP
849 * @param onPresenceListener listener that will receive notifications/subscription events
850 * @return a handle object that can be used to identify this subscription request. It can be
851 * used to unsubscribe from these events in the future
852 * @throws OcException if failure
854 public static OcPresenceHandle subscribePresence(
857 EnumSet<OcConnectivityType> connectivityTypeSet,
858 OnPresenceListener onPresenceListener) throws OcException {
859 OcPlatform.initCheck();
862 for (OcConnectivityType connType : OcConnectivityType.values()) {
863 if (connectivityTypeSet.contains(connType))
864 connTypeInt |= connType.getValue();
866 return OcPlatform.subscribePresence1(
873 private static native OcPresenceHandle subscribePresence1(
876 int connectivityType,
877 OnPresenceListener onPresenceListener) throws OcException;
880 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
881 * a short time still receive events from the server since it may take time for the
882 * unsubscribe to take effect.
884 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
885 * identifies this subscription
886 * @throws OcException if failure
888 public static void unsubscribePresence(
889 OcPresenceHandle ocPresenceHandle) throws OcException {
890 OcPlatform.initCheck();
891 OcPlatform.unsubscribePresence0(ocPresenceHandle);
894 private static native void unsubscribePresence0(
895 OcPresenceHandle ocPresenceHandle) throws OcException;
898 * Subscribes to a server's device presence change events.
900 * @param host The IP address/addressable name of the server to subscribe to.
901 * @param di Vector which can have the devices id.
902 * @param connectivityTypeSet Set of connectivity types, e.g. IP.
903 * @param onObserveListener The handler method will be invoked with a map
904 * of attribute name and values.
905 * @return a handle object that can be used to identify this subscription request.
906 * It can be used to unsubscribe from these events in the future.
907 * @throws OcException if failure.
909 public static OcPresenceHandle subscribeDevicePresence(
912 EnumSet<OcConnectivityType> connectivityTypeSet,
913 OcResource.OnObserveListener onObserveListener) throws OcException {
914 OcPlatform.initCheck();
917 for (OcConnectivityType connType : OcConnectivityType.values()) {
918 if (connectivityTypeSet.contains(connType))
919 connTypeInt |= connType.getValue();
921 return OcPlatform.subscribeDevicePresence0(
923 di.toArray(new String[di.size()]),
928 private static native OcPresenceHandle subscribeDevicePresence0(
931 int connectivityType,
932 OcResource.OnObserveListener onObserveListener) throws OcException;
935 * Creates a resource proxy object so that get/put/observe functionality can be used without
936 * discovering the object in advance. Note that the consumer of this method needs to provide
937 * all of the details required to correctly contact and observe the object. If the consumer
938 * lacks any of this information, they should discover the resource object normally.
939 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
942 * @param host a string containing a resolvable host address of the server holding
944 * @param uri the rest of the resource's URI that will permit messages to be
947 * @param connectivityTypeSet Set of types of connectivity. Example: IP
948 * @param isObservable a boolean containing whether the resource supports observation
949 * @param resourceTypeList a collection of resource types implemented by the resource
950 * @param interfaceList a collection of interfaces that the resource supports/implements
951 * @return new resource object
952 * @throws OcException if failure
954 public static OcResource constructResourceObject(
957 EnumSet<OcConnectivityType> connectivityTypeSet,
958 boolean isObservable,
959 List<String> resourceTypeList,
960 List<String> interfaceList) throws OcException {
961 OcPlatform.initCheck();
964 for (OcConnectivityType connType : OcConnectivityType.values()) {
965 if (connectivityTypeSet.contains(connType))
966 connTypeInt |= connType.getValue();
968 return OcPlatform.constructResourceObject0(
973 resourceTypeList.toArray(new String[resourceTypeList.size()]),
974 interfaceList.toArray(new String[interfaceList.size()])
978 private static native OcResource constructResourceObject0(
981 int connectivityType,
982 boolean isObservable,
983 String[] resourceTypes,
984 String[] interfaces) throws OcException;
987 * Allows application entity handler to send response to an incoming request.
989 * @param ocResourceResponse resource response
990 * @throws OcException if failure
992 public static void sendResponse(OcResourceResponse ocResourceResponse)
994 OcPlatform.initCheck();
995 OcPlatform.sendResponse0(ocResourceResponse);
998 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
1002 * Method to find all devices which are eligible for direct pairing and return the list.
1004 * @param timeout timeout for discovering direct pair devices.
1005 * @param FindDirectPairingListener Callback function, which will receive the list of direct
1007 * @throws OcException
1009 public static native void findDirectPairingDevices(int timeout,
1010 FindDirectPairingListener onFindDirectPairingListener) throws OcException;
1013 * Method to get list of all paired devices for a given device.
1015 * @param GetDirectPairedListener Callback function, which will receive the list of direct
1017 * @throws OcException
1019 public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
1023 * Method to perform direct pairing between two devices.
1025 * @param peer Target peer
1026 * @param prmType Pairing Method to be used for Pairing
1028 * @param DirectPairingListener Callback function, which will be called after
1029 * completion of direct pairing.
1030 * @throws OcException
1032 public static void doDirectPairing(
1033 OcDirectPairDevice peer,
1036 DirectPairingListener onDirectPairingListener) throws OcException {
1038 OcPlatform.doDirectPairing0(
1042 onDirectPairingListener
1046 private static native void doDirectPairing0(OcDirectPairDevice peer,
1047 int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
1051 * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
1052 * Event listeners are notified asynchronously
1054 public interface FindDirectPairingListener {
1055 public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
1059 * Listerner to Get List of already Direct Paired devices.
1060 * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
1061 * Event listeners are notified asynchronously
1063 public interface GetDirectPairedListener {
1064 public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
1068 * Listner to get result of doDirectPairing.
1069 * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
1070 * Event listeners are notified asynchronously
1072 public interface DirectPairingListener {
1073 public void onDirectPairingListener(String devId, int result);
1077 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
1078 * Event listeners are notified asynchronously
1080 public interface OnResourceFoundListener {
1081 public void onResourceFound(OcResource resource);
1082 public void onFindResourceFailed(Throwable ex, String uri);
1086 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
1087 * Event listeners are notified asynchronously
1089 public interface OnDeviceFoundListener {
1090 public void onDeviceFound(OcRepresentation ocRepresentation);
1094 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
1095 * Event listeners are notified asynchronously
1097 public interface OnPlatformFoundListener {
1098 public void onPlatformFound(OcRepresentation ocRepresentation);
1102 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
1103 * Event listeners are notified asynchronously
1105 public interface OnPresenceListener {
1106 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
1110 * An EntityHandler can be registered via the OcPlatform.registerResource call.
1111 * Event listeners are notified asynchronously
1113 * @note entityhandler callback :
1114 * When you set specific return value like EntityHandlerResult.OK, SLOW
1115 * and etc in entity handler callback,
1116 * ocstack will be not send response automatically to client
1117 * except for error return value like EntityHandlerResult.ERROR
1118 * If you want to send response to client with specific result,
1119 * sendResponse API should be called with the result value.
1121 public interface EntityHandler {
1122 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
1125 private static void initCheck() {
1126 if (!sIsPlatformInitialized) {
1127 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
1128 "OcPlatform.Configure before any other API calls are permitted");
1133 * Gets platform quality of service
1135 * @return quality of service
1137 public static QualityOfService getPlatformQualityOfService() {
1138 OcPlatform.initCheck();
1139 return sPlatformQualityOfService;
1143 * Create an account manager object that can be used for doing request to account server.
1144 * You can only create this object if OCPlatform was initialized to be a Client or
1145 * Client/Server. Otherwise, this will return an empty shared ptr.
1147 * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
1148 * methods of this object to work since device id is not generated on Client mode.
1150 * @param host Host IP Address of a account server.
1151 * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP
1152 * @return new AccountManager object
1153 * @throws OcException if failure
1155 public static OcAccountManager constructAccountManagerObject(
1157 EnumSet<OcConnectivityType> connectivityTypeSet) throws OcException {
1158 OcPlatform.initCheck();
1159 int connTypeInt = 0;
1161 for (OcConnectivityType connType : OcConnectivityType.values()) {
1162 if (connectivityTypeSet.contains(connType))
1164 connTypeInt |= connType.getValue();
1167 return OcPlatform.constructAccountManagerObject0(
1173 private static native OcAccountManager constructAccountManagerObject0(
1175 int connectivityType) throws OcException;
1177 * Method to get device Id in byte array.
1178 * @return My DeviceId.
1180 public static native byte[] getDeviceId();
1183 * Method to set DeviceId.
1185 public static native void setDeviceId(byte[] deviceId) throws OcException;