Merging primitive services(TM, SSM and NM) from android-api branch.
[platform/upstream/iotivity.git] / service / things-manager / sdk / java / src / org / iotivity / service / tm / ThingsManager.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  * @file    ThingsManager.java
22  *
23  * @brief    This file provides a class for a set of APIs relating to group management,
24  *        synchronization of group, configuration of things, and diagnostics
25  *        about things.
26  *
27  */
28
29 package org.iotivity.service.tm;
30
31 import java.util.Map;
32 import java.util.Vector;
33
34 import org.iotivity.base.OcException;
35 import org.iotivity.base.OcResource;
36 import org.iotivity.base.OcResourceHandle;
37
38 import android.util.Log;
39
40 /**
41  * This class provides a set of APIs relating to group management,
42  * synchronization of group, configuration of things, and diagnostics
43  * about things.
44  *
45  */
46 public class ThingsManager {
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 final String                   LOG_TAG = this.getClass()
55                                                            .getSimpleName();
56
57     private final ThingsManagerCallback    thingsManagerCallbackInterfaceObj;
58     private final ThingsManagerInterface   thingsManagerInterfaceObj;
59
60     static {
61         System.loadLibrary("gnustl_shared");
62         System.loadLibrary("oc_logger");
63         System.loadLibrary("connectivity_abstraction");
64         System.loadLibrary("ca-interface");
65         System.loadLibrary("octbstack");
66         System.loadLibrary("oc");
67         System.loadLibrary("TGMSDKLibrary");
68         System.loadLibrary("ocstack-jni");
69         System.loadLibrary("things-manager-jni");
70     }
71
72     /**
73      * Constructor for ThingsManager. Constructs a new ThingsManager.
74      */
75     public ThingsManager() {
76         thingsManagerCallbackInterfaceObj = ThingsManagerCallback.getInstance();
77         thingsManagerInterfaceObj = ThingsManagerInterface.getInstance();
78     }
79
80     /**
81      * Set listener for receiving notification of resource discovery.
82      *
83      * @param listener
84      *            IFindCandidateResourceListener to receive the
85      *            discovered resources.
86      */
87     public void setFindCandidateResourceListener(
88             IFindCandidateResourceListener listener) {
89         resourceListener = listener;
90         thingsManagerCallbackInterfaceObj
91                 .registerFindCandidateResourceListener(listener);
92         thingsManagerInterfaceObj
93                 .registerFindCandidateResourceListener(listener);
94     }
95
96     /**
97      * Set listener for receiving child resource presence notifications.
98      *
99      * @param listener
100      *            ISubscribePresenceListener to receive child resource
101      *            presence state.
102      */
103     public void setSubscribePresenceListener(ISubscribePresenceListener listener) {
104         presenceListener = listener;
105         thingsManagerCallbackInterfaceObj
106                 .registerSubscribePresenceListener(listener);
107         thingsManagerInterfaceObj.registerSubscribePresenceListener(listener);
108     }
109
110     /**
111      * Set listener for receiving notification on whether the requested group is
112      * found or not.
113      *
114      * @param listener
115      *            IFindGroupListener to receive group discovery status.
116      */
117     public void setGroupListener(IFindGroupListener listener) {
118         groupListener = listener;
119         thingsManagerCallbackInterfaceObj.registerGroupListener(listener);
120         thingsManagerInterfaceObj.registerGroupListener(listener);
121     }
122
123     /**
124      * Set listener for receiving asynchronous response for configuration APIs.
125      *
126      * @param listener
127      *            IConfigurationListener to receive asynchronous response
128      *            for configuration APIs.
129      */
130     public void setConfigurationListener(IConfigurationListener listener) {
131         configurationListener = listener;
132         thingsManagerCallbackInterfaceObj
133                 .registerConfigurationListener(listener);
134         thingsManagerInterfaceObj.registerConfigurationListener(listener);
135     }
136
137     /**
138      * Set listener for receiving asynchronous response for diagnostic feature
139      * APIs.
140      *
141      * @param listener
142      *            IDiagnosticsListener to receive asynchronous response
143      *            for diagnostic feature APIs.
144      */
145     public void setDiagnosticsListener(IDiagnosticsListener listener) {
146         diagnosticsListener = listener;
147         thingsManagerCallbackInterfaceObj.registerDiagnosticsListener(listener);
148     }
149
150     /**
151      * Set listener for receiving responses of Get, PUT and POST requests.
152      *
153      * @param listener
154      *            IActionListener to receive Get, PUT and POST request
155      *            responses.
156      */
157     public void setActionListener(IActionListener listener) {
158         actionListener = listener;
159         thingsManagerCallbackInterfaceObj.registerActionListener(listener);
160     }
161
162     /**
163      * API for discovering candidate resources with waiting delay. This
164      * operation returns all resources of given type on the network service.
165      * This operation is sent via multicast to all services. However, the filter
166      * limits the responders to just those that support the resource type in the
167      * query. Currently only exact matches are supported.
168      * <p>
169      * Listener should be set using setFindCandidateResourceListener API
170      * <p>
171      * Listener IFindCandidateResourceListener::onResourceCallback
172      *       will be notified when resource is discovered in network.
173      *
174      * @param resourceTypes
175      *            required resource types(called "candidate")
176      * @param waitTime
177      *            Delay time to add in seconds before starting to find the
178      *            resources in network.
179      *
180      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
181      *         code.
182      *
183      */
184     public OCStackResult findCandidateResources(Vector<String> resourceTypes,
185             int waitTime) {
186         if (null == resourceListener) {
187             Log.e(LOG_TAG,"findCandidateResources: listener not set!");
188             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
189         }
190
191         OCStackResult result = thingsManagerInterfaceObj.findCandidateResources(
192                               resourceTypes, waitTime);
193         if (OCStackResult.OC_STACK_OK != result) {
194             Log.e(LOG_TAG, "findCandidateResources: returned error: " + result.name());
195         }
196
197         return result;
198     }
199
200     /**
201      * API for subscribing child's state. It subscribes the presence state of
202      * the resource. By making this subscription, every time a server
203      * adds/removes/alters a resource, starts or is intentionally stopped, a
204      * notification is sent to subscriber.
205      *
206      * <p>
207      * Listener should be set using setSubscribePresenceListener API.
208      * <p>
209      * Listener ISubscribePresenceListener::onPresenceCallback will
210      *       be notified for resource presence status
211      *
212      * @param resource
213      *            collection resource for subscribing presence of all child
214      *            resources
215      *
216      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
217      *         code.
218      *
219      */
220     public OCStackResult subscribeCollectionPresence(OcResource resource)
221             throws OcException {
222         if (null == presenceListener) {
223             Log.e(LOG_TAG,"subscribeCollectionPresence: listener not set!");
224             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
225         }
226
227         OCStackResult result = thingsManagerInterfaceObj
228                               .subscribeCollectionPresence(resource);
229         if (OCStackResult.OC_STACK_OK != result) {
230             Log.e(LOG_TAG, "subscribeCollectionPresence: returned error: " + result.name());
231         }
232
233         return result;
234     }
235
236     /**
237      * API for finding a specific remote group when a resource tries to join a
238      * group.
239      * <p>
240      * Listener should be set using setGroupListener API
241      * <p>
242      * Listener IFindGroupListener::onGroupFindCallback will be
243      *       called to notify whenever a requested group is found.
244      *
245      * @param collectionResourceTypes
246      *            resource types of a group to find and join
247      *
248      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
249      *         code.
250      *
251      *
252      */
253     public OCStackResult findGroup(Vector<String> collectionResourceTypes) {
254         if (null == groupListener) {
255             Log.e(LOG_TAG,"findGroup: listener not set!");
256             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
257         }
258
259         OCStackResult result = result = thingsManagerInterfaceObj.findGroup(collectionResourceTypes);
260         if (OCStackResult.OC_STACK_OK != result) {
261             Log.e(LOG_TAG, "findGroup: returned error: " + result.name());
262         }
263
264         return result;
265     }
266
267     /**
268      * API for creating a new group.
269      *
270      * @param collectionResourceType
271      *            resource type of a group to create
272      *
273      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
274      *         code.
275      */
276     public OCStackResult createGroup(String collectionResourceType) {
277         OCStackResult result = thingsManagerInterfaceObj.createGroup(collectionResourceType);
278         if (OCStackResult.OC_STACK_OK != result) {
279             Log.e(LOG_TAG, "createGroup: returned error: " + result.name());
280         }
281
282         return result;
283     }
284
285     /**
286      * API for joining a group. This API is used for joining the resource
287      * to local group which is created using @createGroup API.
288      *
289      * @param collectionResourceType
290      *            resource type of a group to join.
291      * @param resourceHandle
292      *            resource handle to join a group.
293      *
294      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
295      *         code.
296      *
297      */
298     public OCStackResult joinGroup(String collectionResourceType,
299             OcResourceHandle resourceHandle) {
300         OCStackResult result = thingsManagerInterfaceObj.joinGroup(collectionResourceType,
301                               resourceHandle);
302         if (OCStackResult.OC_STACK_OK != result) {
303             Log.e(LOG_TAG, "joinGroup: returned error: " + result.name());
304         }
305
306         return result;
307     }
308
309     /**
310      * API for joining a group. This API is used for joining the resource to
311      * remote group.
312      *
313      * @param resource
314      *            group resource to join.
315      * @param resourceHandle
316      *            resource handle to join a group.
317      *
318      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
319      *         code.
320      *
321      */
322     public OCStackResult joinGroup(OcResource resource,
323             OcResourceHandle resourceHandle) throws OcException {
324         OCStackResult result = thingsManagerInterfaceObj.joinGroup(resource, resourceHandle);
325         if (OCStackResult.OC_STACK_OK != result) {
326             Log.e(LOG_TAG, "joinGroup: returned error: " + result.name());
327         }
328
329         return result;
330     }
331
332     /**
333      * API for leaving a joined local group.
334      *
335      * @param collectionResourceType
336      *            resource type of a group to leave.
337      * @param resourceHandle
338      *            resource handle to leave a group.
339      *
340      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
341      *         code.
342      *
343      */
344     public OCStackResult leaveGroup(String collectionResourceType,
345             OcResourceHandle resourceHandle) {
346         OCStackResult result = thingsManagerInterfaceObj.leaveGroup(collectionResourceType,
347                               resourceHandle);
348         if (OCStackResult.OC_STACK_OK != result) {
349             Log.e(LOG_TAG, "leaveGroup: returned error: " + result.name());
350         }
351
352         return result;
353     }
354
355     /**
356      * API for leaving a joined remote group.
357      *
358      * @param resource
359      *            resource of a group to leave.
360      * @param collectionResourceType
361      *            resource type of a group to leave.
362      * @param resourceHandle
363      *            resource handle to leave a group.
364      *
365      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
366      *         code.
367      *
368      */
369     public OCStackResult leaveGroup(OcResource resource, String collectionResourceType,
370             OcResourceHandle resourceHandle) {
371         OCStackResult result = thingsManagerInterfaceObj.leaveGroup(resource, collectionResourceType,
372                               resourceHandle);
373         if (OCStackResult.OC_STACK_OK != result) {
374             Log.e(LOG_TAG, "leaveGroup: returned error: " + result.name());
375         }
376
377         return result;
378     }
379
380     /**
381      * API for deleting a created group.
382      *
383      * @param collectionResourceType
384      *            resource type of a group to delete.
385      *
386      */
387     public void deleteGroup(String collectionResourceType) {
388         thingsManagerInterfaceObj.deleteGroup(collectionResourceType);
389     }
390
391     /**
392      * API for getting a list of local groups.
393      *
394      * @return Returns the map with the group resource type and group
395      *         resource handle on successs otherwise null.
396      *
397      */
398     public Map<String, OcResourceHandle> getGroupList() {
399        return thingsManagerInterfaceObj.getGroupList();
400     }
401
402     /**
403      * API for registering and binding a resource to group.
404      *
405      * @param resource
406      *            resource for register and bind to group. It has all data.
407      * @param collectionHandle
408      *            collection resource handle. It will be the added child
409      *            resource.
410      *
411      * @return OcResourceHandle - Child resource handle.
412      *
413      */
414     public OcResourceHandle bindResourceToGroup(OcResource resource,
415             OcResourceHandle collectionHandle)
416             throws OcException {
417         return thingsManagerInterfaceObj.bindResourceToGroup(resource,
418                               collectionHandle);
419     }
420
421     /**
422      * API for updating configuration value of multiple things of a target group
423      * or a single thing to a resource server(s).
424      *
425      * <p>
426      * Listener should be set using setConfigurationListener API.
427      * <p>
428      * Listener IConfigurationListener::onUpdateConfigurationsCallback will be
429      * notified when the response of update configuration arrives.
430      *
431      * @param resource
432      *            resource representing the target group or the single thing.
433      *            It is a pointer of resource instance of Configuration
434      *            resource. The resource pointer can be acquired by performing
435      *            findResource() function with a dedicated resource type,
436      *            "oic.con". Note that, the resource pointer represents not only
437      *            a single simple resource but also a collection resource
438      *            composing multiple simple resources. In other words, using
439      *            these APIs, developers can send a series of requests to
440      *            multiple things by calling the corresponding function at once.
441      * @param configurations
442      *            ConfigurationUnit: a nickname of attribute of target
443      *            resource (e.g., installed location, currency, (IP)address)
444      *            Value : a value to be updated. It represents an indicator of
445      *            which resource developers want to access and which value
446      *            developers want to update. Basically, developers could use a
447      *            resource URI to access a specific resource but a resource URI
448      *            might be hard for all developers to memorize lots of URIs,
449      *            especially in the case of long URIs. To relieve the problem,
450      *            Things Configuration introduces a easy-memorizing name, called
451      *            ConfigurationName, instead of URI. And ConfigurationValue used
452      *            in updateConfiguration() function indicates a value to be
453      *            updated. Note that, only one configuration parameter is
454      *            supported in this release. Multiple configuration parameters
455      *            will be supported in future release.
456      *
457      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
458      *         code.
459      *
460      */
461     public OCStackResult updateConfigurations(OcResource resource,
462             Map<String, String> configurations) throws OcException {
463         if (null == configurationListener) {
464             Log.e(LOG_TAG,"updateConfigurations: listener not set!");
465             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
466         }
467
468         OCStackResult result = thingsManagerInterfaceObj.updateConfigurations(resource,
469                               configurations);
470         if (OCStackResult.OC_STACK_OK != result) {
471             Log.e(LOG_TAG, "updateConfigurations: returned error: " + result.name());
472         }
473
474         return result;
475     }
476
477     /**
478      * API for getting configuration value of multiple things of a target group
479      * or a single thing.To get a value, users need to know a Configuration Name
480      * indicating the target resource. In this release, the Configuration Name
481      * is "configuration".An update value is not needed. After that, users store
482      * them in form of a Vector and then use a getConfigurations() function.
483      *
484      * @param resource
485      *            resource representing the target group or the single thing.
486      * @param configurations
487      *            ConfigurationUnit: a nickname of attribute of target
488      *            resource.
489      *
490      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
491      *         code.
492      *
493      */
494     public OCStackResult getConfigurations(OcResource resource,
495             Vector<String> configurations) throws OcException {
496         if (null == configurationListener) {
497             Log.e(LOG_TAG,"getConfigurations: listener not set!");
498             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
499         }
500
501         OCStackResult result = thingsManagerInterfaceObj.getConfigurations(resource,
502                               configurations);
503         if (OCStackResult.OC_STACK_OK != result) {
504             Log.e(LOG_TAG, "getConfigurations: returned error: " + result.name());
505         }
506
507         return result;
508     }
509
510     /**
511      * API for getting the list of supported configuration units (configurable
512      * parameters). It shows which Configuration Names are supported and their
513      * brief descriptions. This information is provided in JSON format.
514      *
515      * @return Returns the configuration list in JSON format.
516      *
517      */
518     public String getListOfSupportedConfigurationUnits() {
519         return thingsManagerInterfaceObj.getListOfSupportedConfigurationUnits();
520     }
521
522     /**
523      * API for bootstrapping system configuration parameters from a bootstrap
524      * server.
525      * <p>
526      * Listener should be set using setConfigurationListener API.
527      * <p>
528      * Listener IConfigurationListener::onBootStrapCallback will be
529      * notified when the response arrives.
530      *
531      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
532      *         code.
533      *
534      */
535     public OCStackResult doBootstrap() {
536         if (null == configurationListener) {
537             Log.e(LOG_TAG,"doBootstrap: listener not set!");
538             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
539         }
540
541         OCStackResult result = thingsManagerInterfaceObj.doBootstrap();
542         if (OCStackResult.OC_STACK_OK != result) {
543             Log.e(LOG_TAG, "doBootstrap: returned error: " + result.name());
544         }
545
546         return result;
547     }
548
549     /**
550      * API to is used to send a request to a server(thing or device) to be
551      * rebooted. On receiving the request, the server attempts to reboot itself
552      * in a deterministic time. The target thing could be a group of multiple
553      * things or a single thing.
554      * <p>
555      * Listener should be set using setDiagnosticsListener API.
556      * <p>
557      * Listener IDiagnosticsListener::onRebootCallback will be
558      * notified when the response arrives.
559      * @param resource
560      *            resource pointer representing the target group
561      *
562      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
563      *         code.
564      *
565      */
566     public OCStackResult reboot(OcResource resource) throws OcException {
567         if (null == diagnosticsListener) {
568             Log.e(LOG_TAG,"reboot: listener not set!");
569             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
570         }
571
572         OCStackResult result = thingsManagerInterfaceObj.reboot(resource);
573         if (OCStackResult.OC_STACK_OK != result) {
574             Log.e(LOG_TAG, "reboot: returned error: " + result.name());
575         }
576
577         return result;
578     }
579
580     /**
581      * API to restore all configuration parameters to default one on
582      * thing(device). All configuration parameters refers Configuration
583      * resource, which they could have been modified for various reasons (e.g.,
584      * for a request to update a value). If developers on the client want to
585      * restore the parameters, just use the factoryReset function.The target
586      * thing could be a group of multiple things or a single thing.
587      *
588      * <p>
589      * Listener should be set using setDiagnosticsListener API.
590      * <p>
591      * Listener IDiagnosticsListener::onFactoryResetCallback will be
592      * notified when the response arrives.
593      *
594      * @param resource
595      *            resource pointer representing the target group
596      *
597      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
598      *         code.
599      *
600      */
601     public OCStackResult factoryReset(OcResource resource) throws OcException {
602         if (null == diagnosticsListener) {
603             Log.e(LOG_TAG,"factoryReset: listener not set!");
604             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
605         }
606
607         OCStackResult result = thingsManagerInterfaceObj.factoryReset(resource);
608         if (OCStackResult.OC_STACK_OK != result) {
609             Log.e(LOG_TAG, "factoryReset: returned error: " + result.name());
610         }
611
612         return result;
613     }
614
615     /**
616      * API for adding a new ActionSet onto a specific resource.
617      *
618      * <p>
619      * Listener should be set using setActionListener API.
620      * <p>
621      * Listener IActionListener::onPutResponseCallback will be
622      * notified when the response of PUT operation arrives.
623      * @param resource
624      *            resource pointer of the group resource
625      * @param actionSet
626      *            pointer of ActionSet
627      *
628      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
629      *         code.
630      *
631      */
632     public OCStackResult addActionSet(OcResource resource, ActionSet actionSet)
633             throws OcException {
634         if (null == actionListener) {
635             Log.e(LOG_TAG,"addActionSet: listener not set!");
636             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
637         }
638
639         OCStackResult result = thingsManagerInterfaceObj
640                                   .addActionSet(resource, actionSet);
641         if (OCStackResult.OC_STACK_OK != result) {
642             Log.e(LOG_TAG, "addActionSet: returned error: " + result.name());
643         }
644
645         return result;
646     }
647
648     /**
649      * API for executing a specific ActionSet belonging to a specific resource.
650      *
651      * <p>
652      * Listener should be set using setActionListener API.
653      * <p>
654      * Listener IActionListener::onPostResponseCallback will be
655      * notified when the response of POST operation arrives.
656      *
657      * @param resource
658      *            resource pointer of the group resource
659      * @param actionsetName
660      *            ActionSet name for removing the ActionSet
661      *
662      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
663      *         code.
664      *
665      */
666     public OCStackResult executeActionSet(OcResource resource,
667             String actionsetName) throws OcException {
668         if (null == actionListener) {
669             Log.e(LOG_TAG,"executeActionSet: listener not set!");
670             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
671         }
672
673         OCStackResult result = thingsManagerInterfaceObj
674                                   .executeActionSet(resource, actionsetName);
675         if (OCStackResult.OC_STACK_OK != result) {
676             Log.e(LOG_TAG, "executeActionSet: returned error: " + result.name());
677         }
678
679         return result;
680     }
681
682     /**
683      * API for executing a specific ActionSet belonging to a specific resource.
684      *
685      * <p>
686      * Listener should be set using setActionListener API.
687      * <p>
688      * Listener IActionListener::onPostResponseCallback will be
689      * notified when the response of POST operation arrives.
690      *
691      * @param resource
692      *            resource pointer of the group resource
693      * @param actionsetName
694      *            ActionSet name for removing the ActionSet
695      * @param delay
696      *            Wait time for the ActionSet execution
697      *
698      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
699      *         code.
700      *
701      */
702     public OCStackResult executeActionSet(OcResource resource,
703             String actionsetName, long delay) throws OcException {
704         if (null == actionListener) {
705             Log.e(LOG_TAG,"executeActionSet: listener not set!");
706             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
707         }
708
709         OCStackResult result = thingsManagerInterfaceObj
710                                   .executeActionSet(resource, actionsetName, delay);
711         if (OCStackResult.OC_STACK_OK != result) {
712             Log.e(LOG_TAG, "executeActionSet: returned error: " + result.name());
713         }
714
715         return result;
716     }
717
718     /**
719      * API to cancel the existing ActionSet.
720      *
721      * <p>
722      * Listener should be set using setActionListener API.
723      * <p>
724      * Listener IActionListener::onPostResponseCallback will be
725      *       notified when the response of POST operation arrives.
726      * @param resource
727      *            resource pointer of the group resource.
728      * @param actionsetName
729      *            ActionSet name that has to be cancelled.
730      *
731      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
732      *         code.
733      *
734      */
735
736     public OCStackResult cancelActionSet(OcResource resource,
737             String actionsetName) throws OcException {
738         if (null == actionListener) {
739             Log.e(LOG_TAG,"cancelActionSet: listener not set!");
740             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
741         }
742
743         OCStackResult result = thingsManagerInterfaceObj.cancelActionSet(resource,
744                               actionsetName);
745         if (OCStackResult.OC_STACK_OK != result) {
746             Log.e(LOG_TAG, "cancelActionSet: returned error: " + result.name());
747         }
748
749         return result;
750     }
751
752     /**
753      * API to to get an existing ActionSet belonging to a specific resource.
754      *
755      * <p>
756      * Listener should be set using setActionListener API.
757      * <p>
758      * Listener IActionListener::onPostResponseCallback will be
759      * notified when the response of POST operation arrives.
760      * @param resource
761      *            resource pointer of the group resource
762      * @param actionsetName
763      *            ActionSet name for removing the ActionSet
764      *
765      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
766      *         code.
767      *
768      */
769     public OCStackResult getActionSet(OcResource resource, String actionsetName)
770             throws OcException {
771         if (null == actionListener) {
772             Log.e(LOG_TAG,"getActionSet: listener not set!");
773             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
774         }
775
776         OCStackResult result = thingsManagerInterfaceObj.getActionSet(resource,
777                                   actionsetName);
778         if (OCStackResult.OC_STACK_OK != result) {
779             Log.e(LOG_TAG, "getActionSet: returned error: " + result.name());
780         }
781
782         return result;
783     }
784
785     /**
786      * API to delete an existing ActionSet belonging to a specific resource.
787      *
788      * <p>
789      * Listener should be set using setActionListener API.
790      * <p>
791      * Listener IActionListener::onPutResponseCallback will be
792      * notified when the response of PUT operation arrives.
793      *
794      * @param resource
795      *            resource pointer of the group resource
796      * @param actionsetName
797      *            ActionSet name for removing the ActionSet
798      *
799      * @return OCStackResult - OC_STACK_OK on success, otherwise a failure error
800      *         code.
801      *
802      */
803     public OCStackResult deleteActionSet(OcResource resource,
804             String actionsetName) throws OcException {
805         if (null == actionListener) {
806             Log.e(LOG_TAG,"deleteActionSet: listener not set!");
807             return OCStackResult.OC_STACK_LISTENER_NOT_SET;
808         }
809
810         OCStackResult result = thingsManagerInterfaceObj.deleteActionSet(resource,
811                                   actionsetName);
812         if (OCStackResult.OC_STACK_OK != result) {
813             Log.e(LOG_TAG, "deleteActionSet: returned error: " + result.name());
814         }
815
816         return result;
817     }
818
819 }