1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
22 * @file ThingsManagerCallback.java
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
30 package org.iotivity.service.tm;
32 import java.util.Vector;
34 import org.iotivity.base.OcHeaderOption;
35 import org.iotivity.base.OcRepresentation;
36 import org.iotivity.base.OcResource;
38 import android.util.Log;
41 * This class provides a set of callback functions for group management,
42 * synchronization of group, configuration of things, and diagnostics
46 class ThingsManagerCallback {
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;
56 private ThingsManagerCallback() {
60 * Function for Getting instance of ThingsManagerCallback object.
62 * @return ThingsManagerCallback instance.
65 public static synchronized ThingsManagerCallback getInstance() {
66 if (null == thingsManagerCallbackInterfaceObj) {
67 thingsManagerCallbackInterfaceObj = new ThingsManagerCallback();
69 return thingsManagerCallbackInterfaceObj;
73 * Register listener for findCandidateResource callback.
76 * interface for getting notification when resources are
77 * discovered in network.
80 public void registerFindCandidateResourceListener(
81 IFindCandidateResourceListener listener) {
82 resourceListener = listener;
86 * Register listener for subscribeCollectionPresence callback.
89 * interface for getting notification regarding child resource
93 public void registerSubscribePresenceListener(
94 ISubscribePresenceListener listener) {
95 presenceListener = listener;
99 * Register listener for find group callback.
102 * interface for getting notification on whether the group is
106 public void registerGroupListener(IFindGroupListener listener) {
107 groupListener = listener;
111 * Register listener for updateConfigurations and getConfigurations
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.
120 public void registerConfigurationListener(IConfigurationListener listener) {
121 configurationListener = listener;
125 * Register listener for doBootstrap, reboot and factoryReset callbacks.
128 * interface for receiving asynchronous response for diagnostic
132 public void registerDiagnosticsListener(IDiagnosticsListener listener) {
133 diagnosticsListener = listener;
137 * Register listener for getActionSet, executeActionSet and deleteActionSet
141 * interface for receiving the callback for the GET, PUT and
142 * POST requested actions.
145 public void registerActionListener(IActionListener listener) {
146 actionListener = listener;
150 * Unregister listener for findCandidateResource callback.
153 public void unregisterFindCandidateResourceListener() {
154 resourceListener = null;
158 * Unregister listener for subscribeCollectionPresence callback.
161 public void unregisterSubscribePresenceListener() {
162 presenceListener = null;
166 * Unregister listener for find group callback.
169 public void unregisterGroupListener() {
170 groupListener = null;
174 * Unregister listener for updateConfigurations and getConfigurations
178 public void unregisterConfigurationListener() {
179 configurationListener = null;
183 * Unregister listener for doBootstrap, reboot and factoryReset callbacks.
186 public void unregisterDiagnosticsListener() {
187 diagnosticsListener = null;
191 * Unregister listener for getActionSet, executeActionSet and
192 * deleteActionSet callback.
195 public void unregisterActionListener() {
196 actionListener = null;
200 * This callback method will be called whenever resource is discovered in
204 * List of resources discovered in the network
207 public void onResourceCallback(Vector<OcResource> resources) {
208 if (null != resourceListener)
209 resourceListener.onResourceCallback(resources);
213 * This callback method is called when a response for the executeActionSet
214 * or deleteActionSet request just arrives.
216 * @param headerOptions
217 * It comprises of optionID and optionData as members.
219 * Configuration parameters are carried as a pair of attribute
220 * key and value in a form of OCRepresentation instance.
225 public void onPostResponseCallback(Vector<OcHeaderOption> headerOptions,
226 OcRepresentation rep, int errorValue) {
227 if (null != actionListener)
228 actionListener.onPostResponseCallback(headerOptions, rep,
233 * This callback method is called when a response for the addActionSet
234 * request just arrives.
236 * @param headerOptions
237 * It comprises of optionID and optionData as members.
239 * Configuration parameters are carried as a pair of attribute
240 * key and value in a form of OCRepresentation instance.
245 public void onPutResponseCallback(Vector<OcHeaderOption> headerOptions,
246 OcRepresentation rep, int errorValue) {
247 if (null != actionListener)
249 .onPutResponseCallback(headerOptions, rep, errorValue);
253 * This callback method is called when a response for the getActionSet
254 * request just arrives.
256 * @param headerOptions
257 * It comprises of optionID and optionData as members.
259 * Configuration parameters are carried as a pair of attribute
260 * key and value in a form of OCRepresentation instance.
265 public void onGetResponseCallback(Vector<OcHeaderOption> headerOptions,
266 OcRepresentation rep, int errorValue) {
267 if (null != actionListener)
269 .onGetResponseCallback(headerOptions, rep, errorValue);
273 * This callback method is called when a response for the
274 * updateConfigurations request just arrives.
276 * @param headerOptions
277 * It comprises of optionID and optionData as members.
279 * Configuration parameters are carried as a pair of attribute
280 * key and value in a form of OCRepresentation instance.
285 public void onUpdateConfigurationsCallback(
286 Vector<OcHeaderOption> headerOptions, OcRepresentation rep,
288 if (null != configurationListener)
289 configurationListener.onUpdateConfigurationsCallback(headerOptions,
294 * This callback method is called when a response for the getConfigurations
295 * request just arrives.
297 * @param headerOptions
298 * It comprises of optionID and optionData as members.
300 * Configuration parameters are carried as a pair of attribute
301 * key and value in a form of OCRepresentation instance.
306 public void onGetConfigurationsCallback(
307 Vector<OcHeaderOption> headerOptions, OcRepresentation rep,
309 if (null != configurationListener)
310 configurationListener.onGetConfigurationsCallback(headerOptions,
315 * This callback method is called when a response for the doBootstrap
316 * request just arrives.
318 * @param headerOptions
319 * It comprises of optionID and optionData as members.
321 * Configuration parameters are carried as a pair of attribute
322 * key and value in a form of OCRepresentation instance.
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,
338 * This callback method is called when a response for the reboot request
341 * @param headerOptions
342 * It comprises of optionID and optionData as members.
344 * Configuration parameters are carried as a pair of attribute
345 * key and value in a form of OCRepresentation instance.
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");
356 .onRebootCallback(headerOptions, rep, errorValue);
361 * This callback method is called when a response for the factoryReset
362 * request just arrives.
364 * @param headerOptions
365 * It comprises of optionID and optionData as members.
367 * Configuration parameters are carried as a pair of attribute
368 * key and value in a form of OCRepresentation instance.
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,
384 * This callback method is called to notify whether group is found or not.
390 public void onGroupFindCallback(OcResource resource) {
391 if (null != groupListener) {
392 Log.i("ThingsManagerCallback : onGroupFindCallback",
393 "Received Callback from JNI");
394 groupListener.onGroupFindCallback(resource);
399 * This callback method is called for child resource presence status.
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);