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