Throw OcException for invalid (null) parameters in Java Layer of android_api.
[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      * Register Platform Info
566      *
567      * @param ocPlatformInfo object containing all the platform specific information
568      * @throws OcException if failure
569      */
570     public static void registerPlatformInfo(
571             OcPlatformInfo ocPlatformInfo) throws OcException {
572         OcPlatform.initCheck();
573         OcPlatform.registerPlatformInfo0(
574                 ocPlatformInfo.getPlatformId(),
575                 ocPlatformInfo.getManufacturerName(),
576                 ocPlatformInfo.getManufacturerUrl(),
577                 ocPlatformInfo.getModelNumber(),
578                 ocPlatformInfo.getDateOfManufacture(),
579                 ocPlatformInfo.getPlatformVersion(),
580                 ocPlatformInfo.getOperatingSystemVersion(),
581                 ocPlatformInfo.getHardwareVersion(),
582                 ocPlatformInfo.getFirmwareVersion(),
583                 ocPlatformInfo.getSupportUrl(),
584                 ocPlatformInfo.getSystemTime()
585         );
586     }
587
588     private static native void registerPlatformInfo0(
589             String platformId, String manufacturerName, String manufacturerUrl,
590             String modelNumber, String dateOfManufacture, String platformVersion,
591             String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
592             String supportUrl, String systemTime
593     ) throws OcException;
594
595     /**
596      * This API unregisters a resource with the server NOTE: This API applies to server side only.
597      *
598      * @param ocResourceHandle This is the resource handle which we which to unregister from the
599      *                         server
600      * @throws OcException if failure
601      */
602     public static void unregisterResource(
603             OcResourceHandle ocResourceHandle) throws OcException {
604         OcPlatform.initCheck();
605         OcPlatform.unregisterResource0(ocResourceHandle);
606     }
607
608     private static native void unregisterResource0(
609             OcResourceHandle ocResourceHandle) throws OcException;
610
611
612     /**
613      * Add a resource to a collection resource
614      *
615      * @param ocResourceCollectionHandle handle to the collection resource
616      * @param ocResourceHandle           handle to resource to be added to the collection resource
617      * @throws OcException if failure
618      */
619     public static void bindResource(
620             OcResourceHandle ocResourceCollectionHandle,
621             OcResourceHandle ocResourceHandle) throws OcException {
622         OcPlatform.initCheck();
623         OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
624     }
625
626     private static native void bindResource0(
627             OcResourceHandle ocResourceCollectionHandle,
628             OcResourceHandle ocResourceHandle) throws OcException;
629
630     /**
631      * Add multiple resources to a collection resource.
632      *
633      * @param ocResourceCollectionHandle handle to the collection resource
634      * @param ocResourceHandleList       reference to list of resource handles to be added to the
635      *                                   collection resource
636      * @throws OcException if failure
637      */
638     public static void bindResources(
639             OcResourceHandle ocResourceCollectionHandle,
640             List<OcResourceHandle> ocResourceHandleList) throws OcException {
641         OcPlatform.initCheck();
642
643         if (ocResourceHandleList == null) {
644             throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
645         }
646
647         OcPlatform.bindResources0(
648                 ocResourceCollectionHandle,
649                 ocResourceHandleList.toArray(
650                         new OcResourceHandle[ocResourceHandleList.size()])
651         );
652     }
653
654     private static native void bindResources0(
655             OcResourceHandle ocResourceCollectionHandle,
656             OcResourceHandle[] ocResourceHandleArray) throws OcException;
657
658     /**
659      * Unbind a resource from a collection resource.
660      *
661      * @param ocResourceCollectionHandle handle to the collection resource
662      * @param ocResourceHandle           resource handle to be unbound from the collection resource
663      * @throws OcException if failure
664      */
665     public static void unbindResource(
666             OcResourceHandle ocResourceCollectionHandle,
667             OcResourceHandle ocResourceHandle) throws OcException {
668         OcPlatform.initCheck();
669         OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
670     }
671
672     private static native void unbindResource0(
673             OcResourceHandle ocResourceCollectionHandle,
674             OcResourceHandle ocResourceHandle) throws OcException;
675
676     /**
677      * Unbind resources from a collection resource.
678      *
679      * @param ocResourceCollectionHandle Handle to the collection resource
680      * @param ocResourceHandleList       List of resource handles to be unbound from the collection
681      *                                   resource
682      * @throws OcException if failure
683      */
684     public static void unbindResources(
685             OcResourceHandle ocResourceCollectionHandle,
686             List<OcResourceHandle> ocResourceHandleList) throws OcException {
687         OcPlatform.initCheck();
688
689         if (ocResourceHandleList == null) {
690             throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null");
691         }
692
693         OcPlatform.unbindResources0(
694                 ocResourceCollectionHandle,
695                 ocResourceHandleList.toArray(
696                         new OcResourceHandle[ocResourceHandleList.size()])
697         );
698     }
699
700     private static native void unbindResources0(
701             OcResourceHandle ocResourceCollectionHandle,
702             OcResourceHandle[] ocResourceHandleArray) throws OcException;
703
704     /**
705      * Binds a type to a particular resource
706      *
707      * @param ocResourceHandle handle to the resource
708      * @param resourceTypeName new typename to bind to the resource
709      * @throws OcException if failure
710      */
711     public static void bindTypeToResource(
712             OcResourceHandle ocResourceHandle,
713             String resourceTypeName) throws OcException {
714         OcPlatform.initCheck();
715         OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
716     }
717
718     private static native void bindTypeToResource0(
719             OcResourceHandle ocResourceHandle,
720             String resourceTypeName) throws OcException;
721
722     /**
723      * Binds an interface to a particular resource
724      *
725      * @param ocResourceHandle      handle to the resource
726      * @param resourceInterfaceName new interface to bind to the resource
727      * @throws OcException if failure
728      */
729     public static void bindInterfaceToResource(
730             OcResourceHandle ocResourceHandle,
731             String resourceInterfaceName) throws OcException {
732         OcPlatform.initCheck();
733         OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
734     }
735
736     private static native void bindInterfaceToResource0(
737             OcResourceHandle ocResourceHandle,
738             String resourceInterfaceName) throws OcException;
739
740     /**
741      * Start Presence announcements.
742      *
743      * @param ttl time to live in seconds
744      * @throws OcException if failure
745      */
746     public static void startPresence(int ttl) throws OcException {
747         OcPlatform.initCheck();
748         OcPlatform.startPresence0(ttl);
749     }
750
751     private static native void startPresence0(int ttl) throws OcException;
752
753     /**
754      * Stop Presence announcements.
755      *
756      * @throws OcException if failure
757      */
758     public static void stopPresence() throws OcException {
759         OcPlatform.initCheck();
760         OcPlatform.stopPresence0();
761     }
762
763     private static native void stopPresence0() throws OcException;
764
765     /**
766      * Subscribes to a server's presence change events. By making this subscription, every time a
767      * server adds/removes/alters a resource, starts or is intentionally stopped
768      *
769      * @param host                The IP address/addressable name of the server to subscribe to
770      * @param connectivityTypeSet Set of types of connectivity. Example: IP
771      * @param onPresenceListener  listener that will receive notifications/subscription events
772      * @return a handle object that can be used to identify this subscription request. It can be
773      * used to unsubscribe from these events in the future
774      * @throws OcException if failure
775      */
776     public static OcPresenceHandle subscribePresence(
777             String host,
778             EnumSet<OcConnectivityType> connectivityTypeSet,
779             OnPresenceListener onPresenceListener) throws OcException {
780         OcPlatform.initCheck();
781         int connTypeInt = 0;
782
783         for (OcConnectivityType connType : OcConnectivityType.values()) {
784             if (connectivityTypeSet.contains(connType))
785                 connTypeInt |= connType.getValue();
786         }
787         return OcPlatform.subscribePresence0(
788                 host,
789                 connTypeInt,
790                 onPresenceListener
791         );
792     }
793
794     private static native OcPresenceHandle subscribePresence0(
795             String host,
796             int connectivityType,
797             OnPresenceListener onPresenceListener) throws OcException;
798
799     /**
800      * Subscribes to a server's presence change events. By making this subscription, every time a
801      * server adds/removes/alters a resource, starts or is intentionally stopped
802      *
803      * @param host                The IP address/addressable name of the server to subscribe to
804      * @param resourceType        a resource type specified as a filter for subscription events.
805      * @param connectivityTypeSet Set of types of connectivity. Example: IP
806      * @param onPresenceListener  listener that will receive notifications/subscription events
807      * @return a handle object that can be used to identify this subscription request. It can be
808      * used to unsubscribe from these events in the future
809      * @throws OcException if failure
810      */
811     public static OcPresenceHandle subscribePresence(
812             String host,
813             String resourceType,
814             EnumSet<OcConnectivityType> connectivityTypeSet,
815             OnPresenceListener onPresenceListener) throws OcException {
816         OcPlatform.initCheck();
817         int connTypeInt = 0;
818
819         for (OcConnectivityType connType : OcConnectivityType.values()) {
820             if (connectivityTypeSet.contains(connType))
821                 connTypeInt |= connType.getValue();
822         }
823         return OcPlatform.subscribePresence1(
824                 host,
825                 resourceType,
826                 connTypeInt,
827                 onPresenceListener);
828     }
829
830     private static native OcPresenceHandle subscribePresence1(
831             String host,
832             String resourceType,
833             int connectivityType,
834             OnPresenceListener onPresenceListener) throws OcException;
835
836     /**
837      * Unsubscribes from a previously subscribed server's presence events. Note that you may for
838      * a short time still receive events from the server since it may take time for the
839      * unsubscribe to take effect.
840      *
841      * @param ocPresenceHandle the handle object provided by the subscribePresence call that
842      *                         identifies this subscription
843      * @throws OcException if failure
844      */
845     public static void unsubscribePresence(
846             OcPresenceHandle ocPresenceHandle) throws OcException {
847         OcPlatform.initCheck();
848         OcPlatform.unsubscribePresence0(ocPresenceHandle);
849     }
850
851     private static native void unsubscribePresence0(
852             OcPresenceHandle ocPresenceHandle) throws OcException;
853
854     /**
855      * Subscribes to a server's device presence change events.
856      *
857      * @param host                The IP address/addressable name of the server to subscribe to.
858      * @param di                  Vector which can have the devices id.
859      * @param connectivityTypeSet Set of connectivity types, e.g. IP.
860      * @param onObserveListener   The handler method will be invoked with a map
861      *                            of attribute name and values.
862      * @return a handle object that can be used to identify this subscription request.
863      *         It can be used to unsubscribe from these events in the future.
864      * @throws OcException if failure.
865      */
866     public static OcPresenceHandle subscribeDevicePresence(
867             String host,
868             List<String> di,
869             EnumSet<OcConnectivityType> connectivityTypeSet,
870             OcResource.OnObserveListener onObserveListener) throws OcException {
871         OcPlatform.initCheck();
872         int connTypeInt = 0;
873
874         for (OcConnectivityType connType : OcConnectivityType.values()) {
875             if (connectivityTypeSet.contains(connType))
876                 connTypeInt |= connType.getValue();
877         }
878         return OcPlatform.subscribeDevicePresence0(
879                 host,
880                 di.toArray(new String[di.size()]),
881                 connTypeInt,
882                 onObserveListener);
883     }
884
885     private static native OcPresenceHandle subscribeDevicePresence0(
886             String host,
887             String[] di,
888             int connectivityType,
889             OcResource.OnObserveListener onObserveListener) throws OcException;
890
891     /**
892      * Creates a resource proxy object so that get/put/observe functionality can be used without
893      * discovering the object in advance. Note that the consumer of this method needs to provide
894      * all of the details required to correctly contact and observe the object. If the consumer
895      * lacks any of this information, they should discover the resource object normally.
896      * Additionally, you can only create this object if OcPlatform was initialized to be a Client
897      * or Client/Server.
898      *
899      * @param host                a string containing a resolvable host address of the server holding
900      *                            the resource
901      * @param uri                 the rest of the resource's URI that will permit messages to be
902      *                            properly routed.
903      *                            Example: /a/light
904      * @param connectivityTypeSet Set of types of connectivity. Example: IP
905      * @param isObservable        a boolean containing whether the resource supports observation
906      * @param resourceTypeList    a collection of resource types implemented by the resource
907      * @param interfaceList       a collection of interfaces that the resource supports/implements
908      * @return new resource object
909      * @throws OcException if failure
910      */
911     public static OcResource constructResourceObject(
912             String host,
913             String uri,
914             EnumSet<OcConnectivityType> connectivityTypeSet,
915             boolean isObservable,
916             List<String> resourceTypeList,
917             List<String> interfaceList) throws OcException {
918         OcPlatform.initCheck();
919         int connTypeInt = 0;
920
921         for (OcConnectivityType connType : OcConnectivityType.values()) {
922             if (connectivityTypeSet.contains(connType))
923                 connTypeInt |= connType.getValue();
924         }
925         return OcPlatform.constructResourceObject0(
926                 host,
927                 uri,
928                 connTypeInt,
929                 isObservable,
930                 resourceTypeList.toArray(new String[resourceTypeList.size()]),
931                 interfaceList.toArray(new String[interfaceList.size()])
932         );
933     }
934
935     private static native OcResource constructResourceObject0(
936             String host,
937             String uri,
938             int connectivityType,
939             boolean isObservable,
940             String[] resourceTypes,
941             String[] interfaces) throws OcException;
942
943     /**
944      * Allows application entity handler to send response to an incoming request.
945      *
946      * @param ocResourceResponse resource response
947      * @throws OcException if failure
948      */
949     public static void sendResponse(OcResourceResponse ocResourceResponse)
950             throws OcException {
951         OcPlatform.initCheck();
952         OcPlatform.sendResponse0(ocResourceResponse);
953     }
954
955     private static native void sendResponse0(OcResourceResponse ocResourceResponse)
956             throws OcException;
957
958     /**
959      *  Method to find all devices which are eligible for direct pairing and return the list.
960      *
961      *  @param timeout timeout for discovering direct pair devices.
962      *  @param FindDirectPairingListener Callback function, which will receive the list of direct
963      *                                  pairable devices.
964      *  @throws OcException
965      */
966    public static native void findDirectPairingDevices(int timeout,
967             FindDirectPairingListener onFindDirectPairingListener) throws OcException;
968
969     /**
970      *  Method to get list of all paired devices for a given device.
971      *
972      *  @param GetDirectPairedListener Callback function, which will receive the list of direct
973      *                                 paired devices.
974      *  @throws OcException
975      */
976     public native void getDirectPairedDevices(GetDirectPairedListener onGetDirectPairedListener)
977         throws OcException;
978
979     /**
980      *  Method to perform direct pairing between two devices.
981      *
982      *  @param peer  Target peer
983      *  @param prmType Pairing Method to be used for Pairing
984      *  @param pin pin
985      *  @param DirectPairingListener Callback function, which will be called after
986      *                                      completion of direct pairing.
987      *  @throws OcException
988      */
989     public static void doDirectPairing(
990             OcDirectPairDevice peer,
991             OcPrmType prmType,
992             String pin,
993             DirectPairingListener onDirectPairingListener) throws OcException {
994
995         OcPlatform.doDirectPairing0(
996                 peer,
997                 prmType.getValue(),
998                 pin,
999                 onDirectPairingListener
1000                 );
1001     }
1002
1003     private static native void doDirectPairing0(OcDirectPairDevice peer,
1004             int pmSel, String pinNumber, DirectPairingListener onDirectPairingListener)
1005     throws OcException;
1006
1007     /**
1008      * API to publish resource to remote resource-directory.
1009      *
1010      * @param host                        Host Address of a service to publish resource.
1011      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1012      * @param onPublishResourceListener   Handles events, success states and failure states.
1013      * @throws OcException if failure
1014      */
1015     public static void publishResourceToRD(
1016             String host,
1017             EnumSet<OcConnectivityType> connectivityTypeSet,
1018             OnPublishResourceListener onPublishResourceListener) throws OcException {
1019         OcPlatform.initCheck();
1020
1021         int connTypeInt = 0;
1022
1023         for (OcConnectivityType connType : OcConnectivityType.values()) {
1024             if (connectivityTypeSet.contains(connType)) {
1025                 connTypeInt |= connType.getValue();
1026             }
1027         }
1028
1029         OcPlatform.publishResourceToRD0(
1030                 host,
1031                 connTypeInt,
1032                 onPublishResourceListener,
1033                 sPlatformQualityOfService.getValue()
1034         );
1035     }
1036
1037     /**
1038      * API to publish resource to remote resource-directory.
1039      *
1040      * @param host                        Host Address of a service to publish resource.
1041      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1042      * @param onPublishResourceListener   Handles events, success states and failure states.
1043      * @param qualityOfService            the quality of communication.
1044      * @throws OcException if failure
1045      */
1046     public static void publishResourceToRD(
1047             String host,
1048             EnumSet<OcConnectivityType> connectivityTypeSet,
1049             OnPublishResourceListener onPublishResourceListener,
1050             QualityOfService qualityOfService) throws OcException {
1051         OcPlatform.initCheck();
1052
1053         int connTypeInt = 0;
1054
1055         for (OcConnectivityType connType : OcConnectivityType.values()) {
1056             if (connectivityTypeSet.contains(connType)) {
1057                 connTypeInt |= connType.getValue();
1058             }
1059         }
1060
1061         OcPlatform.publishResourceToRD0(
1062                 host,
1063                 connTypeInt,
1064                 onPublishResourceListener,
1065                 qualityOfService.getValue()
1066         );
1067     }
1068
1069     private static native void publishResourceToRD0(
1070             String host,
1071             int connectivityType,
1072             OnPublishResourceListener onPublishResourceListener,
1073             int qualityOfService) throws OcException;
1074
1075     /**
1076      * API to publish resource to remote resource-directory.
1077      *
1078      * @param host                        Host Address of a service to publish resource.
1079      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1080      * @param ocResourceHandleList        reference to list of resource handles to be published.
1081      * @param onPublishResourceListener   Handles events, success states and failure states.
1082      * @throws OcException if failure
1083      */
1084     public static void publishResourceToRD(
1085             String host,
1086             EnumSet<OcConnectivityType> connectivityTypeSet,
1087             List<OcResourceHandle> ocResourceHandleList,
1088             OnPublishResourceListener onPublishResourceListener) throws OcException {
1089         OcPlatform.initCheck();
1090
1091         int connTypeInt = 0;
1092
1093         for (OcConnectivityType connType : OcConnectivityType.values()) {
1094             if (connectivityTypeSet.contains(connType)) {
1095                 connTypeInt |= connType.getValue();
1096             }
1097         }
1098
1099         OcPlatform.publishResourceToRD1(
1100                 host,
1101                 connTypeInt,
1102                 ocResourceHandleList.toArray(
1103                         new OcResourceHandle[ocResourceHandleList.size()]),
1104                 onPublishResourceListener,
1105                 sPlatformQualityOfService.getValue()
1106         );
1107     }
1108
1109     /**
1110      * API to publish resource to remote resource-directory.
1111      *
1112      * @param host                        Host IP Address of a service to publish resource.
1113      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1114      * @param ocResourceHandleList        reference to list of resource handles to be published.
1115      * @param onPublishResourceListener   Handles events, success states and failure states.
1116      * @param qualityOfService            the quality of communication
1117      * @throws OcException if failure
1118      */
1119     public static void publishResourceToRD(
1120             String host,
1121             EnumSet<OcConnectivityType> connectivityTypeSet,
1122             List<OcResourceHandle> ocResourceHandleList,
1123             OnPublishResourceListener onPublishResourceListener,
1124             QualityOfService qualityOfService) throws OcException {
1125         OcPlatform.initCheck();
1126
1127         int connTypeInt = 0;
1128
1129         for (OcConnectivityType connType : OcConnectivityType.values()) {
1130             if (connectivityTypeSet.contains(connType)) {
1131                 connTypeInt |= connType.getValue();
1132             }
1133         }
1134
1135         OcPlatform.publishResourceToRD1(
1136             host,
1137             connTypeInt,
1138             ocResourceHandleList.toArray(
1139                     new OcResourceHandle[ocResourceHandleList.size()]),
1140             onPublishResourceListener,
1141             qualityOfService.getValue()
1142         );
1143     }
1144
1145     private static native void publishResourceToRD1(
1146             String host,
1147             int connectivityType,
1148             OcResourceHandle[] ocResourceHandleArray,
1149             OnPublishResourceListener onPublishResourceListener,
1150             int qualityOfService) throws OcException;
1151
1152     /**
1153      * API to delete resource from remote resource-directory.
1154      *
1155      * @param host                        Host Address of a service to publish resource.
1156      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1157      * @param onDeleteResourceListener    Handles events, success states and failure states.
1158      * @throws OcException if failure
1159      */
1160     public static void deleteResourceFromRD(
1161             String host,
1162             EnumSet<OcConnectivityType> connectivityTypeSet,
1163             OnDeleteResourceListener onDeleteResourceListener) throws OcException {
1164         OcPlatform.initCheck();
1165
1166         int connTypeInt = 0;
1167
1168         for (OcConnectivityType connType : OcConnectivityType.values()) {
1169             if (connectivityTypeSet.contains(connType)) {
1170                 connTypeInt |= connType.getValue();
1171             }
1172         }
1173
1174         OcPlatform.deleteResourceFromRD0(
1175                 host,
1176                 connTypeInt,
1177                 onDeleteResourceListener,
1178                 sPlatformQualityOfService.getValue()
1179         );
1180     }
1181
1182     /**
1183      * API to delete resource from remote resource-directory.
1184      *
1185      * @param host                        Host Address of a service to publish resource.
1186      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1187      * @param onDeleteResourceListener    Handles events, success states and failure states.
1188      * @param qualityOfService            the quality of communication.
1189      * @throws OcException if failure
1190      */
1191     public static void deleteResourceFromRD(
1192             String host,
1193             EnumSet<OcConnectivityType> connectivityTypeSet,
1194             OnDeleteResourceListener onDeleteResourceListener,
1195             QualityOfService qualityOfService) throws OcException {
1196         OcPlatform.initCheck();
1197
1198         int connTypeInt = 0;
1199
1200         for (OcConnectivityType connType : OcConnectivityType.values()) {
1201             if (connectivityTypeSet.contains(connType)) {
1202                 connTypeInt |= connType.getValue();
1203             }
1204         }
1205
1206         OcPlatform.deleteResourceFromRD0(
1207                 host,
1208                 connTypeInt,
1209                 onDeleteResourceListener,
1210                 qualityOfService.getValue()
1211         );
1212     }
1213
1214     private static native void deleteResourceFromRD0(
1215             String host,
1216             int connectivityType,
1217             OnDeleteResourceListener onDeleteResourceListener,
1218             int qualityOfService) throws OcException;
1219
1220     /**
1221      * API to delete resource from remote resource-directory.
1222      *
1223      * @param host                        Host Address of a service to publish resource.
1224      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1225      * @param ocResourceHandleList        reference to list of resource handles to be published.
1226      * @param onDeleteResourceListener          Handles events, success states and failure states.
1227      * @throws OcException if failure
1228      */
1229     public static void deleteResourceFromRD(
1230             String host,
1231             EnumSet<OcConnectivityType> connectivityTypeSet,
1232             List<OcResourceHandle> ocResourceHandleList,
1233             OnDeleteResourceListener onDeleteResourceListener) throws OcException {
1234         OcPlatform.initCheck();
1235
1236         int connTypeInt = 0;
1237
1238         for (OcConnectivityType connType : OcConnectivityType.values()) {
1239             if (connectivityTypeSet.contains(connType)) {
1240                 connTypeInt |= connType.getValue();
1241             }
1242         }
1243
1244         OcPlatform.deleteResourceFromRD1(
1245                 host,
1246                 connTypeInt,
1247                 ocResourceHandleList.toArray(
1248                         new OcResourceHandle[ocResourceHandleList.size()]),
1249                 onDeleteResourceListener,
1250                 sPlatformQualityOfService.getValue()
1251         );
1252     }
1253
1254     /**
1255      * API to delete resource from remote resource-directory.
1256      *
1257      * @param host                        Host IP Address of a service to publish resource.
1258      * @param connectivityTypeSet         Set of types of connectivity. Example: IP
1259      * @param ocResourceHandleList        reference to list of resource handles to be published.
1260      * @param onDeleteResourceListener    Handles events, success states and failure states.
1261      * @param qualityOfService            the quality of communication
1262      * @throws OcException if failure
1263      */
1264     public static void deleteResourceFromRD(
1265             String host,
1266             EnumSet<OcConnectivityType> connectivityTypeSet,
1267             List<OcResourceHandle> ocResourceHandleList,
1268             OnDeleteResourceListener onDeleteResourceListener,
1269             QualityOfService qualityOfService) throws OcException {
1270         OcPlatform.initCheck();
1271
1272         int connTypeInt = 0;
1273
1274         for (OcConnectivityType connType : OcConnectivityType.values()) {
1275             if (connectivityTypeSet.contains(connType)) {
1276                 connTypeInt |= connType.getValue();
1277             }
1278         }
1279
1280         OcPlatform.deleteResourceFromRD1(
1281             host,
1282             connTypeInt,
1283             ocResourceHandleList.toArray(
1284                     new OcResourceHandle[ocResourceHandleList.size()]),
1285             onDeleteResourceListener,
1286             qualityOfService.getValue()
1287         );
1288     }
1289
1290     private static native void deleteResourceFromRD1(
1291             String host,
1292             int connectivityType,
1293             OcResourceHandle[] ocResourceHandleArray,
1294             OnDeleteResourceListener onDeleteResourceListener,
1295             int qualityOfService) throws OcException;
1296
1297     /**
1298      * An OnPublishResourceListener can be registered via the OcPlatform.publishResourceToRD call.
1299      * Event listeners are notified asynchronously
1300      */
1301     public interface OnPublishResourceListener {
1302         public void onPublishResourceCompleted(OcRepresentation ocRepresentation);
1303         public void onPublishResourceFailed(Throwable ex);
1304     }
1305
1306     /**
1307      * An OnDeleteResourceListener can be registered via the OcPlatform.deleteResourceFromRD call.
1308      * Event listeners are notified asynchronously
1309      */
1310     public interface OnDeleteResourceListener {
1311         public void onDeleteResourceCompleted(int result);
1312     }
1313
1314     /**
1315      * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call.
1316      * Event listeners are notified asynchronously
1317      */
1318     public interface FindDirectPairingListener {
1319         public void onFindDirectPairingListener(List<OcDirectPairDevice> ocPairedDeviceList);
1320     }
1321
1322     /**
1323      * Listerner to Get List of already Direct Paired devices.
1324      * An GetDirectPairedListener can be registered via the OcPlatform.getDirectPairedDevices call.
1325      * Event listeners are notified asynchronously
1326      */
1327     public interface GetDirectPairedListener {
1328         public void onGetDirectPairedListener(List<OcDirectPairDevice> ocPairedDeviceList);
1329     }
1330
1331     /**
1332      * Listner to get result of doDirectPairing.
1333      * An DirectPairingListener can be registered via the OcPlatform.doDirectPairing call.
1334      * Event listeners are notified asynchronously
1335      */
1336     public interface DirectPairingListener {
1337         public void onDirectPairingListener(String devId, int result);
1338     }
1339
1340     /**
1341      * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
1342      * Event listeners are notified asynchronously
1343      */
1344     public interface OnResourceFoundListener {
1345         public void onResourceFound(OcResource resource);
1346         public void onFindResourceFailed(Throwable ex, String uri);
1347     }
1348
1349     /**
1350      * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
1351      * Event listeners are notified asynchronously
1352      */
1353     public interface OnDeviceFoundListener {
1354         public void onDeviceFound(OcRepresentation ocRepresentation);
1355     }
1356
1357     /**
1358      * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
1359      * Event listeners are notified asynchronously
1360      */
1361     public interface OnPlatformFoundListener {
1362         public void onPlatformFound(OcRepresentation ocRepresentation);
1363     }
1364
1365     /**
1366      * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
1367      * Event listeners are notified asynchronously
1368      */
1369     public interface OnPresenceListener {
1370         public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
1371     }
1372
1373     /**
1374      * An EntityHandler can be registered via the OcPlatform.registerResource call.
1375      * Event listeners are notified asynchronously
1376      *
1377      * @note entityhandler callback :
1378      * When you set specific return value like EntityHandlerResult.OK, SLOW
1379      * and etc in entity handler callback,
1380      * ocstack will be not send response automatically to client
1381      * except for error return value like EntityHandlerResult.ERROR
1382      * If you want to send response to client with specific result,
1383      * sendResponse API should be called with the result value.
1384      */
1385     public interface EntityHandler {
1386         public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
1387     }
1388
1389     private static void initCheck() {
1390         if (!sIsPlatformInitialized) {
1391             throw new IllegalStateException("OcPlatform must be configured by making a call to " +
1392                     "OcPlatform.Configure before any other API calls are permitted");
1393         }
1394     }
1395
1396     /**
1397      * Gets platform quality of service
1398      *
1399      * @return quality of service
1400      */
1401     public static QualityOfService getPlatformQualityOfService() {
1402         OcPlatform.initCheck();
1403         return sPlatformQualityOfService;
1404     }
1405
1406     /**
1407      * Create an account manager object that can be used for doing request to account server.
1408      * You can only create this object if OCPlatform was initialized to be a Client or
1409      * Client/Server. Otherwise, this will return an empty shared ptr.
1410      *
1411      * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the
1412      *       methods of this object to work since device id is not generated on Client mode.
1413      *
1414      * @param host                Host IP Address of a account server.
1415      * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP
1416      * @return new AccountManager object
1417      * @throws OcException if failure
1418      */
1419     public static OcAccountManager constructAccountManagerObject(
1420             String host,
1421             EnumSet<OcConnectivityType> connectivityTypeSet) throws OcException {
1422         OcPlatform.initCheck();
1423         int connTypeInt = 0;
1424
1425         for (OcConnectivityType connType : OcConnectivityType.values()) {
1426             if (connectivityTypeSet.contains(connType))
1427             {
1428                 connTypeInt |= connType.getValue();
1429             }
1430         }
1431         return OcPlatform.constructAccountManagerObject0(
1432                 host,
1433                 connTypeInt
1434                 );
1435     }
1436
1437     private static native OcAccountManager constructAccountManagerObject0(
1438             String host,
1439             int connectivityType) throws OcException;
1440 }