replace : iotivity -> iotivity-sec
[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      * Method to get a string representation of the human friendly name defined by the vendor.
578      *
579      * @return human friendly name
580      */
581     public native String getDeviceName();
582
583     /**
584      * An OnGetListener can be registered via the resource get call.
585      * Event listeners are notified asynchronously
586      */
587     public interface OnGetListener {
588         public void onGetCompleted(List<OcHeaderOption> headerOptionList,
589                                    OcRepresentation ocRepresentation);
590
591         public void onGetFailed(Throwable ex);
592     }
593
594     /**
595      * An OnPutListener can be registered via the resource put call.
596      * Event listeners are notified asynchronously
597      */
598     public interface OnPutListener {
599         public void onPutCompleted(List<OcHeaderOption> headerOptionList,
600                                    OcRepresentation ocRepresentation);
601
602         public void onPutFailed(Throwable ex);
603     }
604
605     /**
606      * An OnPostListener can be registered via the resource post call.
607      * Event listeners are notified asynchronously
608      */
609     public interface OnPostListener {
610         public void onPostCompleted(List<OcHeaderOption> headerOptionList,
611                                     OcRepresentation ocRepresentation);
612
613         public void onPostFailed(Throwable ex);
614     }
615
616     /**
617      * An OnDeleteListener can be registered via the resource delete call.
618      * Event listeners are notified asynchronously
619      */
620     public interface OnDeleteListener {
621         public void onDeleteCompleted(List<OcHeaderOption> headerOptionList);
622
623         public void onDeleteFailed(Throwable ex);
624     }
625
626     /**
627      * An OnObserveListener can be registered via the resource observe call.
628      * Event listeners are notified asynchronously
629      */
630     public interface OnObserveListener {
631         /**
632          * To Register.
633          */
634         public static final int REGISTER = 0;
635         /**
636          * To Deregister.
637          */
638         public static final int DEREGISTER = 1;
639         /**
640          * Others.
641          */
642         public static final int NO_OPTION = 2;
643
644         public void onObserveCompleted(List<OcHeaderOption> headerOptionList,
645                                        OcRepresentation ocRepresentation,
646                                        int sequenceNumber);
647
648         public void onObserveFailed(Throwable ex);
649     }
650
651     @Override
652     protected void finalize() throws Throwable {
653         super.finalize();
654
655         dispose();
656     }
657
658     private native void dispose();
659
660     private long mNativeHandle;
661
662     /**
663      * Method to discovery Topics
664      *
665      * @param queryParamsMap    map which can have the query parameter name and value
666      * @param onTopicFoundListener    event handler The handler method will be invoked with a map
667      *                                of attribute name and values.
668      * @param qualityOfService the quality of communication.
669      * @throws OcException
670      */
671     public void discoveryMQTopics(Map<String, String> queryParamsMap,
672                                   OnMQTopicFoundListener onTopicFoundListener,
673                                   QualityOfService qualityOfService) throws OcException {
674
675         if (qualityOfService == null) {
676             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
677         }
678
679         this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener,
680                                    qualityOfService.getValue());
681     }
682
683     private synchronized native void discoveryMQTopicsImpl(
684             Map<String, String> queryParamsMap,
685             OnMQTopicFoundListener onTopicFoundListener,
686             int qualityOfService) throws OcException;
687
688     /**
689      * Method to create Topic into MQ Brober.
690      *
691      * @param ocRepresentation  representation of the MQ Broker.
692      * @param uri               new MQ Topic uri which want to create.
693      * @param queryParamsMap    map which can have the query parameter name and value.
694      * @param onTopicCreatedListener    event handler The handler method will be invoked with a map
695      *                                  of attribute name and values.
696      * @param qualityOfService the quality of communication.
697      * @throws OcException
698      */
699     public void createMQTopic(OcRepresentation ocRepresentation,
700                               String uri,
701                               Map<String, String> queryParamsMap,
702                               OnMQTopicCreatedListener onTopicCreatedListener,
703                               QualityOfService qualityOfService) throws OcException {
704
705         if (qualityOfService == null) {
706             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
707         }
708
709         this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap,
710                                onTopicCreatedListener, qualityOfService.getValue());
711     }
712
713     private synchronized native void createMQTopicImpl(
714             OcRepresentation ocRepresentation,
715             String uri,
716             Map<String, String> queryParamsMap,
717             OnMQTopicCreatedListener onTopicCreatedListener,
718             int qualityOfService) throws OcException;
719
720     /**
721      * Method to set subscribe on the Topic.
722      *
723      * @param queryParamsMap    map which can have the query parameter name and value.
724      * @param onObserveListener event handler The handler method will be invoked with a map
725      *                          of attribute name and values.
726      * @param qualityOfService the quality of communication.
727      * @throws OcException
728      */
729     public void subscribeMQTopic(Map<String, String> queryParamsMap,
730                                  OnObserveListener onObserveListener,
731                                  QualityOfService qualityOfService) throws OcException {
732
733         if (qualityOfService == null) {
734             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
735         }
736
737         this.subscribeMQTopicImpl(queryParamsMap,
738                                   onObserveListener,
739                                   qualityOfService.getValue());
740     }
741
742     private synchronized native void subscribeMQTopicImpl(Map<String, String> queryParamsMap,
743             OnObserveListener onObserveListener,
744             int qualityOfService) throws OcException;
745
746     /**
747      * Method to cancel the observation on the Topic.
748      *
749      * @param qualityOfService the quality of communication.
750      * @throws OcException
751      */
752     public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{
753
754         if (qualityOfService == null) {
755             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
756         }
757
758         this.unsubscribeMQTopicImpl(qualityOfService.getValue());
759     }
760
761     private native void unsubscribeMQTopicImpl(
762             int qualityOfService) throws OcException;
763
764     /**
765      * Method to requestMQPublish on a Topic
766      *
767      * @param queryParamsMap   Map which can have the query parameter name and value
768      * @param onPostListener   event handler The event handler will be invoked with a map of
769      *                         attribute name and values.
770      * @param qualityOfService the quality of communication.
771      * @throws OcException
772      */
773     public void requestMQPublish(Map<String, String> queryParamsMap,
774                      OnPostListener onPostListener,
775                      QualityOfService qualityOfService) throws OcException {
776
777         if (qualityOfService == null) {
778             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
779         }
780
781         this.requestMQPublishImpl(queryParamsMap,
782                                   onPostListener,
783                                   qualityOfService.getValue());
784     }
785
786     private native void requestMQPublishImpl(Map<String, String> queryParamsMap,
787                               OnPostListener onPostListener,
788                               int qualityOfService) throws OcException;
789
790     /**
791      * Method to publishMQTopic on a Topic
792      *
793      * @param ocRepresentation representation of the resource
794      * @param queryParamsMap   Map which can have the query parameter name and value
795      * @param onPostListener   event handler The event handler will be invoked with a map of
796      *                         attribute name and values.
797      * @param qualityOfService the quality of communication.
798      * @throws OcException
799      */
800     public void publishMQTopic(OcRepresentation ocRepresentation,
801                      Map<String, String> queryParamsMap,
802                      OnPostListener onPostListener,
803                      QualityOfService qualityOfService) throws OcException {
804
805         if (qualityOfService == null) {
806             throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
807         }
808
809         this.publishMQTopicImpl(ocRepresentation,
810                                 queryParamsMap,
811                                 onPostListener,
812                                 qualityOfService.getValue());
813     }
814
815     private native void publishMQTopicImpl(OcRepresentation ocRepresentation,
816                               Map<String, String> queryParamsMap,
817                               OnPostListener onPostListener,
818                               int qualityOfService) throws OcException;
819
820     /**
821      * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call.
822      * Event listeners are notified asynchronously
823      */
824     public interface OnMQTopicFoundListener {
825         public void onTopicDiscoveried(OcResource resource);
826         public void onDiscoveryTopicFailed(Throwable ex, String uri);
827     }
828
829     /**
830      * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call.
831      * Event listeners are notified asynchronously
832      */
833     public interface OnMQTopicCreatedListener {
834         public void onTopicResourceCreated(OcResource resource);
835         public void onCreateTopicFailed(Throwable ex, String uri);
836     }
837
838     /**
839      * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call.
840      * Event listeners are notified asynchronously
841      */
842     public interface OnMQTopicSubscribeListener {
843         /**
844          * To Subscriber.
845          */
846         public static final int SUBSCRIBER = 0;
847         /**
848          * To Unrubscriber.
849          */
850         public static final int UNSUBSCRIBER = 1;
851         /**
852          * Others.
853          */
854         public static final int NO_OPTION = 2;
855         public void onSubScribeCompleted(List<OcHeaderOption> headerOptionList,
856                 OcRepresentation ocRepresentation,
857                 int sequenceNumber);
858         public void onUnsubScribeCompleted(OcRepresentation ocRepresentation,
859                 int sequenceNumber);
860         public void onSubScribeFailed(Throwable ex);
861     }
862 }