Add timer_util, timer_types 52/56552/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 11 Jan 2016 07:07:05 +0000 (16:07 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 11 Jan 2016 07:07:05 +0000 (16:07 +0900)
Change-Id: Ic51eb467c608b7b6c7b9d8b2e55524bb6f734773
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/timer_mgr.h
include/timer_types.h [new file with mode: 0644]
include/timer_util.h [new file with mode: 0644]
src/timer_util.cpp [new file with mode: 0644]

index 732cfdf..034ef4f 100644 (file)
 #ifndef __CONTEXT_TIMER_MANAGER_H__
 #define __CONTEXT_TIMER_MANAGER_H__
 
+#include <timer_types.h>
+
 namespace ctx {
        /* Forward Declaration */
        class timer_listener_iface;
 
        namespace timer_manager {
 
-               enum day_of_week_e {
-                       SUN = 0x01,
-                       MON = 0x02,
-                       TUE = 0x04,
-                       WED = 0x08,
-                       THU = 0x10,
-                       FRI = 0x20,
-                       SAT = 0x40,
-                       WEEKDAY = MON | TUE | WED | THU | FRI,
-                       WEEKEND = SAT | SUN,
-                       EVERYDAY = SUN | MON | TUE | WED | THU | FRI | SAT,
-               };
-
                /**
                 * @brief               Sets a repeated timer for a given interval of time (s).
                 * @details             It is recommended to minize the number of timers initiated, to reduce battery consumptions.
diff --git a/include/timer_types.h b/include/timer_types.h
new file mode 100644 (file)
index 0000000..4b4b17c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_TIMER_TYPES_H__
+#define __CONTEXT_TIMER_TYPES_H__
+
+#include <string>
+
+#define MAX_HOUR       24
+#define MAX_DAY                7
+
+#define TIMER_TYPES_MON "Mon"
+#define TIMER_TYPES_TUE "Tue"
+#define TIMER_TYPES_WED "Wed"
+#define TIMER_TYPES_THU "Thu"
+#define TIMER_TYPES_FRI "Fri"
+#define TIMER_TYPES_SAT "Sat"
+#define TIMER_TYPES_SUN "Sun"
+#define TIMER_TYPES_WEEKDAY "Weekday"
+#define TIMER_TYPES_WEEKEND "Weekend"
+#define TIMER_TYPES_EVERYDAY "Everyday"
+
+namespace ctx {
+
+       namespace timer_types {
+
+               enum day_of_week_e {
+                       SUN = 0x01,
+                       MON = 0x02,
+                       TUE = 0x04,
+                       WED = 0x08,
+                       THU = 0x10,
+                       FRI = 0x20,
+                       SAT = 0x40,
+                       WEEKDAY = MON | TUE | WED | THU | FRI,
+                       WEEKEND = SAT | SUN,
+                       EVERYDAY = SUN | MON | TUE | WED | THU | FRI | SAT,
+               };
+
+       }
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_TIMER_TYPES_H__ */
diff --git a/include/timer_util.h b/include/timer_util.h
new file mode 100644 (file)
index 0000000..8bd73b9
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 __CONTEXT_TIMER_UTIL_H__
+#define __CONTEXT_TIMER_UTIL_H__
+
+#include <string>
+#include <timer_types.h>
+
+namespace ctx {
+
+       namespace timer_util {
+
+               std::string convert_day_of_week_int_to_string(int d);
+               int convert_day_of_week_string_to_int(std::string d);
+
+       }
+}      /* namespace ctx */
+
+#endif /* __CONTEXT_TIMER_UTIL_H__ */
diff --git a/src/timer_util.cpp b/src/timer_util.cpp
new file mode 100644 (file)
index 0000000..b727964
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * 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 <timer_util.h>
+
+using namespace ctx::timer_types;
+
+std::string ctx::timer_util::convert_day_of_week_int_to_string(int d)
+{
+       switch(d) {
+       case SUN:
+               return TIMER_TYPES_SUN;
+       case MON:
+               return TIMER_TYPES_MON;
+       case TUE:
+               return TIMER_TYPES_TUE;
+       case WED:
+               return TIMER_TYPES_WED;
+       case THU:
+               return TIMER_TYPES_THU;
+       case FRI:
+               return TIMER_TYPES_FRI;
+       case SAT:
+               return TIMER_TYPES_SAT;
+       case WEEKDAY:
+               return TIMER_TYPES_WEEKDAY;
+       case WEEKEND:
+               return TIMER_TYPES_WEEKEND;
+       case EVERYDAY:
+               return TIMER_TYPES_EVERYDAY;
+       default:
+               break;
+       }
+
+       return "";
+}
+
+int ctx::timer_util::convert_day_of_week_string_to_int(std::string d)
+{
+       int day = 0;
+
+       if (d.compare(TIMER_TYPES_SUN) == 0) {
+               day = SUN;
+       } else if (d.compare(TIMER_TYPES_MON) == 0) {
+               day = MON;
+       } else if (d.compare(TIMER_TYPES_TUE) == 0) {
+               day = TUE;
+       } else if (d.compare(TIMER_TYPES_WED) == 0) {
+               day = WED;
+       } else if (d.compare(TIMER_TYPES_THU) == 0) {
+               day = THU;
+       } else if (d.compare(TIMER_TYPES_FRI) == 0) {
+               day = FRI;
+       } else if (d.compare(TIMER_TYPES_SAT) == 0) {
+               day = SAT;
+       } else if (d.compare(TIMER_TYPES_WEEKDAY) == 0) {
+               day = WEEKDAY;
+       } else if (d.compare(TIMER_TYPES_WEEKEND) == 0) {
+               day = WEEKEND;
+       } else if (d.compare(TIMER_TYPES_EVERYDAY) == 0) {
+               day = EVERYDAY;
+       }
+
+       return day;
+}