f9cc04f40848646160a8b0771e22f618e7abc70d
[platform/upstream/iotivity.git] / android / android_api / base / src / main / java / org / iotivity / base / OcResource.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 java.util.EnumSet;
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * OcResource represents an OC resource. A resource could be a light controller, temperature sensor,
31  * smoke detector, etc. A resource comes with a well-defined contract or interface onto which you
32  * can perform different operations, such as turning on the light, getting the current temperature
33  * or subscribing for event notifications from the smoke detector. A resource can be composed of
34  * one or more resources.
35  */
36 public class OcResource {
37     public static final String CREATED_URI_KEY = "createduri";
38
39     private OcResource(long nativeHandle) {
40         this.mNativeHandle = nativeHandle;
41     }
42
43     /**
44      * Method to get the attributes of a resource.
45      *
46      * @param queryParamsMap map which can have the query parameter name and value
47      * @param onGetListener  The event handler will be invoked with a map of attribute name and
48      *                       values. The event handler will also have the result from this Get
49      *                       operation This will have error codes
50      * @throws OcException if failure
51      */
52     public native void get(Map<String, String> queryParamsMap,
53                            OnGetListener onGetListener) throws OcException;
54
55     /**
56      * Method to get the attributes of a resource.
57      *
58      * @param queryParamsMap   map which can have the query parameter name and value
59      * @param onGetListener    The event handler will be invoked with a map of attribute name and
60      *                         values. The event handler will also have the result from this Get
61      *                         operation This will have error codes
62      * @param qualityOfService the quality of communication
63      * @throws OcException if failure
64      */
65     public void get(Map<String, String> queryParamsMap,
66                     OnGetListener onGetListener,
67                     QualityOfService qualityOfService) throws OcException {
68
69         if (qualityOfService == null) {
70             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
71         }
72
73         this.get1(queryParamsMap, onGetListener, qualityOfService.getValue());
74     }
75
76     private native void get1(Map<String, String> queryParamsMap,
77                              OnGetListener onGetListener,
78                              int qualityOfService) throws OcException;
79
80     /**
81      * Method to get the attributes of a resource.
82      *
83      * @param resourceType      resourceType of the resource to operate on
84      * @param resourceInterface interface type of the resource to operate on
85      * @param queryParamsMap    map which can have the query parameter name and value
86      * @param onGetListener     The event handler will be invoked with a map of attribute name and
87      *                          values. The event handler will also have the result from this Get
88      *                          operation This will have error codes
89      * @throws OcException if failure
90      */
91     public void get(String resourceType,
92                     String resourceInterface,
93                     Map<String, String> queryParamsMap,
94                     OnGetListener onGetListener) throws OcException {
95         this.get2(
96                 resourceType,
97                 resourceInterface,
98                 queryParamsMap,
99                 onGetListener);
100     }
101
102     private native void get2(String resourceType,
103                              String resourceInterface,
104                              Map<String, String> queryParamsMap,
105                              OnGetListener onGetListener) throws OcException;
106
107     /**
108      * Method to get the attributes of a resource.
109      *
110      * @param resourceType      resourceType of the resource to operate on
111      * @param resourceInterface interface type of the resource to operate on
112      * @param queryParamsMap    map which can have the query parameter name and value
113      * @param onGetListener     The event handler will be invoked with a map of attribute name and
114      *                          values. The event handler will also have the result from this Get
115      *                          operation This will have error codes
116      * @param qualityOfService  the quality of communication
117      * @throws OcException if failure
118      */
119     public void get(String resourceType,
120                     String resourceInterface,
121                     Map<String, String> queryParamsMap,
122                     OnGetListener onGetListener,
123                     QualityOfService qualityOfService) throws OcException {
124
125         if (qualityOfService == null) {
126             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
127         }
128
129         this.get3(
130                 resourceType,
131                 resourceInterface,
132                 queryParamsMap,
133                 onGetListener,
134                 qualityOfService.getValue());
135     }
136
137     private native void get3(String resourceType,
138                              String resourceInterface,
139                              Map<String, String> queryParamsMap,
140                              OnGetListener onGetListener,
141                              int qualityOfService) throws OcException;
142
143     /**
144      * Method to set the representation of a resource (via PUT)
145      *
146      * @param representation representation of the resource
147      * @param queryParamsMap Map which can have the query parameter name and value
148      * @param onPutListener  event handler The event handler will be invoked with a map of attribute
149      *                       name and values.
150      * @throws OcException if failure
151      */
152     public native void put(OcRepresentation representation,
153                            Map<String, String> queryParamsMap,
154                            OnPutListener onPutListener) throws OcException;
155
156     /**
157      * Method to set the representation of a resource (via PUT)
158      *
159      * @param ocRepresentation representation of the resource
160      * @param queryParamsMap   Map which can have the query parameter name and value
161      * @param onPutListener    event handler The event handler will be invoked with a map of
162      *                         attribute name and values.
163      * @param qualityOfService the quality of communication
164      * @throws OcException if failure
165      */
166     public void put(OcRepresentation ocRepresentation,
167                     Map<String, String> queryParamsMap,
168                     OnPutListener onPutListener,
169                     QualityOfService qualityOfService) throws OcException {
170
171         if (qualityOfService == null) {
172             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
173         }
174
175         this.put1(
176                 ocRepresentation,
177                 queryParamsMap,
178                 onPutListener,
179                 qualityOfService.getValue());
180     }
181
182     private native void put1(OcRepresentation ocRepresentation,
183                              Map<String, String> queryParamsMap,
184                              OnPutListener onPutListener,
185                              int qualityOfService) throws OcException;
186
187     /**
188      * Method to set the representation of a resource (via PUT)
189      *
190      * @param resourceType      resource type of the resource to operate on
191      * @param resourceInterface interface type of the resource to operate on
192      * @param ocRepresentation  representation of the resource
193      * @param queryParamsMap    Map which can have the query parameter name and value
194      * @param onPutListener     event handler The event handler will be invoked with a map of
195      *                          attribute name and values.
196      * @throws OcException if failure
197      */
198     public void put(String resourceType,
199                     String resourceInterface,
200                     OcRepresentation ocRepresentation,
201                     Map<String, String> queryParamsMap,
202                     OnPutListener onPutListener) throws OcException {
203         this.put2(
204                 resourceType,
205                 resourceInterface,
206                 ocRepresentation,
207                 queryParamsMap,
208                 onPutListener);
209     }
210
211     private native void put2(String resourceType,
212                              String resourceInterface,
213                              OcRepresentation ocRepresentation,
214                              Map<String, String> queryParamsMap,
215                              OnPutListener onPutListener) throws OcException;
216
217     /**
218      * Method to set the representation of a resource (via PUT)
219      *
220      * @param resourceType      resource type of the resource to operate on
221      * @param resourceInterface interface type of the resource to operate on
222      * @param ocRepresentation  representation of the resource
223      * @param queryParamsMap    Map which can have the query parameter name and value
224      * @param onPutListener     event handler The event handler will be invoked with a map of
225      *                          attribute name and values.
226      * @param qualityOfService  the quality of communication
227      * @throws OcException if failure
228      */
229     public void put(String resourceType,
230                     String resourceInterface,
231                     OcRepresentation ocRepresentation,
232                     Map<String, String> queryParamsMap,
233                     OnPutListener onPutListener,
234                     QualityOfService qualityOfService) throws OcException {
235
236         if (qualityOfService == null) {
237             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
238         }
239
240         this.put3(
241                 resourceType,
242                 resourceInterface,
243                 ocRepresentation,
244                 queryParamsMap,
245                 onPutListener,
246                 qualityOfService.getValue());
247     }
248
249     private native void put3(String resourceType,
250                              String resourceInterface,
251                              OcRepresentation ocRepresentation,
252                              Map<String, String> queryParamsMap,
253                              OnPutListener onPutListener,
254                              int qualityOfService) throws OcException;
255
256     /**
257      * Method to POST on a resource
258      *
259      * @param ocRepresentation representation of the resource
260      * @param queryParamsMap   Map which can have the query parameter name and value
261      * @param onPostListener   event handler The event handler will be invoked with a map of
262      *                         attribute name and values.
263      * @throws OcException if failure
264      */
265     public native void post(OcRepresentation ocRepresentation,
266                             Map<String, String> queryParamsMap,
267                             OnPostListener onPostListener) throws OcException;
268
269     /**
270      * Method to POST on a resource
271      *
272      * @param ocRepresentation representation of the resource
273      * @param queryParamsMap   Map which can have the query parameter name and value
274      * @param onPostListener   event handler The event handler will be invoked with a map of
275      *                         attribute name and values.
276      * @param qualityOfService the quality of communication
277      * @throws OcException if failure
278      */
279     public void post(OcRepresentation ocRepresentation,
280                      Map<String, String> queryParamsMap,
281                      OnPostListener onPostListener,
282                      QualityOfService qualityOfService) throws OcException {
283
284         if (qualityOfService == null) {
285             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
286         }
287
288         this.post1(
289                 ocRepresentation,
290                 queryParamsMap,
291                 onPostListener,
292                 qualityOfService.getValue());
293     }
294
295     private native void post1(OcRepresentation ocRepresentation,
296                               Map<String, String> queryParamsMap,
297                               OnPostListener onPostListener,
298                               int qualityOfService) throws OcException;
299
300     /**
301      * Method to POST on a resource
302      *
303      * @param resourceType      resource type of the resource to operate on
304      * @param resourceInterface interface type of the resource to operate on
305      * @param ocRepresentation  representation of the resource
306      * @param queryParamsMap    Map which can have the query parameter name and value
307      * @param onPostListener    event handler The event handler will be invoked with a map of
308      *                          attribute name and values.
309      * @throws OcException if failure
310      */
311     public void post(String resourceType,
312                      String resourceInterface,
313                      OcRepresentation ocRepresentation,
314                      Map<String, String> queryParamsMap,
315                      OnPostListener onPostListener) throws OcException {
316         this.post2(
317                 resourceType,
318                 resourceInterface,
319                 ocRepresentation,
320                 queryParamsMap,
321                 onPostListener);
322     }
323
324     private native void post2(String resourceType,
325                               String resourceInterface,
326                               OcRepresentation ocRepresentation,
327                               Map<String, String> queryParamsMap,
328                               OnPostListener onPostListener) throws OcException;
329
330     /**
331      * Method to POST on a resource
332      *
333      * @param resourceType      resource type of the resource to operate on
334      * @param resourceInterface interface type of the resource to operate on
335      * @param ocRepresentation  representation of the resource
336      * @param queryParamsMap    Map which can have the query parameter name and value
337      * @param onPostListener    event handler The event handler will be invoked with a map of
338      *                          attribute name and values.
339      * @param qualityOfService  the quality of communication
340      * @throws OcException
341      */
342     public void post(String resourceType,
343                      String resourceInterface,
344                      OcRepresentation ocRepresentation,
345                      Map<String, String> queryParamsMap,
346                      OnPostListener onPostListener,
347                      QualityOfService qualityOfService) throws OcException {
348
349         if (qualityOfService == null) {
350             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
351         }
352
353         this.post3(
354                 resourceType,
355                 resourceInterface,
356                 ocRepresentation,
357                 queryParamsMap,
358                 onPostListener,
359                 qualityOfService.getValue());
360     }
361
362     private native void post3(String resourceType,
363                               String resourceInterface,
364                               OcRepresentation ocRepresentation,
365                               Map<String, String> queryParamsMap,
366                               OnPostListener onPostListener,
367                               int qualityOfService) throws OcException;
368
369     /**
370      * Method to perform DELETE operation
371      *
372      * @param onDeleteListener event handler The event handler will have headerOptionList
373      */
374     public native void deleteResource(OnDeleteListener onDeleteListener) throws OcException;
375
376     /**
377      * Method to perform DELETE operation
378      *
379      * @param onDeleteListener event handler The event handler will have headerOptionList
380      * @param qualityOfService the quality of communication
381      */
382     public void deleteResource(OnDeleteListener onDeleteListener,
383                                QualityOfService qualityOfService) throws OcException {
384
385         if (qualityOfService == null) {
386             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
387         }
388
389         this.deleteResource1(onDeleteListener,
390                 qualityOfService.getValue());
391     }
392
393     private native void deleteResource1(OnDeleteListener onDeleteListener,
394                                         int qualityOfService) throws OcException;
395
396     /**
397      * Method to set observation on the resource
398      *
399      * @param observeType       allows the client to specify how it wants to observe
400      * @param queryParamsMap    map which can have the query parameter name and value
401      * @param onObserveListener event handler The handler method will be invoked with a map
402      *                          of attribute name and values.
403      * @throws OcException
404      */
405     public void observe(ObserveType observeType,
406                         Map<String, String> queryParamsMap,
407                         OnObserveListener onObserveListener) throws OcException {
408
409         if (observeType == null) {
410             throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null");
411         }
412
413         this.observe(
414                 observeType.getValue(),
415                 queryParamsMap,
416                 onObserveListener);
417     }
418
419     private synchronized native void observe(int observeType,
420                                              Map<String, String> queryParamsMap,
421                                              OnObserveListener onObserveListener) throws OcException;
422
423     /**
424      * Method to set observation on the resource
425      *
426      * @param observeType       allows the client to specify how it wants to observe
427      * @param queryParamsMap    map which can have the query parameter name and value
428      * @param onObserveListener event handler The handler method will be invoked with a map
429      *                          of attribute name and values.
430      * @param qualityOfService  the quality of communication
431      * @throws OcException
432      */
433     public void observe(ObserveType observeType,
434                         Map<String, String> queryParamsMap,
435                         OnObserveListener onObserveListener,
436                         QualityOfService qualityOfService) throws OcException {
437
438         if (observeType == null) {
439             throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null");
440         }
441
442         if (qualityOfService == null) {
443             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
444         }
445
446         this.observe1(
447                 observeType.getValue(),
448                 queryParamsMap,
449                 onObserveListener,
450                 qualityOfService.getValue());
451     }
452
453     private synchronized native void observe1(int observeType,
454                                               Map<String, String> queryParamsMap,
455                                               OnObserveListener onObserveListener,
456                                               int qualityOfService) throws OcException;
457
458     /**
459      * Method to cancel the observation on the resource
460      *
461      * @throws OcException
462      */
463     public void cancelObserve() throws OcException{
464         this.cancelObserve(OcPlatform.getPlatformQualityOfService());
465     }
466
467     /**
468      * Method to cancel the observation on the resource
469      *
470      * @param qualityOfService the quality of communication
471      * @throws OcException
472      */
473     public void cancelObserve(QualityOfService qualityOfService) throws OcException {
474
475         if (qualityOfService == null) {
476             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
477         }
478
479         this.cancelObserve1(qualityOfService.getValue());
480     }
481
482     private native void cancelObserve1(int qualityOfService) throws OcException;
483
484     /**
485      * Method to set header options
486      *
487      * @param headerOptionList List<OcHeaderOption> where header information(header optionID and
488      *                         optionData is passed
489      * @throws OcException
490      */
491     public void setHeaderOptions(List<OcHeaderOption> headerOptionList) throws OcException {
492
493         if (headerOptionList == null) {
494             throw new OcException(ErrorCode.INVALID_PARAM, "headerOptionList cannot be null");
495         }
496
497         this.setHeaderOptions(headerOptionList.toArray(
498                         new OcHeaderOption[headerOptionList.size()])
499         );
500     }
501
502     private native void setHeaderOptions(OcHeaderOption[] headerOptionList);
503
504     /**
505      * Method to unset header options
506      */
507     public native void unsetHeaderOptions();
508
509     /**
510      * Method to get the host address of this resource
511      *
512      * @return host address NOTE: This might or might not be exposed in future due to
513      * security concerns
514      */
515     public native String getHost();
516
517     /**
518      * Method to get the URI for this resource
519      *
520      * @return resource URI
521      */
522     public native String getUri();
523
524     /**
525      * Method to get the connectivity type of this resource
526      *
527      * @return EnumSet<OcConnectivityType></OcConnectivityType> connectivity type set
528      */
529     public EnumSet<OcConnectivityType> getConnectivityTypeSet() {
530         return OcConnectivityType.convertToEnumSet(
531                 this.getConnectivityTypeN()
532         );
533     }
534
535     private native int getConnectivityTypeN();
536
537     /**
538      * Method to provide ability to check if this resource is observable or not
539      *
540      * @return true indicates resource is observable; false indicates resource is not observable
541      */
542     public native boolean isObservable();
543
544     /**
545      * Method to get the list of resource types
546      *
547      * @return List of resource types
548      */
549     public native List<String> getResourceTypes();
550
551     /**
552      * Method to get the list of resource interfaces
553      *
554      * @return List of resource interface
555      */
556     public native List<String> getResourceInterfaces();
557
558     /**
559      * Method to get a unique identifier for this resource across network interfaces.  This will
560      * be guaranteed unique for every resource-per-server independent of how this was discovered.
561      *
562      * @return OcResourceIdentifier object, which can be used for all comparison and hashing
563      */
564     public native OcResourceIdentifier getUniqueIdentifier();
565
566     /**
567      * Method to get a string representation of the resource's server ID.
568      * <p>
569      * This is unique per- server independent on how it was discovered.
570      * </p>
571      *
572      * @return server ID
573      */
574     public native String getServerId();
575
576     /**
577      * An OnGetListener can be registered via the resource get call.
578      * Event listeners are notified asynchronously
579      */
580     public interface OnGetListener {
581         public void onGetCompleted(List<OcHeaderOption> headerOptionList,
582                                    OcRepresentation ocRepresentation);
583
584         public void onGetFailed(Throwable ex);
585     }
586
587     /**
588      * An OnPutListener can be registered via the resource put call.
589      * Event listeners are notified asynchronously
590      */
591     public interface OnPutListener {
592         public void onPutCompleted(List<OcHeaderOption> headerOptionList,
593                                    OcRepresentation ocRepresentation);
594
595         public void onPutFailed(Throwable ex);
596     }
597
598     /**
599      * An OnPostListener can be registered via the resource post call.
600      * Event listeners are notified asynchronously
601      */
602     public interface OnPostListener {
603         public void onPostCompleted(List<OcHeaderOption> headerOptionList,
604                                     OcRepresentation ocRepresentation);
605
606         public void onPostFailed(Throwable ex);
607     }
608
609     /**
610      * An OnDeleteListener can be registered via the resource delete call.
611      * Event listeners are notified asynchronously
612      */
613     public interface OnDeleteListener {
614         public void onDeleteCompleted(List<OcHeaderOption> headerOptionList);
615
616         public void onDeleteFailed(Throwable ex);
617     }
618
619     /**
620      * An OnObserveListener can be registered via the resource observe call.
621      * Event listeners are notified asynchronously
622      */
623     public interface OnObserveListener {
624         /**
625          * To Register.
626          */
627         public static final int REGISTER = 0;
628         /**
629          * To Deregister.
630          */
631         public static final int DEREGISTER = 1;
632         /**
633          * Others.
634          */
635         public static final int NO_OPTION = 2;
636
637         public void onObserveCompleted(List<OcHeaderOption> headerOptionList,
638                                        OcRepresentation ocRepresentation,
639                                        int sequenceNumber);
640
641         public void onObserveFailed(Throwable ex);
642     }
643
644     @Override
645     protected void finalize() throws Throwable {
646         super.finalize();
647
648         dispose();
649     }
650
651     private native void dispose();
652
653     private long mNativeHandle;
654
655     /**
656      * Method to discovery Topics
657      *
658      * @param queryParamsMap    map which can have the query parameter name and value
659      * @param onTopicFoundListener    event handler The handler method will be invoked with a map
660      *                                of attribute name and values.
661      * @param qualityOfService the quality of communication.
662      * @throws OcException
663      */
664     public void discoveryMQTopics(Map<String, String> queryParamsMap,
665                                   OnMQTopicFoundListener onTopicFoundListener,
666                                   QualityOfService qualityOfService) throws OcException {
667
668         if (qualityOfService == null) {
669             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
670         }
671
672         this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener,
673                                    qualityOfService.getValue());
674     }
675
676     private synchronized native void discoveryMQTopicsImpl(
677             Map<String, String> queryParamsMap,
678             OnMQTopicFoundListener onTopicFoundListener,
679             int qualityOfService) throws OcException;
680
681     /**
682      * Method to create Topic into MQ Brober.
683      *
684      * @param ocRepresentation  representation of the MQ Broker.
685      * @param uri               new MQ Topic uri which want to create.
686      * @param queryParamsMap    map which can have the query parameter name and value.
687      * @param onTopicCreatedListener    event handler The handler method will be invoked with a map
688      *                                  of attribute name and values.
689      * @param qualityOfService the quality of communication.
690      * @throws OcException
691      */
692     public void createMQTopic(OcRepresentation ocRepresentation,
693                               String uri,
694                               Map<String, String> queryParamsMap,
695                               OnMQTopicCreatedListener onTopicCreatedListener,
696                               QualityOfService qualityOfService) throws OcException {
697
698         if (qualityOfService == null) {
699             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
700         }
701
702         this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap,
703                                onTopicCreatedListener, qualityOfService.getValue());
704     }
705
706     private synchronized native void createMQTopicImpl(
707             OcRepresentation ocRepresentation,
708             String uri,
709             Map<String, String> queryParamsMap,
710             OnMQTopicCreatedListener onTopicCreatedListener,
711             int qualityOfService) throws OcException;
712
713     /**
714      * Method to set subscribe on the Topic.
715      *
716      * @param queryParamsMap    map which can have the query parameter name and value.
717      * @param onObserveListener event handler The handler method will be invoked with a map
718      *                          of attribute name and values.
719      * @param qualityOfService the quality of communication.
720      * @throws OcException
721      */
722     public void subscribeMQTopic(Map<String, String> queryParamsMap,
723                                  OnObserveListener onObserveListener,
724                                  QualityOfService qualityOfService) throws OcException {
725
726         if (qualityOfService == null) {
727             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
728         }
729
730         this.subscribeMQTopicImpl(queryParamsMap,
731                                   onObserveListener,
732                                   qualityOfService.getValue());
733     }
734
735     private synchronized native void subscribeMQTopicImpl(Map<String, String> queryParamsMap,
736             OnObserveListener onObserveListener,
737             int qualityOfService) throws OcException;
738
739     /**
740      * Method to cancel the observation on the Topic.
741      *
742      * @param qualityOfService the quality of communication.
743      * @throws OcException
744      */
745     public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{
746
747         if (qualityOfService == null) {
748             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
749         }
750
751         this.unsubscribeMQTopicImpl(qualityOfService.getValue());
752     }
753
754     private native void unsubscribeMQTopicImpl(
755             int qualityOfService) throws OcException;
756
757     /**
758      * Method to requestMQPublish on a Topic
759      *
760      * @param queryParamsMap   Map which can have the query parameter name and value
761      * @param onPostListener   event handler The event handler will be invoked with a map of
762      *                         attribute name and values.
763      * @param qualityOfService the quality of communication.
764      * @throws OcException
765      */
766     public void requestMQPublish(Map<String, String> queryParamsMap,
767                      OnPostListener onPostListener,
768                      QualityOfService qualityOfService) throws OcException {
769
770         if (qualityOfService == null) {
771             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
772         }
773
774         this.requestMQPublishImpl(queryParamsMap,
775                                   onPostListener,
776                                   qualityOfService.getValue());
777     }
778
779     private native void requestMQPublishImpl(Map<String, String> queryParamsMap,
780                               OnPostListener onPostListener,
781                               int qualityOfService) throws OcException;
782
783     /**
784      * Method to publishMQTopic on a Topic
785      *
786      * @param ocRepresentation representation of the resource
787      * @param queryParamsMap   Map which can have the query parameter name and value
788      * @param onPostListener   event handler The event handler will be invoked with a map of
789      *                         attribute name and values.
790      * @param qualityOfService the quality of communication.
791      * @throws OcException
792      */
793     public void publishMQTopic(OcRepresentation ocRepresentation,
794                      Map<String, String> queryParamsMap,
795                      OnPostListener onPostListener,
796                      QualityOfService qualityOfService) throws OcException {
797
798         if (qualityOfService == null) {
799             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
800         }
801
802         this.publishMQTopicImpl(ocRepresentation,
803                                 queryParamsMap,
804                                 onPostListener,
805                                 qualityOfService.getValue());
806     }
807
808     private native void publishMQTopicImpl(OcRepresentation ocRepresentation,
809                               Map<String, String> queryParamsMap,
810                               OnPostListener onPostListener,
811                               int qualityOfService) throws OcException;
812
813     /**
814      * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call.
815      * Event listeners are notified asynchronously
816      */
817     public interface OnMQTopicFoundListener {
818         public void onTopicDiscoveried(OcResource resource);
819         public void onDiscoveryTopicFailed(Throwable ex, String uri);
820     }
821
822     /**
823      * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call.
824      * Event listeners are notified asynchronously
825      */
826     public interface OnMQTopicCreatedListener {
827         public void onTopicResourceCreated(OcResource resource);
828         public void onCreateTopicFailed(Throwable ex, String uri);
829     }
830
831     /**
832      * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call.
833      * Event listeners are notified asynchronously
834      */
835     public interface OnMQTopicSubscribeListener {
836         /**
837          * To Subscriber.
838          */
839         public static final int SUBSCRIBER = 0;
840         /**
841          * To Unrubscriber.
842          */
843         public static final int UNSUBSCRIBER = 1;
844         /**
845          * Others.
846          */
847         public static final int NO_OPTION = 2;
848         public void onSubScribeCompleted(List<OcHeaderOption> headerOptionList,
849                 OcRepresentation ocRepresentation,
850                 int sequenceNumber);
851         public void onUnsubScribeCompleted(OcRepresentation ocRepresentation,
852                 int sequenceNumber);
853         public void onSubScribeFailed(Throwable ex);
854     }
855 }