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