Removed executable bit from non-executable files.
[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 = "oc.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 = "oc.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 = "oc.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 = "oc.mi.grp";\r
65 \r
66     public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oc/core";\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 PRESENCE_URI = "/oc/presence";\r
72 \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                 ocDeviceInfo.getHostName(),\r
411                 ocDeviceInfo.getDeviceUuid(),\r
412                 ocDeviceInfo.getContentType(),\r
413                 ocDeviceInfo.getVersion(),\r
414                 ocDeviceInfo.getManufacturerName(),\r
415                 ocDeviceInfo.getManufacturerUrl(),\r
416                 ocDeviceInfo.getModelNumber(),\r
417                 ocDeviceInfo.getDateOfManufacture(),\r
418                 ocDeviceInfo.getPlatformVersion(),\r
419                 ocDeviceInfo.getFirmwareVersion(),\r
420                 ocDeviceInfo.getSupportUrl()\r
421         );\r
422     }\r
423 \r
424     private static native void registerDeviceInfo0(\r
425             String deviceName,\r
426             String hostName,\r
427             String deviceUUID,\r
428             String contentType,\r
429             String version,\r
430             String manufacturerName,\r
431             String manufacturerUrl,\r
432             String modelNumber,\r
433             String dateOfManufacture,\r
434             String platformVersion,\r
435             String firmwareVersion,\r
436             String supportUrl) throws OcException;\r
437 \r
438     /**\r
439      * This API unregisters a resource with the server NOTE: This API applies to server side only.\r
440      *\r
441      * @param ocResourceHandle This is the resource handle which we which to unregister from the\r
442      *                         server\r
443      * @throws OcException\r
444      */\r
445     public static void unregisterResource(\r
446             OcResourceHandle ocResourceHandle) throws OcException {\r
447         OcPlatform.initCheck();\r
448         OcPlatform.unregisterResource0(ocResourceHandle);\r
449     }\r
450 \r
451     private static native void unregisterResource0(\r
452             OcResourceHandle ocResourceHandle) throws OcException;\r
453 \r
454 \r
455     /**\r
456      * Add a resource to a collection resource\r
457      *\r
458      * @param ocResourceCollectionHandle handle to the collection resource\r
459      * @param ocResourceHandle           handle to resource to be added to the collection resource\r
460      * @throws OcException\r
461      */\r
462     public static void bindResource(\r
463             OcResourceHandle ocResourceCollectionHandle,\r
464             OcResourceHandle ocResourceHandle) throws OcException {\r
465         OcPlatform.initCheck();\r
466         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
467     }\r
468 \r
469     private static native void bindResource0(\r
470             OcResourceHandle ocResourceCollectionHandle,\r
471             OcResourceHandle ocResourceHandle) throws OcException;\r
472 \r
473     /**\r
474      * Add multiple resources to a collection resource.\r
475      *\r
476      * @param ocResourceCollectionHandle handle to the collection resource\r
477      * @param ocResourceHandleList       reference to list of resource handles to be added to the\r
478      *                                   collection resource\r
479      * @throws OcException\r
480      */\r
481     public static void bindResources(\r
482             OcResourceHandle ocResourceCollectionHandle,\r
483             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
484         OcPlatform.initCheck();\r
485         OcPlatform.bindResources0(\r
486                 ocResourceCollectionHandle,\r
487                 ocResourceHandleList.toArray(\r
488                         new OcResourceHandle[ocResourceHandleList.size()])\r
489         );\r
490     }\r
491 \r
492     private static native void bindResources0(\r
493             OcResourceHandle ocResourceCollectionHandle,\r
494             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
495 \r
496     /**\r
497      * Unbind a resource from a collection resource.\r
498      *\r
499      * @param ocResourceCollectionHandle handle to the collection resource\r
500      * @param ocResourceHandle           resource handle to be unbound from the collection resource\r
501      * @throws OcException\r
502      */\r
503     public static void unbindResource(\r
504             OcResourceHandle ocResourceCollectionHandle,\r
505             OcResourceHandle ocResourceHandle) throws OcException {\r
506         OcPlatform.initCheck();\r
507         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
508     }\r
509 \r
510     private static native void unbindResource0(\r
511             OcResourceHandle ocResourceCollectionHandle,\r
512             OcResourceHandle ocResourceHandle) throws OcException;\r
513 \r
514     /**\r
515      * Unbind resources from a collection resource.\r
516      *\r
517      * @param ocResourceCollectionHandle Handle to the collection resource\r
518      * @param ocResourceHandleList       List of resource handles to be unbound from the collection\r
519      *                                   resource\r
520      * @throws OcException\r
521      */\r
522     public static void unbindResources(\r
523             OcResourceHandle ocResourceCollectionHandle,\r
524             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
525         OcPlatform.initCheck();\r
526         OcPlatform.unbindResources0(\r
527                 ocResourceCollectionHandle,\r
528                 ocResourceHandleList.toArray(\r
529                         new OcResourceHandle[ocResourceHandleList.size()])\r
530         );\r
531     }\r
532 \r
533     private static native void unbindResources0(\r
534             OcResourceHandle ocResourceCollectionHandle,\r
535             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
536 \r
537     /**\r
538      * Binds a type to a particular resource\r
539      *\r
540      * @param ocResourceHandle handle to the resource\r
541      * @param resourceTypeName new typename to bind to the resource\r
542      * @throws OcException\r
543      */\r
544     public static void bindTypeToResource(\r
545             OcResourceHandle ocResourceHandle,\r
546             String resourceTypeName) throws OcException {\r
547         OcPlatform.initCheck();\r
548         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);\r
549     }\r
550 \r
551     private static native void bindTypeToResource0(\r
552             OcResourceHandle ocResourceHandle,\r
553             String resourceTypeName) throws OcException;\r
554 \r
555     /**\r
556      * Binds an interface to a particular resource\r
557      *\r
558      * @param ocResourceHandle      handle to the resource\r
559      * @param resourceInterfaceName new interface to bind to the resource\r
560      * @throws OcException\r
561      */\r
562     public static void bindInterfaceToResource(\r
563             OcResourceHandle ocResourceHandle,\r
564             String resourceInterfaceName) throws OcException {\r
565         OcPlatform.initCheck();\r
566         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);\r
567     }\r
568 \r
569     private static native void bindInterfaceToResource0(\r
570             OcResourceHandle ocResourceHandle,\r
571             String resourceInterfaceName) throws OcException;\r
572 \r
573     /**\r
574      * Start Presence announcements.\r
575      *\r
576      * @param ttl time to live in seconds\r
577      * @throws OcException\r
578      */\r
579     public static void startPresence(int ttl) throws OcException {\r
580         OcPlatform.initCheck();\r
581         OcPlatform.startPresence0(ttl);\r
582     }\r
583 \r
584     private static native void startPresence0(int ttl) throws OcException;\r
585 \r
586     /**\r
587      * Stop Presence announcements.\r
588      *\r
589      * @throws OcException\r
590      */\r
591     public static void stopPresence() throws OcException {\r
592         OcPlatform.initCheck();\r
593         OcPlatform.stopPresence0();\r
594     }\r
595 \r
596     private static native void stopPresence0() throws OcException;\r
597 \r
598     /**\r
599      * Subscribes to a server's presence change events. By making this subscription, every time a\r
600      * server adds/removes/alters a resource, starts or is intentionally stopped\r
601      *\r
602      * @param host               The IP address/addressable name of the server to subscribe to\r
603      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
604      *                           IPV6, ALL\r
605      * @param onPresenceListener listener that will receive notifications/subscription events\r
606      * @return a handle object that can be used to identify this subscription request. It can be\r
607      * used to unsubscribe from these events in the future\r
608      * @throws OcException\r
609      */\r
610     public static OcPresenceHandle subscribePresence(\r
611             String host,\r
612             OcConnectivityType connectivityType,\r
613             OnPresenceListener onPresenceListener) throws OcException {\r
614         OcPlatform.initCheck();\r
615         return OcPlatform.subscribePresence0(\r
616                 host,\r
617                 connectivityType.getValue(),\r
618                 onPresenceListener\r
619         );\r
620     }\r
621 \r
622     private static native OcPresenceHandle subscribePresence0(\r
623             String host,\r
624             int connectivityType,\r
625             OnPresenceListener onPresenceListener) throws OcException;\r
626 \r
627     /**\r
628      * Subscribes to a server's presence change events. By making this subscription, every time a\r
629      * server adds/removes/alters a resource, starts or is intentionally stopped\r
630      *\r
631      * @param host               The IP address/addressable name of the server to subscribe to\r
632      * @param resourceType       a resource type specified as a filter for subscription events.\r
633      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
634      *                           IPV6, ALL\r
635      * @param onPresenceListener listener that will receive notifications/subscription events\r
636      * @return a handle object that can be used to identify this subscription request. It can be\r
637      * used to unsubscribe from these events in the future\r
638      * @throws OcException\r
639      */\r
640     public static OcPresenceHandle subscribePresence(\r
641             String host,\r
642             String resourceType,\r
643             OcConnectivityType connectivityType,\r
644             OnPresenceListener onPresenceListener) throws OcException {\r
645         OcPlatform.initCheck();\r
646         return OcPlatform.subscribePresence1(\r
647                 host,\r
648                 resourceType,\r
649                 connectivityType.getValue(),\r
650                 onPresenceListener);\r
651     }\r
652 \r
653     private static native OcPresenceHandle subscribePresence1(\r
654             String host,\r
655             String resourceType,\r
656             int connectivityType,\r
657             OnPresenceListener onPresenceListener) throws OcException;\r
658 \r
659     /**\r
660      * Unsubscribes from a previously subscribed server's presence events. Note that you may for\r
661      * a short time still receive events from the server since it may take time for the\r
662      * unsubscribe to take effect.\r
663      *\r
664      * @param ocPresenceHandle the handle object provided by the subscribePresence call that\r
665      *                         identifies this subscription\r
666      * @throws OcException\r
667      */\r
668     public static void unsubscribePresence(\r
669             OcPresenceHandle ocPresenceHandle) throws OcException {\r
670         OcPlatform.initCheck();\r
671         OcPlatform.unsubscribePresence0(ocPresenceHandle);\r
672     }\r
673 \r
674     private static native void unsubscribePresence0(\r
675             OcPresenceHandle ocPresenceHandle) throws OcException;\r
676 \r
677     /**\r
678      * Creates a resource proxy object so that get/put/observe functionality can be used without\r
679      * discovering the object in advance. Note that the consumer of this method needs to provide\r
680      * all of the details required to correctly contact and observe the object. If the consumer\r
681      * lacks any of this information, they should discover the resource object normally.\r
682      * Additionally, you can only create this object if OcPlatform was initialized to be a Client\r
683      * or Client/Server.\r
684      *\r
685      * @param host             a string containing a resolvable host address of the server holding\r
686      *                         the resource\r
687      * @param uri              the rest of the resource's URI that will permit messages to be\r
688      *                         properly routed.\r
689      *                         Example: /a/light\r
690      * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,\r
691      *                         IPV6, ALL\r
692      * @param isObservable     a boolean containing whether the resource supports observation\r
693      * @param resourceTypeList a collection of resource types implemented by the resource\r
694      * @param interfaceList    a collection of interfaces that the resource supports/implements\r
695      * @return new resource object\r
696      * @throws OcException\r
697      */\r
698     public static OcResource constructResourceObject(\r
699             String host,\r
700             String uri,\r
701             OcConnectivityType connectivityType,\r
702             boolean isObservable,\r
703             List<String> resourceTypeList,\r
704             List<String> interfaceList) throws OcException {\r
705         OcPlatform.initCheck();\r
706         return OcPlatform.constructResourceObject0(\r
707                 host,\r
708                 uri,\r
709                 connectivityType.getValue(),\r
710                 isObservable,\r
711                 resourceTypeList.toArray(new String[resourceTypeList.size()]),\r
712                 interfaceList.toArray(new String[interfaceList.size()])\r
713         );\r
714     }\r
715 \r
716     private static native OcResource constructResourceObject0(\r
717             String host,\r
718             String uri,\r
719             int connectivityType,\r
720             boolean isObservable,\r
721             String[] resourceTypes,\r
722             String[] interfaces) throws OcException;\r
723 \r
724     /**\r
725      * Allows application entity handler to send response to an incoming request.\r
726      *\r
727      * @param ocResourceResponse resource response\r
728      * @throws OcException\r
729      */\r
730     public static void sendResponse(OcResourceResponse ocResourceResponse)\r
731             throws OcException {\r
732         OcPlatform.initCheck();\r
733         OcPlatform.sendResponse0(ocResourceResponse);\r
734     }\r
735 \r
736     private static native void sendResponse0(OcResourceResponse ocResourceResponse)\r
737             throws OcException;\r
738 \r
739     /**\r
740      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.\r
741      * Event listeners are notified asynchronously\r
742      */\r
743     public interface OnResourceFoundListener {\r
744         public void onResourceFound(OcResource resource);\r
745     }\r
746 \r
747     /**\r
748      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.\r
749      * Event listeners are notified asynchronously\r
750      */\r
751     public interface OnDeviceFoundListener {\r
752         public void onDeviceFound(OcRepresentation ocRepresentation);\r
753     }\r
754 \r
755     /**\r
756      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.\r
757      * Event listeners are notified asynchronously\r
758      */\r
759     public interface OnPresenceListener {\r
760         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);\r
761     }\r
762 \r
763     /**\r
764      * An EntityHandler can be registered via the OcPlatform.registerResource call.\r
765      * Event listeners are notified asynchronously\r
766      */\r
767     public interface EntityHandler {\r
768         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);\r
769     }\r
770 \r
771     private static void initCheck() {\r
772         if (!sIsPlatformInitialized) {\r
773             throw new IllegalStateException("OcPlatform must be configured by making a call to " +\r
774                     "OcPlatform.Configure before any other API calls are permitted");\r
775         }\r
776     }\r
777 }\r