2 * //******************************************************************
\r
4 * // Copyright 2015 Intel Corporation.
\r
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
8 * // Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * // you may not use this file except in compliance with the License.
\r
10 * // You may obtain a copy of the License at
\r
12 * // http://www.apache.org/licenses/LICENSE-2.0
\r
14 * // Unless required by applicable law or agreed to in writing, software
\r
15 * // distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * // See the License for the specific language governing permissions and
\r
18 * // limitations under the License.
\r
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\r
23 package org.iotivity.base;
\r
25 import org.iotivity.ca.CaInterface;
\r
27 import java.util.EnumSet;
\r
28 import java.util.Iterator;
\r
29 import java.util.List;
\r
32 * Contains the main entrance/functionality of the product. To set a custom configuration, the
\r
33 * implementer must make a call to OcPlatform.Configure before the first usage of a function in this
\r
36 public final class OcPlatform {
\r
39 System.loadLibrary("oc_logger");
\r
40 System.loadLibrary("octbstack");
\r
41 System.loadLibrary("connectivity_abstraction");
\r
42 System.loadLibrary("oc");
\r
43 System.loadLibrary("ocstack-jni");
\r
49 public static final String DEFAULT_INTERFACE = "oic.if.baseline";
\r
52 * Used in discovering (GET) links to other resources of a collection
\r
54 public static final String LINK_INTERFACE = "oic.if.ll";
\r
57 * Used in GET, PUT, POST, DELETE methods on links to other resources of a collection
\r
59 public static final String BATCH_INTERFACE = "oic.if.b";
\r
62 * Used in GET, PUT, POST methods on links to other remote resources of a group
\r
64 public static final String GROUP_INTERFACE = "oic.mi.grp";
\r
66 public static final String WELL_KNOWN_QUERY = "224.0.1.187:5683/oic/res";
\r
67 public static final String MULTICAST_PREFIX = "224.0.1.187:5683";
\r
68 public static final String MULTICAST_IP = "224.0.1.187";
\r
69 public static final int MULTICAST_PORT = 5683;
\r
70 public static final int DEFAULT_PRESENCE_TTL = 60;
\r
71 public static final String DEVICE_URI = "/oic/d";
\r
72 public static final String PRESENCE_URI = "/oic/ad";
\r
74 private static volatile boolean sIsPlatformInitialized = false;
\r
76 private OcPlatform() {
\r
80 * API for setting the configuration of the OcPlatform.
\r
81 * Note: Any calls made to this AFTER the first call to OcPlatform.Configure will have no affect
\r
83 * @param platformConfig platform configuration
\r
85 public synchronized static void Configure(PlatformConfig platformConfig) {
\r
86 if (!sIsPlatformInitialized) {
\r
87 CaInterface.initialize(platformConfig.getContext());
\r
89 OcPlatform.configure(
\r
90 platformConfig.getServiceType().getValue(),
\r
91 platformConfig.getModeType().getValue(),
\r
92 platformConfig.getIpAddress(),
\r
93 platformConfig.getPort(),
\r
94 platformConfig.getQualityOfService().getValue(),
95 platformConfig.getSvrDbPath()
98 sIsPlatformInitialized = true;
\r
102 private static native void configure(int serviceType,
\r
106 int qualityOfService,
110 * API for notifying base that resource's attributes have changed.
\r
112 * @param ocResourceHandle resource handle of the resource
\r
113 * @throws OcException
\r
115 public static void notifyAllObservers(
\r
116 OcResourceHandle ocResourceHandle) throws OcException {
\r
117 OcPlatform.initCheck();
\r
118 OcPlatform.notifyAllObservers0(ocResourceHandle);
\r
121 private static native void notifyAllObservers0(
\r
122 OcResourceHandle ocResourceHandle) throws OcException;
\r
125 * API for notifying base that resource's attributes have changed.
\r
127 * @param ocResourceHandle resource handle of the resource
\r
128 * @param qualityOfService the quality of communication
\r
129 * @throws OcException
\r
131 public static void notifyAllObservers(
\r
132 OcResourceHandle ocResourceHandle,
\r
133 QualityOfService qualityOfService) throws OcException {
\r
134 OcPlatform.initCheck();
\r
135 OcPlatform.notifyAllObservers1(ocResourceHandle, qualityOfService.getValue());
\r
138 private static native void notifyAllObservers1(
\r
139 OcResourceHandle ocResourceHandle,
\r
140 int qualityOfService) throws OcException;
\r
143 * API for notifying only specific clients that resource's attributes have changed.
\r
145 * @param ocResourceHandle resource handle of the resource
\r
146 * @param ocObservationIdList These set of ids are ones which which will be notified upon
\r
148 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
\r
149 * this resource change
\r
150 * @throws OcException
\r
152 public static void notifyListOfObservers(
\r
153 OcResourceHandle ocResourceHandle,
\r
154 List<Byte> ocObservationIdList,
\r
155 OcResourceResponse ocResourceResponse) throws OcException {
\r
156 OcPlatform.initCheck();
\r
158 byte[] idArr = new byte[ocObservationIdList.size()];
\r
159 Iterator<Byte> it = ocObservationIdList.iterator();
\r
161 while (it.hasNext()) {
\r
162 idArr[i++] = (byte) it.next();
\r
165 OcPlatform.notifyListOfObservers2(
\r
168 ocResourceResponse);
\r
171 private static native void notifyListOfObservers2(
\r
172 OcResourceHandle ocResourceHandle,
\r
173 byte[] ocObservationIdArray,
\r
174 OcResourceResponse ocResourceResponse) throws OcException;
\r
177 * API for notifying only specific clients that resource's attributes have changed.
\r
179 * @param ocResourceHandle resource handle of the resource
\r
180 * @param ocObservationIdList These set of ids are ones which which will be notified upon
\r
182 * @param ocResourceResponse OcResourceResponse object used by app to fill the response for
\r
183 * this resource change
\r
184 * @param qualityOfService the quality of communication
\r
185 * @throws OcException
\r
187 public static void notifyListOfObservers(
\r
188 OcResourceHandle ocResourceHandle,
\r
189 List<Byte> ocObservationIdList,
\r
190 OcResourceResponse ocResourceResponse,
\r
191 QualityOfService qualityOfService) throws OcException {
\r
192 OcPlatform.initCheck();
\r
194 byte[] idArr = new byte[ocObservationIdList.size()];
\r
195 Iterator<Byte> it = ocObservationIdList.iterator();
\r
197 while (it.hasNext()) {
\r
198 idArr[i++] = (byte) it.next();
\r
201 OcPlatform.notifyListOfObservers3(
\r
204 ocResourceResponse,
\r
205 qualityOfService.getValue()
\r
209 private static native void notifyListOfObservers3(
\r
210 OcResourceHandle ocResourceHandle,
\r
211 byte[] ocObservationIdArray,
\r
212 OcResourceResponse ocResourceResponse,
\r
213 int qualityOfService) throws OcException;
\r
216 * API for Service and Resource Discovery. NOTE: This API applies to client side only
\r
218 * @param host Host IP Address of a service to direct resource discovery query.
\r
219 * If empty, performs multicast resource discovery query
\r
220 * @param resourceUri name of the resource. If null or empty, performs search for all
\r
222 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
224 * @param onResourceFoundListener Handles events, success states and failure states.
\r
225 * @throws OcException
\r
227 public static void findResource(
\r
229 String resourceUri,
\r
230 OcConnectivityType connectivityType,
\r
231 OnResourceFoundListener onResourceFoundListener) throws OcException {
\r
232 OcPlatform.initCheck();
\r
233 OcPlatform.findResource0(
\r
236 connectivityType.getValue(),
\r
237 onResourceFoundListener
\r
241 private static native void findResource0(
\r
243 String resourceUri,
\r
244 int connectivityType,
\r
245 OnResourceFoundListener onResourceFoundListener) throws OcException;
\r
248 * API for Service and Resource Discovery. NOTE: This API applies to client side only
\r
250 * @param host Host IP Address of a service to direct resource discovery query.
\r
251 * If empty, performs multicast resource discovery query
\r
252 * @param resourceUri name of the resource. If null or empty, performs search for all
\r
254 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
256 * @param onResourceFoundListener Handles events, success states and failure states.
\r
257 * @param qualityOfService the quality of communication
\r
258 * @throws OcException
\r
260 public static void findResource(
\r
262 String resourceUri,
\r
263 OcConnectivityType connectivityType,
\r
264 OnResourceFoundListener onResourceFoundListener,
\r
265 QualityOfService qualityOfService) throws OcException {
\r
266 OcPlatform.initCheck();
\r
267 OcPlatform.findResource1(host,
\r
269 connectivityType.getValue(),
\r
270 onResourceFoundListener,
\r
271 qualityOfService.getValue()
\r
275 private static native void findResource1(
\r
277 String resourceUri,
\r
278 int connectivityType,
\r
279 OnResourceFoundListener onResourceFoundListener,
\r
280 int qualityOfService) throws OcException;
\r
283 * API for Device Discovery
\r
285 * @param host Host IP Address. If null or empty, Multicast is performed.
\r
286 * @param deviceUri Uri containing address to the virtual device
\r
287 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
289 * @param onDeviceFoundListener Handles events, success states and failure states.
\r
290 * @throws OcException
\r
292 public static void getDeviceInfo(
\r
295 OcConnectivityType connectivityType,
\r
296 OnDeviceFoundListener onDeviceFoundListener) throws OcException {
\r
297 OcPlatform.initCheck();
\r
298 OcPlatform.getDeviceInfo0(
\r
301 connectivityType.getValue(),
\r
302 onDeviceFoundListener
\r
306 private static native void getDeviceInfo0(
\r
309 int connectivityType,
\r
310 OnDeviceFoundListener onDeviceFoundListener) throws OcException;
\r
313 * API for Device Discovery
\r
315 * @param host Host IP Address. If null or empty, Multicast is performed.
\r
316 * @param deviceUri Uri containing address to the virtual device
\r
317 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
319 * @param onDeviceFoundListener Handles events, success states and failure states.
\r
320 * @param qualityOfService the quality of communication
\r
321 * @throws OcException
\r
323 public static void getDeviceInfo(
\r
326 OcConnectivityType connectivityType,
\r
327 OnDeviceFoundListener onDeviceFoundListener,
\r
328 QualityOfService qualityOfService) throws OcException {
\r
329 OcPlatform.initCheck();
\r
330 OcPlatform.getDeviceInfo1(
\r
333 connectivityType.getValue(),
\r
334 onDeviceFoundListener,
\r
335 qualityOfService.getValue()
\r
339 private static native void getDeviceInfo1(
\r
342 int connectivityType,
\r
343 OnDeviceFoundListener onDeviceFoundListener,
\r
344 int qualityOfService) throws OcException;
347 * API for Platform Discovery
349 * @param host Host IP Address. If null or empty, Multicast is performed.
350 * @param platformUri Uri containing address to the platform
351 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
353 * @param onPlatformFoundListener Handles events, success states and failure states.
354 * @throws OcException
357 public static void getPlatformInfo(
360 OcConnectivityType connectivityType,
361 OnPlatformFoundListener onPlatformFoundListener) throws OcException {
362 OcPlatform.initCheck();
363 OcPlatform.getPlatformInfo0(
366 connectivityType.getValue(),
367 onPlatformFoundListener
371 private static native void getPlatformInfo0(
374 int connectivityType,
375 OnPlatformFoundListener onPlatformInfoFoundListener) throws OcException;
378 * API for Platform Discovery
380 * @param host Host IP Address. If null or empty, Multicast is performed.
381 * @param platformUri Uri containing address to the platform
382 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
384 * @param onPlatformFoundListener Handles events, success states and failure states.
385 * @param qualityOfService the quality of communication
386 * @throws OcException
389 public static void getPlatformInfo(
392 OcConnectivityType connectivityType,
393 OnPlatformFoundListener onPlatformFoundListener,
394 QualityOfService qualityOfService) throws OcException {
395 OcPlatform.initCheck();
396 OcPlatform.getPlatformInfo1(
399 connectivityType.getValue(),
400 onPlatformFoundListener,
401 qualityOfService.getValue()
405 private static native void getPlatformInfo1(
408 int connectivityType,
409 OnPlatformFoundListener onPlatformFoundListener,
410 int qualityOfService) throws OcException;
\r
413 * This API registers a resource with the server NOTE: This API applies to server side only.
\r
415 * @param ocResource The instance of OcResource with all data filled
\r
416 * @return resource handle
\r
417 * @throws OcException
\r
419 public static OcResourceHandle registerResource(
\r
420 OcResource ocResource) throws OcException {
\r
421 OcPlatform.initCheck();
\r
422 return OcPlatform.registerResource0(ocResource);
\r
425 private static native OcResourceHandle registerResource0(
\r
426 OcResource ocResource) throws OcException;
\r
429 * This API registers a resource with the server NOTE: This API applies to server side only.
\r
431 * @param resourceUri The URI of the resource. Example: "a/light"
\r
432 * @param resourceTypeName The resource type. Example: "light"
\r
433 * @param resourceInterface The resource interface (whether it is collection etc).
\r
434 * @param entityHandler entity handler.
\r
435 * @param resourcePropertySet indicates the property of the resource
\r
436 * @return resource handle
\r
437 * @throws OcException
\r
439 public static OcResourceHandle registerResource(
\r
440 String resourceUri,
\r
441 String resourceTypeName,
\r
442 String resourceInterface,
\r
443 EntityHandler entityHandler,
\r
444 EnumSet<ResourceProperty> resourcePropertySet) throws OcException {
\r
445 OcPlatform.initCheck();
\r
447 int resProperty = 0;
\r
449 for (ResourceProperty prop : ResourceProperty.values()) {
\r
450 if (resourcePropertySet.contains(prop))
\r
451 resProperty |= prop.getValue();
\r
454 return OcPlatform.registerResource1(resourceUri,
\r
461 private static native OcResourceHandle registerResource1(
\r
462 String resourceUri,
\r
463 String resourceTypeName,
\r
464 String resourceInterface,
\r
465 EntityHandler entityHandler,
\r
466 int resourceProperty) throws OcException;
\r
469 * Register Device Info
\r
471 * @param ocDeviceInfo object containing all the device specific information
\r
472 * @throws OcException
\r
474 public static void registerDeviceInfo(
\r
475 OcDeviceInfo ocDeviceInfo) throws OcException {
\r
476 OcPlatform.initCheck();
\r
477 OcPlatform.registerDeviceInfo0(
\r
478 ocDeviceInfo.getDeviceName()
\r
482 private static native void registerDeviceInfo0(
\r
484 ) throws OcException;
\r
487 * Register Platform Info
489 * @param ocPlatformInfo object containing all the platform specific information
490 * @throws OcException
492 public static void registerPlatformInfo(
493 OcPlatformInfo ocPlatformInfo) throws OcException {
494 OcPlatform.initCheck();
495 OcPlatform.registerPlatformInfo0(
496 ocPlatformInfo.getPlatformID(),
497 ocPlatformInfo.getManufacturerName(),
498 ocPlatformInfo.getManufacturerUrl(),
499 ocPlatformInfo.getModelNumber(),
500 ocPlatformInfo.getDateOfManufacture(),
501 ocPlatformInfo.getPlatformVersion(),
502 ocPlatformInfo.getOperatingSystemVersion(),
503 ocPlatformInfo.getHardwareVersion(),
504 ocPlatformInfo.getFirmwareVersion(),
505 ocPlatformInfo.getSupportUrl(),
506 ocPlatformInfo.getSystemTime()
510 private static native void registerPlatformInfo0(
511 String platformId, String manufacturerName, String manufacturerUrl,
512 String modelNumber, String dateOfManufacture, String platformVersion,
513 String operatingSystemVersion, String hardwareVersion, String firmwareVersion,
514 String supportUrl, String systemTime
515 ) throws OcException;
518 * This API unregisters a resource with the server NOTE: This API applies to server side only.
\r
520 * @param ocResourceHandle This is the resource handle which we which to unregister from the
\r
522 * @throws OcException
\r
524 public static void unregisterResource(
\r
525 OcResourceHandle ocResourceHandle) throws OcException {
\r
526 OcPlatform.initCheck();
\r
527 OcPlatform.unregisterResource0(ocResourceHandle);
\r
530 private static native void unregisterResource0(
\r
531 OcResourceHandle ocResourceHandle) throws OcException;
\r
535 * Add a resource to a collection resource
\r
537 * @param ocResourceCollectionHandle handle to the collection resource
\r
538 * @param ocResourceHandle handle to resource to be added to the collection resource
\r
539 * @throws OcException
\r
541 public static void bindResource(
\r
542 OcResourceHandle ocResourceCollectionHandle,
\r
543 OcResourceHandle ocResourceHandle) throws OcException {
\r
544 OcPlatform.initCheck();
\r
545 OcPlatform.bindResource0(ocResourceCollectionHandle, ocResourceHandle);
\r
548 private static native void bindResource0(
\r
549 OcResourceHandle ocResourceCollectionHandle,
\r
550 OcResourceHandle ocResourceHandle) throws OcException;
\r
553 * Add multiple resources to a collection resource.
\r
555 * @param ocResourceCollectionHandle handle to the collection resource
\r
556 * @param ocResourceHandleList reference to list of resource handles to be added to the
\r
557 * collection resource
\r
558 * @throws OcException
\r
560 public static void bindResources(
\r
561 OcResourceHandle ocResourceCollectionHandle,
\r
562 List<OcResourceHandle> ocResourceHandleList) throws OcException {
\r
563 OcPlatform.initCheck();
\r
564 OcPlatform.bindResources0(
\r
565 ocResourceCollectionHandle,
\r
566 ocResourceHandleList.toArray(
\r
567 new OcResourceHandle[ocResourceHandleList.size()])
\r
571 private static native void bindResources0(
\r
572 OcResourceHandle ocResourceCollectionHandle,
\r
573 OcResourceHandle[] ocResourceHandleArray) throws OcException;
\r
576 * Unbind a resource from a collection resource.
\r
578 * @param ocResourceCollectionHandle handle to the collection resource
\r
579 * @param ocResourceHandle resource handle to be unbound from the collection resource
\r
580 * @throws OcException
\r
582 public static void unbindResource(
\r
583 OcResourceHandle ocResourceCollectionHandle,
\r
584 OcResourceHandle ocResourceHandle) throws OcException {
\r
585 OcPlatform.initCheck();
\r
586 OcPlatform.unbindResource0(ocResourceCollectionHandle, ocResourceHandle);
\r
589 private static native void unbindResource0(
\r
590 OcResourceHandle ocResourceCollectionHandle,
\r
591 OcResourceHandle ocResourceHandle) throws OcException;
\r
594 * Unbind resources from a collection resource.
\r
596 * @param ocResourceCollectionHandle Handle to the collection resource
\r
597 * @param ocResourceHandleList List of resource handles to be unbound from the collection
\r
599 * @throws OcException
\r
601 public static void unbindResources(
\r
602 OcResourceHandle ocResourceCollectionHandle,
\r
603 List<OcResourceHandle> ocResourceHandleList) throws OcException {
\r
604 OcPlatform.initCheck();
\r
605 OcPlatform.unbindResources0(
\r
606 ocResourceCollectionHandle,
\r
607 ocResourceHandleList.toArray(
\r
608 new OcResourceHandle[ocResourceHandleList.size()])
\r
612 private static native void unbindResources0(
\r
613 OcResourceHandle ocResourceCollectionHandle,
\r
614 OcResourceHandle[] ocResourceHandleArray) throws OcException;
\r
617 * Binds a type to a particular resource
\r
619 * @param ocResourceHandle handle to the resource
\r
620 * @param resourceTypeName new typename to bind to the resource
\r
621 * @throws OcException
\r
623 public static void bindTypeToResource(
\r
624 OcResourceHandle ocResourceHandle,
\r
625 String resourceTypeName) throws OcException {
\r
626 OcPlatform.initCheck();
\r
627 OcPlatform.bindTypeToResource0(ocResourceHandle, resourceTypeName);
\r
630 private static native void bindTypeToResource0(
\r
631 OcResourceHandle ocResourceHandle,
\r
632 String resourceTypeName) throws OcException;
\r
635 * Binds an interface to a particular resource
\r
637 * @param ocResourceHandle handle to the resource
\r
638 * @param resourceInterfaceName new interface to bind to the resource
\r
639 * @throws OcException
\r
641 public static void bindInterfaceToResource(
\r
642 OcResourceHandle ocResourceHandle,
\r
643 String resourceInterfaceName) throws OcException {
\r
644 OcPlatform.initCheck();
\r
645 OcPlatform.bindInterfaceToResource0(ocResourceHandle, resourceInterfaceName);
\r
648 private static native void bindInterfaceToResource0(
\r
649 OcResourceHandle ocResourceHandle,
\r
650 String resourceInterfaceName) throws OcException;
\r
653 * Start Presence announcements.
\r
655 * @param ttl time to live in seconds
\r
656 * @throws OcException
\r
658 public static void startPresence(int ttl) throws OcException {
\r
659 OcPlatform.initCheck();
\r
660 OcPlatform.startPresence0(ttl);
\r
663 private static native void startPresence0(int ttl) throws OcException;
\r
666 * Stop Presence announcements.
\r
668 * @throws OcException
\r
670 public static void stopPresence() throws OcException {
\r
671 OcPlatform.initCheck();
\r
672 OcPlatform.stopPresence0();
\r
675 private static native void stopPresence0() throws OcException;
\r
678 * Subscribes to a server's presence change events. By making this subscription, every time a
\r
679 * server adds/removes/alters a resource, starts or is intentionally stopped
\r
681 * @param host The IP address/addressable name of the server to subscribe to
\r
682 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
684 * @param onPresenceListener listener that will receive notifications/subscription events
\r
685 * @return a handle object that can be used to identify this subscription request. It can be
\r
686 * used to unsubscribe from these events in the future
\r
687 * @throws OcException
\r
689 public static OcPresenceHandle subscribePresence(
\r
691 OcConnectivityType connectivityType,
\r
692 OnPresenceListener onPresenceListener) throws OcException {
\r
693 OcPlatform.initCheck();
\r
694 return OcPlatform.subscribePresence0(
\r
696 connectivityType.getValue(),
\r
701 private static native OcPresenceHandle subscribePresence0(
\r
703 int connectivityType,
\r
704 OnPresenceListener onPresenceListener) throws OcException;
\r
707 * Subscribes to a server's presence change events. By making this subscription, every time a
\r
708 * server adds/removes/alters a resource, starts or is intentionally stopped
\r
710 * @param host The IP address/addressable name of the server to subscribe to
\r
711 * @param resourceType a resource type specified as a filter for subscription events.
\r
712 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
714 * @param onPresenceListener listener that will receive notifications/subscription events
\r
715 * @return a handle object that can be used to identify this subscription request. It can be
\r
716 * used to unsubscribe from these events in the future
\r
717 * @throws OcException
\r
719 public static OcPresenceHandle subscribePresence(
\r
721 String resourceType,
\r
722 OcConnectivityType connectivityType,
\r
723 OnPresenceListener onPresenceListener) throws OcException {
\r
724 OcPlatform.initCheck();
\r
725 return OcPlatform.subscribePresence1(
\r
728 connectivityType.getValue(),
\r
729 onPresenceListener);
\r
732 private static native OcPresenceHandle subscribePresence1(
\r
734 String resourceType,
\r
735 int connectivityType,
\r
736 OnPresenceListener onPresenceListener) throws OcException;
\r
739 * Unsubscribes from a previously subscribed server's presence events. Note that you may for
\r
740 * a short time still receive events from the server since it may take time for the
\r
741 * unsubscribe to take effect.
\r
743 * @param ocPresenceHandle the handle object provided by the subscribePresence call that
\r
744 * identifies this subscription
\r
745 * @throws OcException
\r
747 public static void unsubscribePresence(
\r
748 OcPresenceHandle ocPresenceHandle) throws OcException {
\r
749 OcPlatform.initCheck();
\r
750 OcPlatform.unsubscribePresence0(ocPresenceHandle);
\r
753 private static native void unsubscribePresence0(
\r
754 OcPresenceHandle ocPresenceHandle) throws OcException;
\r
757 * Creates a resource proxy object so that get/put/observe functionality can be used without
\r
758 * discovering the object in advance. Note that the consumer of this method needs to provide
\r
759 * all of the details required to correctly contact and observe the object. If the consumer
\r
760 * lacks any of this information, they should discover the resource object normally.
\r
761 * Additionally, you can only create this object if OcPlatform was initialized to be a Client
\r
762 * or Client/Server.
\r
764 * @param host a string containing a resolvable host address of the server holding
\r
766 * @param uri the rest of the resource's URI that will permit messages to be
\r
768 * Example: /a/light
\r
769 * @param connectivityType a type of connectivity indicating the interface. Example: IPV4,
\r
771 * @param isObservable a boolean containing whether the resource supports observation
\r
772 * @param resourceTypeList a collection of resource types implemented by the resource
\r
773 * @param interfaceList a collection of interfaces that the resource supports/implements
\r
774 * @return new resource object
\r
775 * @throws OcException
\r
777 public static OcResource constructResourceObject(
\r
780 OcConnectivityType connectivityType,
\r
781 boolean isObservable,
\r
782 List<String> resourceTypeList,
\r
783 List<String> interfaceList) throws OcException {
\r
784 OcPlatform.initCheck();
\r
785 return OcPlatform.constructResourceObject0(
\r
788 connectivityType.getValue(),
\r
790 resourceTypeList.toArray(new String[resourceTypeList.size()]),
\r
791 interfaceList.toArray(new String[interfaceList.size()])
\r
795 private static native OcResource constructResourceObject0(
\r
798 int connectivityType,
\r
799 boolean isObservable,
\r
800 String[] resourceTypes,
\r
801 String[] interfaces) throws OcException;
\r
804 * Allows application entity handler to send response to an incoming request.
\r
806 * @param ocResourceResponse resource response
\r
807 * @throws OcException
\r
809 public static void sendResponse(OcResourceResponse ocResourceResponse)
\r
810 throws OcException {
\r
811 OcPlatform.initCheck();
\r
812 OcPlatform.sendResponse0(ocResourceResponse);
\r
815 private static native void sendResponse0(OcResourceResponse ocResourceResponse)
\r
816 throws OcException;
\r
819 * An OnResourceFoundListener can be registered via the OcPlatform.findResource call.
\r
820 * Event listeners are notified asynchronously
\r
822 public interface OnResourceFoundListener {
\r
823 public void onResourceFound(OcResource resource);
\r
827 * An OnDeviceFoundListener can be registered via the OcPlatform.getDeviceInfo call.
\r
828 * Event listeners are notified asynchronously
\r
830 public interface OnDeviceFoundListener {
\r
831 public void onDeviceFound(OcRepresentation ocRepresentation);
\r
835 * An OnPlatformFoundListener can be registered via the OcPlatform.getPlatformInfo call.
836 * Event listeners are notified asynchronously
838 public interface OnPlatformFoundListener {
839 public void onPlatformFound(OcRepresentation ocRepresentation);
843 * An OnPresenceListener can be registered via the OcPlatform.subscribePresence call.
\r
844 * Event listeners are notified asynchronously
\r
846 public interface OnPresenceListener {
\r
847 public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress);
\r
851 * An EntityHandler can be registered via the OcPlatform.registerResource call.
\r
852 * Event listeners are notified asynchronously
\r
854 public interface EntityHandler {
\r
855 public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
\r
858 private static void initCheck() {
\r
859 if (!sIsPlatformInitialized) {
\r
860 throw new IllegalStateException("OcPlatform must be configured by making a call to " +
\r
861 "OcPlatform.Configure before any other API calls are permitted");
\r