Added support for device discovery at oic/d.
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcPlatform.java
1 /*\r
2  * //******************************************************************\r
3  * //\r
4  * // Copyright 2015 Intel Corporation.\r
5  * //\r
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
7  * //\r
8  * // Licensed under the Apache License, Version 2.0 (the "License");\r
9  * // you may not use this file except in compliance with the License.\r
10  * // You may obtain a copy of the License at\r
11  * //\r
12  * //      http://www.apache.org/licenses/LICENSE-2.0\r
13  * //\r
14  * // Unless required by applicable law or agreed to in writing, software\r
15  * // distributed under the License is distributed on an "AS IS" BASIS,\r
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * // See the License for the specific language governing permissions and\r
18  * // limitations under the License.\r
19  * //\r
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
21  */\r
22 \r
23 package org.iotivity.base;\r
24 \r
25 import org.iotivity.ca.CaInterface;\r
26 \r
27 import java.util.EnumSet;\r
28 import java.util.Iterator;\r
29 import java.util.List;\r
30 \r
31 /**\r
32  * Contains the main entrance/functionality of the product. To set a custom configuration, the\r
33  * implementer must make a call to OcPlatform.Configure before the first usage of a function in this\r
34  * class.\r
35  */\r
36 public final class OcPlatform {\r
37 \r
38     static {\r
39         System.loadLibrary("oc_logger");\r
40         System.loadLibrary("octbstack");\r
41         System.loadLibrary("connectivity_abstraction");\r
42         System.loadLibrary("oc");\r
43         System.loadLibrary("ocstack-jni");\r
44     }\r
45 \r
46     /**\r
47      * Default interface\r
48      */\r
49     public static final String DEFAULT_INTERFACE = "oic.mi.def";\r
50 \r
51     /**\r
52      * Used in discovering (GET) links to other resources of a collection\r
53      */\r
54     public static final String LINK_INTERFACE = "oic.mi.ll";\r
55 \r
56     /**\r
57      * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection\r
58      */\r
59     public static final String BATCH_INTERFACE = "oic.mi.b";\r
60 \r
61     /**\r
62      * Used in GET, PUT, POST methods on links to other remote resources of a group\r
63      */\r
64     public static final String GROUP_INTERFACE = "oic.mi.grp";\r
65 \r
66     public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res";\r
67     public static final String MULTICAST_PREFIX = "224.0.1.187:5683";\r
68     public static final String MULTICAST_IP = "224.0.1.187";\r
69     public static final int MULTICAST_PORT = 5683;\r
70     public static final int DEFAULT_PRESENCE_TTL = 60;\r
71     public static final String DEVICE_URI = "/oic/d";\r
72     public static final String PRESENCE_URI = "/oic/ad";\r
73     private static volatile boolean sIsPlatformInitialized = false;\r
74 \r
75     private OcPlatform() {\r
76     }\r
77 \r
78     /**\r
79      * API for setting the configuration of the OcPlatform.\r
80      * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect\r
81      *\r
82      * @param platformConfig platform configuration\r
83      */\r
84     public synchronized static void Configure(PlatformConfig platformConfig) {\r
85         if (!sIsPlatformInitialized) {\r
86             CaInterface.initialize(platformConfig.getContext());\r
87 \r
88             OcPlatform.configure(\r
89                     platformConfig.getServiceType().getValue(),\r
90                     platformConfig.getModeType().getValue(),\r
91                     platformConfig.getIpAddress(),\r
92                     platformConfig.getPort(),\r
93                     platformConfig.getQualityOfService().getValue()\r
94             );\r
95 \r
96             sIsPlatformInitialized = true;\r
97         }\r
98     }\r
99 \r
100     private static native void configure(int serviceType,\r
101                                          int modeType,\r
102                                          String ipAddress,\r
103                                          int port,\r
104                                          int qualityOfService);\r
105 \r
106     /**\r
107      * API for notifying base that resource's attributes have changed.\r
108      *\r
109      * @param ocResourceHandle resource handle of the resource\r
110      * @throws OcException\r
111      */\r
112     public static void notifyAllObservers(\r
113             OcResourceHandle ocResourceHandle) throws OcException {\r
114         OcPlatform.initCheck();\r
115         OcPlatform.notifyAllObservers0(ocResourceHandle);\r
116     }\r
117 \r
118     private static native void notifyAllObservers0(\r
119             OcResourceHandle ocResourceHandle) throws OcException;\r
120 \r
121     /**\r
122      * API for notifying base that resource's attributes have changed.\r
123      *\r
124      * @param ocResourceHandle resource handle of the resource\r
125      * @param qualityOfService the quality of communication\r
126      * @throws OcException\r
127      */\r
128     public static void notifyAllObservers(\r
129             OcResourceHandle ocResourceHandle,\r
130             QualityOfService qualityOfService) throws OcException {\r
131         OcPlatform.initCheck();\r
132         OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());\r
133     }\r
134 \r
135     private static native void notifyAllObservers1(\r
136             OcResourceHandle ocResourceHandle,\r
137             int qualityOfService) throws OcException;\r
138 \r
139     /**\r
140      * API for notifying only specific clients that resource's attributes have changed.\r
141      *\r
142      * @param ocResourceHandle    resource handle of the resource\r
143      * @param ocObservationIdList These set of ids are ones which which will be notified upon\r
144      *                            resource change.\r
145      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for\r
146      *                            this resource change\r
147      * @throws OcException\r
148      */\r
149     public static void notifyListOfObservers(\r
150             OcResourceHandle ocResourceHandle,\r
151             List<Byte> ocObservationIdList,\r
152             OcResourceResponse ocResourceResponse) throws OcException {\r
153         OcPlatform.initCheck();\r
154 \r
155         byte[] idArr = new byte[ocObservationIdList.size()];\r
156         Iterator<Byte> it = ocObservationIdList.iterator();\r
157         int i = 0;\r
158         while (it.hasNext()) {\r
159             idArr[i++] = (byte) it.next();\r
160         }\r
161 \r
162         OcPlatform.notifyListOfObservers2(\r
163                 ocResourceHandle,\r
164                 idArr,\r
165                 ocResourceResponse);\r
166     }\r
167 \r
168     private static native void notifyListOfObservers2(\r
169             OcResourceHandle ocResourceHandle,\r
170             byte[] ocObservationIdArray,\r
171             OcResourceResponse ocResourceResponse) throws OcException;\r
172 \r
173     /**\r
174      * API for notifying only specific clients that resource's attributes have changed.\r
175      *\r
176      * @param ocResourceHandle    resource handle of the resource\r
177      * @param ocObservationIdList These set of ids are ones which which will be notified upon\r
178      *                            resource change.\r
179      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for\r
180      *                            this resource change\r
181      * @param qualityOfService    the quality of communication\r
182      * @throws OcException\r
183      */\r
184     public static void notifyListOfObservers(\r
185             OcResourceHandle ocResourceHandle,\r
186             List<Byte> ocObservationIdList,\r
187             OcResourceResponse ocResourceResponse,\r
188             QualityOfService qualityOfService) throws OcException {\r
189         OcPlatform.initCheck();\r
190 \r
191         byte[] idArr = new byte[ocObservationIdList.size()];\r
192         Iterator<Byte> it = ocObservationIdList.iterator();\r
193         int i = 0;\r
194         while (it.hasNext()) {\r
195             idArr[i++] = (byte) it.next();\r
196         }\r
197 \r
198         OcPlatform.notifyListOfObservers3(\r
199                 ocResourceHandle,\r
200                 idArr,\r
201                 ocResourceResponse,\r
202                 qualityOfService.getValue()\r
203         );\r
204     }\r
205 \r
206     private static native void notifyListOfObservers3(\r
207             OcResourceHandle ocResourceHandle,\r
208             byte[] ocObservationIdArray,\r
209             OcResourceResponse ocResourceResponse,\r
210             int qualityOfService) throws OcException;\r
211 \r
212     /**\r
213      * API for Service and Resource Discovery. NOTE: This API applies to client side only\r
214      *\r
215      * @param host                    Host IP Address of a service to direct resource discovery query.\r
216      *                                If empty, performs multicast resource discovery query\r
217      * @param resourceUri             name of the resource. If null or empty, performs search for all\r
218      *                                resource names\r
219      * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
220      *                                IPV6, ALL\r
221      * @param onResourceFoundListener Handles events, success states and failure states.\r
222      * @throws OcException\r
223      */\r
224     public static void findResource(\r
225             String host,\r
226             String resourceUri,\r
227             OcConnectivityType connectivityType,\r
228             OnResourceFoundListener onResourceFoundListener) throws OcException {\r
229         OcPlatform.initCheck();\r
230         OcPlatform.findResource0(\r
231                 host,\r
232                 resourceUri,\r
233                 connectivityType.getValue(),\r
234                 onResourceFoundListener\r
235         );\r
236     }\r
237 \r
238     private static native void findResource0(\r
239             String host,\r
240             String resourceUri,\r
241             int connectivityType,\r
242             OnResourceFoundListener onResourceFoundListener) throws OcException;\r
243 \r
244     /**\r
245      * API for Service and Resource Discovery. NOTE: This API applies to client side only\r
246      *\r
247      * @param host                    Host IP Address of a service to direct resource discovery query.\r
248      *                                If empty, performs multicast resource discovery query\r
249      * @param resourceUri             name of the resource. If null or empty, performs search for all\r
250      *                                resource names\r
251      * @param connectivityType        a type of connectivity indicating the interface. Example: IPV4,\r
252      *                                IPV6, ALL\r
253      * @param onResourceFoundListener Handles events, success states and failure states.\r
254      * @param qualityOfService        the quality of communication\r
255      * @throws OcException\r
256      */\r
257     public static void findResource(\r
258             String host,\r
259             String resourceUri,\r
260             OcConnectivityType connectivityType,\r
261             OnResourceFoundListener onResourceFoundListener,\r
262             QualityOfService qualityOfService) throws OcException {\r
263         OcPlatform.initCheck();\r
264         OcPlatform.findResource1(host,\r
265                 resourceUri,\r
266                 connectivityType.getValue(),\r
267                 onResourceFoundListener,\r
268                 qualityOfService.getValue()\r
269         );\r
270     }\r
271 \r
272     private static native void findResource1(\r
273             String host,\r
274             String resourceUri,\r
275             int connectivityType,\r
276             OnResourceFoundListener onResourceFoundListener,\r
277             int qualityOfService) throws OcException;\r
278 \r
279     /**\r
280      * API for Device Discovery\r
281      *\r
282      * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
283      * @param deviceUri             Uri containing address to the virtual device\r
284      * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
285      *                              IPV6, ALL\r
286      * @param onDeviceFoundListener Handles events, success states and failure states.\r
287      * @throws OcException\r
288      */\r
289     public static void getDeviceInfo(\r
290             String host,\r
291             String deviceUri,\r
292             OcConnectivityType connectivityType,\r
293             OnDeviceFoundListener onDeviceFoundListener) throws OcException {\r
294         OcPlatform.initCheck();\r
295         OcPlatform.getDeviceInfo0(\r
296                 host,\r
297                 deviceUri,\r
298                 connectivityType.getValue(),\r
299                 onDeviceFoundListener\r
300         );\r
301     }\r
302 \r
303     private static native void getDeviceInfo0(\r
304             String host,\r
305             String deviceUri,\r
306             int connectivityType,\r
307             OnDeviceFoundListener onDeviceFoundListener) throws OcException;\r
308 \r
309     /**\r
310      * API for Device Discovery\r
311      *\r
312      * @param host                  Host IP Address. If null or empty, Multicast is performed.\r
313      * @param deviceUri             Uri containing address to the virtual device\r
314      * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,\r
315      *                              IPV6, ALL\r
316      * @param onDeviceFoundListener Handles events, success states and failure states.\r
317      * @param qualityOfService      the quality of communication\r
318      * @throws OcException\r
319      */\r
320     public static void getDeviceInfo(\r
321             String host,\r
322             String deviceUri,\r
323             OcConnectivityType connectivityType,\r
324             OnDeviceFoundListener onDeviceFoundListener,\r
325             QualityOfService qualityOfService) throws OcException {\r
326         OcPlatform.initCheck();\r
327         OcPlatform.getDeviceInfo1(\r
328                 host,\r
329                 deviceUri,\r
330                 connectivityType.getValue(),\r
331                 onDeviceFoundListener,\r
332                 qualityOfService.getValue()\r
333         );\r
334     }\r
335 \r
336     private static native void getDeviceInfo1(\r
337             String host,\r
338             String deviceUri,\r
339             int connectivityType,\r
340             OnDeviceFoundListener onDeviceFoundListener,\r
341             int qualityOfService) throws OcException;\r
342 \r
343     /**\r
344      * This API registers a resource with the server NOTE: This API applies to server side only.\r
345      *\r
346      * @param ocResource The instance of OcResource with all data filled\r
347      * @return resource handle\r
348      * @throws OcException\r
349      */\r
350     public static OcResourceHandle registerResource(\r
351             OcResource ocResource) throws OcException {\r
352         OcPlatform.initCheck();\r
353         return OcPlatform.registerResource0(ocResource);\r
354     }\r
355 \r
356     private static native OcResourceHandle registerResource0(\r
357             OcResource ocResource) throws OcException;\r
358 \r
359     /**\r
360      * This API registers a resource with the server NOTE: This API applies to server side only.\r
361      *\r
362      * @param resourceUri         The URI of the resource. Example: "a/light"\r
363      * @param resourceTypeName    The resource type. Example: "light"\r
364      * @param resourceInterface   The resource interface (whether it is collection etc).\r
365      * @param entityHandler       entity handler.\r
366      * @param resourcePropertySet indicates the property of the resource\r
367      * @return resource handle\r
368      * @throws OcException\r
369      */\r
370     public static OcResourceHandle registerResource(\r
371             String resourceUri,\r
372             String resourceTypeName,\r
373             String resourceInterface,\r
374             EntityHandler entityHandler,\r
375             EnumSet<ResourceProperty> resourcePropertySet) throws OcException {\r
376         OcPlatform.initCheck();\r
377 \r
378         int resProperty = 0;\r
379 \r
380         for (ResourceProperty prop : ResourceProperty.values()) {\r
381             if (resourcePropertySet.contains(prop))\r
382                 resProperty |= prop.getValue();\r
383         }\r
384 \r
385         return OcPlatform.registerResource1(resourceUri,\r
386                 resourceTypeName,\r
387                 resourceInterface,\r
388                 entityHandler,\r
389                 resProperty);\r
390     }\r
391 \r
392     private static native OcResourceHandle registerResource1(\r
393             String resourceUri,\r
394             String resourceTypeName,\r
395             String resourceInterface,\r
396             EntityHandler entityHandler,\r
397             int resourceProperty) throws OcException;\r
398 \r
399     /**\r
400      * Register Device Info\r
401      *\r
402      * @param ocDeviceInfo object containing all the device specific information\r
403      * @throws OcException\r
404      */\r
405     public static void registerDeviceInfo(\r
406             OcDeviceInfo ocDeviceInfo) throws OcException {\r
407         OcPlatform.initCheck();\r
408         OcPlatform.registerDeviceInfo0(\r
409                 ocDeviceInfo.getDeviceName()\r
410         );\r
411     }\r
412 \r
413     private static native void registerDeviceInfo0(\r
414             String deviceName\r
415             ) throws OcException;\r
416 \r
417     /**\r
418      * This API unregisters a resource with the server NOTE: This API applies to server side only.\r
419      *\r
420      * @param ocResourceHandle This is the resource handle which we which to unregister from the\r
421      *                         server\r
422      * @throws OcException\r
423      */\r
424     public static void unregisterResource(\r
425             OcResourceHandle ocResourceHandle) throws OcException {\r
426         OcPlatform.initCheck();\r
427         OcPlatform.unregisterResource0(ocResourceHandle);\r
428     }\r
429 \r
430     private static native void unregisterResource0(\r
431             OcResourceHandle ocResourceHandle) throws OcException;\r
432 \r
433 \r
434     /**\r
435      * Add a resource to a collection resource\r
436      *\r
437      * @param ocResourceCollectionHandle handle to the collection resource\r
438      * @param ocResourceHandle           handle to resource to be added to the collection resource\r
439      * @throws OcException\r
440      */\r
441     public static void bindResource(\r
442             OcResourceHandle ocResourceCollectionHandle,\r
443             OcResourceHandle ocResourceHandle) throws OcException {\r
444         OcPlatform.initCheck();\r
445         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
446     }\r
447 \r
448     private static native void bindResource0(\r
449             OcResourceHandle ocResourceCollectionHandle,\r
450             OcResourceHandle ocResourceHandle) throws OcException;\r
451 \r
452     /**\r
453      * Add multiple resources to a collection resource.\r
454      *\r
455      * @param ocResourceCollectionHandle handle to the collection resource\r
456      * @param ocResourceHandleList       reference to list of resource handles to be added to the\r
457      *                                   collection resource\r
458      * @throws OcException\r
459      */\r
460     public static void bindResources(\r
461             OcResourceHandle ocResourceCollectionHandle,\r
462             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
463         OcPlatform.initCheck();\r
464         OcPlatform.bindResources0(\r
465                 ocResourceCollectionHandle,\r
466                 ocResourceHandleList.toArray(\r
467                         new OcResourceHandle[ocResourceHandleList.size()])\r
468         );\r
469     }\r
470 \r
471     private static native void bindResources0(\r
472             OcResourceHandle ocResourceCollectionHandle,\r
473             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
474 \r
475     /**\r
476      * Unbind a resource from a collection resource.\r
477      *\r
478      * @param ocResourceCollectionHandle handle to the collection resource\r
479      * @param ocResourceHandle           resource handle to be unbound from the collection resource\r
480      * @throws OcException\r
481      */\r
482     public static void unbindResource(\r
483             OcResourceHandle ocResourceCollectionHandle,\r
484             OcResourceHandle ocResourceHandle) throws OcException {\r
485         OcPlatform.initCheck();\r
486         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
487     }\r
488 \r
489     private static native void unbindResource0(\r
490             OcResourceHandle ocResourceCollectionHandle,\r
491             OcResourceHandle ocResourceHandle) throws OcException;\r
492 \r
493     /**\r
494      * Unbind resources from a collection resource.\r
495      *\r
496      * @param ocResourceCollectionHandle Handle to the collection resource\r
497      * @param ocResourceHandleList       List of resource handles to be unbound from the collection\r
498      *                                   resource\r
499      * @throws OcException\r
500      */\r
501     public static void unbindResources(\r
502             OcResourceHandle ocResourceCollectionHandle,\r
503             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
504         OcPlatform.initCheck();\r
505         OcPlatform.unbindResources0(\r
506                 ocResourceCollectionHandle,\r
507                 ocResourceHandleList.toArray(\r
508                         new OcResourceHandle[ocResourceHandleList.size()])\r
509         );\r
510     }\r
511 \r
512     private static native void unbindResources0(\r
513             OcResourceHandle ocResourceCollectionHandle,\r
514             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
515 \r
516     /**\r
517      * Binds a type to a particular resource\r
518      *\r
519      * @param ocResourceHandle handle to the resource\r
520      * @param resourceTypeName new typename to bind to the resource\r
521      * @throws OcException\r
522      */\r
523     public static void bindTypeToResource(\r
524             OcResourceHandle ocResourceHandle,\r
525             String resourceTypeName) throws OcException {\r
526         OcPlatform.initCheck();\r
527         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);\r
528     }\r
529 \r
530     private static native void bindTypeToResource0(\r
531             OcResourceHandle ocResourceHandle,\r
532             String resourceTypeName) throws OcException;\r
533 \r
534     /**\r
535      * Binds an interface to a particular resource\r
536      *\r
537      * @param ocResourceHandle      handle to the resource\r
538      * @param resourceInterfaceName new interface to bind to the resource\r
539      * @throws OcException\r
540      */\r
541     public static void bindInterfaceToResource(\r
542             OcResourceHandle ocResourceHandle,\r
543             String resourceInterfaceName) throws OcException {\r
544         OcPlatform.initCheck();\r
545         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);\r
546     }\r
547 \r
548     private static native void bindInterfaceToResource0(\r
549             OcResourceHandle ocResourceHandle,\r
550             String resourceInterfaceName) throws OcException;\r
551 \r
552     /**\r
553      * Start Presence announcements.\r
554      *\r
555      * @param ttl time to live in seconds\r
556      * @throws OcException\r
557      */\r
558     public static void startPresence(int ttl) throws OcException {\r
559         OcPlatform.initCheck();\r
560         OcPlatform.startPresence0(ttl);\r
561     }\r
562 \r
563     private static native void startPresence0(int ttl) throws OcException;\r
564 \r
565     /**\r
566      * Stop Presence announcements.\r
567      *\r
568      * @throws OcException\r
569      */\r
570     public static void stopPresence() throws OcException {\r
571         OcPlatform.initCheck();\r
572         OcPlatform.stopPresence0();\r
573     }\r
574 \r
575     private static native void stopPresence0() throws OcException;\r
576 \r
577     /**\r
578      * Subscribes to a server's presence change events. By making this subscription, every time a\r
579      * server adds/removes/alters a resource, starts or is intentionally stopped\r
580      *\r
581      * @param host               The IP address/addressable name of the server to subscribe to\r
582      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
583      *                           IPV6, ALL\r
584      * @param onPresenceListener listener that will receive notifications/subscription events\r
585      * @return a handle object that can be used to identify this subscription request. It can be\r
586      * used to unsubscribe from these events in the future\r
587      * @throws OcException\r
588      */\r
589     public static OcPresenceHandle subscribePresence(\r
590             String host,\r
591             OcConnectivityType connectivityType,\r
592             OnPresenceListener onPresenceListener) throws OcException {\r
593         OcPlatform.initCheck();\r
594         return OcPlatform.subscribePresence0(\r
595                 host,\r
596                 connectivityType.getValue(),\r
597                 onPresenceListener\r
598         );\r
599     }\r
600 \r
601     private static native OcPresenceHandle subscribePresence0(\r
602             String host,\r
603             int connectivityType,\r
604             OnPresenceListener onPresenceListener) throws OcException;\r
605 \r
606     /**\r
607      * Subscribes to a server's presence change events. By making this subscription, every time a\r
608      * server adds/removes/alters a resource, starts or is intentionally stopped\r
609      *\r
610      * @param host               The IP address/addressable name of the server to subscribe to\r
611      * @param resourceType       a resource type specified as a filter for subscription events.\r
612      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
613      *                           IPV6, ALL\r
614      * @param onPresenceListener listener that will receive notifications/subscription events\r
615      * @return a handle object that can be used to identify this subscription request. It can be\r
616      * used to unsubscribe from these events in the future\r
617      * @throws OcException\r
618      */\r
619     public static OcPresenceHandle subscribePresence(\r
620             String host,\r
621             String resourceType,\r
622             OcConnectivityType connectivityType,\r
623             OnPresenceListener onPresenceListener) throws OcException {\r
624         OcPlatform.initCheck();\r
625         return OcPlatform.subscribePresence1(\r
626                 host,\r
627                 resourceType,\r
628                 connectivityType.getValue(),\r
629                 onPresenceListener);\r
630     }\r
631 \r
632     private static native OcPresenceHandle subscribePresence1(\r
633             String host,\r
634             String resourceType,\r
635             int connectivityType,\r
636             OnPresenceListener onPresenceListener) throws OcException;\r
637 \r
638     /**\r
639      * Unsubscribes from a previously subscribed server's presence events. Note that you may for\r
640      * a short time still receive events from the server since it may take time for the\r
641      * unsubscribe to take effect.\r
642      *\r
643      * @param ocPresenceHandle the handle object provided by the subscribePresence call that\r
644      *                         identifies this subscription\r
645      * @throws OcException\r
646      */\r
647     public static void unsubscribePresence(\r
648             OcPresenceHandle ocPresenceHandle) throws OcException {\r
649         OcPlatform.initCheck();\r
650         OcPlatform.unsubscribePresence0(ocPresenceHandle);\r
651     }\r
652 \r
653     private static native void unsubscribePresence0(\r
654             OcPresenceHandle ocPresenceHandle) throws OcException;\r
655 \r
656     /**\r
657      * Creates a resource proxy object so that get/put/observe functionality can be used without\r
658      * discovering the object in advance. Note that the consumer of this method needs to provide\r
659      * all of the details required to correctly contact and observe the object. If the consumer\r
660      * lacks any of this information, they should discover the resource object normally.\r
661      * Additionally, you can only create this object if OcPlatform was initialized to be a Client\r
662      * or Client/Server.\r
663      *\r
664      * @param host             a string containing a resolvable host address of the server holding\r
665      *                         the resource\r
666      * @param uri              the rest of the resource's URI that will permit messages to be\r
667      *                         properly routed.\r
668      *                         Example: /a/light\r
669      * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,\r
670      *                         IPV6, ALL\r
671      * @param isObservable     a boolean containing whether the resource supports observation\r
672      * @param resourceTypeList a collection of resource types implemented by the resource\r
673      * @param interfaceList    a collection of interfaces that the resource supports/implements\r
674      * @return new resource object\r
675      * @throws OcException\r
676      */\r
677     public static OcResource constructResourceObject(\r
678             String host,\r
679             String uri,\r
680             OcConnectivityType connectivityType,\r
681             boolean isObservable,\r
682             List<String> resourceTypeList,\r
683             List<String> interfaceList) throws OcException {\r
684         OcPlatform.initCheck();\r
685         return OcPlatform.constructResourceObject0(\r
686                 host,\r
687                 uri,\r
688                 connectivityType.getValue(),\r
689                 isObservable,\r
690                 resourceTypeList.toArray(new String[resourceTypeList.size()]),\r
691                 interfaceList.toArray(new String[interfaceList.size()])\r
692         );\r
693     }\r
694 \r
695     private static native OcResource constructResourceObject0(\r
696             String host,\r
697             String uri,\r
698             int connectivityType,\r
699             boolean isObservable,\r
700             String[] resourceTypes,\r
701             String[] interfaces) throws OcException;\r
702 \r
703     /**\r
704      * Allows application entity handler to send response to an incoming request.\r
705      *\r
706      * @param ocResourceResponse resource response\r
707      * @throws OcException\r
708      */\r
709     public static void sendResponse(OcResourceResponse ocResourceResponse)\r
710             throws OcException {\r
711         OcPlatform.initCheck();\r
712         OcPlatform.sendResponse0(ocResourceResponse);\r
713     }\r
714 \r
715     private static native void sendResponse0(OcResourceResponse ocResourceResponse)\r
716             throws OcException;\r
717 \r
718     /**\r
719      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.\r
720      * Event listeners are notified asynchronously\r
721      */\r
722     public interface OnResourceFoundListener {\r
723         public void onResourceFound(OcResource resource);\r
724     }\r
725 \r
726     /**\r
727      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.\r
728      * Event listeners are notified asynchronously\r
729      */\r
730     public interface OnDeviceFoundListener {\r
731         public void onDeviceFound(OcRepresentation ocRepresentation);\r
732     }\r
733 \r
734     /**\r
735      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.\r
736      * Event listeners are notified asynchronously\r
737      */\r
738     public interface OnPresenceListener {\r
739         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);\r
740     }\r
741 \r
742     /**\r
743      * An EntityHandler can be registered via the OcPlatform.registerResource call.\r
744      * Event listeners are notified asynchronously\r
745      */\r
746     public interface EntityHandler {\r
747         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);\r
748     }\r
749 \r
750     private static void initCheck() {\r
751         if (!sIsPlatformInitialized) {\r
752             throw new IllegalStateException("OcPlatform must be configured by making a call to " +\r
753                     "OcPlatform.Configure before any other API calls are permitted");\r
754         }\r
755     }\r
756 }\r