2 *******************************************************************
4 * Copyright 2015 Intel Corporation.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.base;
25 import org.iotivity.ca.CaInterface;
27 import java.util.EnumSet;
28 import java.util.Iterator;
29 import java.util.List;
32 * This class contains the main entrance/functionality of the product. To set a custom
33 * configuration, the implementer must make a call to OcPlatform.Configure before the first usage
34 * of a method in this class.
36 public final class OcPlatform {
39 System.loadLibrary("oc_logger");
40 System.loadLibrary("octbstack");
41 System.loadLibrary("connectivity_abstraction");
42 System.loadLibrary("oc");
43 System.loadLibrary("ocstack-jni");
49 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
52 * Used in discovering (GET) links to other resources of a collection
54 public static final String LINK_INTERFACE = "oic.if.ll";
57 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
59 public static final String BATCH_INTERFACE = "oic.if.b";
62 * Used in GET, PUT, POST methods on links to other remote resources of a group
64 public static final String GROUP_INTERFACE = "oic.mi.grp";
66 public static final String WELL_KNOWN_QUERY = "/oic/res";
67 public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
68 public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
69 public static final int DEFAULT_PRESENCE_TTL = 60;
70 public static final String PRESENCE_URI = "/oic/ad";
72 private static volatile boolean sIsPlatformInitialized = false;
73 private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
75 private OcPlatform() {
79 * API for setting the configuration of the OcPlatform.
81 * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
84 * @param platformConfig platform configuration
86 public synchronized static void Configure(PlatformConfig platformConfig) {
87 if (!sIsPlatformInitialized) {
88 CaInterface.initialize(platformConfig.getActivity(), platformConfig.getContext());
90 sPlatformQualityOfService = platformConfig.getQualityOfService();
93 platformConfig.getServiceType().getValue(),
94 platformConfig.getModeType().getValue(),
95 platformConfig.getIpAddress(),
96 platformConfig.getPort(),
97 platformConfig.getQualityOfService().getValue(),
98 platformConfig.getSvrDbPath()
101 sIsPlatformInitialized = true;
105 private static native void configure(int serviceType,
109 int qualityOfService,
113 * API for notifying base that resource's attributes have changed.
115 * Note: This API is for server side only.
118 * @param ocResourceHandle resource handle of the resource
119 * @throws OcException if failure
121 public static void notifyAllObservers(
122 OcResourceHandle ocResourceHandle) throws OcException {
123 OcPlatform.initCheck();
124 OcPlatform.notifyAllObservers0(ocResourceHandle);
127 private static native void notifyAllObservers0(
128 OcResourceHandle ocResourceHandle) throws OcException;
131 * API for notifying base that resource's attributes have changed.
133 * Note: This API is for server side only.
136 * @param ocResourceHandle resource handle of the resource
137 * @param qualityOfService the quality of communication
138 * @throws OcException if failure
140 public static void notifyAllObservers(
141 OcResourceHandle ocResourceHandle,
142 QualityOfService qualityOfService) throws OcException {
143 OcPlatform.initCheck();
144 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
147 private static native void notifyAllObservers1(
148 OcResourceHandle ocResourceHandle,
149 int qualityOfService) throws OcException;
152 * API for notifying only specific clients that resource's attributes have changed.
154 * Note: This API is for server side only.
157 * @param ocResourceHandle resource handle of the resource
158 * @param ocObservationIdList These set of ids are ones which which will be notified upon
160 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
161 * this resource change
162 * @throws OcException if failure
164 public static void notifyListOfObservers(
165 OcResourceHandle ocResourceHandle,
166 List<Byte> ocObservationIdList,
167 OcResourceResponse ocResourceResponse) throws OcException {
168 OcPlatform.initCheck();
170 byte[] idArr = new byte[ocObservationIdList.size()];
171 Iterator<Byte> it = ocObservationIdList.iterator();
173 while (it.hasNext()) {
174 idArr[i++] = (byte) it.next();
177 OcPlatform.notifyListOfObservers2(
183 private static native void notifyListOfObservers2(
184 OcResourceHandle ocResourceHandle,
185 byte[] ocObservationIdArray,
186 OcResourceResponse ocResourceResponse) throws OcException;
189 * API for notifying only specific clients that resource's attributes have changed.
191 * Note: This API is for server side only.
194 * @param ocResourceHandle resource handle of the resource
195 * @param ocObservationIdList These set of ids are ones which which will be notified upon
197 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
198 * this resource change
199 * @param qualityOfService the quality of communication
200 * @throws OcException if failure
202 public static void notifyListOfObservers(
203 OcResourceHandle ocResourceHandle,
204 List<Byte> ocObservationIdList,
205 OcResourceResponse ocResourceResponse,
206 QualityOfService qualityOfService) throws OcException {
207 OcPlatform.initCheck();
209 byte[] idArr = new byte[ocObservationIdList.size()];
210 Iterator<Byte> it = ocObservationIdList.iterator();
212 while (it.hasNext()) {
213 idArr[i++] = (byte) it.next();
216 OcPlatform.notifyListOfObservers3(
220 qualityOfService.getValue()
224 private static native void notifyListOfObservers3(
225 OcResourceHandle ocResourceHandle,
226 byte[] ocObservationIdArray,
227 OcResourceResponse ocResourceResponse,
228 int qualityOfService) throws OcException;
231 * API for Service and Resource Discovery
233 * Note: This API is for client side only.
236 * @param host Host Address of a service to direct resource discovery query.
237 * If empty, performs multicast resource discovery query
238 * @param resourceUri name of the resource. If null or empty, performs search for all
240 * @param connectivityTypeSet Set of types of connectivity. Example: IP
241 * @param onResourceFoundListener Handles events, success states and failure states.
242 * @throws OcException if failure
244 public static void findResource(
247 EnumSet<OcConnectivityType> connectivityTypeSet,
248 OnResourceFoundListener onResourceFoundListener) throws OcException {
249 OcPlatform.initCheck();
253 for (OcConnectivityType connType : OcConnectivityType.values()) {
254 if (connectivityTypeSet.contains(connType))
255 connTypeInt |= connType.getValue();
258 OcPlatform.findResource0(
262 onResourceFoundListener
266 private static native void findResource0(
269 int connectivityType,
270 OnResourceFoundListener onResourceFoundListener) throws OcException;
273 * API for Service and Resource Discovery.
275 * Note: This API is for client side only.
278 * @param host Host IP Address of a service to direct resource discovery query.
279 * If empty, performs multicast resource discovery query
280 * @param resourceUri name of the resource. If null or empty, performs search for all
282 * @param connectivityTypeSet Set of types of connectivity. Example: IP
283 * @param onResourceFoundListener Handles events, success states and failure states.
284 * @param qualityOfService the quality of communication
285 * @throws OcException if failure
287 public static void findResource(
290 EnumSet<OcConnectivityType> connectivityTypeSet,
291 OnResourceFoundListener onResourceFoundListener,
292 QualityOfService qualityOfService) throws OcException {
293 OcPlatform.initCheck();
297 for (OcConnectivityType connType : OcConnectivityType.values()) {
298 if (connectivityTypeSet.contains(connType))
299 connTypeInt |= connType.getValue();
302 OcPlatform.findResource1(host,
305 onResourceFoundListener,
306 qualityOfService.getValue()
310 private static native void findResource1(
313 int connectivityType,
314 OnResourceFoundListener onResourceFoundListener,
315 int qualityOfService) throws OcException;
318 * API for Device Discovery
320 * @param host Host IP Address. If null or empty, Multicast is performed.
321 * @param deviceUri Uri containing address to the virtual device
322 * @param connectivityTypeSet Set of types of connectivity. Example: IP
323 * @param onDeviceFoundListener Handles events, success states and failure states.
324 * @throws OcException if failure
326 public static void getDeviceInfo(
329 EnumSet<OcConnectivityType> connectivityTypeSet,
330 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
331 OcPlatform.initCheck();
334 for (OcConnectivityType connType : OcConnectivityType.values()) {
335 if (connectivityTypeSet.contains(connType))
336 connTypeInt |= connType.getValue();
338 OcPlatform.getDeviceInfo0(
342 onDeviceFoundListener
346 private static native void getDeviceInfo0(
349 int connectivityType,
350 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
353 * API for Device Discovery
355 * @param host Host IP Address. If null or empty, Multicast is performed.
356 * @param deviceUri Uri containing address to the virtual device
357 * @param connectivityTypeSet Set of types of connectivity. Example: IP
358 * @param onDeviceFoundListener Handles events, success states and failure states.
359 * @param qualityOfService the quality of communication
360 * @throws OcException if failure
362 public static void getDeviceInfo(
365 EnumSet<OcConnectivityType> connectivityTypeSet,
366 OnDeviceFoundListener onDeviceFoundListener,
367 QualityOfService qualityOfService) throws OcException {
368 OcPlatform.initCheck();
371 for (OcConnectivityType connType : OcConnectivityType.values()) {
372 if (connectivityTypeSet.contains(connType))
373 connTypeInt |= connType.getValue();
375 OcPlatform.getDeviceInfo1(
379 onDeviceFoundListener,
380 qualityOfService.getValue()
384 private static native void getDeviceInfo1(
387 int connectivityType,
388 OnDeviceFoundListener onDeviceFoundListener,
389 int qualityOfService) throws OcException;
392 * API for Platform Discovery
394 * @param host Host IP Address. If null or empty, Multicast is performed.
395 * @param platformUri Uri containing address to the platform
396 * @param connectivityTypeSet Set of types of connectivity. Example: IP
397 * @param onPlatformFoundListener Handles events, success states and failure states.
398 * @throws OcException if failure
401 public static void getPlatformInfo(
404 EnumSet<OcConnectivityType> connectivityTypeSet,
405 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
406 OcPlatform.initCheck();
409 for (OcConnectivityType connType : OcConnectivityType.values()) {
410 if (connectivityTypeSet.contains(connType))
411 connTypeInt |= connType.getValue();
413 OcPlatform.getPlatformInfo0(
417 onPlatformFoundListener
421 private static native void getPlatformInfo0(
424 int connectivityType,
425 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
428 * API for Platform Discovery
430 * @param host Host IP Address. If null or empty, Multicast is performed.
431 * @param platformUri Uri containing address to the platform
432 * @param connectivityTypeSet Set of types of connectivity. Example: IP
433 * @param onPlatformFoundListener Handles events, success states and failure states.
434 * @param qualityOfService the quality of communication
435 * @throws OcException if failure
438 public static void getPlatformInfo(
441 EnumSet<OcConnectivityType> connectivityTypeSet,
442 OnPlatformFoundListener onPlatformFoundListener,
443 QualityOfService qualityOfService) throws OcException {
444 OcPlatform.initCheck();
447 for (OcConnectivityType connType : OcConnectivityType.values()) {
448 if (connectivityTypeSet.contains(connType))
449 connTypeInt |= connType.getValue();
451 OcPlatform.getPlatformInfo1(
455 onPlatformFoundListener,
456 qualityOfService.getValue()
460 private static native void getPlatformInfo1(
463 int connectivityType,
464 OnPlatformFoundListener onPlatformFoundListener,
465 int qualityOfService) throws OcException;
468 * This API registers a resource with the server
470 * Note: This API applies to server & client side.
473 * @param ocResource The instance of OcResource with all data filled
474 * @return resource handle
475 * @throws OcException if failure
477 public static OcResourceHandle registerResource(
478 OcResource ocResource) throws OcException {
479 OcPlatform.initCheck();
480 return OcPlatform.registerResource0(ocResource);
483 private static native OcResourceHandle registerResource0(
484 OcResource ocResource) throws OcException;
487 * This API registers a resource with the server NOTE: This API applies to server side only.
489 * Note: This API applies to server side only.
492 * @param resourceUri The URI of the resource. Example: "a/light"
493 * @param resourceTypeName The resource type. Example: "light"
494 * @param resourceInterface The resource interface (whether it is collection etc).
495 * @param entityHandler entity handler.
496 * @param resourcePropertySet indicates the property of the resource
497 * @return resource handle
498 * @throws OcException if failure
500 public static OcResourceHandle registerResource(
502 String resourceTypeName,
503 String resourceInterface,
504 EntityHandler entityHandler,
505 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
506 OcPlatform.initCheck();
510 for (ResourceProperty prop : ResourceProperty.values()) {
511 if (resourcePropertySet.contains(prop))
512 resProperty |= prop.getValue();
515 return OcPlatform.registerResource1(resourceUri,
522 private static native OcResourceHandle registerResource1(
524 String resourceTypeName,
525 String resourceInterface,
526 EntityHandler entityHandler,
527 int resourceProperty) throws OcException;
530 * Register Device Info
532 * @param ocDeviceInfo object containing all the device specific information
533 * @throws OcException if failure
535 public static void registerDeviceInfo(
536 OcDeviceInfo ocDeviceInfo) throws OcException {
537 OcPlatform.initCheck();
538 OcPlatform.registerDeviceInfo0(
539 ocDeviceInfo.getDeviceName()
543 private static native void registerDeviceInfo0(
545 ) throws OcException;
548 * Register Platform Info
550 * @param ocPlatformInfo object containing all the platform specific information
551 * @throws OcException if failure
553 public static void registerPlatformInfo(
554 OcPlatformInfo ocPlatformInfo) throws OcException {
555 OcPlatform.initCheck();
556 OcPlatform.registerPlatformInfo0(
557 ocPlatformInfo.getPlatformId(),
558 ocPlatformInfo.getManufacturerName(),
559 ocPlatformInfo.getManufacturerUrl(),
560 ocPlatformInfo.getModelNumber(),
561 ocPlatformInfo.getDateOfManufacture(),
562 ocPlatformInfo.getPlatformVersion(),
563 ocPlatformInfo.getOperatingSystemVersion(),
564 ocPlatformInfo.getHardwareVersion(),
565 ocPlatformInfo.getFirmwareVersion(),
566 ocPlatformInfo.getSupportUrl(),
567 ocPlatformInfo.getSystemTime()
571 private static native void registerPlatformInfo0(
572 String platformId, String manufacturerName, String manufacturerUrl,
573 String modelNumber, String dateOfManufacture, String platformVersion,
574 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
575 String supportUrl, String systemTime
576 ) throws OcException;
579 * This API unregisters a resource with the server NOTE: This API applies to server side only.
581 * @param ocResourceHandle This is the resource handle which we which to unregister from the
583 * @throws OcException if failure
585 public static void unregisterResource(
586 OcResourceHandle ocResourceHandle) throws OcException {
587 OcPlatform.initCheck();
588 OcPlatform.unregisterResource0(ocResourceHandle);
591 private static native void unregisterResource0(
592 OcResourceHandle ocResourceHandle) throws OcException;
596 * Add a resource to a collection resource
598 * @param ocResourceCollectionHandle handle to the collection resource
599 * @param ocResourceHandle handle to resource to be added to the collection resource
600 * @throws OcException if failure
602 public static void bindResource(
603 OcResourceHandle ocResourceCollectionHandle,
604 OcResourceHandle ocResourceHandle) throws OcException {
605 OcPlatform.initCheck();
606 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
609 private static native void bindResource0(
610 OcResourceHandle ocResourceCollectionHandle,
611 OcResourceHandle ocResourceHandle) throws OcException;
614 * Add multiple resources to a collection resource.
616 * @param ocResourceCollectionHandle handle to the collection resource
617 * @param ocResourceHandleList reference to list of resource handles to be added to the
618 * collection resource
619 * @throws OcException if failure
621 public static void bindResources(
622 OcResourceHandle ocResourceCollectionHandle,
623 List<OcResourceHandle> ocResourceHandleList) throws OcException {
624 OcPlatform.initCheck();
625 OcPlatform.bindResources0(
626 ocResourceCollectionHandle,
627 ocResourceHandleList.toArray(
628 new OcResourceHandle[ocResourceHandleList.size()])
632 private static native void bindResources0(
633 OcResourceHandle ocResourceCollectionHandle,
634 OcResourceHandle[] ocResourceHandleArray) throws OcException;
637 * Unbind a resource from a collection resource.
639 * @param ocResourceCollectionHandle handle to the collection resource
640 * @param ocResourceHandle resource handle to be unbound from the collection resource
641 * @throws OcException if failure
643 public static void unbindResource(
644 OcResourceHandle ocResourceCollectionHandle,
645 OcResourceHandle ocResourceHandle) throws OcException {
646 OcPlatform.initCheck();
647 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
650 private static native void unbindResource0(
651 OcResourceHandle ocResourceCollectionHandle,
652 OcResourceHandle ocResourceHandle) throws OcException;
655 * Unbind resources from a collection resource.
657 * @param ocResourceCollectionHandle Handle to the collection resource
658 * @param ocResourceHandleList List of resource handles to be unbound from the collection
660 * @throws OcException if failure
662 public static void unbindResources(
663 OcResourceHandle ocResourceCollectionHandle,
664 List<OcResourceHandle> ocResourceHandleList) throws OcException {
665 OcPlatform.initCheck();
666 OcPlatform.unbindResources0(
667 ocResourceCollectionHandle,
668 ocResourceHandleList.toArray(
669 new OcResourceHandle[ocResourceHandleList.size()])
673 private static native void unbindResources0(
674 OcResourceHandle ocResourceCollectionHandle,
675 OcResourceHandle[] ocResourceHandleArray) throws OcException;
678 * Binds a type to a particular resource
680 * @param ocResourceHandle handle to the resource
681 * @param resourceTypeName new typename to bind to the resource
682 * @throws OcException if failure
684 public static void bindTypeToResource(
685 OcResourceHandle ocResourceHandle,
686 String resourceTypeName) throws OcException {
687 OcPlatform.initCheck();
688 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
691 private static native void bindTypeToResource0(
692 OcResourceHandle ocResourceHandle,
693 String resourceTypeName) throws OcException;
696 * Binds an interface to a particular resource
698 * @param ocResourceHandle handle to the resource
699 * @param resourceInterfaceName new interface to bind to the resource
700 * @throws OcException if failure
702 public static void bindInterfaceToResource(
703 OcResourceHandle ocResourceHandle,
704 String resourceInterfaceName) throws OcException {
705 OcPlatform.initCheck();
706 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
709 private static native void bindInterfaceToResource0(
710 OcResourceHandle ocResourceHandle,
711 String resourceInterfaceName) throws OcException;
714 * Start Presence announcements.
716 * @param ttl time to live in seconds
717 * @throws OcException if failure
719 public static void startPresence(int ttl) throws OcException {
720 OcPlatform.initCheck();
721 OcPlatform.startPresence0(ttl);
724 private static native void startPresence0(int ttl) throws OcException;
727 * Stop Presence announcements.
729 * @throws OcException if failure
731 public static void stopPresence() throws OcException {
732 OcPlatform.initCheck();
733 OcPlatform.stopPresence0();
736 private static native void stopPresence0() throws OcException;
739 * Subscribes to a server's presence change events. By making this subscription, every time a
740 * server adds/removes/alters a resource, starts or is intentionally stopped
742 * @param host The IP address/addressable name of the server to subscribe to
743 * @param connectivityTypeSet Set of types of connectivity. Example: IP
744 * @param onPresenceListener listener that will receive notifications/subscription events
745 * @return a handle object that can be used to identify this subscription request. It can be
746 * used to unsubscribe from these events in the future
747 * @throws OcException if failure
749 public static OcPresenceHandle subscribePresence(
751 EnumSet<OcConnectivityType> connectivityTypeSet,
752 OnPresenceListener onPresenceListener) throws OcException {
753 OcPlatform.initCheck();
756 for (OcConnectivityType connType : OcConnectivityType.values()) {
757 if (connectivityTypeSet.contains(connType))
758 connTypeInt |= connType.getValue();
760 return OcPlatform.subscribePresence0(
767 private static native OcPresenceHandle subscribePresence0(
769 int connectivityType,
770 OnPresenceListener onPresenceListener) throws OcException;
773 * Subscribes to a server's presence change events. By making this subscription, every time a
774 * server adds/removes/alters a resource, starts or is intentionally stopped
776 * @param host The IP address/addressable name of the server to subscribe to
777 * @param resourceType a resource type specified as a filter for subscription events.
778 * @param connectivityTypeSet Set of types of connectivity. Example: IP
779 * @param onPresenceListener listener that will receive notifications/subscription events
780 * @return a handle object that can be used to identify this subscription request. It can be
781 * used to unsubscribe from these events in the future
782 * @throws OcException if failure
784 public static OcPresenceHandle subscribePresence(
787 EnumSet<OcConnectivityType> connectivityTypeSet,
788 OnPresenceListener onPresenceListener) throws OcException {
789 OcPlatform.initCheck();
792 for (OcConnectivityType connType : OcConnectivityType.values()) {
793 if (connectivityTypeSet.contains(connType))
794 connTypeInt |= connType.getValue();
796 return OcPlatform.subscribePresence1(
803 private static native OcPresenceHandle subscribePresence1(
806 int connectivityType,
807 OnPresenceListener onPresenceListener) throws OcException;
810 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
811 * a short time still receive events from the server since it may take time for the
812 * unsubscribe to take effect.
814 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
815 * identifies this subscription
816 * @throws OcException if failure
818 public static void unsubscribePresence(
819 OcPresenceHandle ocPresenceHandle) throws OcException {
820 OcPlatform.initCheck();
821 OcPlatform.unsubscribePresence0(ocPresenceHandle);
824 private static native void unsubscribePresence0(
825 OcPresenceHandle ocPresenceHandle) throws OcException;
828 * Creates a resource proxy object so that get/put/observe functionality can be used without
829 * discovering the object in advance. Note that the consumer of this method needs to provide
830 * all of the details required to correctly contact and observe the object. If the consumer
831 * lacks any of this information, they should discover the resource object normally.
832 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
835 * @param host a string containing a resolvable host address of the server holding
837 * @param uri the rest of the resource's URI that will permit messages to be
840 * @param connectivityTypeSet Set of types of connectivity. Example: IP
841 * @param isObservable a boolean containing whether the resource supports observation
842 * @param resourceTypeList a collection of resource types implemented by the resource
843 * @param interfaceList a collection of interfaces that the resource supports/implements
844 * @return new resource object
845 * @throws OcException if failure
847 public static OcResource constructResourceObject(
850 EnumSet<OcConnectivityType> connectivityTypeSet,
851 boolean isObservable,
852 List<String> resourceTypeList,
853 List<String> interfaceList) throws OcException {
854 OcPlatform.initCheck();
857 for (OcConnectivityType connType : OcConnectivityType.values()) {
858 if (connectivityTypeSet.contains(connType))
859 connTypeInt |= connType.getValue();
861 return OcPlatform.constructResourceObject0(
866 resourceTypeList.toArray(new String[resourceTypeList.size()]),
867 interfaceList.toArray(new String[interfaceList.size()])
871 private static native OcResource constructResourceObject0(
874 int connectivityType,
875 boolean isObservable,
876 String[] resourceTypes,
877 String[] interfaces) throws OcException;
880 * Allows application entity handler to send response to an incoming request.
882 * @param ocResourceResponse resource response
883 * @throws OcException if failure
885 public static void sendResponse(OcResourceResponse ocResourceResponse)
887 OcPlatform.initCheck();
888 OcPlatform.sendResponse0(ocResourceResponse);
891 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
895 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
896 * Event listeners are notified asynchronously
898 public interface OnResourceFoundListener {
899 public void onResourceFound(OcResource resource);
903 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
904 * Event listeners are notified asynchronously
906 public interface OnDeviceFoundListener {
907 public void onDeviceFound(OcRepresentation ocRepresentation);
911 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
912 * Event listeners are notified asynchronously
914 public interface OnPlatformFoundListener {
915 public void onPlatformFound(OcRepresentation ocRepresentation);
919 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
920 * Event listeners are notified asynchronously
922 public interface OnPresenceListener {
923 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
927 * An EntityHandler can be registered via the OcPlatform.registerResource call.
928 * Event listeners are notified asynchronously
930 public interface EntityHandler {
931 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
934 private static void initCheck() {
935 if (!sIsPlatformInitialized) {
936 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
937 "OcPlatform.Configure before any other API calls are permitted");
942 * Gets platform quality of service
944 * @return quality of service
946 public static QualityOfService getPlatformQualityOfService() {
947 OcPlatform.initCheck();
948 return sPlatformQualityOfService;