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;
565 * Register Platform Info
567 * @param ocPlatformInfo object containing all the platform specific information
568 * @throws OcException if failure
570 public static void registerPlatformInfo(
571 OcPlatformInfo ocPlatformInfo) throws OcException {
572 OcPlatform.initCheck();
573 OcPlatform.registerPlatformInfo0(
574 ocPlatformInfo.getPlatformId(),
575 ocPlatformInfo.getManufacturerName(),
576 ocPlatformInfo.getManufacturerUrl(),
577 ocPlatformInfo.getModelNumber(),
578 ocPlatformInfo.getDateOfManufacture(),
579 ocPlatformInfo.getPlatformVersion(),
580 ocPlatformInfo.getOperatingSystemVersion(),
581 ocPlatformInfo.getHardwareVersion(),
582 ocPlatformInfo.getFirmwareVersion(),
583 ocPlatformInfo.getSupportUrl(),
584 ocPlatformInfo.getSystemTime()
588 private static native void registerPlatformInfo0(
589 String platformId, String manufacturerName, String manufacturerUrl,
590 String modelNumber, String dateOfManufacture, String platformVersion,
591 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
592 String supportUrl, String systemTime
593 ) throws OcException;
596 * This API unregisters a resource with the server NOTE: This API applies to server side only.
598 * @param ocResourceHandle This is the resource handle which we which to unregister from the
600 * @throws OcException if failure
602 public static void unregisterResource(
603 OcResourceHandle ocResourceHandle) throws OcException {
604 OcPlatform.initCheck();
605 OcPlatform.unregisterResource0(ocResourceHandle);
608 private static native void unregisterResource0(
609 OcResourceHandle ocResourceHandle) throws OcException;
613 * Add a resource to a collection resource
615 * @param ocResourceCollectionHandle handle to the collection resource
616 * @param ocResourceHandle handle to resource to be added to the collection resource
617 * @throws OcException if failure
619 public static void bindResource(
620 OcResourceHandle ocResourceCollectionHandle,
621 OcResourceHandle ocResourceHandle) throws OcException {
622 OcPlatform.initCheck();
623 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
626 private static native void bindResource0(
627 OcResourceHandle ocResourceCollectionHandle,
628 OcResourceHandle ocResourceHandle) throws OcException;
631 * Add multiple resources to a collection resource.
633 * @param ocResourceCollectionHandle handle to the collection resource
634 * @param ocResourceHandleList reference to list of resource handles to be added to the
635 * collection resource
636 * @throws OcException if failure
638 public static void bindResources(
639 OcResourceHandle ocResourceCollectionHandle,
640 List<OcResourceHandle> ocResourceHandleList) throws OcException {
641 OcPlatform.initCheck();
643 if (ocResourceHandleList == null) {
644 throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
647 OcPlatform.bindResources0(
648 ocResourceCollectionHandle,
649 ocResourceHandleList.toArray(
650 new OcResourceHandle[ocResourceHandleList.size()])
654 private static native void bindResources0(
655 OcResourceHandle ocResourceCollectionHandle,
656 OcResourceHandle[] ocResourceHandleArray) throws OcException;
659 * Unbind a resource from a collection resource.
661 * @param ocResourceCollectionHandle handle to the collection resource
662 * @param ocResourceHandle resource handle to be unbound from the collection resource
663 * @throws OcException if failure
665 public static void unbindResource(
666 OcResourceHandle ocResourceCollectionHandle,
667 OcResourceHandle ocResourceHandle) throws OcException {
668 OcPlatform.initCheck();
669 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
672 private static native void unbindResource0(
673 OcResourceHandle ocResourceCollectionHandle,
674 OcResourceHandle ocResourceHandle) throws OcException;
677 * Unbind resources from a collection resource.
679 * @param ocResourceCollectionHandle Handle to the collection resource
680 * @param ocResourceHandleList List of resource handles to be unbound from the collection
682 * @throws OcException if failure
684 public static void unbindResources(
685 OcResourceHandle ocResourceCollectionHandle,
686 List<OcResourceHandle> ocResourceHandleList) throws OcException {
687 OcPlatform.initCheck();
689 if (ocResourceHandleList == null) {
690 throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
693 OcPlatform.unbindResources0(
694 ocResourceCollectionHandle,
695 ocResourceHandleList.toArray(
696 new OcResourceHandle[ocResourceHandleList.size()])
700 private static native void unbindResources0(
701 OcResourceHandle ocResourceCollectionHandle,
702 OcResourceHandle[] ocResourceHandleArray) throws OcException;
705 * Binds a type to a particular resource
707 * @param ocResourceHandle handle to the resource
708 * @param resourceTypeName new typename to bind to the resource
709 * @throws OcException if failure
711 public static void bindTypeToResource(
712 OcResourceHandle ocResourceHandle,
713 String resourceTypeName) throws OcException {
714 OcPlatform.initCheck();
715 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
718 private static native void bindTypeToResource0(
719 OcResourceHandle ocResourceHandle,
720 String resourceTypeName) throws OcException;
723 * Binds an interface to a particular resource
725 * @param ocResourceHandle handle to the resource
726 * @param resourceInterfaceName new interface to bind to the resource
727 * @throws OcException if failure
729 public static void bindInterfaceToResource(
730 OcResourceHandle ocResourceHandle,
731 String resourceInterfaceName) throws OcException {
732 OcPlatform.initCheck();
733 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
736 private static native void bindInterfaceToResource0(
737 OcResourceHandle ocResourceHandle,
738 String resourceInterfaceName) throws OcException;
741 * Start Presence announcements.
743 * @param ttl time to live in seconds
744 * @throws OcException if failure
746 public static void startPresence(int ttl) throws OcException {
747 OcPlatform.initCheck();
748 OcPlatform.startPresence0(ttl);
751 private static native void startPresence0(int ttl) throws OcException;
754 * Stop Presence announcements.
756 * @throws OcException if failure
758 public static void stopPresence() throws OcException {
759 OcPlatform.initCheck();
760 OcPlatform.stopPresence0();
763 private static native void stopPresence0() throws OcException;
766 * Subscribes to a server's presence change events. By making this subscription, every time a
767 * server adds/removes/alters a resource, starts or is intentionally stopped
769 * @param host The IP address/addressable name of the server to subscribe to
770 * @param connectivityTypeSet Set of types of connectivity. Example: IP
771 * @param onPresenceListener listener that will receive notifications/subscription events
772 * @return a handle object that can be used to identify this subscription request. It can be
773 * used to unsubscribe from these events in the future
774 * @throws OcException if failure
776 public static OcPresenceHandle subscribePresence(
778 EnumSet<OcConnectivityType> connectivityTypeSet,
779 OnPresenceListener onPresenceListener) throws OcException {
780 OcPlatform.initCheck();
783 for (OcConnectivityType connType : OcConnectivityType.values()) {
784 if (connectivityTypeSet.contains(connType))
785 connTypeInt |= connType.getValue();
787 return OcPlatform.subscribePresence0(
794 private static native OcPresenceHandle subscribePresence0(
796 int connectivityType,
797 OnPresenceListener onPresenceListener) throws OcException;
800 * Subscribes to a server's presence change events. By making this subscription, every time a
801 * server adds/removes/alters a resource, starts or is intentionally stopped
803 * @param host The IP address/addressable name of the server to subscribe to
804 * @param resourceType a resource type specified as a filter for subscription events.
805 * @param connectivityTypeSet Set of types of connectivity. Example: IP
806 * @param onPresenceListener listener that will receive notifications/subscription events
807 * @return a handle object that can be used to identify this subscription request. It can be
808 * used to unsubscribe from these events in the future
809 * @throws OcException if failure
811 public static OcPresenceHandle subscribePresence(
814 EnumSet<OcConnectivityType> connectivityTypeSet,
815 OnPresenceListener onPresenceListener) throws OcException {
816 OcPlatform.initCheck();
819 for (OcConnectivityType connType : OcConnectivityType.values()) {
820 if (connectivityTypeSet.contains(connType))
821 connTypeInt |= connType.getValue();
823 return OcPlatform.subscribePresence1(
830 private static native OcPresenceHandle subscribePresence1(
833 int connectivityType,
834 OnPresenceListener onPresenceListener) throws OcException;
837 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
838 * a short time still receive events from the server since it may take time for the
839 * unsubscribe to take effect.
841 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
842 * identifies this subscription
843 * @throws OcException if failure
845 public static void unsubscribePresence(
846 OcPresenceHandle ocPresenceHandle) throws OcException {
847 OcPlatform.initCheck();
848 OcPlatform.unsubscribePresence0(ocPresenceHandle);
851 private static native void unsubscribePresence0(
852 OcPresenceHandle ocPresenceHandle) throws OcException;
855 * Subscribes to a server's device presence change events.
857 * @param host The IP address/addressable name of the server to subscribe to.
858 * @param di Vector which can have the devices id.
859 * @param connectivityTypeSet Set of connectivity types, e.g. IP.
860 * @param onObserveListener The handler method will be invoked with a map
861 * of attribute name and values.
862 * @return a handle object that can be used to identify this subscription request.
863 * It can be used to unsubscribe from these events in the future.
864 * @throws OcException if failure.
866 public static OcPresenceHandle subscribeDevicePresence(
869 EnumSet<OcConnectivityType> connectivityTypeSet,
870 OcResource.OnObserveListener onObserveListener) throws OcException {
871 OcPlatform.initCheck();
874 for (OcConnectivityType connType : OcConnectivityType.values()) {
875 if (connectivityTypeSet.contains(connType))
876 connTypeInt |= connType.getValue();
878 return OcPlatform.subscribeDevicePresence0(
880 di.toArray(new String[di.size()]),
885 private static native OcPresenceHandle subscribeDevicePresence0(
888 int connectivityType,
889 OcResource.OnObserveListener onObserveListener) throws OcException;
892 * Creates a resource proxy object so that get/put/observe functionality can be used without
893 * discovering the object in advance. Note that the consumer of this method needs to provide
894 * all of the details required to correctly contact and observe the object. If the consumer
895 * lacks any of this information, they should discover the resource object normally.
896 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
899 * @param host a string containing a resolvable host address of the server holding
901 * @param uri the rest of the resource's URI that will permit messages to be
904 * @param connectivityTypeSet Set of types of connectivity. Example: IP
905 * @param isObservable a boolean containing whether the resource supports observation
906 * @param resourceTypeList a collection of resource types implemented by the resource
907 * @param interfaceList a collection of interfaces that the resource supports/implements
908 * @return new resource object
909 * @throws OcException if failure
911 public static OcResource constructResourceObject(
914 EnumSet<OcConnectivityType> connectivityTypeSet,
915 boolean isObservable,
916 List<String> resourceTypeList,
917 List<String> interfaceList) throws OcException {
918 OcPlatform.initCheck();
921 for (OcConnectivityType connType : OcConnectivityType.values()) {
922 if (connectivityTypeSet.contains(connType))
923 connTypeInt |= connType.getValue();
925 return OcPlatform.constructResourceObject0(
930 resourceTypeList.toArray(new String[resourceTypeList.size()]),
931 interfaceList.toArray(new String[interfaceList.size()])
935 private static native OcResource constructResourceObject0(
938 int connectivityType,
939 boolean isObservable,
940 String[] resourceTypes,
941 String[] interfaces) throws OcException;
944 * Allows application entity handler to send response to an incoming request.
946 * @param ocResourceResponse resource response
947 * @throws OcException if failure
949 public static void sendResponse(OcResourceResponse ocResourceResponse)
951 OcPlatform.initCheck();
952 OcPlatform.sendResponse0(ocResourceResponse);
955 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
959 * Method to find all devices which are eligible for direct pairing and return the list.
961 * @param timeout timeout for discovering direct pair devices.
962 * @param FindDirectPairingListener Callback function, which will receive the list of direct
964 * @throws OcException
966 public static native void findDirectPairingDevices(int timeout,
967 FindDirectPairingListener onFindDirectPairingListener) throws OcException;
970 * Method to get list of all paired devices for a given device.
972 * @param GetDirectPairedListener Callback function, which will receive the list of direct
974 * @throws OcException
976 public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
980 * Method to perform direct pairing between two devices.
982 * @param peer Target peer
983 * @param prmType Pairing Method to be used for Pairing
985 * @param DirectPairingListener Callback function, which will be called after
986 * completion of direct pairing.
987 * @throws OcException
989 public static void doDirectPairing(
990 OcDirectPairDevice peer,
993 DirectPairingListener onDirectPairingListener) throws OcException {
995 OcPlatform.doDirectPairing0(
999 onDirectPairingListener
1003 private static native void doDirectPairing0(OcDirectPairDevice peer,
1004 int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
1008 * API to publish resource to remote resource-directory.
1010 * @param host Host Address of a service to publish resource.
1011 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1012 * @param onPublishResourceListener Handles events, success states and failure states.
1013 * @throws OcException if failure
1015 public static void publishResourceToRD(
1017 EnumSet<OcConnectivityType> connectivityTypeSet,
1018 OnPublishResourceListener onPublishResourceListener) throws OcException {
1019 OcPlatform.initCheck();
1021 int connTypeInt = 0;
1023 for (OcConnectivityType connType : OcConnectivityType.values()) {
1024 if (connectivityTypeSet.contains(connType)) {
1025 connTypeInt |= connType.getValue();
1029 OcPlatform.publishResourceToRD0(
1032 onPublishResourceListener,
1033 sPlatformQualityOfService.getValue()
1038 * API to publish resource to remote resource-directory.
1040 * @param host Host Address of a service to publish resource.
1041 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1042 * @param onPublishResourceListener Handles events, success states and failure states.
1043 * @param qualityOfService the quality of communication.
1044 * @throws OcException if failure
1046 public static void publishResourceToRD(
1048 EnumSet<OcConnectivityType> connectivityTypeSet,
1049 OnPublishResourceListener onPublishResourceListener,
1050 QualityOfService qualityOfService) throws OcException {
1051 OcPlatform.initCheck();
1053 int connTypeInt = 0;
1055 for (OcConnectivityType connType : OcConnectivityType.values()) {
1056 if (connectivityTypeSet.contains(connType)) {
1057 connTypeInt |= connType.getValue();
1061 OcPlatform.publishResourceToRD0(
1064 onPublishResourceListener,
1065 qualityOfService.getValue()
1069 private static native void publishResourceToRD0(
1071 int connectivityType,
1072 OnPublishResourceListener onPublishResourceListener,
1073 int qualityOfService) throws OcException;
1076 * API to publish resource to remote resource-directory.
1078 * @param host Host Address of a service to publish resource.
1079 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1080 * @param ocResourceHandleList reference to list of resource handles to be published.
1081 * @param onPublishResourceListener Handles events, success states and failure states.
1082 * @throws OcException if failure
1084 public static void publishResourceToRD(
1086 EnumSet<OcConnectivityType> connectivityTypeSet,
1087 List<OcResourceHandle> ocResourceHandleList,
1088 OnPublishResourceListener onPublishResourceListener) throws OcException {
1089 OcPlatform.initCheck();
1091 int connTypeInt = 0;
1093 for (OcConnectivityType connType : OcConnectivityType.values()) {
1094 if (connectivityTypeSet.contains(connType)) {
1095 connTypeInt |= connType.getValue();
1099 OcPlatform.publishResourceToRD1(
1102 ocResourceHandleList.toArray(
1103 new OcResourceHandle[ocResourceHandleList.size()]),
1104 onPublishResourceListener,
1105 sPlatformQualityOfService.getValue()
1110 * API to publish resource to remote resource-directory.
1112 * @param host Host IP Address of a service to publish resource.
1113 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1114 * @param ocResourceHandleList reference to list of resource handles to be published.
1115 * @param onPublishResourceListener Handles events, success states and failure states.
1116 * @param qualityOfService the quality of communication
1117 * @throws OcException if failure
1119 public static void publishResourceToRD(
1121 EnumSet<OcConnectivityType> connectivityTypeSet,
1122 List<OcResourceHandle> ocResourceHandleList,
1123 OnPublishResourceListener onPublishResourceListener,
1124 QualityOfService qualityOfService) throws OcException {
1125 OcPlatform.initCheck();
1127 int connTypeInt = 0;
1129 for (OcConnectivityType connType : OcConnectivityType.values()) {
1130 if (connectivityTypeSet.contains(connType)) {
1131 connTypeInt |= connType.getValue();
1135 OcPlatform.publishResourceToRD1(
1138 ocResourceHandleList.toArray(
1139 new OcResourceHandle[ocResourceHandleList.size()]),
1140 onPublishResourceListener,
1141 qualityOfService.getValue()
1145 private static native void publishResourceToRD1(
1147 int connectivityType,
1148 OcResourceHandle[] ocResourceHandleArray,
1149 OnPublishResourceListener onPublishResourceListener,
1150 int qualityOfService) throws OcException;
1153 * API to delete resource from remote resource-directory.
1155 * @param host Host Address of a service to publish resource.
1156 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1157 * @param onDeleteResourceListener Handles events, success states and failure states.
1158 * @throws OcException if failure
1160 public static void deleteResourceFromRD(
1162 EnumSet<OcConnectivityType> connectivityTypeSet,
1163 OnDeleteResourceListener onDeleteResourceListener) throws OcException {
1164 OcPlatform.initCheck();
1166 int connTypeInt = 0;
1168 for (OcConnectivityType connType : OcConnectivityType.values()) {
1169 if (connectivityTypeSet.contains(connType)) {
1170 connTypeInt |= connType.getValue();
1174 OcPlatform.deleteResourceFromRD0(
1177 onDeleteResourceListener,
1178 sPlatformQualityOfService.getValue()
1183 * API to delete resource from remote resource-directory.
1185 * @param host Host Address of a service to publish resource.
1186 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1187 * @param onDeleteResourceListener Handles events, success states and failure states.
1188 * @param qualityOfService the quality of communication.
1189 * @throws OcException if failure
1191 public static void deleteResourceFromRD(
1193 EnumSet<OcConnectivityType> connectivityTypeSet,
1194 OnDeleteResourceListener onDeleteResourceListener,
1195 QualityOfService qualityOfService) throws OcException {
1196 OcPlatform.initCheck();
1198 int connTypeInt = 0;
1200 for (OcConnectivityType connType : OcConnectivityType.values()) {
1201 if (connectivityTypeSet.contains(connType)) {
1202 connTypeInt |= connType.getValue();
1206 OcPlatform.deleteResourceFromRD0(
1209 onDeleteResourceListener,
1210 qualityOfService.getValue()
1214 private static native void deleteResourceFromRD0(
1216 int connectivityType,
1217 OnDeleteResourceListener onDeleteResourceListener,
1218 int qualityOfService) throws OcException;
1221 * API to delete resource from remote resource-directory.
1223 * @param host Host Address of a service to publish resource.
1224 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1225 * @param ocResourceHandleList reference to list of resource handles to be published.
1226 * @param onDeleteResourceListener Handles events, success states and failure states.
1227 * @throws OcException if failure
1229 public static void deleteResourceFromRD(
1231 EnumSet<OcConnectivityType> connectivityTypeSet,
1232 List<OcResourceHandle> ocResourceHandleList,
1233 OnDeleteResourceListener onDeleteResourceListener) throws OcException {
1234 OcPlatform.initCheck();
1236 int connTypeInt = 0;
1238 for (OcConnectivityType connType : OcConnectivityType.values()) {
1239 if (connectivityTypeSet.contains(connType)) {
1240 connTypeInt |= connType.getValue();
1244 OcPlatform.deleteResourceFromRD1(
1247 ocResourceHandleList.toArray(
1248 new OcResourceHandle[ocResourceHandleList.size()]),
1249 onDeleteResourceListener,
1250 sPlatformQualityOfService.getValue()
1255 * API to delete resource from remote resource-directory.
1257 * @param host Host IP Address of a service to publish resource.
1258 * @param connectivityTypeSet Set of types of connectivity. Example: IP
1259 * @param ocResourceHandleList reference to list of resource handles to be published.
1260 * @param onDeleteResourceListener Handles events, success states and failure states.
1261 * @param qualityOfService the quality of communication
1262 * @throws OcException if failure
1264 public static void deleteResourceFromRD(
1266 EnumSet<OcConnectivityType> connectivityTypeSet,
1267 List<OcResourceHandle> ocResourceHandleList,
1268 OnDeleteResourceListener onDeleteResourceListener,
1269 QualityOfService qualityOfService) throws OcException {
1270 OcPlatform.initCheck();
1272 int connTypeInt = 0;
1274 for (OcConnectivityType connType : OcConnectivityType.values()) {
1275 if (connectivityTypeSet.contains(connType)) {
1276 connTypeInt |= connType.getValue();
1280 OcPlatform.deleteResourceFromRD1(
1283 ocResourceHandleList.toArray(
1284 new OcResourceHandle[ocResourceHandleList.size()]),
1285 onDeleteResourceListener,
1286 qualityOfService.getValue()
1290 private static native void deleteResourceFromRD1(
1292 int connectivityType,
1293 OcResourceHandle[] ocResourceHandleArray,
1294 OnDeleteResourceListener onDeleteResourceListener,
1295 int qualityOfService) throws OcException;
1298 * An OnPublishResourceListener can be registered via the OcPlatform.publishResourceToRD call.
1299 * Event listeners are notified asynchronously
1301 public interface OnPublishResourceListener {
1302 public void onPublishResourceCompleted(OcRepresentation ocRepresentation);
1303 public void onPublishResourceFailed(Throwable ex);
1307 * An OnDeleteResourceListener can be registered via the OcPlatform.deleteResourceFromRD call.
1308 * Event listeners are notified asynchronously
1310 public interface OnDeleteResourceListener {
1311 public void onDeleteResourceCompleted(int result);
1315 * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
1316 * Event listeners are notified asynchronously
1318 public interface FindDirectPairingListener {
1319 public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
1323 * Listerner to Get List of already Direct Paired devices.
1324 * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
1325 * Event listeners are notified asynchronously
1327 public interface GetDirectPairedListener {
1328 public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
1332 * Listner to get result of doDirectPairing.
1333 * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
1334 * Event listeners are notified asynchronously
1336 public interface DirectPairingListener {
1337 public void onDirectPairingListener(String devId, int result);
1341 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
1342 * Event listeners are notified asynchronously
1344 public interface OnResourceFoundListener {
1345 public void onResourceFound(OcResource resource);
1346 public void onFindResourceFailed(Throwable ex, String uri);
1350 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
1351 * Event listeners are notified asynchronously
1353 public interface OnDeviceFoundListener {
1354 public void onDeviceFound(OcRepresentation ocRepresentation);
1358 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
1359 * Event listeners are notified asynchronously
1361 public interface OnPlatformFoundListener {
1362 public void onPlatformFound(OcRepresentation ocRepresentation);
1366 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
1367 * Event listeners are notified asynchronously
1369 public interface OnPresenceListener {
1370 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
1374 * An EntityHandler can be registered via the OcPlatform.registerResource call.
1375 * Event listeners are notified asynchronously
1377 * @note entityhandler callback :
1378 * When you set specific return value like EntityHandlerResult.OK, SLOW
1379 * and etc in entity handler callback,
1380 * ocstack will be not send response automatically to client
1381 * except for error return value like EntityHandlerResult.ERROR
1382 * If you want to send response to client with specific result,
1383 * sendResponse API should be called with the result value.
1385 public interface EntityHandler {
1386 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
1389 private static void initCheck() {
1390 if (!sIsPlatformInitialized) {
1391 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
1392 "OcPlatform.Configure before any other API calls are permitted");
1397 * Gets platform quality of service
1399 * @return quality of service
1401 public static QualityOfService getPlatformQualityOfService() {
1402 OcPlatform.initCheck();
1403 return sPlatformQualityOfService;
1407 * Create an account manager object that can be used for doing request to account server.
1408 * You can only create this object if OCPlatform was initialized to be a Client or
1409 * Client/Server. Otherwise, this will return an empty shared ptr.
1411 * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
1412 * methods of this object to work since device id is not generated on Client mode.
1414 * @param host Host IP Address of a account server.
1415 * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP
1416 * @return new AccountManager object
1417 * @throws OcException if failure
1419 public static OcAccountManager constructAccountManagerObject(
1421 EnumSet<OcConnectivityType> connectivityTypeSet) throws OcException {
1422 OcPlatform.initCheck();
1423 int connTypeInt = 0;
1425 for (OcConnectivityType connType : OcConnectivityType.values()) {
1426 if (connectivityTypeSet.contains(connType))
1428 connTypeInt |= connType.getValue();
1431 return OcPlatform.constructAccountManagerObject0(
1437 private static native OcAccountManager constructAccountManagerObject0(
1439 int connectivityType) throws OcException;