+#define DESC_DELIMITER "\""
+#define ACTION_DELIMITER "*"
+#define ATTR_DELIMITER "|"
+#define ATTR_ASSIGN "="
+
+// Definitions for operations related to actions
+#define DO_ACTION "DoAction"
+#define GET_ACTIONSET "GetActionSet"
+#define ACTIONSET "ActionSet"
+#define DELETE_ACTIONSET "DelActionSet"
+
+#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
+}