Fix Android SetPropertyValue function call
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcPlatform.java
1 /*
2  *******************************************************************
3  *
4  * Copyright 2015 Intel Corporation.
5  *
6  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base;
24
25 import org.iotivity.ca.CaInterface;
26 import org.iotivity.base.BuildConfig;
27
28 import java.util.EnumSet;
29 import java.util.Iterator;
30 import java.util.List;
31
32 /**
33  * This class contains the main entrance/functionality of the product. To set a custom
34  * configuration, the implementer must make a call to OcPlatform.Configure before the first usage
35  * of a method in this class.
36  */
37 public final class OcPlatform {
38
39     static {
40         System.loadLibrary("oc_logger");
41         System.loadLibrary("octbstack");
42         System.loadLibrary("connectivity_abstraction");
43         System.loadLibrary("oc");
44         if (0 != BuildConfig.SECURED)
45         {
46             System.loadLibrary("ocprovision");
47         }
48         System.loadLibrary("ocstack-jni");
49     }
50
51     /**
52      * Default interface
53      */
54     public static final String DEFAULT_INTERFACE = "oic.if.baseline";
55
56     /**
57      * Used in discovering (GET) links to other resources of a collection
58      */
59     public static final String LINK_INTERFACE = "oic.if.ll";
60
61     /**
62      * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
63      */
64     public static final String BATCH_INTERFACE = "oic.if.b";
65
66     /**
67      * Used in GET, PUT, POST methods on links to other remote resources of a group
68      */
69     public static final String GROUP_INTERFACE = "oic.mi.grp";
70
71     public static final String WELL_KNOWN_QUERY = "/oic/res";
72     public static final String WELL_KNOWN_DEVICE_QUERY = "/oic/d";
73     public static final String WELL_KNOWN_PLATFORM_QUERY = "/oic/p";
74     public static final int DEFAULT_PRESENCE_TTL = 60;
75     public static final String PRESENCE_URI = "/oic/ad";
76
77     private static volatile boolean sIsPlatformInitialized = false;
78     private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
79
80     private OcPlatform() {
81     }
82
83     /**
84      * API for setting the configuration of the OcPlatform.
85      * <p>
86      * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
87      * </p>
88      *
89      * @param platformConfig platform configuration
90      */
91     public synchronized static void Configure(PlatformConfig platformConfig) {
92         if (!sIsPlatformInitialized) {
93             CaInterface.initialize(platformConfig.getActivity(), platformConfig.getContext());
94
95             sPlatformQualityOfService = platformConfig.getQualityOfService();
96
97             OcPlatform.configure(
98                     platformConfig.getServiceType().getValue(),
99                     platformConfig.getModeType().getValue(),
100                     platformConfig.getIpAddress(),
101                     platformConfig.getPort(),
102                     platformConfig.getQualityOfService().getValue(),
103                     platformConfig.getSvrDbPath()
104             );
105
106             sIsPlatformInitialized = true;
107         }
108     }
109
110     private static native void configure(int serviceType,
111                                          int modeType,
112                                          String ipAddress,
113                                          int port,
114                                          int qualityOfService,
115                                          String dbPath);
116
117     /**
118      * API for notifying base that resource's attributes have changed.
119      * <p>
120      * Note: This API is for server side only.
121      * </p>
122      *
123      * @param ocResourceHandle resource handle of the resource
124      * @throws OcException if failure
125      */
126     public static void notifyAllObservers(
127             OcResourceHandle ocResourceHandle) throws OcException {
128         OcPlatform.initCheck();
129         OcPlatform.notifyAllObservers0(ocResourceHandle);
130     }
131
132     private static native void notifyAllObservers0(
133             OcResourceHandle ocResourceHandle) throws OcException;
134
135     /**
136      * API for notifying base that resource's attributes have changed.
137      * <p>
138      * Note: This API is for server side only.
139      * </p>
140      *
141      * @param ocResourceHandle resource handle of the resource
142      * @param qualityOfService the quality of communication
143      * @throws OcException if failure
144      */
145     public static void notifyAllObservers(
146             OcResourceHandle ocResourceHandle,
147             QualityOfService qualityOfService) throws OcException {
148         OcPlatform.initCheck();
149         OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
150     }
151
152     private static native void notifyAllObservers1(
153             OcResourceHandle ocResourceHandle,
154             int qualityOfService) throws OcException;
155
156     /**
157      * API for notifying only specific clients that resource's attributes have changed.
158      * <p>
159      * Note: This API is for server side only.
160      * </p>
161      *
162      * @param ocResourceHandle    resource handle of the resource
163      * @param ocObservationIdList These set of ids are ones which which will be notified upon
164      *                            resource change.
165      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
166      *                            this resource change
167      * @throws OcException if failure
168      */
169     public static void notifyListOfObservers(
170             OcResourceHandle ocResourceHandle,
171             List<Byte> ocObservationIdList,
172             OcResourceResponse ocResourceResponse) throws OcException {
173         OcPlatform.initCheck();
174
175         if (ocObservationIdList == null) {
176             throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null");
177         }
178
179         byte[] idArr = new byte[ocObservationIdList.size()];
180         Iterator<Byte> it = ocObservationIdList.iterator();
181         int i = 0;
182         while (it.hasNext()) {
183             idArr[i++] = (byte) it.next();
184         }
185
186         OcPlatform.notifyListOfObservers2(
187                 ocResourceHandle,
188                 idArr,
189                 ocResourceResponse);
190     }
191
192     private static native void notifyListOfObservers2(
193             OcResourceHandle ocResourceHandle,
194             byte[] ocObservationIdArray,
195             OcResourceResponse ocResourceResponse) throws OcException;
196
197     /**
198      * API for notifying only specific clients that resource's attributes have changed.
199      * <p>
200      * Note: This API is for server side only.
201      * </p>
202      *
203      * @param ocResourceHandle    resource handle of the resource
204      * @param ocObservationIdList These set of ids are ones which which will be notified upon
205      *                            resource change.
206      * @param ocResourceResponse  OcResourceResponse object used by app to fill the response for
207      *                            this resource change
208      * @param qualityOfService    the quality of communication
209      * @throws OcException if failure
210      */
211     public static void notifyListOfObservers(
212             OcResourceHandle ocResourceHandle,
213             List<Byte> ocObservationIdList,
214             OcResourceResponse ocResourceResponse,
215             QualityOfService qualityOfService) throws OcException {
216         OcPlatform.initCheck();
217
218         if (ocObservationIdList == null) {
219             throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null");
220         }
221
222         byte[] idArr = new byte[ocObservationIdList.size()];
223         Iterator<Byte> it = ocObservationIdList.iterator();
224         int i = 0;
225         while (it.hasNext()) {
226             idArr[i++] = (byte) it.next();
227         }
228
229         OcPlatform.notifyListOfObservers3(
230                 ocResourceHandle,
231                 idArr,
232                 ocResourceResponse,
233                 qualityOfService.getValue()
234         );
235     }
236
237     private static native void notifyListOfObservers3(
238             OcResourceHandle ocResourceHandle,
239             byte[] ocObservationIdArray,
240             OcResourceResponse ocResourceResponse,
241             int qualityOfService) throws OcException;
242
243     /**
244      * API for Service and Resource Discovery
245      * <p>
246      * Note: This API is for client side only.
247      * </p>
248      *
249      * @param host                    Host Address of a service to direct resource discovery query.
250      *                                If empty, performs multicast resource discovery query
251      * @param resourceUri             name of the resource. If null or empty, performs search for all
252      *                                resource names
253      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
254      * @param onResourceFoundListener Handles events, success states and failure states.
255      * @throws OcException if failure
256      */
257     public static void findResource(
258             String host,
259             String resourceUri,
260             EnumSet<OcConnectivityType> connectivityTypeSet,
261             OnResourceFoundListener onResourceFoundListener) throws OcException {
262         OcPlatform.initCheck();
263
264         int connTypeInt = 0;
265
266         for (OcConnectivityType connType : OcConnectivityType.values()) {
267             if (connectivityTypeSet.contains(connType))
268                 connTypeInt |= connType.getValue();
269         }
270
271         OcPlatform.findResource0(
272                 host,
273                 resourceUri,
274                 connTypeInt,
275                 onResourceFoundListener
276         );
277     }
278
279     private static native void findResource0(
280             String host,
281             String resourceUri,
282             int connectivityType,
283             OnResourceFoundListener onResourceFoundListener) throws OcException;
284
285     /**
286      * API for Service and Resource Discovery.
287      * <p>
288      * Note: This API is for client side only.
289      * </p>
290      *
291      * @param host                    Host IP Address of a service to direct resource discovery query.
292      *                                If empty, performs multicast resource discovery query
293      * @param resourceUri             name of the resource. If null or empty, performs search for all
294      *                                resource names
295      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
296      * @param onResourceFoundListener Handles events, success states and failure states.
297      * @param qualityOfService        the quality of communication
298      * @throws OcException if failure
299      */
300     public static void findResource(
301             String host,
302             String resourceUri,
303             EnumSet<OcConnectivityType> connectivityTypeSet,
304             OnResourceFoundListener onResourceFoundListener,
305             QualityOfService qualityOfService) throws OcException {
306         OcPlatform.initCheck();
307
308         int connTypeInt = 0;
309
310         for (OcConnectivityType connType : OcConnectivityType.values()) {
311             if (connectivityTypeSet.contains(connType))
312                 connTypeInt |= connType.getValue();
313         }
314
315         OcPlatform.findResource1(host,
316                 resourceUri,
317                 connTypeInt,
318                 onResourceFoundListener,
319                 qualityOfService.getValue()
320         );
321     }
322
323     private static native void findResource1(
324             String host,
325             String resourceUri,
326             int connectivityType,
327             OnResourceFoundListener onResourceFoundListener,
328             int qualityOfService) throws OcException;
329
330     /**
331      * API for Device Discovery
332      *
333      * @param host                  Host IP Address. If null or empty, Multicast is performed.
334      * @param deviceUri             Uri containing address to the virtual device
335      * @param connectivityTypeSet   Set of types of connectivity. Example: IP
336      * @param onDeviceFoundListener Handles events, success states and failure states.
337      * @throws OcException if failure
338      */
339     public static void getDeviceInfo(
340             String host,
341             String deviceUri,
342             EnumSet<OcConnectivityType> connectivityTypeSet,
343             OnDeviceFoundListener onDeviceFoundListener) throws OcException {
344         OcPlatform.initCheck();
345         int connTypeInt = 0;
346
347         for (OcConnectivityType connType : OcConnectivityType.values()) {
348             if (connectivityTypeSet.contains(connType))
349                 connTypeInt |= connType.getValue();
350         }
351         OcPlatform.getDeviceInfo0(
352                 host,
353                 deviceUri,
354                 connTypeInt,
355                 onDeviceFoundListener
356         );
357     }
358
359     private static native void getDeviceInfo0(
360             String host,
361             String deviceUri,
362             int connectivityType,
363             OnDeviceFoundListener onDeviceFoundListener) throws OcException;
364
365     /**
366      * API for Device Discovery
367      *
368      * @param host                  Host IP Address. If null or empty, Multicast is performed.
369      * @param deviceUri             Uri containing address to the virtual device
370      * @param connectivityTypeSet   Set of types of connectivity. Example: IP
371      * @param onDeviceFoundListener Handles events, success states and failure states.
372      * @param qualityOfService      the quality of communication
373      * @throws OcException if failure
374      */
375     public static void getDeviceInfo(
376             String host,
377             String deviceUri,
378             EnumSet<OcConnectivityType> connectivityTypeSet,
379             OnDeviceFoundListener onDeviceFoundListener,
380             QualityOfService qualityOfService) throws OcException {
381         OcPlatform.initCheck();
382         int connTypeInt = 0;
383
384         for (OcConnectivityType connType : OcConnectivityType.values()) {
385             if (connectivityTypeSet.contains(connType))
386                 connTypeInt |= connType.getValue();
387         }
388         OcPlatform.getDeviceInfo1(
389                 host,
390                 deviceUri,
391                 connTypeInt,
392                 onDeviceFoundListener,
393                 qualityOfService.getValue()
394         );
395     }
396
397     private static native void getDeviceInfo1(
398             String host,
399             String deviceUri,
400             int connectivityType,
401             OnDeviceFoundListener onDeviceFoundListener,
402             int qualityOfService) throws OcException;
403
404     /**
405      * API for Platform Discovery
406      *
407      * @param host                    Host IP Address. If null or empty, Multicast is performed.
408      * @param platformUri             Uri containing address to the platform
409      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
410      * @param onPlatformFoundListener Handles events, success states and failure states.
411      * @throws OcException if failure
412      */
413
414     public static void getPlatformInfo(
415             String host,
416             String platformUri,
417             EnumSet<OcConnectivityType> connectivityTypeSet,
418             OnPlatformFoundListener onPlatformFoundListener) throws OcException {
419         OcPlatform.initCheck();
420         int connTypeInt = 0;
421
422         for (OcConnectivityType connType : OcConnectivityType.values()) {
423             if (connectivityTypeSet.contains(connType))
424                 connTypeInt |= connType.getValue();
425         }
426         OcPlatform.getPlatformInfo0(
427                 host,
428                 platformUri,
429                 connTypeInt,
430                 onPlatformFoundListener
431         );
432     }
433
434     private static native void getPlatformInfo0(
435             String host,
436             String platformUri,
437             int connectivityType,
438             OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
439
440     /**
441      * API for Platform Discovery
442      *
443      * @param host                    Host IP Address. If null or empty, Multicast is performed.
444      * @param platformUri             Uri containing address to the platform
445      * @param connectivityTypeSet     Set of types of connectivity. Example: IP
446      * @param onPlatformFoundListener Handles events, success states and failure states.
447      * @param qualityOfService        the quality of communication
448      * @throws OcException if failure
449      */
450
451     public static void getPlatformInfo(
452             String host,
453             String platformUri,
454             EnumSet<OcConnectivityType> connectivityTypeSet,
455             OnPlatformFoundListener onPlatformFoundListener,
456             QualityOfService qualityOfService) throws OcException {
457         OcPlatform.initCheck();
458         int connTypeInt = 0;
459
460         for (OcConnectivityType connType : OcConnectivityType.values()) {
461             if (connectivityTypeSet.contains(connType))
462                 connTypeInt |= connType.getValue();
463         }
464         OcPlatform.getPlatformInfo1(
465                 host,
466                 platformUri,
467                 connTypeInt,
468                 onPlatformFoundListener,
469                 qualityOfService.getValue()
470         );
471     }
472
473     private static native void getPlatformInfo1(
474             String host,
475             String platformUri,
476             int connectivityType,
477             OnPlatformFoundListener onPlatformFoundListener,
478             int qualityOfService) throws OcException;
479
480     /**
481      * This API registers a resource with the server
482      * <p/>
483      * Note: This API applies to server & client side.
484      * </P>
485      *
486      * @param ocResource The instance of OcResource with all data filled
487      * @return resource handle
488      * @throws OcException if failure
489      */
490     public static OcResourceHandle registerResource(
491             OcResource ocResource) throws OcException {
492         OcPlatform.initCheck();
493         return OcPlatform.registerResource0(ocResource);
494     }
495
496     private static native OcResourceHandle registerResource0(
497             OcResource ocResource) throws OcException;
498
499     /**
500      * This API registers a resource with the server NOTE: This API applies to server side only.
501      * <p/>
502      * Note: This API applies to server side only.
503      * </P>
504      *
505      * @param resourceUri         The URI of the resource. Example: "a/light"
506      * @param resourceTypeName    The resource type. Example: "light"
507      * @param resourceInterface   The resource interface (whether it is collection etc).
508      * @param entityHandler       entity handler.
509      * @param resourcePropertySet indicates the property of the resource
510      * @return resource handle
511      * @throws OcException if failure
512      */
513     public static OcResourceHandle registerResource(
514             String resourceUri,
515             String resourceTypeName,
516             String resourceInterface,
517             EntityHandler entityHandler,
518             EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
519         OcPlatform.initCheck();
520
521         int resProperty = 0;
522
523         for (ResourceProperty prop : ResourceProperty.values()) {
524             if (resourcePropertySet.contains(prop))
525                 resProperty |= prop.getValue();
526         }
527
528         return OcPlatform.registerResource1(resourceUri,
529                 resourceTypeName,
530                 resourceInterface,
531                 entityHandler,
532                 resProperty);
533     }
534
535     private static native OcResourceHandle registerResource1(
536             String resourceUri,
537             String resourceTypeName,
538             String resourceInterface,
539             EntityHandler entityHandler,
540             int resourceProperty) throws OcException;
541
542     /**
543      * Register Device Info
544      *
545      * @param ocDeviceInfo object containing all the device specific information
546      * @throws OcException if failure
547      */
548     public static void registerDeviceInfo(
549             OcDeviceInfo ocDeviceInfo) throws OcException {
550         OcPlatform.initCheck();
551         OcPlatform.registerDeviceInfo0(
552                 ocDeviceInfo.getDeviceName(),
553                 ocDeviceInfo.getDeviceTypes().toArray(
554                         new String[ocDeviceInfo.getDeviceTypes().size()]
555                 )
556         );
557     }
558
559     private static native void registerDeviceInfo0(
560             String deviceName,
561             String[] deviceTypes
562     ) throws OcException;
563
564     /**
565      * Set param Info
566      *
567      * @param ocDeviceInfo object containing all the device specific information
568      * @throws OcException if failure
569      */
570     public static void setPropertyValue(
571             int path, String propName, String propValue) throws OcException {
572         OcPlatform.initCheck();
573         OcPlatform.setPropertyValue1(path, propName, propValue);
574     }
575
576     public static void setPropertyValue(
577             int path, String propName, List<String> propValue) throws OcException {
578         OcPlatform.initCheck();
579         OcPlatform.setPropertyValue0(path, propName, propValue.toArray(new String[propValue.size()]));
580     }
581
582     public static void getPropertyValue(
583             int path, String propName, String propValue) throws OcException {
584         OcPlatform.initCheck();
585         OcPlatform.getPropertyValue0(path, propName, propValue);
586     }
587
588     private static native void setPropertyValue1(
589             int path,
590             String propName,
591             String propValue
592     ) throws OcException;
593
594
595     private static native void setPropertyValue0(
596             int path,
597             String propName,
598             String[] propValue
599     ) throws OcException;
600
601     private static native void getPropertyValue0(
602             int path,
603             String propName,
604             String propValue
605     ) throws OcException;
606
607     /**
608      * Register Platform Info
609      *
610      * @param ocPlatformInfo object containing all the platform specific information
611      * @throws OcException if failure
612      */
613     public static void registerPlatformInfo(
614             OcPlatformInfo ocPlatformInfo) throws OcException {
615         OcPlatform.initCheck();
616         OcPlatform.registerPlatformInfo0(
617                 ocPlatformInfo.getPlatformId(),
618                 ocPlatformInfo.getManufacturerName(),
619                 ocPlatformInfo.getManufacturerUrl(),
620                 ocPlatformInfo.getModelNumber(),
621                 ocPlatformInfo.getDateOfManufacture(),
622                 ocPlatformInfo.getPlatformVersion(),
623                 ocPlatformInfo.getOperatingSystemVersion(),
624                 ocPlatformInfo.getHardwareVersion(),
625                 ocPlatformInfo.getFirmwareVersion(),
626                 ocPlatformInfo.getSupportUrl(),
627                 ocPlatformInfo.getSystemTime()
628         );
629     }
630
631     private static native void registerPlatformInfo0(
632             String platformId, String manufacturerName, String manufacturerUrl,
633             String modelNumber, String dateOfManufacture, String platformVersion,
634             String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
635             String supportUrl, String systemTime
636     ) throws OcException;
637
638     /**
639      * This API unregisters a resource with the server NOTE: This API applies to server side only.
640      *
641      * @param ocResourceHandle This is the resource handle which we which to unregister from the
642      *                         server
643      * @throws OcException if failure
644      */
645     public static void unregisterResource(
646             OcResourceHandle ocResourceHandle) throws OcException {
647         OcPlatform.initCheck();
648         OcPlatform.unregisterResource0(ocResourceHandle);
649     }
650
651     private static native void unregisterResource0(
652             OcResourceHandle ocResourceHandle) throws OcException;
653
654
655     /**
656      * Add a resource to a collection resource
657      *
658      * @param ocResourceCollectionHandle handle to the collection resource
659      * @param ocResourceHandle           handle to resource to be added to the collection resource
660      * @throws OcException if failure
661      */
662     public static void bindResource(
663             OcResourceHandle ocResourceCollectionHandle,
664             OcResourceHandle ocResourceHandle) throws OcException {
665         OcPlatform.initCheck();
666         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
667     }
668
669     private static native void bindResource0(
670             OcResourceHandle ocResourceCollectionHandle,
671             OcResourceHandle ocResourceHandle) throws OcException;
672
673     /**
674      * Add multiple resources to a collection resource.
675      *
676      * @param ocResourceCollectionHandle handle to the collection resource
677      * @param ocResourceHandleList       reference to list of resource handles to be added to the
678      *                                   collection resource
679      * @throws OcException if failure
680      */
681     public static void bindResources(
682             OcResourceHandle ocResourceCollectionHandle,
683             List<OcResourceHandle> ocResourceHandleList) throws OcException {
684         OcPlatform.initCheck();
685
686         if (ocResourceHandleList == null) {
687             throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
688         }
689
690         OcPlatform.bindResources0(
691                 ocResourceCollectionHandle,
692                 ocResourceHandleList.toArray(
693                         new OcResourceHandle[ocResourceHandleList.size()])
694         );
695     }
696
697     private static native void bindResources0(
698             OcResourceHandle ocResourceCollectionHandle,
699             OcResourceHandle[] ocResourceHandleArray) throws OcException;
700
701     /**
702      * Unbind a resource from a collection resource.
703      *
704      * @param ocResourceCollectionHandle handle to the collection resource
705      * @param ocResourceHandle           resource handle to be unbound from the collection resource
706      * @throws OcException if failure
707      */
708     public static void unbindResource(
709             OcResourceHandle ocResourceCollectionHandle,
710             OcResourceHandle ocResourceHandle) throws OcException {
711         OcPlatform.initCheck();
712         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
713     }
714
715     private static native void unbindResource0(
716             OcResourceHandle ocResourceCollectionHandle,
717             OcResourceHandle ocResourceHandle) throws OcException;
718
719     /**
720      * Unbind resources from a collection resource.
721      *
722      * @param ocResourceCollectionHandle Handle to the collection resource
723      * @param ocResourceHandleList       List of resource handles to be unbound from the collection
724      *                                   resource
725      * @throws OcException if failure
726      */
727     public static void unbindResources(
728             OcResourceHandle ocResourceCollectionHandle,
729             List<OcResourceHandle> ocResourceHandleList) throws OcException {
730         OcPlatform.initCheck();
731
732         if (ocResourceHandleList == null) {
733             throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
734         }
735
736         OcPlatform.unbindResources0(
737                 ocResourceCollectionHandle,
738                 ocResourceHandleList.toArray(
739                         new OcResourceHandle[ocResourceHandleList.size()])
740         );
741     }
742
743     private static native void unbindResources0(
744             OcResourceHandle ocResourceCollectionHandle,
745             OcResourceHandle[] ocResourceHandleArray) throws OcException;
746
747     /**
748      * Binds a type to a particular resource
749      *
750      * @param ocResourceHandle handle to the resource
751      * @param resourceTypeName new typename to bind to the resource
752      * @throws OcException if failure
753      */
754     public static void bindTypeToResource(
755             OcResourceHandle ocResourceHandle,
756             String resourceTypeName) throws OcException {
757         OcPlatform.initCheck();
758         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
759     }
760
761     private static native void bindTypeToResource0(
762             OcResourceHandle ocResourceHandle,
763             String resourceTypeName) throws OcException;
764
765     /**
766      * Binds an interface to a particular resource
767      *
768      * @param ocResourceHandle      handle to the resource
769      * @param resourceInterfaceName new interface to bind to the resource
770      * @throws OcException if failure
771      */
772     public static void bindInterfaceToResource(
773             OcResourceHandle ocResourceHandle,
774             String resourceInterfaceName) throws OcException {
775         OcPlatform.initCheck();
776         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
777     }
778
779     private static native void bindInterfaceToResource0(
780             OcResourceHandle ocResourceHandle,
781             String resourceInterfaceName) throws OcException;
782
783     /**
784      * Start Presence announcements.
785      *
786      * @param ttl time to live in seconds
787      * @throws OcException if failure
788      */
789     public static void startPresence(int ttl) throws OcException {
790         OcPlatform.initCheck();
791         OcPlatform.startPresence0(ttl);
792     }
793
794     private static native void startPresence0(int ttl) throws OcException;
795
796     /**
797      * Stop Presence announcements.
798      *
799      * @throws OcException if failure
800      */
801     public static void stopPresence() throws OcException {
802         OcPlatform.initCheck();
803         OcPlatform.stopPresence0();
804     }
805
806     private static native void stopPresence0() throws OcException;
807
808     /**
809      * Subscribes to a server's presence change events. By making this subscription, every time a
810      * server adds/removes/alters a resource, starts or is intentionally stopped
811      *
812      * @param host                The IP address/addressable name of the server to subscribe to
813      * @param connectivityTypeSet Set of types of connectivity. Example: IP
814      * @param onPresenceListener  listener that will receive notifications/subscription events
815      * @return a handle object that can be used to identify this subscription request. It can be
816      * used to unsubscribe from these events in the future
817      * @throws OcException if failure
818      */
819     public static OcPresenceHandle subscribePresence(
820             String host,
821             EnumSet<OcConnectivityType> connectivityTypeSet,
822             OnPresenceListener onPresenceListener) throws OcException {
823         OcPlatform.initCheck();
824         int connTypeInt = 0;
825
826         for (OcConnectivityType connType : OcConnectivityType.values()) {
827             if (connectivityTypeSet.contains(connType))
828                 connTypeInt |= connType.getValue();
829         }
830         return OcPlatform.subscribePresence0(
831                 host,
832                 connTypeInt,
833                 onPresenceListener
834         );
835     }
836
837     private static native OcPresenceHandle subscribePresence0(
838             String host,
839             int connectivityType,
840             OnPresenceListener onPresenceListener) throws OcException;
841
842     /**
843      * Subscribes to a server's presence change events. By making this subscription, every time a
844      * server adds/removes/alters a resource, starts or is intentionally stopped
845      *
846      * @param host                The IP address/addressable name of the server to subscribe to
847      * @param resourceType        a resource type specified as a filter for subscription events.
848      * @param connectivityTypeSet Set of types of connectivity. Example: IP
849      * @param onPresenceListener  listener that will receive notifications/subscription events
850      * @return a handle object that can be used to identify this subscription request. It can be
851      * used to unsubscribe from these events in the future
852      * @throws OcException if failure
853      */
854     public static OcPresenceHandle subscribePresence(
855             String host,
856             String resourceType,
857             EnumSet<OcConnectivityType> connectivityTypeSet,
858             OnPresenceListener onPresenceListener) throws OcException {
859         OcPlatform.initCheck();
860         int connTypeInt = 0;
861
862         for (OcConnectivityType connType : OcConnectivityType.values()) {
863             if (connectivityTypeSet.contains(connType))
864                 connTypeInt |= connType.getValue();
865         }
866         return OcPlatform.subscribePresence1(
867                 host,
868                 resourceType,
869                 connTypeInt,
870                 onPresenceListener);
871     }
872
873     private static native OcPresenceHandle subscribePresence1(
874             String host,
875             String resourceType,
876             int connectivityType,
877             OnPresenceListener onPresenceListener) throws OcException;
878
879     /**
880      * Unsubscribes from a previously subscribed server's presence events. Note that you may for
881      * a short time still receive events from the server since it may take time for the
882      * unsubscribe to take effect.
883      *
884      * @param ocPresenceHandle the handle object provided by the subscribePresence call that
885      *                         identifies this subscription
886      * @throws OcException if failure
887      */
888     public static void unsubscribePresence(
889             OcPresenceHandle ocPresenceHandle) throws OcException {
890         OcPlatform.initCheck();
891         OcPlatform.unsubscribePresence0(ocPresenceHandle);
892     }
893
894     private static native void unsubscribePresence0(
895             OcPresenceHandle ocPresenceHandle) throws OcException;
896
897     /**
898      * Subscribes to a server's device presence change events.
899      *
900      * @param host                The IP address/addressable name of the server to subscribe to.
901      * @param di                  Vector which can have the devices id.
902      * @param connectivityTypeSet Set of connectivity types, e.g. IP.
903      * @param onObserveListener   The handler method will be invoked with a map
904      *                            of attribute name and values.
905      * @return a handle object that can be used to identify this subscription request.
906      *         It can be used to unsubscribe from these events in the future.
907      * @throws OcException if failure.
908      */
909     public static OcPresenceHandle subscribeDevicePresence(
910             String host,
911             List<String> di,
912             EnumSet<OcConnectivityType> connectivityTypeSet,
913             OcResource.OnObserveListener onObserveListener) throws OcException {
914         OcPlatform.initCheck();
915         int connTypeInt = 0;
916
917         for (OcConnectivityType connType : OcConnectivityType.values()) {
918             if (connectivityTypeSet.contains(connType))
919                 connTypeInt |= connType.getValue();
920         }
921         return OcPlatform.subscribeDevicePresence0(
922                 host,
923                 di.toArray(new String[di.size()]),
924                 connTypeInt,
925                 onObserveListener);
926     }
927
928     private static native OcPresenceHandle subscribeDevicePresence0(
929             String host,
930             String[] di,
931             int connectivityType,
932             OcResource.OnObserveListener onObserveListener) throws OcException;
933
934     /**
935      * Creates a resource proxy object so that get/put/observe functionality can be used without
936      * discovering the object in advance. Note that the consumer of this method needs to provide
937      * all of the details required to correctly contact and observe the object. If the consumer
938      * lacks any of this information, they should discover the resource object normally.
939      * Additionally, you can only create this object if OcPlatform was initialized to be a Client
940      * or Client/Server.
941      *
942      * @param host                a string containing a resolvable host address of the server holding
943      *                            the resource
944      * @param uri                 the rest of the resource's URI that will permit messages to be
945      *                            properly routed.
946      *                            Example: /a/light
947      * @param connectivityTypeSet Set of types of connectivity. Example: IP
948      * @param isObservable        a boolean containing whether the resource supports observation
949      * @param resourceTypeList    a collection of resource types implemented by the resource
950      * @param interfaceList       a collection of interfaces that the resource supports/implements
951      * @return new resource object
952      * @throws OcException if failure
953      */
954     public static OcResource constructResourceObject(
955             String host,
956             String uri,
957             EnumSet<OcConnectivityType> connectivityTypeSet,
958             boolean isObservable,
959             List<String> resourceTypeList,
960             List<String> interfaceList) throws OcException {
961         OcPlatform.initCheck();
962         int connTypeInt = 0;
963
964         for (OcConnectivityType connType : OcConnectivityType.values()) {
965             if (connectivityTypeSet.contains(connType))
966                 connTypeInt |= connType.getValue();
967         }
968         return OcPlatform.constructResourceObject0(
969                 host,
970                 uri,
971                 connTypeInt,
972                 isObservable,
973                 resourceTypeList.toArray(new String[resourceTypeList.size()]),
974                 interfaceList.toArray(new String[interfaceList.size()])
975         );
976     }
977
978     private static native OcResource constructResourceObject0(
979             String host,
980             String uri,
981             int connectivityType,
982             boolean isObservable,
983             String[] resourceTypes,
984             String[] interfaces) throws OcException;
985
986     /**
987      * Allows application entity handler to send response to an incoming request.
988      *
989      * @param ocResourceResponse resource response
990      * @throws OcException if failure
991      */
992     public static void sendResponse(OcResourceResponse ocResourceResponse)
993             throws OcException {
994         OcPlatform.initCheck();
995         OcPlatform.sendResponse0(ocResourceResponse);
996     }
997
998     private static native void sendResponse0(OcResourceResponse ocResourceResponse)
999             throws OcException;
1000
1001     /**
1002      *  Method to find all devices which are eligible for direct pairing and return the list.
1003      *
1004      *  @param timeout timeout for discovering direct pair devices.
1005      *  @param FindDirectPairingListener Callback function, which will receive the list of direct
1006      *                                  pairable devices.
1007      *  @throws OcException
1008      */
1009    public static native void findDirectPairingDevices(int timeout,
1010             FindDirectPairingListener onFindDirectPairingListener) throws OcException;
1011
1012     /**
1013      *  Method to get list of all paired devices for a given device.
1014      *
1015      *  @param GetDirectPairedListener Callback function, which will receive the list of direct
1016      *                                 paired devices.
1017      *  @throws OcException
1018      */
1019     public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
1020         throws OcException;
1021
1022     /**
1023      *  Method to perform direct pairing between two devices.
1024      *
1025      *  @param peer  Target peer
1026      *  @param prmType Pairing Method to be used for Pairing
1027      *  @param pin pin
1028      *  @param DirectPairingListener Callback function, which will be called after
1029      *                                      completion of direct pairing.
1030      *  @throws OcException
1031      */
1032     public static void doDirectPairing(
1033             OcDirectPairDevice peer,
1034             OcPrmType prmType,
1035             String pin,
1036             DirectPairingListener onDirectPairingListener) throws OcException {
1037
1038         OcPlatform.doDirectPairing0(
1039                 peer,
1040                 prmType.getValue(),
1041                 pin,
1042                 onDirectPairingListener
1043                 );
1044     }
1045
1046     private static native void doDirectPairing0(OcDirectPairDevice peer,
1047             int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
1048     throws OcException;
1049
1050     /**
1051      * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
1052      * Event listeners are notified asynchronously
1053      */
1054     public interface FindDirectPairingListener {
1055         public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
1056     }
1057
1058     /**
1059      * Listerner to Get List of already Direct Paired devices.
1060      * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
1061      * Event listeners are notified asynchronously
1062      */
1063     public interface GetDirectPairedListener {
1064         public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
1065     }
1066
1067     /**
1068      * Listner to get result of doDirectPairing.
1069      * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
1070      * Event listeners are notified asynchronously
1071      */
1072     public interface DirectPairingListener {
1073         public void onDirectPairingListener(String devId, int result);
1074     }
1075
1076     /**
1077      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
1078      * Event listeners are notified asynchronously
1079      */
1080     public interface OnResourceFoundListener {
1081         public void onResourceFound(OcResource resource);
1082         public void onFindResourceFailed(Throwable ex, String uri);
1083     }
1084
1085     /**
1086      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
1087      * Event listeners are notified asynchronously
1088      */
1089     public interface OnDeviceFoundListener {
1090         public void onDeviceFound(OcRepresentation ocRepresentation);
1091     }
1092
1093     /**
1094      * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
1095      * Event listeners are notified asynchronously
1096      */
1097     public interface OnPlatformFoundListener {
1098         public void onPlatformFound(OcRepresentation ocRepresentation);
1099     }
1100
1101     /**
1102      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
1103      * Event listeners are notified asynchronously
1104      */
1105     public interface OnPresenceListener {
1106         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
1107     }
1108
1109     /**
1110      * An EntityHandler can be registered via the OcPlatform.registerResource call.
1111      * Event listeners are notified asynchronously
1112      *
1113      * @note entityhandler callback :
1114      * When you set specific return value like EntityHandlerResult.OK, SLOW
1115      * and etc in entity handler callback,
1116      * ocstack will be not send response automatically to client
1117      * except for error return value like EntityHandlerResult.ERROR
1118      * If you want to send response to client with specific result,
1119      * sendResponse API should be called with the result value.
1120      */
1121     public interface EntityHandler {
1122         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
1123     }
1124
1125     private static void initCheck() {
1126         if (!sIsPlatformInitialized) {
1127             throw new IllegalStateException("OcPlatform must be configured by making a call to " +
1128                     "OcPlatform.Configure before any other API calls are permitted");
1129         }
1130     }
1131
1132     /**
1133      * Gets platform quality of service
1134      *
1135      * @return quality of service
1136      */
1137     public static QualityOfService getPlatformQualityOfService() {
1138         OcPlatform.initCheck();
1139         return sPlatformQualityOfService;
1140     }
1141
1142     /**
1143      * Create an account manager object that can be used for doing request to account server.
1144      * You can only create this object if OCPlatform was initialized to be a Client or
1145      * Client/Server. Otherwise, this will return an empty shared ptr.
1146      *
1147      * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
1148      *       methods of this object to work since device id is not generated on Client mode.
1149      *
1150      * @param host                Host IP Address of a account server.
1151      * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP
1152      * @return new AccountManager object
1153      * @throws OcException if failure
1154      */
1155     public static OcAccountManager constructAccountManagerObject(
1156             String host,
1157             EnumSet<OcConnectivityType> connectivityTypeSet) throws OcException {
1158         OcPlatform.initCheck();
1159         int connTypeInt = 0;
1160
1161         for (OcConnectivityType connType : OcConnectivityType.values()) {
1162             if (connectivityTypeSet.contains(connType))
1163             {
1164                 connTypeInt |= connType.getValue();
1165             }
1166         }
1167         return OcPlatform.constructAccountManagerObject0(
1168                 host,
1169                 connTypeInt
1170                 );
1171     }
1172
1173     private static native OcAccountManager constructAccountManagerObject0(
1174             String host,
1175             int connectivityType) throws OcException;
1176     /**
1177      * Method to get device Id in byte array.
1178      * @return My DeviceId.
1179      */
1180     public static native byte[] getDeviceId();
1181
1182     /**
1183      * Method to set DeviceId.
1184      */
1185     public static native void setDeviceId(byte[] deviceId) throws OcException;
1186 }