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