Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
modules/wallclock: add node types for month and year
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Dilly <bruno.dilly@intel.com>
  • Loading branch information
bdilly committed Sep 2, 2015
1 parent b1738b7 commit 3cdbee9
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 2 deletions.
81 changes: 79 additions & 2 deletions src/modules/flow/wallclock/wallclock.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ enum sol_flow_node_wallclock_type {
TIMEOUT_MINUTE,
TIMEOUT_HOUR,
TIMEOUT_WEEKDAY,
TIMEOUT_MONTHDAY
TIMEOUT_MONTHDAY,
TIMEOUT_MONTH,
TIMEOUT_YEAR
};

struct wallclock_timeblock_data {
Expand Down Expand Up @@ -92,6 +94,14 @@ static struct wallclock_timer timers[] = {
.val.step = 1,
.val.min = 1,
.val.max = 31, },
[TIMEOUT_MONTH] = { .clients = SOL_PTR_VECTOR_INIT,
.val.step = 1,
.val.min = 1,
.val.max = 12, },
[TIMEOUT_YEAR] = { .clients = SOL_PTR_VECTOR_INIT,
.val.step = 1,
.val.min = 0,
.val.max = INT32_MAX, },
};

static void
Expand Down Expand Up @@ -175,6 +185,41 @@ wallclock_schedule_next(struct sol_flow_node *node)
} else if (mdata->type == TIMEOUT_HOUR) {
timeout = (MINUTES_IN_HOUR - local_time.tm_min) * SECONDS_IN_MINUTE
- seconds;
} else if (mdata->type == TIMEOUT_MONTH) {
time_t next_time;
struct tm next_month = { 0 };

next_month.tm_isdst = local_time.tm_isdst;
next_month.tm_mday = 1;
if (local_time.tm_mon == 11) {
next_month.tm_year = local_time.tm_year + 1;
} else {
next_month.tm_mon = local_time.tm_mon + 1;
next_month.tm_year = local_time.tm_year;
}

next_time = mktime(&next_month);
if (next_time < 0) {
SOL_WRN("Failed to convert to timestamp");
goto err;
}

timeout = next_time - current_time;
} else if (mdata->type == TIMEOUT_YEAR) {
time_t next_time;
struct tm next_year = { 0 };

next_year.tm_isdst = local_time.tm_isdst;
next_year.tm_mday = 1;
next_year.tm_year = local_time.tm_year + 1;

next_time = mktime(&next_year);
if (next_time < 0) {
SOL_WRN("Failed to convert to timestamp");
goto err;
}

timeout = next_time - current_time;
} else { /* TIMEOUT_MONTHDAY or TIMEOUT_WEEKDAY */
timeout = (HOURS_IN_DAY - local_time.tm_hour) * SECONDS_IN_HOUR
- minutes - seconds;
Expand Down Expand Up @@ -224,8 +269,12 @@ wallclock_update_time(enum sol_flow_node_wallclock_type type,
timer->val.val = local_time.tm_hour;
} else if (type == TIMEOUT_WEEKDAY) {
timer->val.val = local_time.tm_wday;
} else { /* TIMEOUT_MONTHDAY */
} else if (type == TIMEOUT_MONTHDAY) {
timer->val.val = local_time.tm_mday;
} else if (type == TIMEOUT_MONTH) {
timer->val.val = local_time.tm_mon + 1;
} else { /* TIMEOUT_YEAR */
timer->val.val = local_time.tm_year + 1900;
}
}
}
Expand Down Expand Up @@ -376,6 +425,34 @@ wallclock_monthday_open(struct sol_flow_node *node,
return wallclock_open(node, data, opts->send_initial_packet);
}

static int
wallclock_month_open(struct sol_flow_node *node,
void *data,
const struct sol_flow_node_options *options)
{
struct wallclock_data *mdata = data;
const struct sol_flow_node_type_wallclock_month_options *opts;

opts = (const struct sol_flow_node_type_wallclock_month_options *)
options;
mdata->type = TIMEOUT_MONTH;
return wallclock_open(node, data, opts->send_initial_packet);
}

static int
wallclock_year_open(struct sol_flow_node *node,
void *data,
const struct sol_flow_node_options *options)
{
struct wallclock_data *mdata = data;
const struct sol_flow_node_type_wallclock_year_options *opts;

opts = (const struct sol_flow_node_type_wallclock_year_options *)
options;
mdata->type = TIMEOUT_YEAR;
return wallclock_open(node, data, opts->send_initial_packet);
}

static bool
timeblock_send_packet(void *data)
{
Expand Down
58 changes: 58 additions & 0 deletions src/modules/flow/wallclock/wallclock.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,35 @@
"private_data_type": "wallclock_data",
"url": "http://solettaproject.org/doc/latest/node_types/wallclock_minute.html"
},
{
"category": "timer",
"description": "Provides int packets on a timely manner (after each system clock month changes)",
"methods": {
"close": "wallclock_close",
"open": "wallclock_month_open"
},
"name": "wallclock/month",
"options": {
"members": [
{
"data_type": "boolean",
"default": false,
"description": "If true, a packet containing the current month will be sent during initialization",
"name": "send_initial_packet"
}
],
"version": 1
},
"out_ports": [
{
"data_type": "int",
"description": "An int range packet when wallclock month ticks.",
"name": "OUT"
}
],
"private_data_type": "wallclock_data",
"url": "http://solettaproject.org/doc/latest/node_types/wallclock_month.html"
},
{
"category": "timer",
"description": "Provides int packets on a timely manner (after each system clock month day changes)",
Expand Down Expand Up @@ -185,6 +214,35 @@
],
"private_data_type": "wallclock_timeblock_data",
"url": "http://solettaproject.org/doc/latest/node_types/wallclock_timeblock.html"
},
{
"category": "timer",
"description": "Provides int packets on a timely manner (after each system clock year changes)",
"methods": {
"close": "wallclock_close",
"open": "wallclock_year_open"
},
"name": "wallclock/year",
"options": {
"members": [
{
"data_type": "boolean",
"default": false,
"description": "If true, a packet containing the current year will be sent during initialization",
"name": "send_initial_packet"
}
],
"version": 1
},
"out_ports": [
{
"data_type": "int",
"description": "An int range packet when wallclock year ticks.",
"name": "OUT"
}
],
"private_data_type": "wallclock_data",
"url": "http://solettaproject.org/doc/latest/node_types/wallclock_year.html"
}
]
}

0 comments on commit 3cdbee9

Please sign in to comment.