X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=android%2Fandroid_api%2Fbase%2Fsrc%2Fmain%2Fjava%2Forg%2Fiotivity%2Fbase%2FOcResource.java;h=0ea863f3bb8415246e33c22f519d926d44962339;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=333c5b2f1d2f55f423f9e3807db5304faa825fdf;hpb=5b1acfb3a398b5e73ce5696d99f86b5addfc3a2d;p=platform%2Fupstream%2Fiotivity.git diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java index 333c5b2..0ea863f 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -65,6 +65,11 @@ public class OcResource { public void get(Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get1(queryParamsMap, onGetListener, qualityOfService.getValue()); } @@ -116,6 +121,11 @@ public class OcResource { Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get3( resourceType, resourceInterface, @@ -157,6 +167,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put1( ocRepresentation, queryParamsMap, @@ -217,6 +232,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put3( resourceType, resourceInterface, @@ -260,6 +280,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post1( ocRepresentation, queryParamsMap, @@ -320,6 +345,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post3( resourceType, resourceInterface, @@ -351,6 +381,11 @@ public class OcResource { */ public void deleteResource(OnDeleteListener onDeleteListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.deleteResource1(onDeleteListener, qualityOfService.getValue()); } @@ -370,6 +405,11 @@ public class OcResource { public void observe(ObserveType observeType, Map queryParamsMap, OnObserveListener onObserveListener) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + this.observe( observeType.getValue(), queryParamsMap, @@ -394,6 +434,15 @@ public class OcResource { Map queryParamsMap, OnObserveListener onObserveListener, QualityOfService qualityOfService) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.observe1( observeType.getValue(), queryParamsMap, @@ -411,7 +460,9 @@ public class OcResource { * * @throws OcException */ - public native void cancelObserve() throws OcException; + public void cancelObserve() throws OcException{ + this.cancelObserve(OcPlatform.getPlatformQualityOfService()); + } /** * Method to cancel the observation on the resource @@ -420,6 +471,11 @@ public class OcResource { * @throws OcException */ public void cancelObserve(QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.cancelObserve1(qualityOfService.getValue()); } @@ -430,8 +486,14 @@ public class OcResource { * * @param headerOptionList List where header information(header optionID and * optionData is passed + * @throws OcException */ - public void setHeaderOptions(List headerOptionList) { + public void setHeaderOptions(List headerOptionList) throws OcException { + + if (headerOptionList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "headerOptionList cannot be null"); + } + this.setHeaderOptions(headerOptionList.toArray( new OcHeaderOption[headerOptionList.size()]) ); @@ -512,6 +574,13 @@ public class OcResource { public native String getServerId(); /** + * Method to get a string representation of the human friendly name defined by the vendor. + * + * @return human friendly name + */ + public native String getDeviceName(); + + /** * An OnGetListener can be registered via the resource get call. * Event listeners are notified asynchronously */ @@ -589,4 +658,205 @@ public class OcResource { private native void dispose(); private long mNativeHandle; + + /** + * Method to discovery Topics + * + * @param queryParamsMap map which can have the query parameter name and value + * @param onTopicFoundListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void discoveryMQTopics(Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener, + qualityOfService.getValue()); + } + + private synchronized native void discoveryMQTopicsImpl( + Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + int qualityOfService) throws OcException; + + /** + * Method to create Topic into MQ Brober. + * + * @param ocRepresentation representation of the MQ Broker. + * @param uri new MQ Topic uri which want to create. + * @param queryParamsMap map which can have the query parameter name and value. + * @param onTopicCreatedListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void createMQTopic(OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap, + onTopicCreatedListener, qualityOfService.getValue()); + } + + private synchronized native void createMQTopicImpl( + OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + int qualityOfService) throws OcException; + + /** + * Method to set subscribe on the Topic. + * + * @param queryParamsMap map which can have the query parameter name and value. + * @param onObserveListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void subscribeMQTopic(Map queryParamsMap, + OnObserveListener onObserveListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.subscribeMQTopicImpl(queryParamsMap, + onObserveListener, + qualityOfService.getValue()); + } + + private synchronized native void subscribeMQTopicImpl(Map queryParamsMap, + OnObserveListener onObserveListener, + int qualityOfService) throws OcException; + + /** + * Method to cancel the observation on the Topic. + * + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{ + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.unsubscribeMQTopicImpl(qualityOfService.getValue()); + } + + private native void unsubscribeMQTopicImpl( + int qualityOfService) throws OcException; + + /** + * Method to requestMQPublish on a Topic + * + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void requestMQPublish(Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.requestMQPublishImpl(queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void requestMQPublishImpl(Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * Method to publishMQTopic on a Topic + * + * @param ocRepresentation representation of the resource + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void publishMQTopic(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.publishMQTopicImpl(ocRepresentation, + queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void publishMQTopicImpl(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicFoundListener { + public void onTopicDiscoveried(OcResource resource); + public void onDiscoveryTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicCreatedListener { + public void onTopicResourceCreated(OcResource resource); + public void onCreateTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicSubscribeListener { + /** + * To Subscriber. + */ + public static final int SUBSCRIBER = 0; + /** + * To Unrubscriber. + */ + public static final int UNSUBSCRIBER = 1; + /** + * Others. + */ + public static final int NO_OPTION = 2; + public void onSubScribeCompleted(List headerOptionList, + OcRepresentation ocRepresentation, + int sequenceNumber); + public void onUnsubScribeCompleted(OcRepresentation ocRepresentation, + int sequenceNumber); + public void onSubScribeFailed(Throwable ex); + } }