Merge 'security-basecamp' branch into master with CBOR
[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;
345
346     /**
347      * API for Platform Discovery
348      *
349      * @param host                  Host IP Address. If null or empty, Multicast is performed.
350      * @param platformUri           Uri containing address to the platform
351      * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
352      *                              IPV6, ALL
353      * @param onPlatformFoundListener Handles events, success states and failure states.
354      * @throws OcException
355      */
356
357     public static void getPlatformInfo(
358             String host,
359             String platformUri,
360             OcConnectivityType connectivityType,
361             OnPlatformFoundListener onPlatformFoundListener) throws OcException {
362         OcPlatform.initCheck();
363         OcPlatform.getPlatformInfo0(
364                 host,
365                 platformUri,
366                 connectivityType.getValue(),
367                 onPlatformFoundListener
368         );
369     }
370
371     private static native void getPlatformInfo0(
372             String host,
373             String platformUri,
374             int connectivityType,
375             OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
376
377     /**
378      * API for Platform Discovery
379      *
380      * @param host                  Host IP Address. If null or empty, Multicast is performed.
381      * @param platformUri           Uri containing address to the platform
382      * @param connectivityType      a type of connectivity indicating the interface. Example: IPV4,
383      *                              IPV6, ALL
384      * @param onPlatformFoundListener Handles events, success states and failure states.
385      * @param qualityOfService      the quality of communication
386      * @throws OcException
387      */
388
389     public static void getPlatformInfo(
390             String host,
391             String platformUri,
392             OcConnectivityType connectivityType,
393             OnPlatformFoundListener onPlatformFoundListener,
394             QualityOfService qualityOfService) throws OcException {
395         OcPlatform.initCheck();
396         OcPlatform.getPlatformInfo1(
397                 host,
398                 platformUri,
399                 connectivityType.getValue(),
400                 onPlatformFoundListener,
401                 qualityOfService.getValue()
402         );
403     }
404
405     private static native void getPlatformInfo1(
406             String host,
407             String platformUri,
408             int connectivityType,
409             OnPlatformFoundListener onPlatformFoundListener,
410             int qualityOfService) throws OcException;\r
411 \r
412     /**\r
413      * This API registers a resource with the server NOTE: This API applies to server side only.\r
414      *\r
415      * @param ocResource The instance of OcResource with all data filled\r
416      * @return resource handle\r
417      * @throws OcException\r
418      */\r
419     public static OcResourceHandle registerResource(\r
420             OcResource ocResource) throws OcException {\r
421         OcPlatform.initCheck();\r
422         return OcPlatform.registerResource0(ocResource);\r
423     }\r
424 \r
425     private static native OcResourceHandle registerResource0(\r
426             OcResource ocResource) throws OcException;\r
427 \r
428     /**\r
429      * This API registers a resource with the server NOTE: This API applies to server side only.\r
430      *\r
431      * @param resourceUri         The URI of the resource. Example: "a/light"\r
432      * @param resourceTypeName    The resource type. Example: "light"\r
433      * @param resourceInterface   The resource interface (whether it is collection etc).\r
434      * @param entityHandler       entity handler.\r
435      * @param resourcePropertySet indicates the property of the resource\r
436      * @return resource handle\r
437      * @throws OcException\r
438      */\r
439     public static OcResourceHandle registerResource(\r
440             String resourceUri,\r
441             String resourceTypeName,\r
442             String resourceInterface,\r
443             EntityHandler entityHandler,\r
444             EnumSet<ResourceProperty> resourcePropertySet) throws OcException {\r
445         OcPlatform.initCheck();\r
446 \r
447         int resProperty = 0;\r
448 \r
449         for (ResourceProperty prop : ResourceProperty.values()) {\r
450             if (resourcePropertySet.contains(prop))\r
451                 resProperty |= prop.getValue();\r
452         }\r
453 \r
454         return OcPlatform.registerResource1(resourceUri,\r
455                 resourceTypeName,\r
456                 resourceInterface,\r
457                 entityHandler,\r
458                 resProperty);\r
459     }\r
460 \r
461     private static native OcResourceHandle registerResource1(\r
462             String resourceUri,\r
463             String resourceTypeName,\r
464             String resourceInterface,\r
465             EntityHandler entityHandler,\r
466             int resourceProperty) throws OcException;\r
467 \r
468     /**\r
469      * Register Device Info\r
470      *\r
471      * @param ocDeviceInfo object containing all the device specific information\r
472      * @throws OcException\r
473      */\r
474     public static void registerDeviceInfo(\r
475             OcDeviceInfo ocDeviceInfo) throws OcException {\r
476         OcPlatform.initCheck();\r
477         OcPlatform.registerDeviceInfo0(\r
478                 ocDeviceInfo.getDeviceName()\r
479         );\r
480     }\r
481 \r
482     private static native void registerDeviceInfo0(\r
483             String deviceName\r
484             ) throws OcException;\r
485 \r
486     /**\r
487      * Register Platform Info
488      *
489      * @param ocPlatformInfo object containing all the platform specific information
490      * @throws OcException
491      */
492     public static void registerPlatformInfo(
493             OcPlatformInfo ocPlatformInfo) throws OcException {
494         OcPlatform.initCheck();
495         OcPlatform.registerPlatformInfo0(
496                 ocPlatformInfo.getPlatformID(),
497                 ocPlatformInfo.getManufacturerName(),
498                 ocPlatformInfo.getManufacturerUrl(),
499                 ocPlatformInfo.getModelNumber(),
500                 ocPlatformInfo.getDateOfManufacture(),
501                 ocPlatformInfo.getPlatformVersion(),
502                 ocPlatformInfo.getOperatingSystemVersion(),
503                 ocPlatformInfo.getHardwareVersion(),
504                 ocPlatformInfo.getFirmwareVersion(),
505                 ocPlatformInfo.getSupportUrl(),
506                 ocPlatformInfo.getSystemTime()
507         );
508     }
509
510     private static native void registerPlatformInfo0(
511             String platformId, String manufacturerName, String manufacturerUrl,
512             String modelNumber, String dateOfManufacture, String platformVersion,
513             String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
514             String supportUrl, String systemTime
515     ) throws OcException;
516
517     /**
518      * This API unregisters a resource with the server NOTE: This API applies to server side only.\r
519      *\r
520      * @param ocResourceHandle This is the resource handle which we which to unregister from the\r
521      *                         server\r
522      * @throws OcException\r
523      */\r
524     public static void unregisterResource(\r
525             OcResourceHandle ocResourceHandle) throws OcException {\r
526         OcPlatform.initCheck();\r
527         OcPlatform.unregisterResource0(ocResourceHandle);\r
528     }\r
529 \r
530     private static native void unregisterResource0(\r
531             OcResourceHandle ocResourceHandle) throws OcException;\r
532 \r
533 \r
534     /**\r
535      * Add a resource to a collection resource\r
536      *\r
537      * @param ocResourceCollectionHandle handle to the collection resource\r
538      * @param ocResourceHandle           handle to resource to be added to the collection resource\r
539      * @throws OcException\r
540      */\r
541     public static void bindResource(\r
542             OcResourceHandle ocResourceCollectionHandle,\r
543             OcResourceHandle ocResourceHandle) throws OcException {\r
544         OcPlatform.initCheck();\r
545         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
546     }\r
547 \r
548     private static native void bindResource0(\r
549             OcResourceHandle ocResourceCollectionHandle,\r
550             OcResourceHandle ocResourceHandle) throws OcException;\r
551 \r
552     /**\r
553      * Add multiple resources to a collection resource.\r
554      *\r
555      * @param ocResourceCollectionHandle handle to the collection resource\r
556      * @param ocResourceHandleList       reference to list of resource handles to be added to the\r
557      *                                   collection resource\r
558      * @throws OcException\r
559      */\r
560     public static void bindResources(\r
561             OcResourceHandle ocResourceCollectionHandle,\r
562             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
563         OcPlatform.initCheck();\r
564         OcPlatform.bindResources0(\r
565                 ocResourceCollectionHandle,\r
566                 ocResourceHandleList.toArray(\r
567                         new OcResourceHandle[ocResourceHandleList.size()])\r
568         );\r
569     }\r
570 \r
571     private static native void bindResources0(\r
572             OcResourceHandle ocResourceCollectionHandle,\r
573             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
574 \r
575     /**\r
576      * Unbind a resource from a collection resource.\r
577      *\r
578      * @param ocResourceCollectionHandle handle to the collection resource\r
579      * @param ocResourceHandle           resource handle to be unbound from the collection resource\r
580      * @throws OcException\r
581      */\r
582     public static void unbindResource(\r
583             OcResourceHandle ocResourceCollectionHandle,\r
584             OcResourceHandle ocResourceHandle) throws OcException {\r
585         OcPlatform.initCheck();\r
586         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);\r
587     }\r
588 \r
589     private static native void unbindResource0(\r
590             OcResourceHandle ocResourceCollectionHandle,\r
591             OcResourceHandle ocResourceHandle) throws OcException;\r
592 \r
593     /**\r
594      * Unbind resources from a collection resource.\r
595      *\r
596      * @param ocResourceCollectionHandle Handle to the collection resource\r
597      * @param ocResourceHandleList       List of resource handles to be unbound from the collection\r
598      *                                   resource\r
599      * @throws OcException\r
600      */\r
601     public static void unbindResources(\r
602             OcResourceHandle ocResourceCollectionHandle,\r
603             List<OcResourceHandle> ocResourceHandleList) throws OcException {\r
604         OcPlatform.initCheck();\r
605         OcPlatform.unbindResources0(\r
606                 ocResourceCollectionHandle,\r
607                 ocResourceHandleList.toArray(\r
608                         new OcResourceHandle[ocResourceHandleList.size()])\r
609         );\r
610     }\r
611 \r
612     private static native void unbindResources0(\r
613             OcResourceHandle ocResourceCollectionHandle,\r
614             OcResourceHandle[] ocResourceHandleArray) throws OcException;\r
615 \r
616     /**\r
617      * Binds a type to a particular resource\r
618      *\r
619      * @param ocResourceHandle handle to the resource\r
620      * @param resourceTypeName new typename to bind to the resource\r
621      * @throws OcException\r
622      */\r
623     public static void bindTypeToResource(\r
624             OcResourceHandle ocResourceHandle,\r
625             String resourceTypeName) throws OcException {\r
626         OcPlatform.initCheck();\r
627         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);\r
628     }\r
629 \r
630     private static native void bindTypeToResource0(\r
631             OcResourceHandle ocResourceHandle,\r
632             String resourceTypeName) throws OcException;\r
633 \r
634     /**\r
635      * Binds an interface to a particular resource\r
636      *\r
637      * @param ocResourceHandle      handle to the resource\r
638      * @param resourceInterfaceName new interface to bind to the resource\r
639      * @throws OcException\r
640      */\r
641     public static void bindInterfaceToResource(\r
642             OcResourceHandle ocResourceHandle,\r
643             String resourceInterfaceName) throws OcException {\r
644         OcPlatform.initCheck();\r
645         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);\r
646     }\r
647 \r
648     private static native void bindInterfaceToResource0(\r
649             OcResourceHandle ocResourceHandle,\r
650             String resourceInterfaceName) throws OcException;\r
651 \r
652     /**\r
653      * Start Presence announcements.\r
654      *\r
655      * @param ttl time to live in seconds\r
656      * @throws OcException\r
657      */\r
658     public static void startPresence(int ttl) throws OcException {\r
659         OcPlatform.initCheck();\r
660         OcPlatform.startPresence0(ttl);\r
661     }\r
662 \r
663     private static native void startPresence0(int ttl) throws OcException;\r
664 \r
665     /**\r
666      * Stop Presence announcements.\r
667      *\r
668      * @throws OcException\r
669      */\r
670     public static void stopPresence() throws OcException {\r
671         OcPlatform.initCheck();\r
672         OcPlatform.stopPresence0();\r
673     }\r
674 \r
675     private static native void stopPresence0() throws OcException;\r
676 \r
677     /**\r
678      * Subscribes to a server's presence change events. By making this subscription, every time a\r
679      * server adds/removes/alters a resource, starts or is intentionally stopped\r
680      *\r
681      * @param host               The IP address/addressable name of the server to subscribe to\r
682      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
683      *                           IPV6, ALL\r
684      * @param onPresenceListener listener that will receive notifications/subscription events\r
685      * @return a handle object that can be used to identify this subscription request. It can be\r
686      * used to unsubscribe from these events in the future\r
687      * @throws OcException\r
688      */\r
689     public static OcPresenceHandle subscribePresence(\r
690             String host,\r
691             OcConnectivityType connectivityType,\r
692             OnPresenceListener onPresenceListener) throws OcException {\r
693         OcPlatform.initCheck();\r
694         return OcPlatform.subscribePresence0(\r
695                 host,\r
696                 connectivityType.getValue(),\r
697                 onPresenceListener\r
698         );\r
699     }\r
700 \r
701     private static native OcPresenceHandle subscribePresence0(\r
702             String host,\r
703             int connectivityType,\r
704             OnPresenceListener onPresenceListener) throws OcException;\r
705 \r
706     /**\r
707      * Subscribes to a server's presence change events. By making this subscription, every time a\r
708      * server adds/removes/alters a resource, starts or is intentionally stopped\r
709      *\r
710      * @param host               The IP address/addressable name of the server to subscribe to\r
711      * @param resourceType       a resource type specified as a filter for subscription events.\r
712      * @param connectivityType   a type of connectivity indicating the interface. Example: IPV4,\r
713      *                           IPV6, ALL\r
714      * @param onPresenceListener listener that will receive notifications/subscription events\r
715      * @return a handle object that can be used to identify this subscription request. It can be\r
716      * used to unsubscribe from these events in the future\r
717      * @throws OcException\r
718      */\r
719     public static OcPresenceHandle subscribePresence(\r
720             String host,\r
721             String resourceType,\r
722             OcConnectivityType connectivityType,\r
723             OnPresenceListener onPresenceListener) throws OcException {\r
724         OcPlatform.initCheck();\r
725         return OcPlatform.subscribePresence1(\r
726                 host,\r
727                 resourceType,\r
728                 connectivityType.getValue(),\r
729                 onPresenceListener);\r
730     }\r
731 \r
732     private static native OcPresenceHandle subscribePresence1(\r
733             String host,\r
734             String resourceType,\r
735             int connectivityType,\r
736             OnPresenceListener onPresenceListener) throws OcException;\r
737 \r
738     /**\r
739      * Unsubscribes from a previously subscribed server's presence events. Note that you may for\r
740      * a short time still receive events from the server since it may take time for the\r
741      * unsubscribe to take effect.\r
742      *\r
743      * @param ocPresenceHandle the handle object provided by the subscribePresence call that\r
744      *                         identifies this subscription\r
745      * @throws OcException\r
746      */\r
747     public static void unsubscribePresence(\r
748             OcPresenceHandle ocPresenceHandle) throws OcException {\r
749         OcPlatform.initCheck();\r
750         OcPlatform.unsubscribePresence0(ocPresenceHandle);\r
751     }\r
752 \r
753     private static native void unsubscribePresence0(\r
754             OcPresenceHandle ocPresenceHandle) throws OcException;\r
755 \r
756     /**\r
757      * Creates a resource proxy object so that get/put/observe functionality can be used without\r
758      * discovering the object in advance. Note that the consumer of this method needs to provide\r
759      * all of the details required to correctly contact and observe the object. If the consumer\r
760      * lacks any of this information, they should discover the resource object normally.\r
761      * Additionally, you can only create this object if OcPlatform was initialized to be a Client\r
762      * or Client/Server.\r
763      *\r
764      * @param host             a string containing a resolvable host address of the server holding\r
765      *                         the resource\r
766      * @param uri              the rest of the resource's URI that will permit messages to be\r
767      *                         properly routed.\r
768      *                         Example: /a/light\r
769      * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,\r
770      *                         IPV6, ALL\r
771      * @param isObservable     a boolean containing whether the resource supports observation\r
772      * @param resourceTypeList a collection of resource types implemented by the resource\r
773      * @param interfaceList    a collection of interfaces that the resource supports/implements\r
774      * @return new resource object\r
775      * @throws OcException\r
776      */\r
777     public static OcResource constructResourceObject(\r
778             String host,\r
779             String uri,\r
780             OcConnectivityType connectivityType,\r
781             boolean isObservable,\r
782             List<String> resourceTypeList,\r
783             List<String> interfaceList) throws OcException {\r
784         OcPlatform.initCheck();\r
785         return OcPlatform.constructResourceObject0(\r
786                 host,\r
787                 uri,\r
788                 connectivityType.getValue(),\r
789                 isObservable,\r
790                 resourceTypeList.toArray(new String[resourceTypeList.size()]),\r
791                 interfaceList.toArray(new String[interfaceList.size()])\r
792         );\r
793     }\r
794 \r
795     private static native OcResource constructResourceObject0(\r
796             String host,\r
797             String uri,\r
798             int connectivityType,\r
799             boolean isObservable,\r
800             String[] resourceTypes,\r
801             String[] interfaces) throws OcException;\r
802 \r
803     /**\r
804      * Allows application entity handler to send response to an incoming request.\r
805      *\r
806      * @param ocResourceResponse resource response\r
807      * @throws OcException\r
808      */\r
809     public static void sendResponse(OcResourceResponse ocResourceResponse)\r
810             throws OcException {\r
811         OcPlatform.initCheck();\r
812         OcPlatform.sendResponse0(ocResourceResponse);\r
813     }\r
814 \r
815     private static native void sendResponse0(OcResourceResponse ocResourceResponse)\r
816             throws OcException;\r
817 \r
818     /**\r
819      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.\r
820      * Event listeners are notified asynchronously\r
821      */\r
822     public interface OnResourceFoundListener {\r
823         public void onResourceFound(OcResource resource);\r
824     }\r
825 \r
826     /**\r
827      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.\r
828      * Event listeners are notified asynchronously\r
829      */\r
830     public interface OnDeviceFoundListener {\r
831         public void onDeviceFound(OcRepresentation ocRepresentation);\r
832     }
833
834     /**
835      * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
836      * Event listeners are notified asynchronously
837      */
838     public interface OnPlatformFoundListener {
839         public void onPlatformFound(OcRepresentation ocRepresentation);
840     }\r
841 \r
842     /**\r
843      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.\r
844      * Event listeners are notified asynchronously\r
845      */\r
846     public interface OnPresenceListener {\r
847         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);\r
848     }\r
849 \r
850     /**\r
851      * An EntityHandler can be registered via the OcPlatform.registerResource call.\r
852      * Event listeners are notified asynchronously\r
853      */\r
854     public interface EntityHandler {\r
855         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);\r
856     }\r
857 \r
858     private static void initCheck() {\r
859         if (!sIsPlatformInitialized) {\r
860             throw new IllegalStateException("OcPlatform must be configured by making a call to " +\r
861                     "OcPlatform.Configure before any other API calls are permitted");\r
862         }\r
863     }\r
864 }\r