Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / src / org / iotivity / service / tm / ThingsManagerCallback.java
1 /******************************************************************
2  *
3  * Copyright 2015 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
21 /**
22  * @file    ThingsManagerCallback.java
23  *
24  * @brief    This file provides a class for a set of callback functions for group management,
25  *        synchronization of group, configuration of things, and diagnostics
26  *        about things.
27  *
28  */
29
30 package org.iotivity.service.tm;
31
32 import java.util.Vector;
33
34 import org.iotivity.base.OcHeaderOption;
35 import org.iotivity.base.OcRepresentation;
36 import org.iotivity.base.OcResource;
37
38 import android.util.Log;
39
40 /**
41  * This class provides a set of callback functions for group management,
42  * synchronization of group, configuration of things, and diagnostics
43  * about things.
44  *
45  */
46 class ThingsManagerCallback {
47
48     private IFindCandidateResourceListener resourceListener;
49     private ISubscribePresenceListener     presenceListener;
50     private IFindGroupListener             groupListener;
51     private IConfigurationListener         configurationListener;
52     private IDiagnosticsListener           diagnosticsListener;
53     private IActionListener                actionListener;
54     private static ThingsManagerCallback   thingsManagerCallbackInterfaceObj;
55
56     private ThingsManagerCallback() {
57     }
58
59     /**
60      * Function for Getting instance of ThingsManagerCallback object.
61      *
62      * @return ThingsManagerCallback instance.
63      *
64      */
65     public static synchronized ThingsManagerCallback getInstance() {
66         if (null == thingsManagerCallbackInterfaceObj) {
67             thingsManagerCallbackInterfaceObj = new ThingsManagerCallback();
68         }
69         return thingsManagerCallbackInterfaceObj;
70     }
71
72     /**
73      * Register listener for findCandidateResource callback.
74      *
75      * @param listener
76      *            interface for getting notification when resources are
77      *            discovered in network.
78      *
79      */
80     public void registerFindCandidateResourceListener(
81             IFindCandidateResourceListener listener) {
82         resourceListener = listener;
83     }
84
85     /**
86      * Register listener for subscribeCollectionPresence callback.
87      *
88      * @param listener
89      *            interface for getting notification regarding child resource
90      *            presence status.
91      *
92      */
93     public void registerSubscribePresenceListener(
94             ISubscribePresenceListener listener) {
95         presenceListener = listener;
96     }
97
98     /**
99      * Register listener for find group callback.
100      *
101      * @param listener
102      *            interface for getting notification on whether the group is
103      *            found or not.
104      *
105      */
106     public void registerGroupListener(IFindGroupListener listener) {
107         groupListener = listener;
108     }
109
110     /**
111      * Register listener for updateConfigurations and getConfigurations
112      * callback.
113      *
114      * @param listener
115      *            interface for getting notification on configuration values
116      *            information or when configuration value is updated for
117      *            multiple things of a target group or a single thing.
118      *
119      */
120     public void registerConfigurationListener(IConfigurationListener listener) {
121         configurationListener = listener;
122     }
123
124     /**
125      * Register listener for doBootstrap, reboot and factoryReset callbacks.
126      *
127      * @param listener
128      *            interface for receiving asynchronous response for diagnostic
129      *            feature APIs.
130      *
131      */
132     public void registerDiagnosticsListener(IDiagnosticsListener listener) {
133         diagnosticsListener = listener;
134     }
135
136     /**
137      * Register listener for getActionSet, executeActionSet and deleteActionSet
138      * callback.
139      *
140      * @param listener
141      *            interface for receiving the callback for the GET, PUT and
142      *            POST requested actions.
143      *
144      */
145     public void registerActionListener(IActionListener listener) {
146         actionListener = listener;
147     }
148
149     /**
150      * Unregister listener for findCandidateResource callback.
151      *
152      */
153     public void unregisterFindCandidateResourceListener() {
154         resourceListener = null;
155     }
156
157     /**
158      * Unregister listener for subscribeCollectionPresence callback.
159      *
160      */
161     public void unregisterSubscribePresenceListener() {
162         presenceListener = null;
163     }
164
165     /**
166      * Unregister listener for find group callback.
167      *
168      */
169     public void unregisterGroupListener() {
170         groupListener = null;
171     }
172
173     /**
174      * Unregister listener for updateConfigurations and getConfigurations
175      * callback.
176      *
177      */
178     public void unregisterConfigurationListener() {
179         configurationListener = null;
180     }
181
182     /**
183      * Unregister listener for doBootstrap, reboot and factoryReset callbacks.
184      *
185      */
186     public void unregisterDiagnosticsListener() {
187         diagnosticsListener = null;
188     }
189
190     /**
191      * Unregister listener for getActionSet, executeActionSet and
192      * deleteActionSet callback.
193      *
194      */
195     public void unregisterActionListener() {
196         actionListener = null;
197     }
198
199     /**
200      * This callback method will be called whenever resource is discovered in
201      * the network.
202      *
203      * @param resources
204      *            List of resources discovered in the network
205      *
206      */
207     public void onResourceCallback(Vector<OcResource> resources) {
208         if (null != resourceListener)
209             resourceListener.onResourceCallback(resources);
210     }
211
212     /**
213      * This callback method is called when a response for the executeActionSet
214      * or deleteActionSet request just arrives.
215      *
216      * @param headerOptions
217      *            It comprises of optionID and optionData as members.
218      * @param rep
219      *            Configuration parameters are carried as a pair of attribute
220      *            key and value in a form of OCRepresentation instance.
221      * @param errorValue
222      *            error code.
223      *
224      */
225     public void onPostResponseCallback(Vector<OcHeaderOption> headerOptions,
226             OcRepresentation rep, int errorValue) {
227         if (null != actionListener)
228             actionListener.onPostResponseCallback(headerOptions, rep,
229                     errorValue);
230     }
231
232     /**
233      * This callback method is called when a response for the addActionSet
234      * request just arrives.
235      *
236      * @param headerOptions
237      *            It comprises of optionID and optionData as members.
238      * @param rep
239      *            Configuration parameters are carried as a pair of attribute
240      *            key and value in a form of OCRepresentation instance.
241      * @param errorValue
242      *            error code.
243      *
244      */
245     public void onPutResponseCallback(Vector<OcHeaderOption> headerOptions,
246             OcRepresentation rep, int errorValue) {
247         if (null != actionListener)
248             actionListener
249                     .onPutResponseCallback(headerOptions, rep, errorValue);
250     }
251
252     /**
253      * This callback method is called when a response for the getActionSet
254      * request just arrives.
255      *
256      * @param headerOptions
257      *            It comprises of optionID and optionData as members.
258      * @param rep
259      *            Configuration parameters are carried as a pair of attribute
260      *            key and value in a form of OCRepresentation instance.
261      * @param errorValue
262      *            error code.
263      *
264      */
265     public void onGetResponseCallback(Vector<OcHeaderOption> headerOptions,
266             OcRepresentation rep, int errorValue) {
267         if (null != actionListener)
268             actionListener
269                     .onGetResponseCallback(headerOptions, rep, errorValue);
270     }
271
272     /**
273      * This callback method is called when a response for the
274      * updateConfigurations request just arrives.
275      *
276      * @param headerOptions
277      *            It comprises of optionID and optionData as members.
278      * @param rep
279      *            Configuration parameters are carried as a pair of attribute
280      *            key and value in a form of OCRepresentation instance.
281      * @param errorValue
282      *            error code.
283      *
284      */
285     public void onUpdateConfigurationsCallback(
286             Vector<OcHeaderOption> headerOptions, OcRepresentation rep,
287             int errorValue) {
288         if (null != configurationListener)
289             configurationListener.onUpdateConfigurationsCallback(headerOptions,
290                     rep, errorValue);
291     }
292
293     /**
294      * This callback method is called when a response for the getConfigurations
295      * request just arrives.
296      *
297      * @param headerOptions
298      *            It comprises of optionID and optionData as members.
299      * @param rep
300      *            Configuration parameters are carried as a pair of attribute
301      *            key and value in a form of OCRepresentation instance.
302      * @param errorValue
303      *            error code.
304      *
305      */
306     public void onGetConfigurationsCallback(
307             Vector<OcHeaderOption> headerOptions, OcRepresentation rep,
308             int errorValue) {
309         if (null != configurationListener)
310             configurationListener.onGetConfigurationsCallback(headerOptions,
311                     rep, errorValue);
312     }
313
314     /**
315      * This callback method is called when a response for the doBootstrap
316      * request just arrives.
317      *
318      * @param headerOptions
319      *            It comprises of optionID and optionData as members.
320      * @param rep
321      *            Configuration parameters are carried as a pair of attribute
322      *            key and value in a form of OCRepresentation instance.
323      * @param errorValue
324      *            error code.
325      *
326      */
327     public void onBootStrapCallback(Vector<OcHeaderOption> headerOptions,
328             OcRepresentation rep, int errorValue) {
329         if (null != configurationListener) {
330             Log.i("ThingsManagerCallback : onBootStrapCallback",
331                     "Received Callback from JNI");
332             configurationListener.onBootStrapCallback(headerOptions, rep,
333                     errorValue);
334         }
335     }
336
337     /**
338      * This callback method is called when a response for the reboot request
339      * just arrives.
340      *
341      * @param headerOptions
342      *            It comprises of optionID and optionData as members.
343      * @param rep
344      *            Configuration parameters are carried as a pair of attribute
345      *            key and value in a form of OCRepresentation instance.
346      * @param errorValue
347      *            error code.
348      *
349      */
350     public void onRebootCallback(Vector<OcHeaderOption> headerOptions,
351             OcRepresentation rep, int errorValue) {
352         if (null != diagnosticsListener) {
353             Log.i("ThingsManagerCallback : onRebootCallback",
354                     "Received Callback from JNI");
355             diagnosticsListener
356                     .onRebootCallback(headerOptions, rep, errorValue);
357         }
358     }
359
360     /**
361      * This callback method is called when a response for the factoryReset
362      * request just arrives.
363      *
364      * @param headerOptions
365      *            It comprises of optionID and optionData as members.
366      * @param rep
367      *            Configuration parameters are carried as a pair of attribute
368      *            key and value in a form of OCRepresentation instance.
369      * @param errorValue
370      *            error code.
371      *
372      */
373     public void onFactoryResetCallback(Vector<OcHeaderOption> headerOptions,
374             OcRepresentation rep, int errorValue) {
375         if (null != diagnosticsListener) {
376             Log.i("ThingsManagerCallback : onFactoryResetCallback",
377                     "Received Callback from JNI");
378             diagnosticsListener.onFactoryResetCallback(headerOptions, rep,
379                     errorValue);
380         }
381     }
382
383     /**
384      * This callback method is called to notify whether group is found or not.
385      *
386      * @param resource
387      *            Resource URI
388      *
389      */
390     public void onGroupFindCallback(OcResource resource) {
391         if (null != groupListener) {
392             Log.i("ThingsManagerCallback : onGroupFindCallback",
393                     "Received Callback from JNI");
394             groupListener.onGroupFindCallback(resource);
395         }
396     }
397
398     /**
399      * This callback method is called for child resource presence status.
400      *
401      * @param resource
402      *            URI of resource.
403      * @param errorValue
404      *            error code.
405      *
406      */
407     public void onPresenceCallback(String resource, int errorValue) {
408         if (null != presenceListener) {
409             Log.i("ThingsManagerCallback : onPresenceCallback",
410                     "Received Callback from JNI");
411             presenceListener.onPresenceCallback(resource, errorValue);
412         }
413     }
414
415 }