Android: Added/Updated JavaDocs
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcPlatform.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2015 Intel Corporation.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
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
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
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.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import org.iotivity.ca.CaInterface;
26
27 import java.util.EnumSet;
28 import java.util.Iterator;
29 import java.util.List;
30
31 /**
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.
35  */
36 public final class OcPlatform {
37
38     static {
39         System.loadLibrary("oc_logger");
40         System.loadLibrary("octbstack");
41         System.loadLibrary("connectivity_abstraction");
42         System.loadLibrary("oc");
43         System.loadLibrary("ocstack-jni");
44     }
45
46     /**
47      * Default interface
48      */
49     public static final String DEFAULT_INTERFACE = "oic.if.baseline";
50
51     /**
52      * Used in discovering (GET) links to other resources of a collection
53      */
54     public static final String LINK_INTERFACE = "oic.if.ll";
55
56     /**
57      * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
58      */
59     public static final String BATCH_INTERFACE = "oic.if.b";
60
61     /**
62      * Used in GET, PUT, POST methods on links to other remote resources of a group
63      */
64     public static final String GROUP_INTERFACE = "oic.mi.grp";
65
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";
71
72     private static volatile boolean sIsPlatformInitialized = false;
73
74     private OcPlatform() {
75     }
76
77     /**
78      * API for setting the configuration of the OcPlatform.
79      * <p>
80      * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
81      * </p>
82      *
83      * @param platformConfig platform configuration
84      */
85     public synchronized static void Configure(PlatformConfig platformConfig) {
86         if (!sIsPlatformInitialized) {
87             CaInterface.initialize(platformConfig.getContext());
88
89             OcPlatform.configure(
90                     platformConfig.getServiceType().getValue(),
91                     platformConfig.getModeType().getValue(),
92                     platformConfig.getIpAddress(),
93                     platformConfig.getPort(),
94                     platformConfig.getQualityOfService().getValue(),
95                     platformConfig.getSvrDbPath()
96             );
97
98             sIsPlatformInitialized = true;
99         }
100     }
101
102     private static native void configure(int serviceType,
103                                          int modeType,
104                                          String ipAddress,
105                                          int port,
106                                          int qualityOfService,
107                                          String dbPath);
108
109     /**
110      * API for notifying base that resource's attributes have changed.
111      * <p>
112      * Note: This API is for server side only.
113      * </p>
114      *
115      * @param ocResourceHandle resource handle of the resource
116      * @throws OcException if failure
117      */
118     public static void notifyAllObservers(
119             OcResourceHandle ocResourceHandle) throws OcException {
120         OcPlatform.initCheck();
121         OcPlatform.notifyAllObservers0(ocResourceHandle);
122     }
123
124     private static native void notifyAllObservers0(
125             OcResourceHandle ocResourceHandle) throws OcException;
126
127     /**
128      * API for notifying base that resource's attributes have changed.
129      * <p>
130      * Note: This API is for server side only.
131      * </p>
132      *
133      * @param ocResourceHandle resource handle of the resource
134      * @param qualityOfService the quality of communication
135      * @throws OcException if failure
136      */
137     public static void notifyAllObservers(
138             OcResourceHandle ocResourceHandle,
139             QualityOfService qualityOfService) throws OcException {
140         OcPlatform.initCheck();
141         OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
142     }
143
144     private static native void notifyAllObservers1(
145             OcResourceHandle ocResourceHandle,
146             int qualityOfService) throws OcException;
147
148     /**
149      * API for notifying only specific clients that resource's attributes have changed.
150      * <p>
151      * Note: This API is for server side only.
152      * </p>
153      *
154      * @param ocResourceHandle    resource handle of the resource
155      * @param ocObservationIdList These set of ids are ones which which will be notified upon
156      *                            resource change.
157      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
158      *                            this resource change
159      * @throws OcException if failure
160      */
161     public static void notifyListOfObservers(
162             OcResourceHandle ocResourceHandle,
163             List<Byte> ocObservationIdList,
164             OcResourceResponse ocResourceResponse) throws OcException {
165         OcPlatform.initCheck();
166
167         byte[] idArr = new byte[ocObservationIdList.size()];
168         Iterator<Byte> it = ocObservationIdList.iterator();
169         int i = 0;
170         while (it.hasNext()) {
171             idArr[i++] = (byte) it.next();
172         }
173
174         OcPlatform.notifyListOfObservers2(
175                 ocResourceHandle,
176                 idArr,
177                 ocResourceResponse);
178     }
179
180     private static native void notifyListOfObservers2(
181             OcResourceHandle ocResourceHandle,
182             byte[] ocObservationIdArray,
183             OcResourceResponse ocResourceResponse) throws OcException;
184
185     /**
186      * API for notifying only specific clients that resource's attributes have changed.
187      * <p>
188      * Note: This API is for server side only.
189      * </p>
190      *
191      * @param ocResourceHandle    resource handle of the resource
192      * @param ocObservationIdList These set of ids are ones which which will be notified upon
193      *                            resource change.
194      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
195      *                            this resource change
196      * @param qualityOfService    the quality of communication
197      * @throws OcException if failure
198      */
199     public static void notifyListOfObservers(
200             OcResourceHandle ocResourceHandle,
201             List<Byte> ocObservationIdList,
202             OcResourceResponse ocResourceResponse,
203             QualityOfService qualityOfService) throws OcException {
204         OcPlatform.initCheck();
205
206         byte[] idArr = new byte[ocObservationIdList.size()];
207         Iterator<Byte> it = ocObservationIdList.iterator();
208         int i = 0;
209         while (it.hasNext()) {
210             idArr[i++] = (byte) it.next();
211         }
212
213         OcPlatform.notifyListOfObservers3(
214                 ocResourceHandle,
215                 idArr,
216                 ocResourceResponse,
217                 qualityOfService.getValue()
218         );
219     }
220
221     private static native void notifyListOfObservers3(
222             OcResourceHandle ocResourceHandle,
223             byte[] ocObservationIdArray,
224             OcResourceResponse ocResourceResponse,
225             int qualityOfService) throws OcException;
226
227     /**
228      * API for Service and Resource Discovery
229      * <p>
230      * Note: This API is for client side only.
231      * </p>
232      *
233      * @param host                    Host Address of a service to direct resource discovery query.
234      *                                If empty, performs multicast resource discovery query
235      * @param resourceUri             name of the resource. If null or empty, performs search for all
236      *                                resource names
237      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
238      * @param onResourceFoundListener Handles events, success states and failure states.
239      * @throws OcException if failure
240      */
241     public static void findResource(
242             String host,
243             String resourceUri,
244             EnumSet<OcConnectivityType> connectivityTypeSet,
245             OnResourceFoundListener onResourceFoundListener) throws OcException {
246         OcPlatform.initCheck();
247
248         int connTypeInt = 0;
249
250         for (OcConnectivityType connType : OcConnectivityType.values()) {
251             if (connectivityTypeSet.contains(connType))
252                 connTypeInt |= connType.getValue();
253         }
254
255         OcPlatform.findResource0(
256                 host,
257                 resourceUri,
258                 connTypeInt,
259                 onResourceFoundListener
260         );
261     }
262
263     private static native void findResource0(
264             String host,
265             String resourceUri,
266             int connectivityType,
267             OnResourceFoundListener onResourceFoundListener) throws OcException;
268
269     /**
270      * API for Service and Resource Discovery.
271      * <p>
272      * Note: This API is for client side only.
273      * </p>
274      *
275      * @param host                    Host IP Address of a service to direct resource discovery query.
276      *                                If empty, performs multicast resource discovery query
277      * @param resourceUri             name of the resource. If null or empty, performs search for all
278      *                                resource names
279      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
280      * @param onResourceFoundListener Handles events, success states and failure states.
281      * @param qualityOfService        the quality of communication
282      * @throws OcException if failure
283      */
284     public static void findResource(
285             String host,
286             String resourceUri,
287             EnumSet<OcConnectivityType> connectivityTypeSet,
288             OnResourceFoundListener onResourceFoundListener,
289             QualityOfService qualityOfService) throws OcException {
290         OcPlatform.initCheck();
291
292         int connTypeInt = 0;
293
294         for (OcConnectivityType connType : OcConnectivityType.values()) {
295             if (connectivityTypeSet.contains(connType))
296                 connTypeInt |= connType.getValue();
297         }
298
299         OcPlatform.findResource1(host,
300                 resourceUri,
301                 connTypeInt,
302                 onResourceFoundListener,
303                 qualityOfService.getValue()
304         );
305     }
306
307     private static native void findResource1(
308             String host,
309             String resourceUri,
310             int connectivityType,
311             OnResourceFoundListener onResourceFoundListener,
312             int qualityOfService) throws OcException;
313
314     /**
315      * API for Device Discovery
316      *
317      * @param host                  Host IP Address. If null or empty, Multicast is performed.
318      * @param deviceUri             Uri containing address to the virtual device
319      * @param connectivityTypeSet   Set of types of connectivity. Example: IP
320      * @param onDeviceFoundListener Handles events, success states and failure states.
321      * @throws OcException if failure
322      */
323     public static void getDeviceInfo(
324             String host,
325             String deviceUri,
326             EnumSet<OcConnectivityType> connectivityTypeSet,
327             OnDeviceFoundListener onDeviceFoundListener) throws OcException {
328         OcPlatform.initCheck();
329         int connTypeInt = 0;
330
331         for (OcConnectivityType connType : OcConnectivityType.values()) {
332             if (connectivityTypeSet.contains(connType))
333                 connTypeInt |= connType.getValue();
334         }
335         OcPlatform.getDeviceInfo0(
336                 host,
337                 deviceUri,
338                 connTypeInt,
339                 onDeviceFoundListener
340         );
341     }
342
343     private static native void getDeviceInfo0(
344             String host,
345             String deviceUri,
346             int connectivityType,
347             OnDeviceFoundListener onDeviceFoundListener) throws OcException;
348
349     /**
350      * API for Device Discovery
351      *
352      * @param host                  Host IP Address. If null or empty, Multicast is performed.
353      * @param deviceUri             Uri containing address to the virtual device
354      * @param connectivityTypeSet   Set of types of connectivity. Example: IP
355      * @param onDeviceFoundListener Handles events, success states and failure states.
356      * @param qualityOfService      the quality of communication
357      * @throws OcException if failure
358      */
359     public static void getDeviceInfo(
360             String host,
361             String deviceUri,
362             EnumSet<OcConnectivityType> connectivityTypeSet,
363             OnDeviceFoundListener onDeviceFoundListener,
364             QualityOfService qualityOfService) throws OcException {
365         OcPlatform.initCheck();
366         int connTypeInt = 0;
367
368         for (OcConnectivityType connType : OcConnectivityType.values()) {
369             if (connectivityTypeSet.contains(connType))
370                 connTypeInt |= connType.getValue();
371         }
372         OcPlatform.getDeviceInfo1(
373                 host,
374                 deviceUri,
375                 connTypeInt,
376                 onDeviceFoundListener,
377                 qualityOfService.getValue()
378         );
379     }
380
381     private static native void getDeviceInfo1(
382             String host,
383             String deviceUri,
384             int connectivityType,
385             OnDeviceFoundListener onDeviceFoundListener,
386             int qualityOfService) throws OcException;
387
388     /**
389      * API for Platform Discovery
390      *
391      * @param host                    Host IP Address. If null or empty, Multicast is performed.
392      * @param platformUri             Uri containing address to the platform
393      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
394      * @param onPlatformFoundListener Handles events, success states and failure states.
395      * @throws OcException if failure
396      */
397
398     public static void getPlatformInfo(
399             String host,
400             String platformUri,
401             EnumSet<OcConnectivityType> connectivityTypeSet,
402             OnPlatformFoundListener onPlatformFoundListener) throws OcException {
403         OcPlatform.initCheck();
404         int connTypeInt = 0;
405
406         for (OcConnectivityType connType : OcConnectivityType.values()) {
407             if (connectivityTypeSet.contains(connType))
408                 connTypeInt |= connType.getValue();
409         }
410         OcPlatform.getPlatformInfo0(
411                 host,
412                 platformUri,
413                 connTypeInt,
414                 onPlatformFoundListener
415         );
416     }
417
418     private static native void getPlatformInfo0(
419             String host,
420             String platformUri,
421             int connectivityType,
422             OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
423
424     /**
425      * API for Platform Discovery
426      *
427      * @param host                    Host IP Address. If null or empty, Multicast is performed.
428      * @param platformUri             Uri containing address to the platform
429      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
430      * @param onPlatformFoundListener Handles events, success states and failure states.
431      * @param qualityOfService        the quality of communication
432      * @throws OcException if failure
433      */
434
435     public static void getPlatformInfo(
436             String host,
437             String platformUri,
438             EnumSet<OcConnectivityType> connectivityTypeSet,
439             OnPlatformFoundListener onPlatformFoundListener,
440             QualityOfService qualityOfService) throws OcException {
441         OcPlatform.initCheck();
442         int connTypeInt = 0;
443
444         for (OcConnectivityType connType : OcConnectivityType.values()) {
445             if (connectivityTypeSet.contains(connType))
446                 connTypeInt |= connType.getValue();
447         }
448         OcPlatform.getPlatformInfo1(
449                 host,
450                 platformUri,
451                 connTypeInt,
452                 onPlatformFoundListener,
453                 qualityOfService.getValue()
454         );
455     }
456
457     private static native void getPlatformInfo1(
458             String host,
459             String platformUri,
460             int connectivityType,
461             OnPlatformFoundListener onPlatformFoundListener,
462             int qualityOfService) throws OcException;
463
464     /**
465      * This API registers a resource with the server
466      * <P>
467      * Note: This API applies to server & client side.
468      * </P>
469      *
470      * @param ocResource The instance of OcResource with all data filled
471      * @return resource handle
472      * @throws OcException if failure
473      */
474     public static OcResourceHandle registerResource(
475             OcResource ocResource) throws OcException {
476         OcPlatform.initCheck();
477         return OcPlatform.registerResource0(ocResource);
478     }
479
480     private static native OcResourceHandle registerResource0(
481             OcResource ocResource) throws OcException;
482
483     /**
484      * This API registers a resource with the server NOTE: This API applies to server side only.
485      * <P>
486      * Note: This API applies to server side only.
487      * </P>
488      * @param resourceUri         The URI of the resource. Example: "a/light"
489      * @param resourceTypeName    The resource type. Example: "light"
490      * @param resourceInterface   The resource interface (whether it is collection etc).
491      * @param entityHandler       entity handler.
492      * @param resourcePropertySet indicates the property of the resource
493      * @return resource handle
494      * @throws OcException if failure
495      */
496     public static OcResourceHandle registerResource(
497             String resourceUri,
498             String resourceTypeName,
499             String resourceInterface,
500             EntityHandler entityHandler,
501             EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
502         OcPlatform.initCheck();
503
504         int resProperty = 0;
505
506         for (ResourceProperty prop : ResourceProperty.values()) {
507             if (resourcePropertySet.contains(prop))
508                 resProperty |= prop.getValue();
509         }
510
511         return OcPlatform.registerResource1(resourceUri,
512                 resourceTypeName,
513                 resourceInterface,
514                 entityHandler,
515                 resProperty);
516     }
517
518     private static native OcResourceHandle registerResource1(
519             String resourceUri,
520             String resourceTypeName,
521             String resourceInterface,
522             EntityHandler entityHandler,
523             int resourceProperty) throws OcException;
524
525     /**
526      * Register Device Info
527      *
528      * @param ocDeviceInfo object containing all the device specific information
529      * @throws OcException if failure
530      */
531     public static void registerDeviceInfo(
532             OcDeviceInfo ocDeviceInfo) throws OcException {
533         OcPlatform.initCheck();
534         OcPlatform.registerDeviceInfo0(
535                 ocDeviceInfo.getDeviceName()
536         );
537     }
538
539     private static native void registerDeviceInfo0(
540             String deviceName
541     ) throws OcException;
542
543     /**
544      * Register Platform Info
545      *
546      * @param ocPlatformInfo object containing all the platform specific information
547      * @throws OcException if failure
548      */
549     public static void registerPlatformInfo(
550             OcPlatformInfo ocPlatformInfo) throws OcException {
551         OcPlatform.initCheck();
552         OcPlatform.registerPlatformInfo0(
553                 ocPlatformInfo.getPlatformId(),
554                 ocPlatformInfo.getManufacturerName(),
555                 ocPlatformInfo.getManufacturerUrl(),
556                 ocPlatformInfo.getModelNumber(),
557                 ocPlatformInfo.getDateOfManufacture(),
558                 ocPlatformInfo.getPlatformVersion(),
559                 ocPlatformInfo.getOperatingSystemVersion(),
560                 ocPlatformInfo.getHardwareVersion(),
561                 ocPlatformInfo.getFirmwareVersion(),
562                 ocPlatformInfo.getSupportUrl(),
563                 ocPlatformInfo.getSystemTime()
564         );
565     }
566
567     private static native void registerPlatformInfo0(
568             String platformId, String manufacturerName, String manufacturerUrl,
569             String modelNumber, String dateOfManufacture, String platformVersion,
570             String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
571             String supportUrl, String systemTime
572     ) throws OcException;
573
574     /**
575      * This API unregisters a resource with the server NOTE: This API applies to server side only.
576      *
577      * @param ocResourceHandle This is the resource handle which we which to unregister from the
578      *                         server
579      * @throws OcException if failure
580      */
581     public static void unregisterResource(
582             OcResourceHandle ocResourceHandle) throws OcException {
583         OcPlatform.initCheck();
584         OcPlatform.unregisterResource0(ocResourceHandle);
585     }
586
587     private static native void unregisterResource0(
588             OcResourceHandle ocResourceHandle) throws OcException;
589
590
591     /**
592      * Add a resource to a collection resource
593      *
594      * @param ocResourceCollectionHandle handle to the collection resource
595      * @param ocResourceHandle           handle to resource to be added to the collection resource
596      * @throws OcException if failure
597      */
598     public static void bindResource(
599             OcResourceHandle ocResourceCollectionHandle,
600             OcResourceHandle ocResourceHandle) throws OcException {
601         OcPlatform.initCheck();
602         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
603     }
604
605     private static native void bindResource0(
606             OcResourceHandle ocResourceCollectionHandle,
607             OcResourceHandle ocResourceHandle) throws OcException;
608
609     /**
610      * Add multiple resources to a collection resource.
611      *
612      * @param ocResourceCollectionHandle handle to the collection resource
613      * @param ocResourceHandleList       reference to list of resource handles to be added to the
614      *                                   collection resource
615      * @throws OcException if failure
616      */
617     public static void bindResources(
618             OcResourceHandle ocResourceCollectionHandle,
619             List<OcResourceHandle> ocResourceHandleList) throws OcException {
620         OcPlatform.initCheck();
621         OcPlatform.bindResources0(
622                 ocResourceCollectionHandle,
623                 ocResourceHandleList.toArray(
624                         new OcResourceHandle[ocResourceHandleList.size()])
625         );
626     }
627
628     private static native void bindResources0(
629             OcResourceHandle ocResourceCollectionHandle,
630             OcResourceHandle[] ocResourceHandleArray) throws OcException;
631
632     /**
633      * Unbind a resource from a collection resource.
634      *
635      * @param ocResourceCollectionHandle handle to the collection resource
636      * @param ocResourceHandle           resource handle to be unbound from the collection resource
637      * @throws OcException if failure
638      */
639     public static void unbindResource(
640             OcResourceHandle ocResourceCollectionHandle,
641             OcResourceHandle ocResourceHandle) throws OcException {
642         OcPlatform.initCheck();
643         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
644     }
645
646     private static native void unbindResource0(
647             OcResourceHandle ocResourceCollectionHandle,
648             OcResourceHandle ocResourceHandle) throws OcException;
649
650     /**
651      * Unbind resources from a collection resource.
652      *
653      * @param ocResourceCollectionHandle Handle to the collection resource
654      * @param ocResourceHandleList       List of resource handles to be unbound from the collection
655      *                                   resource
656      * @throws OcException if failure
657      */
658     public static void unbindResources(
659             OcResourceHandle ocResourceCollectionHandle,
660             List<OcResourceHandle> ocResourceHandleList) throws OcException {
661         OcPlatform.initCheck();
662         OcPlatform.unbindResources0(
663                 ocResourceCollectionHandle,
664                 ocResourceHandleList.toArray(
665                         new OcResourceHandle[ocResourceHandleList.size()])
666         );
667     }
668
669     private static native void unbindResources0(
670             OcResourceHandle ocResourceCollectionHandle,
671             OcResourceHandle[] ocResourceHandleArray) throws OcException;
672
673     /**
674      * Binds a type to a particular resource
675      *
676      * @param ocResourceHandle handle to the resource
677      * @param resourceTypeName new typename to bind to the resource
678      * @throws OcException if failure
679      */
680     public static void bindTypeToResource(
681             OcResourceHandle ocResourceHandle,
682             String resourceTypeName) throws OcException {
683         OcPlatform.initCheck();
684         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
685     }
686
687     private static native void bindTypeToResource0(
688             OcResourceHandle ocResourceHandle,
689             String resourceTypeName) throws OcException;
690
691     /**
692      * Binds an interface to a particular resource
693      *
694      * @param ocResourceHandle      handle to the resource
695      * @param resourceInterfaceName new interface to bind to the resource
696      * @throws OcException if failure
697      */
698     public static void bindInterfaceToResource(
699             OcResourceHandle ocResourceHandle,
700             String resourceInterfaceName) throws OcException {
701         OcPlatform.initCheck();
702         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
703     }
704
705     private static native void bindInterfaceToResource0(
706             OcResourceHandle ocResourceHandle,
707             String resourceInterfaceName) throws OcException;
708
709     /**
710      * Start Presence announcements.
711      *
712      * @param ttl time to live in seconds
713      * @throws OcException if failure
714      */
715     public static void startPresence(int ttl) throws OcException {
716         OcPlatform.initCheck();
717         OcPlatform.startPresence0(ttl);
718     }
719
720     private static native void startPresence0(int ttl) throws OcException;
721
722     /**
723      * Stop Presence announcements.
724      *
725      * @throws OcException if failure
726      */
727     public static void stopPresence() throws OcException {
728         OcPlatform.initCheck();
729         OcPlatform.stopPresence0();
730     }
731
732     private static native void stopPresence0() throws OcException;
733
734     /**
735      * Subscribes to a server's presence change events. By making this subscription, every time a
736      * server adds/removes/alters a resource, starts or is intentionally stopped
737      *
738      * @param host                The IP address/addressable name of the server to subscribe to
739      * @param connectivityTypeSet Set of types of connectivity. Example: IP
740      * @param onPresenceListener  listener that will receive notifications/subscription events
741      * @return a handle object that can be used to identify this subscription request. It can be
742      * used to unsubscribe from these events in the future
743      * @throws OcException if failure
744      */
745     public static OcPresenceHandle subscribePresence(
746             String host,
747             EnumSet<OcConnectivityType> connectivityTypeSet,
748             OnPresenceListener onPresenceListener) throws OcException {
749         OcPlatform.initCheck();
750         int connTypeInt = 0;
751
752         for (OcConnectivityType connType : OcConnectivityType.values()) {
753             if (connectivityTypeSet.contains(connType))
754                 connTypeInt |= connType.getValue();
755         }
756         return OcPlatform.subscribePresence0(
757                 host,
758                 connTypeInt,
759                 onPresenceListener
760         );
761     }
762
763     private static native OcPresenceHandle subscribePresence0(
764             String host,
765             int connectivityType,
766             OnPresenceListener onPresenceListener) throws OcException;
767
768     /**
769      * Subscribes to a server's presence change events. By making this subscription, every time a
770      * server adds/removes/alters a resource, starts or is intentionally stopped
771      *
772      * @param host                The IP address/addressable name of the server to subscribe to
773      * @param resourceType        a resource type specified as a filter for subscription events.
774      * @param connectivityTypeSet Set of types of connectivity. Example: IP
775      * @param onPresenceListener  listener that will receive notifications/subscription events
776      * @return a handle object that can be used to identify this subscription request. It can be
777      * used to unsubscribe from these events in the future
778      * @throws OcException if failure
779      */
780     public static OcPresenceHandle subscribePresence(
781             String host,
782             String resourceType,
783             EnumSet<OcConnectivityType> connectivityTypeSet,
784             OnPresenceListener onPresenceListener) throws OcException {
785         OcPlatform.initCheck();
786         int connTypeInt = 0;
787
788         for (OcConnectivityType connType : OcConnectivityType.values()) {
789             if (connectivityTypeSet.contains(connType))
790                 connTypeInt |= connType.getValue();
791         }
792         return OcPlatform.subscribePresence1(
793                 host,
794                 resourceType,
795                 connTypeInt,
796                 onPresenceListener);
797     }
798
799     private static native OcPresenceHandle subscribePresence1(
800             String host,
801             String resourceType,
802             int connectivityType,
803             OnPresenceListener onPresenceListener) throws OcException;
804
805     /**
806      * Unsubscribes from a previously subscribed server's presence events. Note that you may for
807      * a short time still receive events from the server since it may take time for the
808      * unsubscribe to take effect.
809      *
810      * @param ocPresenceHandle the handle object provided by the subscribePresence call that
811      *                         identifies this subscription
812      * @throws OcException if failure
813      */
814     public static void unsubscribePresence(
815             OcPresenceHandle ocPresenceHandle) throws OcException {
816         OcPlatform.initCheck();
817         OcPlatform.unsubscribePresence0(ocPresenceHandle);
818     }
819
820     private static native void unsubscribePresence0(
821             OcPresenceHandle ocPresenceHandle) throws OcException;
822
823     /**
824      * Creates a resource proxy object so that get/put/observe functionality can be used without
825      * discovering the object in advance. Note that the consumer of this method needs to provide
826      * all of the details required to correctly contact and observe the object. If the consumer
827      * lacks any of this information, they should discover the resource object normally.
828      * Additionally, you can only create this object if OcPlatform was initialized to be a Client
829      * or Client/Server.
830      *
831      * @param host                a string containing a resolvable host address of the server holding
832      *                            the resource
833      * @param uri                 the rest of the resource's URI that will permit messages to be
834      *                            properly routed.
835      *                            Example: /a/light
836      * @param connectivityTypeSet Set of types of connectivity. Example: IP
837      * @param isObservable        a boolean containing whether the resource supports observation
838      * @param resourceTypeList    a collection of resource types implemented by the resource
839      * @param interfaceList       a collection of interfaces that the resource supports/implements
840      * @return new resource object
841      * @throws OcException if failure
842      */
843     public static OcResource constructResourceObject(
844             String host,
845             String uri,
846             EnumSet<OcConnectivityType> connectivityTypeSet,
847             boolean isObservable,
848             List<String> resourceTypeList,
849             List<String> interfaceList) throws OcException {
850         OcPlatform.initCheck();
851         int connTypeInt = 0;
852
853         for (OcConnectivityType connType : OcConnectivityType.values()) {
854             if (connectivityTypeSet.contains(connType))
855                 connTypeInt |= connType.getValue();
856         }
857         return OcPlatform.constructResourceObject0(
858                 host,
859                 uri,
860                 connTypeInt,
861                 isObservable,
862                 resourceTypeList.toArray(new String[resourceTypeList.size()]),
863                 interfaceList.toArray(new String[interfaceList.size()])
864         );
865     }
866
867     private static native OcResource constructResourceObject0(
868             String host,
869             String uri,
870             int connectivityType,
871             boolean isObservable,
872             String[] resourceTypes,
873             String[] interfaces) throws OcException;
874
875     /**
876      * Allows application entity handler to send response to an incoming request.
877      *
878      * @param ocResourceResponse resource response
879      * @throws OcException if failure
880      */
881     public static void sendResponse(OcResourceResponse ocResourceResponse)
882             throws OcException {
883         OcPlatform.initCheck();
884         OcPlatform.sendResponse0(ocResourceResponse);
885     }
886
887     private static native void sendResponse0(OcResourceResponse ocResourceResponse)
888             throws OcException;
889
890     /**
891      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
892      * Event listeners are notified asynchronously
893      */
894     public interface OnResourceFoundListener {
895         public void onResourceFound(OcResource resource);
896     }
897
898     /**
899      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
900      * Event listeners are notified asynchronously
901      */
902     public interface OnDeviceFoundListener {
903         public void onDeviceFound(OcRepresentation ocRepresentation);
904     }
905
906     /**
907      * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
908      * Event listeners are notified asynchronously
909      */
910     public interface OnPlatformFoundListener {
911         public void onPlatformFound(OcRepresentation ocRepresentation);
912     }
913
914     /**
915      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
916      * Event listeners are notified asynchronously
917      */
918     public interface OnPresenceListener {
919         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
920     }
921
922     /**
923      * An EntityHandler can be registered via the OcPlatform.registerResource call.
924      * Event listeners are notified asynchronously
925      */
926     public interface EntityHandler {
927         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
928     }
929
930     private static void initCheck() {
931         if (!sIsPlatformInitialized) {
932             throw new IllegalStateException("OcPlatform must be configured by making a call to " +
933                     "OcPlatform.Configure before any other API calls are permitted");
934         }
935     }
936 }