replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / android / notification-service / src / main / java / org / iotivity / service / ns / provider / Consumer.java
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 package org.iotivity.service.ns.provider;
21
22 import org.iotivity.service.ns.common.*;
23 import java.util.Vector;
24
25 /**
26  *
27  * This class provides implementation of Notification Consumer object.
28  *
29  */
30 public class Consumer {
31
32     private String mConsumerId = null;
33
34     /**
35      * Constructor of Consumer
36      */
37     public Consumer(final String consumerId) {
38         mConsumerId = consumerId;
39     }
40
41     /**
42      * API for getting consumerId
43      *
44      * @return ConsumerId as string
45      */
46     public String getConsumerId() {
47         return mConsumerId;
48     }
49
50     /**
51      * API for accepting Subscription request. This function is valid only when
52      * subControllability is set true.
53      *
54      * @param accepted
55      *            boolean variable representing Subscription response as
56      *            TRUE/FALSE.
57      *
58      * @throws NSException failure accepting subscription request
59      */
60     public void acceptSubscription(boolean accepted) throws NSException {
61         nativeAcceptSubscription(mConsumerId, accepted);
62     }
63
64     /**
65      * Select a topic for a consumer
66      *
67      * @param topicName
68      *            Topic name to select
69      *
70      * @throws NSException failure selecting a topic
71      */
72     public void setTopic(String topicName) throws NSException {
73         nativeSetConsumerTopic(mConsumerId, topicName);
74     }
75
76     /**
77      * Unselect a topic for a consumer
78      *
79      * @param topicName
80      *            Topic name to Unselect
81      *
82      * @throws NSException failure unselecting topic
83      */
84     public void unsetTopic(String topicName) throws NSException {
85         nativeUnsetConsumerTopic(mConsumerId, topicName);
86     }
87
88     /**
89      * Request topic list with selection state for the consumer
90      *
91      * @return Topic list
92      */
93     public TopicsList getConsumerTopicList() throws NSException {
94         return nativeGetConsumerTopicList(mConsumerId);
95     }
96
97     private native void nativeAcceptSubscription(String consumerId,
98             boolean accepted) throws NSException;
99
100     private native void nativeSetConsumerTopic(String consumerId,
101             String topicName) throws NSException;
102
103     private native void nativeUnsetConsumerTopic(String consumerId,
104             String topicName) throws NSException;
105
106     private native TopicsList nativeGetConsumerTopicList(String consumerId)
107             throws NSException;
108 }