Add freature of Scheduled Group Action.
authorHyunJun Kim <hyunjun2.kim@samsung.com>
Thu, 12 Mar 2015 02:16:03 +0000 (11:16 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 12 Mar 2015 07:41:19 +0000 (07:41 +0000)
We provide function of Scheduled Group Action.
It will send some action message
when preset time is expired.

And we need some function about the time.
These function will use for checking time.

Change-Id: Ib42941db257cd481be4ed6b7f1a8c1b28ff3809e
Signed-off-by: HyunJun Kim <hyunjun2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/436
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
22 files changed:
extlibs/timer/timer.c [new file with mode: 0755]
extlibs/timer/timer.h [new file with mode: 0755]
resource/csdk/SConscript [changed mode: 0644->0755]
resource/csdk/makefile [changed mode: 0644->0755]
resource/csdk/stack/include/internal/ocresource.h [changed mode: 0644->0755]
resource/csdk/stack/include/internal/oicgroup.h
resource/csdk/stack/src/oicgroup.c [changed mode: 0644->0755]
service/things-manager/SConscript
service/things-manager/sampleapp/linux/configuration/SConscript
service/things-manager/sampleapp/linux/configuration/makefile
service/things-manager/sampleapp/linux/groupaction/SConscript
service/things-manager/sampleapp/linux/groupaction/groupserver.cpp [changed mode: 0644->0755]
service/things-manager/sampleapp/linux/groupaction/makefile
service/things-manager/sampleapp/linux/groupsyncaction/SConscript
service/things-manager/sampleapp/linux/groupsyncaction/makefile
service/things-manager/sdk/build/linux/Makefile
service/things-manager/sdk/inc/ActionSet.h [changed mode: 0644->0755]
service/things-manager/sdk/inc/ThingsManager.h
service/things-manager/sdk/src/ActionSet.cpp [new file with mode: 0755]
service/things-manager/sdk/src/GroupManager.cpp [changed mode: 0644->0755]
service/things-manager/sdk/src/GroupManager.h
service/things-manager/sdk/src/ThingsManager.cpp

diff --git a/extlibs/timer/timer.c b/extlibs/timer/timer.c
new file mode 100755 (executable)
index 0000000..0dccd4e
--- /dev/null
@@ -0,0 +1,354 @@
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+
+
+#define _BSD_SOURCE
+
+#ifndef WITH_ARDUINO
+#include <pthread.h>
+#include <unistd.h>
+#include <memory.h>
+#include <stdlib.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+
+#include "timer.h"
+
+#define SECOND (1)
+
+#define TIMEOUTS 10
+
+#define TIMEOUT_USED   1
+#define TIMEOUT_UNUSED  2
+
+#ifndef WITH_ARDUINO
+pthread_t thread_id = 0; // 0: initial thread id (meaningless)
+#endif
+
+struct timelist_t
+{
+    int timeout_state;
+    time_t timeout_seconds;
+    time_t timeout_time;
+    void (*cb)();
+} timeout_list[TIMEOUTS];
+
+/*
+ * Return the number of seconds between before and after, (after - before).
+ * This must be async-signal safe, so it cannot use difftime().
+ */
+time_t timespec_diff(const time_t after, const time_t before)
+{
+    return after - before;
+}
+
+/*
+ * Add positive seconds to a timespec, nothing if seconds is negative.
+ */
+void timespec_add(time_t * to, const time_t seconds)
+{
+    if (to && seconds > 0)
+    {
+        (*to) += seconds;
+    }
+}
+
+#ifndef WITH_ARDUINO
+
+long int getSeconds(struct tm* tp)
+{
+    long int nInterval = 0;
+
+    nInterval = (tp->tm_hour * SECS_PER_HOUR);
+    nInterval += (tp->tm_min * SECS_PER_MIN);
+    nInterval += (tp->tm_sec * SECOND);
+
+    printf("%ld", nInterval);
+
+    return nInterval;
+}
+
+long int getRelativeSecondsOfDayofweek(int ia, int ib)
+{
+    if( ia > ib )
+        return (((long int)(7 - (ib - ia))) * SECS_PER_DAY);
+
+    return (((long int)((ib - ia))) * SECS_PER_DAY);
+}
+
+long int getRelativeIntervalOfWeek(struct tm* tp)
+{
+    time_t current_time;
+    struct tm* current, *midnight;
+    time_t delayed_time = 0;
+
+    time(&current_time);
+    current = localtime(&current_time);
+    midnight = (struct tm* )malloc(sizeof(struct tm));
+    memcpy(midnight, current, sizeof(struct tm));
+
+    midnight->tm_hour = 0;
+    midnight->tm_min = 0;
+    midnight->tm_sec = 0;
+
+    // Seconds.
+    // Seconds from midnight.
+    delayed_time = current_time - mktime(midnight);
+    delayed_time = getRelativeSecondsOfDayofweek(current->tm_wday, tp->tm_wday) - delayed_time;
+    delayed_time = delayed_time + getSeconds(tp);
+
+    return delayed_time;
+}
+
+long int getSecondsFromAbsTime(struct tm* tp)
+{
+   time_t current_time;
+   time_t delayed_time = 0;
+
+   time(&current_time);
+   localtime(&current_time);
+
+   delayed_time = mktime(tp) - current_time;
+
+   return delayed_time;
+}
+
+time_t registerTimer(const time_t seconds, int *id, void *cb)
+{
+    time_t now, then;
+    time_t next;
+    int i, idx;
+
+    if (0 == thread_id)
+    {
+        initThread();
+    }
+
+    if (seconds <= 0)
+        return -1 ;
+
+    // get the current time
+    time(&now);
+
+    for (idx = 0; idx < TIMEOUTS; ++idx)
+        if (!((timeout_list[idx].timeout_state & TIMEOUT_USED) & TIMEOUT_USED))
+            break;
+
+    if (TIMEOUTS == idx) // reach to end of timer list
+        return -1;
+
+    // idx th timeout will be used.
+    // Reset and set state of the timer
+    timeout_list[idx].timeout_state = 0;
+    timeout_list[idx].timeout_state |= TIMEOUT_USED;
+
+    // calculate when the timeout should fire
+    then = now;
+    timespec_add(&then, seconds);
+
+    timeout_list[idx].timeout_time = then;
+    timeout_list[idx].timeout_seconds = seconds;
+
+    // printf( "\nbefore timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
+    timeout_list[idx].cb = cb;
+    // printf( " after timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
+
+    // How long till the next timeout?
+    next = seconds;
+    for (i = 0; i < TIMEOUTS; i++)
+    {
+        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED)) == TIMEOUT_USED)
+        {
+            const time_t secs = timespec_diff(timeout_list[i].timeout_time, now);
+
+            if (secs >= 0 && secs < next)
+                next = secs;
+        }
+    }
+
+    *id = idx;
+    /* Return the timeout number. */
+    return timeout_list[idx].timeout_time;
+}
+
+void unregisterTimer(int idx)
+{
+    if( 0 <= idx && idx <= TIMEOUTS)
+        timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
+}
+
+void checkTimeout()
+{
+    time_t now;
+    int i;
+
+    time(&now);
+
+    /* Check all timeouts that are used and armed, but not passed yet. */
+    for (i = 0; i < TIMEOUTS; i++)
+    {
+        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED)) == TIMEOUT_USED)
+        {
+            const time_t seconds = timespec_diff(timeout_list[i].timeout_time, now);
+
+            if (seconds <= 0)
+            {
+                /* timeout [i] fires! */
+                timeout_list[i].timeout_state = TIMEOUT_UNUSED;
+                if (timeout_list[i].cb)
+                {
+                    timeout_list[i].cb();
+                }
+            }
+        }
+    }
+}
+
+void *loop(void *threadid)
+{
+    while (1)
+    {
+        sleep(SECOND);
+        checkTimeout();
+    }
+
+    return NULL ;
+}
+
+int initThread()
+{
+    int res;
+    long t = 0;
+
+    res = pthread_create(&thread_id, NULL, loop, (void *) t);
+
+    if (res)
+    {
+        printf("ERROR; return code from pthread_create() is %d\n", res);
+        return -1;
+    }
+
+    return 0;
+}
+#else   // WITH_ARDUINO
+time_t timeToSecondsFromNow(tmElements_t *t_then)
+{
+    time_t t, then;
+
+    t = now();
+    then = makeTime((*t_then));
+
+    return (time_t) (then - t);
+}
+
+time_t registerTimer(const time_t seconds, int *id,  void (*cb)())
+{
+    time_t t, then;
+    time_t next;
+    int i, idx;
+
+    if (seconds <= 0)
+    return -1;
+
+    // get the current time
+    t = now();
+
+    for (idx = 0; idx < TIMEOUTS; ++idx)
+    if (!((timeout_list[idx].timeout_state & TIMEOUT_USED) & TIMEOUT_USED))
+    break;
+
+    if (TIMEOUTS == idx)// reach to end of timer list
+    return -1;
+
+    // idx th timeout will be used.
+    // Reset and set state of the timer
+    timeout_list[idx].timeout_state = 0;
+    timeout_list[idx].timeout_state |= TIMEOUT_USED;
+
+    // calculate when the timeout should fire
+    then = t;
+    timespec_add(&then, seconds);
+
+    timeout_list[idx].timeout_time = then;
+    timeout_list[idx].timeout_seconds = seconds;
+
+    // printf( "\nbefore timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
+    timeout_list[idx].cb = cb;
+    // printf( " after timeout_list[idx].cb = %X\n", timeout_list[idx].cb);
+
+    // How long till the next timeout?
+    next = seconds;
+    for (i = 0; i < TIMEOUTS; i++)
+    {
+        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED))
+                == TIMEOUT_USED)
+        {
+            const time_t secs = timespec_diff(timeout_list[i].timeout_time,
+                    t);
+
+            if (secs >= 0 && secs < next)
+            next = secs;
+        }
+    }
+
+    *id = idx;
+    /* Return the timeout number. */
+    return timeout_list[idx].timeout_time;
+}
+
+void unregisterTimer(int idx)
+{
+    if( 0 <= idx && idx <= TIMEOUTS)
+        timeout_list[idx].timeout_state = TIMEOUT_UNUSED;
+}
+
+void checkTimeout()
+{
+    time_t t;
+    int i;
+
+    t = now();
+
+    /* Check all timeouts that are used and armed, but not passed yet. */
+    for (i = 0; i < TIMEOUTS; i++)
+    {
+        if ((timeout_list[i].timeout_state & (TIMEOUT_USED | TIMEOUT_UNUSED))
+                == TIMEOUT_USED)
+        {
+            const time_t seconds = timespec_diff(timeout_list[i].timeout_time,
+                    t);
+
+            if (seconds <= 0)
+            {
+                /* timeout [i] fires! */
+                timeout_list[i].timeout_state = TIMEOUT_UNUSED;
+                if (timeout_list[i].cb)
+                {
+                    timeout_list[i].cb();
+                }
+            }
+        }
+    }
+}
+
+#endif
diff --git a/extlibs/timer/timer.h b/extlibs/timer/timer.h
new file mode 100755 (executable)
index 0000000..3ecff36
--- /dev/null
@@ -0,0 +1,74 @@
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#ifndef TIMER_H_
+#define TIMER_H_
+
+#ifndef WITH_ARDUINO
+#include <sys/time.h>
+#else
+#include <Time.h>
+#endif
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <math.h>
+
+#ifndef WITH_ARDUINO
+#define SECS_PER_MIN  (60L)
+#define SECS_PER_HOUR (SECS_PER_MIN * 60L)
+#define SECS_PER_DAY  (SECS_PER_HOUR * 24L)
+#define DAYS_PER_WEEK (7L)
+#define SECS_PER_WEEK (SECS_PER_DAY * DAYS_PER_WEEK)
+#define SECS_PER_YEAR (SECS_PER_WEEK * 52L)
+#define SECS_YR_2000  (946684800L)
+#endif
+
+time_t timespec_diff(const time_t after, const time_t before);
+void timespec_add(time_t * to, const time_t seconds);
+void checkTimeout();
+
+#ifndef WITH_ARDUINO
+long int getSeconds(struct tm* tp);
+long int getRelativeIntervalOfWeek(struct tm* tp);
+long int getSecondsFromAbsTime(struct tm* tp);
+
+int initThread();
+void *loop(void *threadid);
+time_t registerTimer(const time_t seconds, int *id, void *cb);
+void unregisterTimer(int id);
+
+#else
+
+time_t timeToSecondsFromNow(tmElements_t *t);
+time_t registerTimer(const time_t seconds, int *id,  void (*cb)());
+void unregisterTimer(int id);
+
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* TIMER_H_ */
+
old mode 100644 (file)
new mode 100755 (executable)
index 98af56b..83e9bfa
@@ -17,6 +17,7 @@ if target_os == 'arduino':
 ######################################################################
 liboctbstack_env.PrependUnique(CPPPATH = [
                '../../extlibs/cjson/',
+               '../../extlibs/timer/',
                'ocsocket/include',
                'logger/include',
                'ocrandom/include',
@@ -53,6 +54,7 @@ if not env.get('RELEASE'):
 OCTBSTACK_SRC = 'stack/src/'
 liboctbstack_src = [
        '../../extlibs/cjson/cJSON.c',
+       '../../extlibs/timer/timer.c',
        'occoap/src/occoap.c',
        'occoap/src/occoaphelper.c',
        OCTBSTACK_SRC + 'ocstack.c',
old mode 100644 (file)
new mode 100755 (executable)
index ca77f30..a8c6808
@@ -90,12 +90,14 @@ OCTBSTACK_DIR       = stack
 OCMALLOC_DIR   = ocmalloc
 EXTLIBS_DIR    = ../../extlibs
 CJSON_DIR      = $(EXTLIBS_DIR)/cjson
+TIMER_DIR      = $(EXTLIBS_DIR)/timer
 TINYDTLS_DIR   = $(EXTLIBS_DIR)/tinydtls
 
 OCCOAP_SRC     = $(OCCOAP_DIR)/src
 OCTBSTACK_SRC  = $(OCTBSTACK_DIR)/src
 OCMALLOC_SRC   = $(OCMALLOC_DIR)/src
 CJSON_SRC      = $(CJSON_DIR)
+TIMER_SRC      = $(TIMER_DIR)
 
 OCLOGGER_INC   = $(OCLOGGER_DIR)/include
 OC_LOG_INC     = $(OC_LOG_DIR)/include
@@ -106,6 +108,7 @@ OCCOAP_INC  = $(OCCOAP_DIR)/include
 OCTBSTACK_INC  = $(OCTBSTACK_DIR)/include
 OCMALLOC_INC   = $(OCMALLOC_DIR)/include
 CJSON_INC      = $(CJSON_DIR)
+TIMER_INC      = $(TIMER_DIR)
 
 INC_DIRS       := -I$(OCLOGGER_INC)
 INC_DIRS       += -I$(OC_LOG_INC)
@@ -117,6 +120,7 @@ INC_DIRS    += -I$(OCMALLOC_INC)
 INC_DIRS       += -I$(OCTBSTACK_INC)
 INC_DIRS       += -I$(OCTBSTACK_INC)/internal
 INC_DIRS       += -I$(CJSON_INC)
+INC_DIRS       += -I$(TIMER_INC)
 
 CC_FLAGS.debug         := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
 CC_FLAGS.release       := -Os -Wall -c -fmessage-length=0 -fpic
@@ -125,6 +129,7 @@ CFLAGS              += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFOR
 LDLIBS         += -lcoap
 
 CJSON_SOURCES          := $(CJSON_SRC)/cJSON.c
+TIMER_SOURCES          := $(TIMER_SRC)/timer.c
 
 OCCOAP_SOURCES         := $(OCCOAP_SRC)/occoap.c
 OCCOAP_SOURCES         += $(OCCOAP_SRC)/occoaphelper.c
@@ -139,6 +144,7 @@ OCTBSTACK_SOURCES   += $(OCTBSTACK_SRC)/oicgroup.c
 OCTBSTACK_SOURCES      += $(OCTBSTACK_SRC)/ocsecurity.c
 
 SOURCES                        := $(CJSON_SOURCES)
+SOURCES                        += $(TIMER_SOURCES)
 SOURCES                        += $(OCCOAP_SOURCES)
 SOURCES                        += $(OCTBSTACK_SOURCES)
 
old mode 100644 (file)
new mode 100755 (executable)
index bbd652b..9fc21c8
@@ -74,17 +74,17 @@ typedef struct ocaction {
 } OCAction;
 
 // following structure will be created in occollection.
-typedef struct ocactionset {
-
+typedef struct ocactionset
+{
     struct ocactionset *next;
 
     char *actionsetName;
+    long int timesteps;
+    unsigned int type;
 
     OCAction* head;
 } OCActionSet;
 
-
-
 typedef struct resourcetype_t {
     struct resourcetype_t *next; // linked list; for multiple types on resource
 
index 612e074..3b0c784 100644 (file)
 #ifndef OIC_GROUP_H
 #define OIC_GROUP_H
 
-#include "ocstack.h"
 #include "ocstackinternal.h"
+#include "ocstack.h"
+#include "ocresource.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
 
 void AddCapability(OCCapability** head, OCCapability* node);
 
 void AddAction(OCAction** head, OCAction* node);
 
-void AddActionSet(OCActionSet **head, OCActionSet* node);
+OCStackResult AddActionSet(OCActionSet **head, OCActionSet* node);
 
 void DeleteCapability(OCCapability *del);
 
@@ -56,4 +61,9 @@ OCStackResult
 BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHandlerFlag flag*/,
         OCResource *resource, OCEntityHandlerRequest *ehRequest);
 
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
 #endif // OIC_GROUP_H
old mode 100644 (file)
new mode 100755 (executable)
index 4d73764..6024813
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
 #define _POSIX_C_SOURCE 200112L
+
 #include <string.h>
 
+#include "oicgroup.h"
 #include "cJSON.h"
 #include "ocmalloc.h"
-#include "oicgroup.h"
-#include "ocresource.h"
 #include "occollection.h"
 #include "logger.h"
+#include "timer.h"
+
+#ifndef WITH_ARDUINO
+#include <pthread.h>
+#endif
 
 #define TAG PCF("OICGROUP")
 
 #define ATTR_DELIMITER          "|"
 #define ATTR_ASSIGN             "="
 
+#define OIC_ACTION_PREFIX               "{\"oc\":[{\"rep\":{"
+#define VARIFY_POINTER_NULL(pointer, result, toExit) \
+    if(pointer == NULL) \
+    {\
+        result = OC_STACK_NO_MEMORY;\
+        goto toExit;\
+    }
+#define VARIFY_PARAM_NULL(pointer, result, toExit) \
+    if(pointer == NULL)\
+    {\
+        result = OC_STACK_INVALID_PARAM;\
+        goto exit;\
+    }
+
+#define OCFREE(pointer) \
+    { \
+        OCFree(pointer); \
+        pointer = NULL; \
+    }
+
+#ifndef WITH_ARDUINO
+pthread_mutex_t lock;
+#endif
+
+enum ACTION_TYPE
+{
+    NONE = 0, SCHEDULED, RECURSIVE
+};
+
+typedef struct scheduledresourceinfo
+{
+    OCResource *resource;
+    OCActionSet *actionset;
+
+    int timer_id;
+
+    OCServerRequest *ehRequest;
+
+    time_t time;
+    struct scheduledresourceinfo* next;
+} ScheduledResourceInfo;
+
+ScheduledResourceInfo *scheduleResourceList = NULL;
+
+void AddScheduledResource(ScheduledResourceInfo **head,
+        ScheduledResourceInfo* add)
+{
+    OC_LOG(INFO, TAG, PCF("AddScheduledResource Entering..."));
+
+#ifndef WITH_ARDUINO
+    pthread_mutex_lock(&lock);
+#endif
+    ScheduledResourceInfo *tmp = NULL;
+
+    if (*head != NULL)
+    {
+        tmp = *head;
+
+        while (tmp->next)
+        {
+            tmp = tmp->next;
+        }
+        tmp->next = add;
+    }
+    else
+    {
+        *head = add;
+    }
+#ifndef WITH_ARDUINO
+    pthread_mutex_unlock(&lock);
+#endif
+}
+
+ScheduledResourceInfo* GetScheduledResource(ScheduledResourceInfo *head)
+{
+    OC_LOG(INFO, TAG, PCF("GetScheduledResource Entering..."));
+
+#ifndef WITH_ARDUINO
+    pthread_mutex_lock(&lock);
+#endif
+
+    time_t t_now;
+
+    ScheduledResourceInfo *tmp = NULL;
+    tmp = head;
+
+#ifndef WITH_ARDUINO
+    time(&t_now);
+#else
+    t_now = now();
+#endif
+
+    if (tmp)
+    {
+        while (tmp)
+        {
+            time_t diffTm = 0;
+#ifndef WITH_ARDUINO
+            diffTm = timespec_diff(tmp->time, t_now);
+#else
+            diffTm = timespec_diff(tmp->time, t_now);
+#endif
+
+            if (diffTm <= (time_t) 0)
+            {
+                OC_LOG(INFO, TAG, PCF("return Call INFO."));
+                goto exit;
+            }
+
+            tmp = tmp->next;
+        }
+    }
+
+    exit:
+#ifndef WITH_ARDUINO
+    pthread_mutex_unlock(&lock);
+#endif
+    if (tmp == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Cannot Find Call Info."));
+    }
+    return tmp;
+}
+
+ScheduledResourceInfo* GetScheduledResourceByActionSetName(ScheduledResourceInfo *head, char *setName)
+{
+    OC_LOG(INFO, TAG, PCF("GetScheduledResourceByActionSetName Entering..."));
+
+#ifndef WITH_ARDUINO
+    pthread_mutex_lock(&lock);
+#endif
+    ScheduledResourceInfo *tmp = NULL;
+    tmp = head;
+
+    if (tmp)
+    {
+        while (tmp)
+        {
+            if (strcmp(tmp->actionset->actionsetName, setName) == 0)
+            {
+                OC_LOG(INFO, TAG, PCF("return Call INFO."));
+                goto exit;
+            }
+            tmp = tmp->next;
+        }
+    }
+
+exit:
+#ifndef WITH_ARDUINO
+    pthread_mutex_unlock(&lock);
+#endif
+    if (tmp == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Cannot Find Call Info."));
+    }
+    return tmp;
+}
+
+void RemoveScheduledResource(ScheduledResourceInfo **head,
+        ScheduledResourceInfo* del)
+{
+#ifndef WITH_ARDUINO
+    pthread_mutex_lock(&lock);
+#endif
+    OC_LOG(INFO, TAG, PCF("RemoveScheduledResource Entering..."));
+    ScheduledResourceInfo *tmp = NULL;
+
+    if (del == NULL)
+    {
+        return;
+    }
+
+    if (*head == del)
+    {
+        *head = (*head)->next;
+    }
+    else
+    {
+        tmp = *head;
+        while (tmp->next && (tmp->next != del))
+        {
+            tmp = tmp->next;
+        }
+        if (tmp->next)
+        {
+            tmp->next = del->next;
+        }
+    }
+
+    OCFREE(del)
+#ifndef WITH_ARDUINO
+    pthread_mutex_unlock(&lock);
+#endif
+}
+
 typedef struct aggregatehandleinfo
 {
     OCServerRequest *ehRequest;
@@ -44,9 +244,6 @@ typedef struct aggregatehandleinfo
     struct aggregatehandleinfo *next;
 } ClientRequstInfo;
 
-// unsigned int nHandleIdx = 0;
-// ClientRequstInfo g_AggregateResponseHandle[10];
-
 ClientRequstInfo *clientRequstList = NULL;
 
 void AddClientRequestInfo(ClientRequstInfo **head, ClientRequstInfo* add)
@@ -69,7 +266,8 @@ void AddClientRequestInfo(ClientRequstInfo **head, ClientRequstInfo* add)
     }
 }
 
-ClientRequstInfo* GetClientRequestInfo(ClientRequstInfo *head, OCDoHandle handle)
+ClientRequstInfo* GetClientRequestInfo(ClientRequstInfo *head,
+        OCDoHandle handle)
 {
     ClientRequstInfo *tmp = NULL;
 
@@ -79,7 +277,6 @@ ClientRequstInfo* GetClientRequestInfo(ClientRequstInfo *head, OCDoHandle handle
     {
         while (tmp)
         {
-//            printf("%p :: %p\n", tmp->required, handle);
             if (tmp->required == handle)
             {
                 break;
@@ -88,7 +285,6 @@ ClientRequstInfo* GetClientRequestInfo(ClientRequstInfo *head, OCDoHandle handle
             tmp = tmp->next;
         }
 
-        return tmp;
     }
     return NULL;
 }
@@ -97,6 +293,9 @@ void RemoveClientRequestInfo(ClientRequstInfo **head, ClientRequstInfo* del)
 {
     ClientRequstInfo *tmp = NULL;
 
+    if (del == NULL)
+        return;
+
     if (*head == del)
     {
         *head = (*head)->next;
@@ -115,8 +314,6 @@ void RemoveClientRequestInfo(ClientRequstInfo **head, ClientRequstInfo* del)
     }
 }
 
-
-
 void AddCapability(OCCapability** head, OCCapability* node)
 {
     OCCapability *pointer = *head;
@@ -154,31 +351,46 @@ void AddAction(OCAction** head, OCAction* node)
     }
 }
 
-void AddActionSet(OCActionSet **head, OCActionSet* node)
+OCStackResult AddActionSet(OCActionSet **head, OCActionSet* node)
 {
     OCActionSet *pointer = *head;
+    OCActionSet *prev = NULL;
+    if(node == NULL)
+    {
+        return OC_STACK_ERROR;
+    }
     if (NULL == pointer)
     {
         *head = node;
     }
     else
     {
-
-        while (pointer->next != NULL)
+        prev = pointer;
+        while (pointer != NULL)
         {
+            // check the uniqeness of actionsetname.
+            if (strcmp(pointer->actionsetName, node->actionsetName) == 0)
+            {
+                return OC_STACK_ERROR;
+            }
+
+            prev = pointer;
             pointer = pointer->next;
         }
 
-        pointer->next = node;
+        prev->next = node;
     }
+
+    return OC_STACK_OK;
 }
 
 void DeleteCapability(OCCapability *del)
 {
-    free(del->capability);
+    OCFREE(del->capability)
     del->capability = NULL;
-    free(del->status);
+    OCFREE(del->status)
     del->status = NULL;
+    OCFREE(del)
 }
 
 void DeleteAction(OCAction** action)
@@ -194,13 +406,16 @@ void DeleteAction(OCAction** action)
         DeleteCapability(pDel);
         pDel->next = NULL;
     }
-    OCFree((*action)->resourceUri);
-    (*action)->resourceUri = NULL;
+    OCFREE((*action)->resourceUri)
     (*action)->next = NULL;
+    OCFREE(*action)
 }
 
 void DeleteActionSet(OCActionSet** actionset)
 {
+    if(*actionset == NULL)
+        return;
+
     OCAction* pointer = (*actionset)->head;
     OCAction* pDel = NULL;
 
@@ -210,14 +425,14 @@ void DeleteActionSet(OCActionSet** actionset)
         pointer = pointer->next;
 
         DeleteAction(&pDel);
-        pDel->next = NULL;
     }
-
-    OCFree((*actionset)->actionsetName);
-    (*actionset)->head = NULL;
+    //    (*actionset)->head = NULL;
+    OCFREE((*actionset)->actionsetName)
+    OCFREE(*actionset)
 }
 
-OCStackResult FindAndDeleteActionSet(OCResource **resource, const char * actionsetName)
+OCStackResult FindAndDeleteActionSet(OCResource **resource,
+        const char * actionsetName)
 {
     if (*resource != NULL)
     {
@@ -238,6 +453,7 @@ OCStackResult FindAndDeleteActionSet(OCResource **resource, const char * actions
                     (*resource)->actionsetHead = pointer->next;
                 else
                     (*resource)->actionsetHead = NULL;
+
                 DeleteActionSet(&pointer);
             }
             else if (pointer->next != NULL)
@@ -246,7 +462,8 @@ OCStackResult FindAndDeleteActionSet(OCResource **resource, const char * actions
                 {
                     if (pointer->next != NULL)
                     {
-                        if (strcmp(pointer->next->actionsetName, actionsetName) == 0)
+                        if (strcmp(pointer->next->actionsetName, actionsetName)
+                                == 0)
                         {
                             pDel = pointer->next;
                             pointer->next = pointer->next->next;
@@ -283,7 +500,8 @@ OCStackResult DeleteActionSets(OCResource** resource)
     return OC_STACK_OK;
 }
 
-OCStackResult GetActionSet(const char *actionName, OCActionSet *head, OCActionSet** actionset)
+OCStackResult GetActionSet(const char *actionName, OCActionSet *head,
+        OCActionSet** actionset)
 {
     OCActionSet *pointer = head;
 
@@ -302,58 +520,67 @@ OCStackResult GetActionSet(const char *actionName, OCActionSet *head, OCActionSe
 
 }
 
-
-#define OIC_ACTION_PREFIX               "{\"oc\":[{\"rep\":{"
-#define VARIFY_POINTER_NULL(pointer, result, toExit) \
-    if(pointer == NULL) \
-    {\
-        result = OC_STACK_NO_MEMORY;\
-        goto toExit;\
-    }
-#define VARIFY_PARAM_NULL(pointer, result, toExit) \
-    if(pointer == NULL)\
-    {\
-        result = OC_STACK_INVALID_PARAM;\
-        goto exit;\
-    }
-
-OCStackResult ExtractKeyValueFromRequest(char *request, char **key, char **value)
+OCStackResult ExtractKeyValueFromRequest(char *request, char **key,
+        char **value)
 {
     OCStackResult result = OC_STACK_OK;
     size_t length = 0;
 
-    char* pRequest = (char *)request + strlen(OIC_ACTION_PREFIX);
+    char* pRequest = (char *) request + strlen(OIC_ACTION_PREFIX);
     char* iterToken, *iterTokenPtr;
 
     iterToken = (char *) strtok_r(pRequest, ":", &iterTokenPtr);
     length = strlen(iterToken) + 1;
 
-    *key = (char *)OCMalloc(length);
-    VARIFY_POINTER_NULL(*key, result, exit);
+    *key = (char *) OCMalloc(length);
+    VARIFY_POINTER_NULL(*key, result, exit)
 
     strncpy(*key, iterToken + 1, length);
-    ((*key)[ (( length - 1 ) - 2) ]) = '\0';
+    ((*key)[((length - 1) - 2)]) = '\0';
 
     iterToken = (char *) strtok_r(NULL, "}", &iterTokenPtr);
     length = strlen(iterToken) + 1;
 
-    *value = (char *)OCMalloc(length);
-    VARIFY_POINTER_NULL(*key, result, exit);
+    *value = (char *) OCMalloc(length);
+    VARIFY_POINTER_NULL(*value, result, exit)
 
     strncpy(*value, iterToken + 1, length);
-    ((*value)[ (( length - 1 ) - 2) ]) = '\0';
+    ((*value)[((length - 1) - 2)]) = '\0';
+
 exit:
-    if(result != OC_STACK_OK)
+    if (result != OC_STACK_OK)
     {
-        OCFree(*key);
-        OCFree(*value);
-        *key = NULL;
-        *value = NULL;
+        OCFREE(*key)
+        OCFREE(*value)
     }
 
     return result;
 }
 
+OCStackResult ExtractActionSetNameAndDelaytime(char *pChar, char **setName,
+        long int *pa)
+{
+    char *token, *tokenPtr;
+    OCStackResult result = OC_STACK_OK;
+
+    token = (char*) strtok_r(pChar, ACTION_DELIMITER, &tokenPtr);
+    *setName = (char *) OCMalloc(strlen(token) + 1);
+    VARIFY_POINTER_NULL(*setName, result, exit)
+    VARIFY_PARAM_NULL(token, result, exit)
+    strncpy(*setName, token, strlen(token) + 1);
+
+    token = strtok_r(NULL, ACTION_DELIMITER, &tokenPtr);
+    VARIFY_POINTER_NULL(pa, result, exit)
+    VARIFY_PARAM_NULL(token, result, exit)
+    *pa = atoi(token);
+
+    return OC_STACK_OK;
+
+exit:
+    OCFREE(*setName);
+    return result;
+}
+
 OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
 {
     OCStackResult result = OC_STACK_OK;
@@ -374,62 +601,85 @@ OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
 
     iterToken = (char *) strtok_r(actiondesc, ACTION_DELIMITER, &iterTokenPtr);
 
+    // ActionSet Name
     memset(*set, 0, sizeof(OCActionSet));
-    (*set)->actionsetName = (char *)OCMalloc(sizeof(OCActionSet));
+    (*set)->actionsetName = (char *) OCMalloc(strlen(iterToken) + 1);
     VARIFY_POINTER_NULL((*set)->actionsetName, result, exit)
     VARIFY_PARAM_NULL(iterToken, result, exit)
     strncpy((*set)->actionsetName, iterToken, strlen(iterToken) + 1);
 
+    // Time info. for Scheduled/Recursive Group action.
+    // d is meant Day of the week.
+    // T is meant ActionType.
+    // yyyy-mm-dd hh:mm:ss d
+    iterToken = (char *) strtok_r(NULL, ACTION_DELIMITER, &iterTokenPtr);
+    VARIFY_PARAM_NULL(iterToken, result, exit)
+#ifndef WITH_ARDUINO
+    sscanf(iterToken, "%ld %d", &(*set)->timesteps, &(*set)->type);
+#endif
+
     OC_LOG_V(INFO, TAG, "ActionSet Name : %s", (*set)->actionsetName);
 
     iterToken = (char *) strtok_r(NULL, ACTION_DELIMITER, &iterTokenPtr);
-    while(iterToken)
+    while (iterToken)
     {
-        desc = (char *)OCMalloc(strlen(iterToken) + 1);
+        desc = (char *) OCMalloc(strlen(iterToken) + 1);
+        VARIFY_POINTER_NULL(desc, result, exit)
+        VARIFY_PARAM_NULL(desc, result, exit)
         strncpy(desc, iterToken, strlen(iterToken) + 1);
-        descIterToken = (char *) strtok_r(desc, ATTR_DELIMITER, &descIterTokenPtr);
-        while(descIterToken)
+        descIterToken = (char *) strtok_r(desc, ATTR_DELIMITER,
+                &descIterTokenPtr);
+        while (descIterToken)
         {
-            attr = (char *)OCMalloc(strlen(descIterToken) + 1);
+            attr = (char *) OCMalloc(strlen(descIterToken) + 1);
+            VARIFY_POINTER_NULL(attr, result, exit)
+            VARIFY_PARAM_NULL(descIterToken, result, exit)
             strncpy(attr, descIterToken, strlen(descIterToken) + 1);
 
-            attrIterToken = (char *) strtok_r(attr, ATTR_ASSIGN, &attrIterTokenPtr);
-            key = (char *)OCMalloc(strlen(attrIterToken) + 1);
+            attrIterToken = (char *) strtok_r(attr, ATTR_ASSIGN,
+                    &attrIterTokenPtr);
+            key = (char *) OCMalloc(strlen(attrIterToken) + 1);
             VARIFY_POINTER_NULL(key, result, exit)
-
             VARIFY_PARAM_NULL(attrIterToken, result, exit)
             strncpy(key, attrIterToken, strlen(attrIterToken) + 1);
-            attrIterToken = (char *) strtok_r(NULL, ATTR_ASSIGN, &attrIterTokenPtr);
 
-            value = (char *)OCMalloc(strlen(attrIterToken) + 1);
+            attrIterToken = (char *) strtok_r(NULL, ATTR_ASSIGN,
+                    &attrIterTokenPtr);
+            value = (char *) OCMalloc(strlen(attrIterToken) + 1);
             VARIFY_POINTER_NULL(value, result, exit)
             VARIFY_PARAM_NULL(attrIterToken, result, exit)
             strncpy(value, attrIterToken, strlen(attrIterToken) + 1);
 
-            if(strcmp(key, "uri") == 0)
+            if (strcmp(key, "uri") == 0)
             {
                 OC_LOG(INFO, TAG, PCF("Build OCAction Instance."));
 
-                action = (OCAction*)OCMalloc(sizeof(OCAction));
+                action = (OCAction*) OCMalloc(sizeof(OCAction));
                 VARIFY_POINTER_NULL(action, result, exit)
                 memset(action, 0, sizeof(OCAction));
-                action->resourceUri = (char *)OCMalloc(strlen(value) + 1);
+                action->resourceUri = (char *) OCMalloc(strlen(value) + 1);
                 VARIFY_POINTER_NULL(action->resourceUri, result, exit)
                 VARIFY_PARAM_NULL(value, result, exit)
                 strncpy(action->resourceUri, value, strlen(value) + 1);
             }
             else
             {
-                if(key != NULL) && (value != NULL))
+                if ((key != NULL) && (value != NULL))
                 {
                     OC_LOG(INFO, TAG, PCF("Build OCCapability Instance."));
-                    capa = (OCCapability*)OCMalloc(sizeof(OCCapability));
+
+                    capa = (OCCapability*) OCMalloc(sizeof(OCCapability));
                     VARIFY_POINTER_NULL(capa, result, exit)
                     memset(capa, 0, sizeof(OCCapability));
-                    capa->capability = (char *)OCMalloc(strlen(key) + 1);
-                    capa->status = (char *)OCMalloc(strlen(value) + 1);
 
+                    capa->capability = (char *) OCMalloc(strlen(key) + 1);
+                    VARIFY_POINTER_NULL(capa->capability, result, exit)
+                    VARIFY_PARAM_NULL(key, result, exit)
                     strncpy(capa->capability, key, strlen(key) + 1);
+
+                    capa->status = (char *) OCMalloc(strlen(value) + 1);
+                    VARIFY_POINTER_NULL(capa->status, result, exit)
+                    VARIFY_PARAM_NULL(value, result, exit)
                     strncpy(capa->status, value, strlen(value) + 1);
 
                     VARIFY_POINTER_NULL(action, result, exit)
@@ -438,26 +688,30 @@ OCStackResult BuildActionSetFromString(OCActionSet **set, char* actiondesc)
                 }
             }
 
-            OCFree(key);
-            OCFree(value);
-            OCFree(attr);
+            OCFREE(key)
+            OCFREE(value)
+            OCFREE(attr)
 
-            descIterToken = (char *) strtok_r(NULL, ATTR_DELIMITER, &descIterTokenPtr);
+            descIterToken = (char *) strtok_r(NULL, ATTR_DELIMITER,
+                    &descIterTokenPtr);
         }
 
         AddAction(&(*set)->head, action);
         iterToken = (char *) strtok_r(NULL, ACTION_DELIMITER, &iterTokenPtr);
-        OCFree(desc);
+        OCFREE(desc);
     }
 
     return OC_STACK_OK;
 exit:
-    OCFree(attr);
-    OCFree(desc);
-    OCFree(capa);
-    OCFree(action);
-    OCFree(*set);
-    *set = NULL;
+    OCFREE(attr)
+    OCFREE(desc)
+    OCFREE(capa)
+    OCFREE(action)
+    OCFREE(*set)
+    OCFREE(key)
+    OCFREE(value)
+    OCFREE(attr)
+
     return result;
 }
 
@@ -466,17 +720,13 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
     char temp[1024] = { 0 };
     int remaining = 1023;
 
-    // OCActionSet *as = resource->actionsetHead;
-    // while(as != NULL)
-    // {
-    // printf("\n\n\nAction Set Name :: %s\n", actionset->actionsetName);
     OCAction *action = actionset->head;
 
     if (remaining >= strlen(actionset->actionsetName) + 1)
     {
         strcat(temp, actionset->actionsetName);
         remaining -= strlen(actionset->actionsetName);
-        strcat(temp, "*");
+        strcat(temp, ACTION_DELIMITER);
         remaining--;
     }
     else
@@ -486,7 +736,6 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
 
     while (action != NULL)
     {
-        printf("\tURI :: %s\n", action->resourceUri);
         strcat(temp, "uri=");
         remaining -= strlen("uri=");
         strcat(temp, action->resourceUri);
@@ -497,7 +746,6 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
         OCCapability *capas = action->head;
         while (capas != NULL)
         {
-            printf("\t\t%s = %s\n", capas->capability, capas->status);
             strcat(temp, capas->capability);
             remaining -= strlen(capas->capability);
             strcat(temp, "=");
@@ -515,16 +763,13 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
         action = action->next;
         if (action != NULL)
         {
-            strcat(temp, "*");
+            strcat(temp, ACTION_DELIMITER);
             remaining--;
         }
     }
-    //     as = as->next;
-    // }
 
     *desc = (char *) OCMalloc(1024 - remaining);
     strcpy(*desc, temp);
-    // printf("\t\tPlain Text = %s(%i)\n", *desc, 1024 - remaining);
 
     return OC_STACK_OK;
 }
@@ -532,7 +777,7 @@ OCStackResult BuildStringFromActionSet(OCActionSet* actionset, char** desc)
 OCStackApplicationResult ActionSetCB(void* context, OCDoHandle handle,
         OCClientResponse* clientResponse)
 {
-    printf("\n\n\tcallback is called\n\n");
+    OC_LOG(INFO, TAG, PCF("Entering BuildActionJSON"));
 
     ClientRequstInfo *info = GetClientRequestInfo(clientRequstList, handle);
 
@@ -542,12 +787,13 @@ OCStackApplicationResult ActionSetCB(void* context, OCDoHandle handle,
 
         unsigned char *responseJson;
         responseJson = (unsigned char *) OCMalloc(
-                (unsigned int) (strlen((char *) clientResponse->resJSONPayload) + 1));
+                (unsigned int) (strlen((char *) clientResponse->resJSONPayload)
+                        + 1));
 
         // We need the body of response.
         // Copy the body from the response
-        strcpy((char *) responseJson, ((char *) clientResponse->resJSONPayload
-                + OC_JSON_PREFIX_LEN));
+        strcpy((char *) responseJson,
+                ((char *) clientResponse->resJSONPayload + OC_JSON_PREFIX_LEN));
         idx = strlen((char *) responseJson) - OC_JSON_SUFFIX_LEN;
         // And insert NULL at the end of body.
         (responseJson[idx]) = 0;
@@ -563,22 +809,19 @@ OCStackApplicationResult ActionSetCB(void* context, OCDoHandle handle,
         OCDoResponse(&response);
 
         RemoveClientRequestInfo(&clientRequstList, info);
-        OCFree(responseJson);
+        OCFREE(info)
+        OCFREE(responseJson)
     }
 
-    // g_AggregateResponseHandle
-
     return OC_STACK_KEEP_TRANSACTION;
 }
 
 void ActionSetCD(void *context)
 {
-    // printf("\n\t\tCD is called\n");
-
-    // free( context );
 }
 
-OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr, uint16_t *remaining)
+OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr,
+        uint16_t *remaining)
 {
     OCStackResult ret = OC_STACK_ERROR;
     cJSON *json;
@@ -595,7 +838,8 @@ OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr, uint16
     OCCapability* pointerCapa = action->head;
     while (pointerCapa)
     {
-        cJSON_AddStringToObject(body, pointerCapa->capability, pointerCapa->status);
+        cJSON_AddStringToObject(body, pointerCapa->capability,
+                pointerCapa->status);
         pointerCapa = pointerCapa->next;
     }
 
@@ -618,20 +862,21 @@ OCStackResult BuildActionJSON(OCAction* action, unsigned char* bufferPtr, uint16
 
 unsigned int GetNumOfTargetResource(OCAction *actionset)
 {
-    int numOfREsource = 0;
+    int numOfResource = 0;
 
     OCAction *pointerAction = actionset;
 
     while (pointerAction != NULL)
     {
-        numOfREsource++;
+        numOfResource++;
         pointerAction = pointerAction->next;
     }
 
-    return numOfREsource;
+    return numOfResource;
 }
 
-OCStackResult SendAction(OCDoHandle *handle, const char *targetUri, const unsigned char *action)
+OCStackResult SendAction(OCDoHandle *handle, const char *targetUri,
+        const unsigned char *action)
 {
     OCCallbackData cbdata = { 0 };
     cbdata.cb = &ActionSetCB;
@@ -639,12 +884,125 @@ OCStackResult SendAction(OCDoHandle *handle, const char *targetUri, const unsign
     cbdata.context = (void *) 0x99;
 
     return OCDoResource(handle, OC_REST_PUT, targetUri,
-    //temp->rsrcType->resourcetypename,
-            NULL, (char *) action, OC_NA_QOS, &cbdata, NULL, 0);
+    NULL, (char *) action, OC_NA_QOS, &cbdata, NULL, 0);
+}
+
+OCStackResult DoAction(OCResource* resource, OCActionSet* actionset,
+        OCServerRequest* requestHandle)
+{
+    OCStackResult result = OC_STACK_ERROR;
+    OCAction *pointerAction = actionset->head;
+
+    while (pointerAction != NULL)
+    {
+        unsigned char actionDesc[MAX_RESPONSE_LENGTH] = { 0 };
+        unsigned char* actionDescPtr = actionDesc;
+        uint16_t remaining = MAX_RESPONSE_LENGTH;
+
+        strncpy((char *) actionDescPtr, (const char *) OC_JSON_PREFIX,
+                strlen((const char *) OC_JSON_PREFIX) + 1);
+        BuildActionJSON(pointerAction, actionDescPtr, &remaining);
+        strncat((char *) actionDescPtr, (const char *) OC_JSON_SUFFIX,
+                strlen((const char *) OC_JSON_SUFFIX));
+
+        ClientRequstInfo *info = (ClientRequstInfo *) OCMalloc(
+                sizeof(ClientRequstInfo));
+        memset(info, 0, sizeof(ClientRequstInfo));
+
+        info->collResource = resource;
+        info->ehRequest = requestHandle;
+
+        result = SendAction(&info->required, pointerAction->resourceUri,
+                actionDescPtr);
+        if (result != OC_STACK_OK)
+        {
+            return result;
+        }
+
+        AddClientRequestInfo(&clientRequstList, info);
+
+        pointerAction = pointerAction->next;
+    }
+
+    return result;
+}
+
+void DoScheduledGroupAction()
+{
+    OC_LOG(INFO, TAG, PCF("DoScheduledGroupAction Entering..."));
+    ScheduledResourceInfo* info = GetScheduledResource(scheduleResourceList);
+
+    if (info == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Target resource is NULL"));
+        goto exit;
+    }
+    else if (info->resource == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Target resource is NULL"));
+        goto exit;
+    }
+    else if (info->actionset == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Target ActionSet is NULL"));
+        goto exit;
+    }
+    else if (info->ehRequest == NULL)
+    {
+        OC_LOG(INFO, TAG, PCF("Target ActionSet is NULL"));
+        goto exit;
+    }
+#ifndef WITH_ARDUINO
+    pthread_mutex_lock(&lock);
+#endif
+    DoAction(info->resource, info->actionset, info->ehRequest);
+#ifndef WITH_ARDUINO
+    pthread_mutex_unlock(&lock);
+#endif
+
+    if (info->actionset->type == RECURSIVE)
+    {
+        ScheduledResourceInfo *schedule;
+        schedule = (ScheduledResourceInfo *) OCMalloc(
+                sizeof(ScheduledResourceInfo));
+
+        if (schedule)
+        {
+            OC_LOG(INFO, TAG, PCF("Building New Call Info."));
+            memset(schedule, 0, sizeof(ScheduledResourceInfo));
+
+            if (info->actionset->timesteps > 0)
+            {
+#ifndef WITH_ARDUINO
+                pthread_mutex_lock(&lock);
+#endif
+                schedule->resource = info->resource;
+                schedule->actionset = info->actionset;
+                schedule->ehRequest = info->ehRequest;
+
+                schedule->time = registerTimer(info->actionset->timesteps,
+                        &schedule->timer_id,
+                        &DoScheduledGroupAction);
+
+                OC_LOG(INFO, TAG, PCF("Reregisteration."));
+#ifndef WITH_ARDUINO
+                pthread_mutex_unlock(&lock);
+#endif
+                AddScheduledResource(&scheduleResourceList, schedule);
+            }
+        }
+    }
+
+    RemoveScheduledResource(&scheduleResourceList, info);
+
+    exit:
+
+    return;
 }
 
-OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHandlerFlag flag*/,
-        OCResource *resource, OCEntityHandlerRequest *ehRequest)
+OCStackResult BuildCollectionGroupActionJSONResponse(
+        OCMethod method/*OCEntityHandlerFlag flag*/, OCResource *resource,
+        OCEntityHandlerRequest *ehRequest)
 {
     OCStackResult stackRet = OC_STACK_ERROR;
 
@@ -664,12 +1022,12 @@ OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHa
 
         char *jsonResponse;
 
-        ExtractKeyValueFromRequest((char *)ehRequest->reqJSONPayload, &doWhat, &details);
+        ExtractKeyValueFromRequest((char *) ehRequest->reqJSONPayload, &doWhat,
+                &details);
 
         cJSON *json;
         cJSON *format;
 
-
         if (method == OC_REST_PUT)
         {
             json = cJSON_CreateObject();
@@ -678,15 +1036,26 @@ OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHa
 
             OC_LOG(INFO, TAG, PCF("Group Action[PUT]."));
 
-            if(strcmp(doWhat, "ActionSet") == 0)
+            if (strcmp(doWhat, "ActionSet") == 0)
             {
-                OCActionSet *actionSet;
-                BuildActionSetFromString(&actionSet, details);
+                OCActionSet *actionSet = NULL;
+                stackRet = BuildActionSetFromString(&actionSet, details);
 
-                if(actionSet != NULL)
+                if(stackRet == OC_STACK_OK)
                 {
-                    AddActionSet(&resource->actionsetHead, actionSet);
-                    stackRet = OC_STACK_OK;
+                    if (actionSet != NULL)
+                    {
+                        stackRet = AddActionSet(&resource->actionsetHead,
+                                actionSet);
+                        if (stackRet == OC_STACK_ERROR)
+                        {
+                            if(actionSet != NULL)
+                            {
+                                DeleteActionSet( &actionSet );
+                            }
+                            OC_LOG(INFO, TAG, PCF("Duplicated ActionSet "));
+                        }
+                    }
                 }
                 else
                 {
@@ -715,87 +1084,149 @@ OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHa
             if (bufferLength > 0)
             {
                 OCEntityHandlerResponse response = { 0 };
-                response.ehResult = OC_EH_OK;
+                if(stackRet == OC_STACK_OK)
+                    response.ehResult = OC_EH_OK;
+                else
+                    response.ehResult = OC_EH_ERROR;
                 response.payload = buffer;
                 response.payloadSize = bufferLength + 1;
                 response.persistentBufferFlag = 0;
-                response.requestHandle = (OCRequestHandle) ehRequest->requestHandle;
+                response.requestHandle =
+                        (OCRequestHandle) ehRequest->requestHandle;
                 response.resourceHandle = (OCResourceHandle) collResource;
                 stackRet = OCDoResponse(&response);
             }
-
-            stackRet = OC_STACK_OK;
         }
 
         if (method == OC_REST_POST)
         {
-            OC_LOG(INFO, TAG, PCF("Group Action[POST]."));
-
             OCActionSet *actionset = NULL;
 
             json = cJSON_CreateObject();
             cJSON_AddStringToObject(json, "href", resource->uri);
 
-            if (strcmp(doWhat, "DoAction") == 0)
+            if ((strcmp(doWhat, "DoAction") == 0)
+                    || (strcmp(doWhat, "DoScheduledAction") == 0))
             {
-                if (GetActionSet(details, resource->actionsetHead, &actionset) != OC_STACK_OK)
-                {
-                    OC_LOG(INFO, TAG, PCF("ERROR"));
-                    stackRet = OC_STACK_ERROR;
-                }
+                char *pActionsetName = NULL;
+                long int delay = -1;
 
-                if (actionset == NULL)
+                if (strcmp(doWhat, "DoScheduledAction") == 0)
                 {
-                    OC_LOG(INFO, TAG, PCF("ERROR"));
-                    stackRet = OC_STACK_ERROR;
+                    stackRet = ExtractActionSetNameAndDelaytime(details,
+                            &pActionsetName, &delay);
+
+                    OCFREE(details)
+                    details = pActionsetName;
                 }
                 else
                 {
+                    stackRet = OC_STACK_OK;
+                }
 
-                    OCAction *pointerAction = actionset->head;
-
-                    unsigned int num = GetNumOfTargetResource(pointerAction);
-
-                    ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
-                            HandleAggregateResponse;
-                    ((OCServerRequest *) ehRequest->requestHandle)->numResponses = num + 1;
-
-                    while (pointerAction != NULL)
+                if (stackRet == OC_STACK_OK)
+                {
+                    if (GetActionSet(details, resource->actionsetHead,
+                            &actionset) != OC_STACK_OK)
                     {
-                        unsigned char actionDesc[MAX_RESPONSE_LENGTH] = { 0 };
-                        unsigned char* actionDescPtr = actionDesc;
-                        uint16_t remaining = MAX_RESPONSE_LENGTH;
-
-                        strncpy((char *) actionDescPtr, (const char *) OC_JSON_PREFIX,
-                            strlen((const char *) OC_JSON_PREFIX) + 1);
-                        BuildActionJSON(pointerAction, actionDescPtr, &remaining);
-                        strncat((char *) actionDescPtr, (const char *) OC_JSON_SUFFIX,
-                            strlen((const char *) OC_JSON_SUFFIX));
-
-                        ClientRequstInfo *info = (ClientRequstInfo *) OCMalloc(
-                                sizeof(ClientRequstInfo));
-                        memset(info, 0, sizeof(ClientRequstInfo));
-
-                        info->collResource = resource;
-                        info->ehRequest = (OCServerRequest *) ehRequest->requestHandle;
-
-                        SendAction(&info->required, pointerAction->resourceUri, actionDescPtr);
-
-                        AddClientRequestInfo(&clientRequstList, info);
+                        OC_LOG(INFO, TAG, PCF("ERROR"));
+                        stackRet = OC_STACK_ERROR;
+                    }
 
-                        pointerAction = pointerAction->next;
+                    if (actionset == NULL)
+                    {
+                        OC_LOG(INFO, TAG, PCF("Cannot Find ActionSet"));
+                        stackRet = OC_STACK_ERROR;
                     }
+                    else
+                    {
+                        OC_LOG(INFO, TAG, PCF("Group Action[POST]."));
+                        if (actionset->type == NONE)
+                        {
+                            OC_LOG_V(INFO, TAG, "Execute ActionSet : %s",
+                                    actionset->actionsetName);
+                            unsigned int num = GetNumOfTargetResource(
+                                    actionset->head);
+
+                            ((OCServerRequest *) ehRequest->requestHandle)->ehResponseHandler =
+                                    HandleAggregateResponse;
+                            ((OCServerRequest *) ehRequest->requestHandle)->numResponses =
+                                    num + 1;
+
+                            DoAction(resource, actionset,
+                                    (OCServerRequest*) ehRequest->requestHandle);
+                            stackRet = OC_STACK_OK;
+                        }
+                        else
+                        {
+                            OC_LOG_V(INFO, TAG, "Execute Scheduled ActionSet : %s",
+                                    actionset->actionsetName);
+
+                            delay =
+                                    (delay == -1 ? actionset->timesteps : delay);
+
+                            ScheduledResourceInfo *schedule;
+                            schedule = (ScheduledResourceInfo *) OCMalloc(
+                                    sizeof(ScheduledResourceInfo));
+
+                            if (schedule)
+                            {
+                                OC_LOG(INFO, TAG, PCF("Building New Call Info."));
+                                memset(schedule, 0,
+                                        sizeof(ScheduledResourceInfo));
+
+                                schedule->resource = resource;
+                                schedule->actionset = actionset;
+                                schedule->ehRequest =
+                                        (OCServerRequest*) ehRequest->requestHandle;
+
+                                if (delay > 0)
+                                {
+                                    OC_LOG_V(INFO, TAG, "delay_time is %lf seconds.",
+                                            actionset->timesteps);
+
+                                    schedule->time = registerTimer(delay,
+                                            &schedule->timer_id,
+                                            &DoScheduledGroupAction);
+
+                                    AddScheduledResource(&scheduleResourceList,
+                                            schedule);
+                                    stackRet = OC_STACK_OK;
+                                }
+                                else
+                                {
+                                    stackRet = OC_STACK_ERROR;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            else if (strcmp(doWhat, "CancelAction") == 0)
+            {
+                ScheduledResourceInfo *info =
+                        GetScheduledResourceByActionSetName(scheduleResourceList, details);
 
+                if(info != NULL)
+                {
+                    unregisterTimer(info->timer_id);
 
+                    RemoveScheduledResource(&scheduleResourceList, info);
                     stackRet = OC_STACK_OK;
                 }
+                else
+                {
+                    stackRet = OC_STACK_ERROR;
+                }
             }
+
             else if (strcmp(doWhat, "GetActionSet") == 0)
             {
                 char *plainText = NULL;
                 OCActionSet *actionset = NULL;
 
-                cJSON_AddItemToObject(json, "rep", format = cJSON_CreateObject());
+                cJSON_AddItemToObject(json, "rep", format =
+                        cJSON_CreateObject());
                 GetActionSet(details, resource->actionsetHead, &actionset);
                 if (actionset != NULL)
                 {
@@ -810,6 +1241,7 @@ OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHa
                 }
             }
 
+
             jsonResponse = cJSON_Print(json);
             cJSON_Delete(json);
 
@@ -818,20 +1250,23 @@ OCStackResult BuildCollectionGroupActionJSONResponse(OCMethod method/*OCEntityHa
             bufferLength = strlen((const char *) buffer);
             if (bufferLength > 0)
             {
-                OCEntityHandlerResponse response =
-                { 0 };
-                response.ehResult = OC_EH_OK;
+                OCEntityHandlerResponse response = { 0 };
+                if(stackRet == OC_STACK_OK)
+                    response.ehResult = OC_EH_OK;
+                else
+                    response.ehResult = OC_EH_ERROR;
                 response.payload = buffer;
                 response.payloadSize = bufferLength + 1;
                 response.persistentBufferFlag = 0;
-                response.requestHandle = (OCRequestHandle) ehRequest->requestHandle;
+                response.requestHandle =
+                        (OCRequestHandle) ehRequest->requestHandle;
                 response.resourceHandle = (OCResourceHandle) collResource;
                 stackRet = OCDoResponse(&response);
             }
         }
 
-        OCFree(doWhat);
-        OCFree(details);
+        OCFREE(doWhat)
+        OCFREE(details)
     }
 
     return stackRet;
index dc76c40..cac221a 100644 (file)
@@ -13,7 +13,7 @@ target_os = env.get('TARGET_OS')
 ######################################################################
 # Build flags
 ######################################################################
-things_manager_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src'])
+things_manager_env.AppendUnique(CPPPATH = ['../../extlibs/timer', 'sdk/inc', 'sdk/src'])
 
 if target_os not in ['windows', 'winrt']:
        things_manager_env.AppendUnique(CXXFLAGS = ['-Wall'])
@@ -26,7 +26,7 @@ if target_os == 'android':
 ######################################################################
 # Source files and Targets
 ######################################################################
-tgm_src = env.Glob('sdk/src/*.cpp')
+tgm_src = env.Glob('sdk/src/*.cpp', '../../extlibs/timer/timer.c')
 tgmsdk = things_manager_env.StaticLibrary('TGMSDKLibrary', tgm_src)
 
 things_manager_env.InstallTarget(tgmsdk, 'libTGMSDK')
index b3b08f3..57f9cc5 100644 (file)
@@ -13,6 +13,7 @@ linux_sample_env = lib_env.Clone()
 # Build flags
 ######################################################################
 linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../../../extlibs/timer'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
 linux_sample_env.AppendUnique(CXXFLAGS = ['-Wall', '-pthread'])
index 37824a9..77ec5f3 100644 (file)
@@ -1,4 +1,5 @@
 TGMROOT=../../../
+OIC_ROOT=${TGMROOT}../..
 IOT_BASE=${TGMROOT}../../resource
 RST_NAME=.
 TARGET1=con-server
@@ -13,8 +14,9 @@ CXX=g++
 CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
 
 CXX_INC        := -I../../ -I../../inc/ -I../../../sdk/inc/ -I../../../sdk/src/
+CXX_INC += -I${OIC_ROOT}/extlibs/timer
 CXX_INC        += -I${IOT_BASE}/include/
-CXX_INC        += -I${IOT_BASE}/oc_logger/include
+CXX_INC += -I${IOT_BASE}/oc_logger/include
 CXX_INC        += -I${IOT_BASE}/csdk/stack/include
 CXX_INC        += -I${IOT_BASE}/csdk/ocsocket/include
 CXX_INC        += -I${IOT_BASE}/csdk/ocrandom/include
index 1b20e72..09d181f 100644 (file)
@@ -13,6 +13,7 @@ linux_sample_env = lib_env.Clone()
 # Build flags
 ######################################################################
 linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../../../extlibs/timer'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
 linux_sample_env.AppendUnique(CXXFLAGS = ['-Wall', '-pthread'])
old mode 100644 (file)
new mode 100755 (executable)
index 47177c7..a76fb10
@@ -25,6 +25,8 @@
 #include <pthread.h>
 #include <iostream>
 
+#include "timer.h"
+
 #include <ThingsManager.h>
 
 using namespace std;
@@ -35,41 +37,46 @@ namespace PH = std::placeholders;
 bool isReady = false;
 
 OCResourceHandle resourceHandle;
-std::vector< OCResourceHandle > resourceHandleVector;
+std::vector<OCResourceHandle> resourceHandleVector;
 
-shared_ptr< OCResource > g_resource;
-vector< string > lights;
+shared_ptr<OCResource> g_resource;
+vector<string> lights;
 
 ThingsManager *thingsMgr = new ThingsManager();
 
-void onGet(const HeaderOptions& opt, const OCRepresentation &rep, const int eCode);
+void onGet(const HeaderOptions& opt, const OCRepresentation &rep,
+        const int eCode);
 
-void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+        const int eCode);
 
-void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode);
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+        const int eCode);
 
-void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode,
-        const int& sequenceNumber);
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+        const int& eCode, const int& sequenceNumber);
 
 void allBulbOn();
 void allBulbOff();
 
-void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResource)
+void foundResources(
+        std::vector<std::shared_ptr<OC::OCResource> > listOfResource)
 {
 
-    for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end(); ++rsrc)
+    for (auto rsrc = listOfResource.begin(); rsrc != listOfResource.end();
+            ++rsrc)
     {
         std::string resourceURI = (*rsrc)->uri();
         std::string hostAddress = (*rsrc)->host();
 
         if (resourceURI == "/a/light")
         {
-
             cout << "\tResource URI : " << resourceURI << endl;
             cout << "\tResource Host : " << hostAddress << endl;
 
             OCResourceHandle foundResourceHandle;
-            OCStackResult result = OCPlatform::registerResource(foundResourceHandle, (*rsrc));
+            OCStackResult result = OCPlatform::registerResource(
+                    foundResourceHandle, (*rsrc));
             cout << "\tresource registed!" << endl;
             if (result == OC_STACK_OK)
             {
@@ -88,7 +95,7 @@ void foundResources(std::vector< std::shared_ptr< OC::OCResource > > listOfResou
     isReady = true;
 }
 
-void foundResource(std::shared_ptr< OCResource > resource)
+void foundResource(std::shared_ptr<OCResource> resource)
 {
     std::string resourceURI;
     std::string hostAddress;
@@ -111,7 +118,8 @@ void foundResource(std::shared_ptr< OCResource > resource)
             }
             else if (resourceURI == "/core/bookmark")
             {
-                resource->observe(ObserveType::Observe, QueryParamsMap(), &onObserve);
+                resource->observe(ObserveType::Observe, QueryParamsMap(),
+                        &onObserve);
             }
 
             // p_platform.bindResource(resourceHandle, foundResourceHandle);
@@ -124,24 +132,28 @@ void foundResource(std::shared_ptr< OCResource > resource)
     }
 }
 
-void onGet(const HeaderOptions& opt, const OCRepresentation &rep, const int eCode)
+void onGet(const HeaderOptions& opt, const OCRepresentation &rep,
+        const int eCode)
 {
-    // std::vector<OCRepresentation> children = rep.getChildren();
-
-    // cout << "\n\n\nCHILD RESOURCE OF GROUP" << endl;
-    // for( auto iter = children.begin(); iter != children.end();  ++iter )
-    // {
-    //     lights.push_back((*iter).getUri());
-    //     cout << "\tURI :: " << (*iter).getUri() << endl;
-    // }
+    cout << "\nonGet" << endl;
+    if (eCode == OC_STACK_OK)
+        cout << "\tResult is OK." << endl;
+    else
+        cout << "\tInvalid parameter." << endl;
 }
 
-void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPut(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+        const int eCode)
 {
-    printf("\nonPut\n");
+    cout << "\nonPut" << endl;
+    if (eCode == OC_STACK_OK)
+        cout << "\tResult is OK." << endl;
+    else
+        cout << "\tInvalid parameter." << endl;
 }
 
-void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
+void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+        const int eCode)
 {
     printf("\nonPost\n");
 
@@ -154,17 +166,19 @@ void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, con
             ActionSet *actionset = thingsMgr->getActionSetfromString(plainText);
             if (actionset != NULL)
             {
-                cout << endl << "\tACTIONSET NAME :: " << actionset->actionsetName << endl;
+                cout << endl << "\tACTIONSET NAME :: "
+                        << actionset->actionsetName << endl;
                 for (auto actIter = actionset->listOfAction.begin();
                         actIter != actionset->listOfAction.end(); ++actIter)
                 {
                     cout << "\t\tTARGET :: " << (*actIter)->target << endl;
 
                     for (auto capaIter = (*actIter)->listOfCapability.begin();
-                            capaIter != (*actIter)->listOfCapability.end(); ++capaIter)
+                            capaIter != (*actIter)->listOfCapability.end();
+                            ++capaIter)
                     {
-                        cout << "\t\t\t" << (*capaIter)->capability << " :: " << (*capaIter)->status
-                                << endl;
+                        cout << "\t\t\t" << (*capaIter)->capability << " :: "
+                                << (*capaIter)->status << endl;
                     }
                 }
             }
@@ -195,7 +209,8 @@ void allBulbOff()
 
     if (g_resource)
     {
-        g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(), &onPost);
+        g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
+                &onPost);
     }
 }
 
@@ -207,12 +222,40 @@ void allBulbOn()
 
     if (g_resource)
     {
-        g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(), &onPost);
+        g_resource->post("a.collection", GROUP_INTERFACE, rep, QueryParamsMap(),
+                &onPost);
     }
 }
 
-void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode,
-        const int& sequenceNumber)
+void Scheduled_AllbulbOff()
+{
+    thingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+}
+void Scheduled_AllbulbOffEx()
+{
+    thingsMgr->executeActionSet(g_resource, "AllBulbOffScheduledCall", 10, &onPost);
+}
+void CancelScheduled_AllBulbOff()
+{
+    thingsMgr->cancelActionSet(g_resource, "AllBulbOffScheduledCall", &onPost);
+}
+void Recursive_allBulbOn()
+{
+    thingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+}
+void Recursive_allBulbOnEx()
+{
+    thingsMgr->executeActionSet(g_resource, "AllBulbOnRecursiveCall", 10, &onPost);
+}
+
+void CancelRecursive_allBulbOn()
+{
+
+    thingsMgr->cancelActionSet(g_resource, "AllBulbOnRecursiveCall", &onPost);
+}
+
+void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
+        const int& eCode, const int& sequenceNumber)
 {
     if (eCode == OC_STACK_OK)
     {
@@ -259,18 +302,9 @@ void createActionSet_AllBulbOff()
         action->listOfCapability.push_back(capa);
         allBulbOff->listOfAction.push_back(action);
     }
-    // actionsetDesc = thingsMgr->getStringFromActionSet(allBulbOff);
-
-    // cout << "ActionSet :: " << actionsetDesc << endl;
-
-    // OCRepresentation rep;
-    // rep.setValue("ActionSet", actionsetDesc);
-
     if (g_resource)
     {
         thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
-        // g_resource->put("a.collection", GROUP_INTERFACE, rep,
-        //     QueryParamsMap(), &onPut);
     }
 
     delete allBulbOff;
@@ -294,27 +328,96 @@ void createActionSet_AllBulbOn()
         action->listOfCapability.push_back(capa);
         allBulbOff->listOfAction.push_back(action);
     }
-    // actionsetDesc = thingsMgr->getStringFromActionSet(allBulbOff);
+    if (g_resource)
+    {
+        thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
+    }
 
-    // cout << "ActionSet :: " << actionsetDesc << endl;
+    delete allBulbOff;
+}
 
-    // OCRepresentation rep;
-    // rep.setValue("ActionSet", actionsetDesc);
+void createScheduledActionSet_AllBulbOff()
+{
+    string actionsetDesc;
+    ActionSet *allBulbOff = new ActionSet();
+    allBulbOff->type = OIC::ACTIONSET_TYPE::SCHEDULED;
+    allBulbOff->actionsetName = "AllBulbOffScheduledCall";
+
+    printf("ENTER(YYYY-MM-DD hh:mm:ss) :: ");
+    int res = scanf("%d-%d-%d %d:%d:%d", &allBulbOff->mTime.tm_year,
+            &allBulbOff->mTime.tm_mon, &allBulbOff->mTime.tm_mday,
+            &allBulbOff->mTime.tm_hour, &allBulbOff->mTime.tm_min,
+            &allBulbOff->mTime.tm_sec);
+    if( res < 0 )
+    {
+        printf("Invalid Input. try again.");
+        return;
+    }
+
+    allBulbOff->setDelay(allBulbOff->getSecondsFromAbsoluteTime());
+    printf("DELAY :: %ld\n", allBulbOff->getSecondsFromAbsoluteTime());
 
+    for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+    {
+        Action *action = new Action();
+        action->target = (*iter);
+
+        Capability *capa = new Capability();
+        capa->capability = "power";
+        capa->status = "off";
+
+        action->listOfCapability.push_back(capa);
+        allBulbOff->listOfAction.push_back(action);
+    }
     if (g_resource)
     {
         thingsMgr->addActionSet(g_resource, allBulbOff, onPut);
-        // g_resource->put("a.collection", GROUP_INTERFACE, rep,
-        //     QueryParamsMap(), &onPut);
     }
 
     delete allBulbOff;
 }
 
+void createRecursiveActionSet_AllBulbOn()
+{
+    string actionsetDesc;
+    ActionSet *allBulbOn = new ActionSet();
+    allBulbOn->type = OIC::ACTIONSET_TYPE::RECURSIVE;
+
+    allBulbOn->actionsetName = "AllBulbOnRecursiveCall";
+    allBulbOn->mTime.tm_year = 0;
+    allBulbOn->mTime.tm_mon = 0;
+    allBulbOn->mTime.tm_mday = 0;
+    allBulbOn->mTime.tm_hour = 0;
+    allBulbOn->mTime.tm_min = 0;
+    allBulbOn->mTime.tm_sec = 5;
+
+    allBulbOn->setDelay(allBulbOn->getSecAbsTime());
+
+    for (auto iter = lights.begin(); iter != lights.end(); ++iter)
+    {
+        Action *action = new Action();
+        action->target = (*iter);
+
+        Capability *capa = new Capability();
+        capa->capability = "power";
+        capa->status = "on";
+
+        action->listOfCapability.push_back(capa);
+        allBulbOn->listOfAction.push_back(action);
+    }
+    if (g_resource)
+    {
+        thingsMgr->addActionSet(g_resource, allBulbOn, onPut);
+    }
+
+    delete allBulbOn;
+}
+
 int main()
 {
     PlatformConfig config
-    { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0, OC::QualityOfService::LowQos };
+    { OC::ServiceType::InProc, ModeType::Both, "0.0.0.0", 0,
+            OC::QualityOfService::LowQos };
 
     try
     {
@@ -324,14 +427,12 @@ int main()
         OCPlatform::Configure(config);
 
         // Find lights for group creation.
-        vector< string > types;
+        vector<string> types;
         types.push_back("core.light");
         thingsMgr->findCandidateResources(types, &foundResources, 5);
 
-        OCPlatform::registerResource(resourceHandle, resourceURI, resourceTypeName,
-                resourceInterface, NULL,
-                //&entityHandler, // entityHandler
-                OC_DISCOVERABLE);
+        OCPlatform::registerResource(resourceHandle, resourceURI,
+                resourceTypeName, resourceInterface, NULL, OC_DISCOVERABLE);
 
         cout << "registerResource is called." << endl;
 
@@ -347,77 +448,91 @@ int main()
                 int n;
 
                 cout << endl;
-                cout << "1 :: CREATE ACTIONSET 2 :: EXECUTE ACTIONSET(ALLBULBON)"
-                        << "3 :: EXECUTE ACTIONSET(ALLBULBOFF)" << endl;
-                cout << "4 :: GET ACTIONSET 5 :: DELETE ACTIONSET 6 :: QUIT" << endl;
-                cout << "9 :: FIND GROUP 0 :: FIND BOOKMARK TO OBSERVE" << endl;
+                cout << "1 :: CREATE ACTIONSET" << endl;
+                cout << "2 :: EXECUTE ACTIONSET(ALLBULBON)" << endl;
+                cout << "3 :: EXECUTE ACTIONSET(ALLBULBOFF)" << endl;
+                cout << "4 :: CREATE ACTIONSET(R_ALLBULBON)" << endl;
+                cout << "\t41 :: EXECUTE ACTIONSET 42 :: CANCEL ACTIONSET" << endl;
+                cout << "5 :: CREATE ACTIONSET(S_ALLBULBON)" << endl;
+                cout << "\t51 :: EXECUTE ACTIONSET 52 :: CANCEL ACTIONSET" << endl;
+                cout << "6 :: GET ACTIONSET" << endl;
+                cout << "7 :: DELETE ACTIONSET" << endl;
+                cout << "8 :: QUIT" << endl;
+                cout << "9 :: FIND GROUP" << endl;
+                cout << "0 :: FIND BOOKMARK TO OBSERVE"
+                        << endl;
 
                 fflush(stdin);
                 cin >> n;
 
                 if (n == 9)
                 {
-                    OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=a.collection",
+                    OCPlatform::findResource("",
+                            "coap://224.0.1.187/oc/core?rt=a.collection",
                             &foundResource);
                 }
                 else if (n == 0)
                 {
-                    OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.bookmark",
+                    OCPlatform::findResource("",
+                            "coap://224.0.1.187/oc/core?rt=core.bookmark",
                             &foundResource);
                 }
                 else if (n == 1)
                 {
-
-                    // Craete Action Set
-                    // "AllBulbOff"
-                    //"movieTime*uri=coap://10.251.44.228:49858/a/light|power=10";
                     createActionSet_AllBulbOff();
                     createActionSet_AllBulbOn();
-
                 }
                 else if (n == 2)
                 {
-
                     allBulbOn();
-                    // thingsMgr->executeActionSet(g_resource, "AllBulbOn", onPost);
-
                 }
                 else if (n == 3)
                 {
-
                     allBulbOff();
-                    // thingsMgr->executeActionSet(g_resource, "AllBulbOff", onPost);
-
                 }
                 else if (n == 4)
                 {
-                    // OCRepresentation rep;
-
-                    // rep.setValue("GetActionSet", std::string("AllBulbOff"));
-
-                    // if(g_resource)
-                    // {
-                    //     g_resource->post("a.collection", GROUP_INTERFACE, rep,
-                    //         QueryParamsMap(), &onPost);
-                    // }
-
-                    thingsMgr->getActionSet(g_resource, "AllBulbOff", onPost);
+                    createRecursiveActionSet_AllBulbOn();
+                }
+                else if (n == 41)
+                {
+                    Recursive_allBulbOn();
+                }
+                else if (n == 42)
+                {
+                    CancelRecursive_allBulbOn();
+                }
+                // Exampel of
+                else if (n == 43)
+                {
+                    Recursive_allBulbOnEx();
                 }
                 else if (n == 5)
                 {
-                    // OCRepresentation rep;
-
-                    // rep.setValue("DelActionSet", std::string("AllBulbOff"));
-
-                    // if(g_resource)
-                    // {
-                    //     g_resource->put("a.collection", GROUP_INTERFACE, rep,
-                    //         QueryParamsMap(), &onPut);
-                    // }
-                    thingsMgr->deleteActionSet(g_resource, "AllBulbOff", onPut);
+                    createScheduledActionSet_AllBulbOff();
+                }
+                else if (n == 51)
+                {
+                    Scheduled_AllbulbOff();
+                }
+                else if (n == 52)
+                {
+                    CancelScheduled_AllBulbOff();
+                }
+                else if (n == 53)
+                {
+                    Scheduled_AllbulbOffEx();
                 }
                 else if (n == 6)
                 {
+                    thingsMgr->getActionSet(g_resource, "AllBulbOff", onPost);
+                }
+                else if (n == 7)
+                {
+                    thingsMgr->deleteActionSet(g_resource, "AllBulbOff", onPut);
+                }
+                else if (n == 8)
+                {
                     isRun = false;
                     break;
                 }
@@ -426,7 +541,7 @@ int main()
     }
     catch (OCException& e)
     {
-
+        cout << "ERROR :: " << e.reason() << endl;
     }
 
     return 0;
index 6604c3c..a69cf22 100644 (file)
@@ -1,5 +1,6 @@
 
 TGMROOT=../../../
+OIC_ROOT=${TGMROOT}../..
 IOT_BASE=${TGMROOT}../../resource
 RST_NAME=.
 
@@ -13,6 +14,7 @@ DEPEND_DIR:= ../../../../../resource/dependencies/
 CEREAL_DIR:= $(DEPEND_DIR)/cereal
 
 CXX_INC        := -I../../ -I../../inc/
+CXX_INC += -I${OIC_ROOT}/extlibs/timer
 CXX_INC        += -I${IOT_BASE}/include/
 CXX_INC        += -I${IOT_BASE}/oc_logger/include
 CXX_INC        += -I${IOT_BASE}/csdk/stack/include
index ec09e41..c652eef 100644 (file)
@@ -13,6 +13,7 @@ linux_sample_env = lib_env.Clone()
 # Build flags
 ######################################################################
 linux_sample_env.AppendUnique(CPPPATH = ['include'])
+linux_sample_env.AppendUnique(CPPPATH = ['../../../../../extlibs/timer'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/inc'])
 linux_sample_env.AppendUnique(CPPPATH = ['../../../sdk/src'])
 linux_sample_env.AppendUnique(CXXFLAGS = ['-Wall', '-pthread'])
index 0ee1e5c..e70651a 100644 (file)
@@ -1,5 +1,5 @@
-
 TGMROOT=../../../
+OIC_ROOT=${TGMROOT}../..
 IOT_BASE=${TGMROOT}../../resource
 RST_NAME=.
 TARGET1=group
@@ -13,6 +13,7 @@ CXX=g++
 CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
 
 CXX_INC        := -I../../ -I../../inc/ -I../../../sdk/inc/ -I../../../sdk/src/
+CXX_INC += -I${OIC_ROOT}/extlibs/timer
 CXX_INC        += -I${IOT_BASE}/include/
 CXX_INC += -I${IOT_BASE}/oc_logger/include
 CXX_INC        += -I${IOT_BASE}/csdk/stack/include
index 0e5ec03..fc95280 100644 (file)
@@ -1,7 +1,7 @@
 
 
-#OIC_ROOT=../../../resource/
-IOT_BASE=../../../../../resource
+OIC_ROOT=../../../../..
+IOT_BASE=${OIC_ROOT}/resource
 #BOOST=${BOOST_DIR}
 RST_NAME=.
 
@@ -16,6 +16,7 @@ CXX_FLAGS=-std=c++0x -Wall -pthread -DLINUX -ldl
 
 
 CXX_INC        := -I../../ -I../../inc/ -I../../src/
+CXX_INC += -I${OIC_ROOT}/extlibs/timer
 CXX_INC        += -I${IOT_BASE}/include/ 
 CXX_INC += -I${IOT_BASE}/oc_logger/include
 CXX_INC        += -I${IOT_BASE}/csdk/stack/include 
old mode 100644 (file)
new mode 100755 (executable)
index 0deba88..c3e8331
 
 #include <string>
 #include <vector>
+#include <cstdio>
+#include <iostream>
+
+#include <ctime>
+
+#include <timer.h>
 
 using namespace std;
 
-namespace OIC{
-       class Capability
-    {
-    public:
-        std::string capability;
-        std::string status;
-    };
+namespace OIC
+{
+enum ACTIONSET_TYPE
+{
+    NONE = 0, SCHEDULED, RECURSIVE
+};
+
+typedef tm OCTime;
+
+class Time
+{
+public:
+    long int mDelay;
+    OCTime mTime;
+    ACTIONSET_TYPE type;
+
+    Time();
+    ~Time();
+
+    void setTime(OCTime t);
+    void setTime(unsigned int yy, unsigned int mm, unsigned int dd,
+            unsigned int h, unsigned int m, unsigned int s,
+            int dayoftheweek);
+    void setDayOfWeekForRecursive(int day);
+    unsigned int getYear();
+    unsigned int getMonth();
+    unsigned int getDay();
+    unsigned int getHour();
+    unsigned int getMin();
+    unsigned int getSec();
+    long int getSecondsFromAbsoluteTime();
+    long int getSecAbsTime();
+    long int getSecondsForWeeklySchedule();
+    void setDelay(long int seconds);
+    std::string toString() const;
+};
+
+class Capability
+{
+public:
+    std::string capability;
+    std::string status;
+};
 
-    class Action
-    {
-    public:
-        Action() :
-                target("")
-        {
-        }
-        ~Action()
-        {
-            listOfCapability.clear();
-        }
-        std::string target;
+class Action
+{
+public:
+    Action();
+    ~Action();
 
-        std::vector< Capability* > listOfCapability;
-    };
+    std::string target;
+    std::vector<Capability*> listOfCapability;
+};
 
-    class ActionSet
-    {
-    public:
-        ActionSet() :
-                actionsetName("")
-        {
-        }
-        ~ActionSet()
-        {
-            listOfAction.clear();
-        }
-        std::string actionsetName;
+class ActionSet: public Time
+{
+public:
+    /**
+     * Constructor for ActionSet
+     */
+    ActionSet();
+    /**
+     * Virtual destructor for ActionSet
+     */
+    ~ActionSet();
 
-        std::vector< Action* > listOfAction;
-    };
+    std::string actionsetName;
+    std::vector<Action*> listOfAction;
+};
 }
-#endif 
+#endif
index 4c5ff34..a1058b5 100644 (file)
@@ -383,6 +383,38 @@ namespace OIC
                 std::string actionsetName, PostCallback cb);
 
         /**
+         * API for executing the Action Set.
+         * Callback is called when the response of  POST operation arrives.
+         *
+         * @param resource - resource pointer of the group resource
+         * @param actionsetName - Action Set name for executing the Action set
+         * @param delay - waiting time for until action set run.
+         * @param callback - callback for POST operation.
+         *
+         * @return OCStackResult - return value of this API.
+         *                         It returns OC_STACK_OK if success.
+         *
+         * NOTE: OCStackResult is defined in ocstack.h.
+         */
+        OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
+                std::string actionsetName, long int delay, PostCallback cb);
+
+        /**
+         * API for canceling the Action Set.
+         * Callback is called when the response of POST operation arrives.
+         *
+         * @param resource - resource pointer of the group resource
+         * @param actionsetName - Action Set name for executing the Action set
+         * @param callback - callback for POST operation.
+         *
+         * @return OCStackResult - return value of this API.
+         *                         It returns OC_STACK_OK if success.
+         *
+         * NOTE: OCStackResult is defined in ocstack.h.
+         */
+        OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
+                std::string actionsetName, PostCallback cb);
+        /**
          * API for reading the Action Set.
          * Callback is called when the response of  GET operation arrives.
          *
diff --git a/service/things-manager/sdk/src/ActionSet.cpp b/service/things-manager/sdk/src/ActionSet.cpp
new file mode 100755 (executable)
index 0000000..910a5e6
--- /dev/null
@@ -0,0 +1,165 @@
+//******************************************************************
+//
+// Copyright 2014 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ActionSet.h"
+using namespace std;
+
+namespace OIC
+{
+Time::Time()
+{
+    setTime(0, 0, 0, 0, 0, 0, 0);
+}
+
+Time::~Time()
+{
+}
+
+void Time::setTime(OCTime t)
+{
+    mTime = t;
+}
+void Time::setTime(unsigned int yy, unsigned int mm, unsigned int dd,
+        unsigned int h, unsigned int m, unsigned int s,
+        int dayoftheweek = 0)
+{
+    yy -= 1900;
+    mm -= 1;
+
+    mDelay = 0;
+    mTime.tm_year = yy;
+    mTime.tm_mon = mm;
+    mTime.tm_mday = dd;
+
+    mTime.tm_hour = h;
+    mTime.tm_min = m;
+    mTime.tm_sec = s;
+
+    mTime.tm_wday = (unsigned int) dayoftheweek;
+    type = NONE;
+}
+void Time::setDayOfWeekForRecursive(int day)
+{
+    if (day != -1)
+        type = RECURSIVE;
+    else
+        return;
+
+    setTime(0, 0, 0, 0, 0, 0, day);
+}
+unsigned int Time::getYear()
+{
+    return mTime.tm_year;
+}
+unsigned int Time::getMonth()
+{
+    return mTime.tm_mon;
+}
+unsigned int Time::getDay()
+{
+    return mTime.tm_mday;
+}
+unsigned int Time::getHour()
+{
+    return mTime.tm_hour;
+}
+unsigned int Time::getMin()
+{
+    return mTime.tm_min;
+}
+unsigned int Time::getSec()
+{
+    return mTime.tm_sec;
+}
+long int Time::getSecondsFromAbsoluteTime()
+{
+    if(mTime.tm_year > 1900)
+        mTime.tm_year -= 1900;
+
+    mTime.tm_mon -= 1;
+
+    return getSecondsFromAbsTime(&mTime);
+}
+long int Time::getSecAbsTime()
+{
+    return getSeconds(&mTime);
+}
+long int Time::getSecondsForWeeklySchedule()
+{
+    if(mTime.tm_year > 1900)
+        mTime.tm_year -= 1900;
+
+    mTime.tm_mon -= 1;
+    return getRelativeIntervalOfWeek(&mTime);
+}
+
+void Time::setDelay(long int seconds)
+{
+    if(type != NONE)
+    {
+        mDelay = seconds;
+    }
+}
+
+std::string Time::toString() const
+{
+    char temp[25] = { 0 };
+    // It is shown format which required of scheduled/recursive group action time.
+    // " [delay] [type of actionset] "
+    snprintf(temp, sizeof(temp) / sizeof(char),
+            "%ld %d", mDelay, (unsigned int) type);
+    return std::string(temp);
+}
+
+
+
+
+
+
+
+
+
+
+Action::Action() :
+        target("")
+{
+}
+Action::~Action()
+{
+    listOfCapability.clear();
+}
+
+
+
+
+
+
+
+
+
+ActionSet::ActionSet() :
+        actionsetName("")
+{
+}
+ActionSet::~ActionSet()
+{
+    listOfAction.clear();
+}
+}
old mode 100644 (file)
new mode 100755 (executable)
index 0d761f5..40f7b45
@@ -453,6 +453,8 @@ std::string GroupManager::getStringFromActionSet(const ActionSet *newActionSet)
 
     message = newActionSet->actionsetName;
     message.append("*");
+    message.append(newActionSet->toString());
+    message.append("*");
     for (auto iterAction = newActionSet->listOfAction.begin();
             iterAction != newActionSet->listOfAction.end(); iterAction++)
     {
@@ -519,6 +521,17 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
         goto exit;
     }
 
+    if (token != NULL)
+    {
+        sscanf(token, "%ld %d", &actionset->mDelay, (int*)&actionset->type);
+
+        token = strtok_r(NULL, ACTION_DELIMITER, &plainPtr);
+    }
+    else
+    {
+        goto exit;
+    }
+
     while (token)
     {
         char *descPtr = NULL;
@@ -530,7 +543,6 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
             strcpy(desc, token);
             token = strtok_r(desc, DESC_DELIMITER, &descPtr);
 
-            // cout << "desc :: " << token << endl;
             while (token != NULL)
             {
                 char *attrPtr = NULL;
@@ -538,8 +550,6 @@ ActionSet* GroupManager::getActionSetfromString(std::string description)
 
                 strcpy(attr, token);
 
-                // cout << "attr :: " << attr << endl;
-
                 token = strtok_r(attr, ATTR_DELIMITER, &attrPtr);
                 while (token != NULL)
                 {
@@ -620,10 +630,9 @@ OCStackResult GroupManager::addActionSet(std::shared_ptr< OCResource > resource,
     if ((resource != NULL) && (newActionSet != NULL))
     {
         std::string message = getStringFromActionSet(newActionSet);
-        OCRepresentation rep;
 
+        OCRepresentation rep;
         rep.setValue("ActionSet", message);
-
         return resource->put(resource->getResourceTypes().front(), GROUP_INTERFACE, rep,
                 QueryParamsMap(), cb);
     }
@@ -650,6 +659,47 @@ OCStackResult GroupManager::executeActionSet(std::shared_ptr< OCResource > resou
     }
 }
 
+OCStackResult GroupManager::executeActionSet(std::shared_ptr< OCResource > resource,
+        std::string actionsetName, long int delay, PostCallback cb)
+{
+    if(delay == 0 )
+    {
+        return OC_STACK_INVALID_PARAM;
+    }
+    if (resource != NULL)
+    {
+        std::string value = actionsetName;
+        value.append("*");
+        value.append(std::to_string(delay));
+
+        OCRepresentation rep;
+        rep.setValue("DoScheduledAction", value);
+        return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep,
+                QueryParamsMap(), cb);
+    }
+    else
+    {
+        return OC_STACK_ERROR;
+    }
+}
+
+OCStackResult GroupManager::cancelActionSet(std::shared_ptr< OCResource > resource,
+        std::string actionsetName, PostCallback cb)
+{
+    if (resource != NULL)
+    {
+        OCRepresentation rep;
+
+        rep.setValue("CancelAction", actionsetName);
+        return resource->post(resource->getResourceTypes().front(), GROUP_INTERFACE, rep,
+                QueryParamsMap(), cb);
+    }
+    else
+    {
+        return OC_STACK_ERROR;
+    }
+}
+
 OCStackResult GroupManager::getActionSet(std::shared_ptr< OCResource > resource,
         std::string actionsetName, PostCallback cb)
 {
index ebc7d0c..c8a8f9d 100644 (file)
@@ -82,7 +82,8 @@ public:
     OCStackResult subscribeCollectionPresence(std::shared_ptr< OCResource > resource,
             CollectionPresenceCallback);
 
-    OCStackResult bindResourceToGroup(OCResourceHandle& childHandle, std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
+    OCStackResult bindResourceToGroup(OCResourceHandle& childHandle,
+            std::shared_ptr< OCResource > resource, OCResourceHandle& collectionHandle);
 
 private:
 
@@ -109,6 +110,10 @@ public:
             const ActionSet* newActionSet, PutCallback cb);
     OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
             std::string actionsetName, PostCallback cb);
+    OCStackResult executeActionSet(std::shared_ptr< OCResource > resource,
+            std::string actionsetName, long int delay, PostCallback cb);
+    OCStackResult cancelActionSet(std::shared_ptr< OCResource > resource,
+            std::string actionsetName, PostCallback cb);
     OCStackResult getActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
             PostCallback cb);
     OCStackResult deleteActionSet(std::shared_ptr< OCResource > resource, std::string actionsetName,
index 916e9de..024104f 100644 (file)
@@ -185,6 +185,16 @@ namespace OIC
     {
         return g_groupManager->executeActionSet(resource, actionsetName, cb);
     }
+    OCStackResult ThingsManager::executeActionSet(std::shared_ptr< OCResource > resource,
+                    std::string actionsetName, long int delay, PostCallback cb)
+    {
+        return g_groupManager->executeActionSet(resource, actionsetName, delay, cb);
+    }
+    OCStackResult ThingsManager::cancelActionSet(std::shared_ptr< OCResource > resource,
+                    std::string actionsetName, PostCallback cb)
+    {
+        return g_groupManager->cancelActionSet(resource, actionsetName, cb);
+    }
     OCStackResult ThingsManager::getActionSet(std::shared_ptr< OCResource > resource,
             std::string actionsetName, GetCallback cb)
     {