X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Factions%2Fnotify.c;h=93726468e166004ef10cfb4589358a74ca78c134;hb=0f7c296359bf90005e1dadf2d7a02a4b223a8031;hp=3ce1b00f901f332ecd58a7ee4f8db77c2b95329e;hpb=2d57482cbac710612a36b7beae7b59c277006185;p=lttng-tools.git diff --git a/src/common/actions/notify.c b/src/common/actions/notify.c index 3ce1b00f9..93726468e 100644 --- a/src/common/actions/notify.c +++ b/src/common/actions/notify.c @@ -8,9 +8,11 @@ #include #include #include +#include #include -#include #include +#include +#include #define IS_NOTIFY_ACTION(action) \ (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_NOTIFY) @@ -36,7 +38,7 @@ void lttng_action_notify_destroy(struct lttng_action *action) { struct lttng_action_notify *notify_action; notify_action = action_notify_from_action(action); - lttng_firing_policy_destroy(notify_action->policy); + lttng_rate_policy_destroy(notify_action->policy); free(notify_action); } @@ -55,8 +57,8 @@ int lttng_action_notify_serialize(struct lttng_action *action, DBG("Serializing notify action"); notify_action = action_notify_from_action(action); - DBG("Serializing notify action firing policy"); - ret = lttng_firing_policy_serialize(notify_action->policy, payload); + DBG("Serializing notify action rate policy"); + ret = lttng_rate_policy_serialize(notify_action->policy, payload); end: return ret; @@ -70,12 +72,11 @@ bool lttng_action_notify_is_equal(const struct lttng_action *a, _a = action_notify_from_action_const(a); _b = action_notify_from_action_const(b); - return lttng_firing_policy_is_equal(_a->policy, _b->policy); + return lttng_rate_policy_is_equal(_a->policy, _b->policy); } -static const struct lttng_firing_policy * -lttng_action_notify_internal_get_firing_policy( - const struct lttng_action *action) +static const struct lttng_rate_policy * +lttng_action_notify_internal_get_rate_policy(const struct lttng_action *action) { const struct lttng_action_notify *_action; _action = action_notify_from_action_const(action); @@ -83,9 +84,52 @@ lttng_action_notify_internal_get_firing_policy( return _action->policy; } +static enum lttng_error_code lttng_action_notify_mi_serialize( + const struct lttng_action *action, struct mi_writer *writer) +{ + int ret; + enum lttng_action_status status; + enum lttng_error_code ret_code; + const struct lttng_rate_policy *policy = NULL; + + assert(action); + assert(IS_NOTIFY_ACTION(action)); + assert(writer); + + status = lttng_action_notify_get_rate_policy(action, &policy); + assert(status == LTTNG_ACTION_STATUS_OK); + assert(policy != NULL); + + /* Open action notify. */ + ret = mi_lttng_writer_open_element( + writer, mi_lttng_element_action_notify); + if (ret) { + goto mi_error; + } + + ret_code = lttng_rate_policy_mi_serialize(policy, writer); + if (ret_code != LTTNG_OK) { + goto end; + } + + /* Close action notify element. */ + ret = mi_lttng_writer_close_element(writer); + if (ret) { + goto mi_error; + } + + ret_code = LTTNG_OK; + goto end; + +mi_error: + ret_code = LTTNG_ERR_MI_IO_FAIL; +end: + return ret_code; +} + struct lttng_action *lttng_action_notify_create(void) { - struct lttng_firing_policy *policy = NULL; + struct lttng_rate_policy *policy = NULL; struct lttng_action_notify *notify = NULL; struct lttng_action *action = NULL; @@ -95,7 +139,7 @@ struct lttng_action *lttng_action_notify_create(void) } /* Default policy. */ - policy = lttng_firing_policy_every_n_create(1); + policy = lttng_rate_policy_every_n_create(1); if (!policy) { goto end; } @@ -104,7 +148,9 @@ struct lttng_action *lttng_action_notify_create(void) lttng_action_notify_serialize, lttng_action_notify_is_equal, lttng_action_notify_destroy, - lttng_action_notify_internal_get_firing_policy); + lttng_action_notify_internal_get_rate_policy, + lttng_action_generic_add_error_query_results, + lttng_action_notify_mi_serialize); notify->policy = policy; policy = NULL; @@ -114,7 +160,7 @@ struct lttng_action *lttng_action_notify_create(void) end: free(notify); - lttng_firing_policy_destroy(policy); + lttng_rate_policy_destroy(policy); return action; } @@ -124,12 +170,12 @@ ssize_t lttng_action_notify_create_from_payload( { enum lttng_action_status status; ssize_t consumed_length; - struct lttng_firing_policy *firing_policy = NULL; + struct lttng_rate_policy *rate_policy = NULL; struct lttng_action *_action = NULL; - consumed_length = lttng_firing_policy_create_from_payload( - view, &firing_policy); - if (!firing_policy) { + consumed_length = lttng_rate_policy_create_from_payload( + view, &rate_policy); + if (!rate_policy) { consumed_length = -1; goto end; } @@ -140,7 +186,7 @@ ssize_t lttng_action_notify_create_from_payload( goto end; } - status = lttng_action_notify_set_firing_policy(_action, firing_policy); + status = lttng_action_notify_set_rate_policy(_action, rate_policy); if (status != LTTNG_ACTION_STATUS_OK) { consumed_length = -1; goto end; @@ -150,25 +196,25 @@ ssize_t lttng_action_notify_create_from_payload( _action = NULL; end: - lttng_firing_policy_destroy(firing_policy); + lttng_rate_policy_destroy(rate_policy); lttng_action_destroy(_action); return consumed_length; } -enum lttng_action_status lttng_action_notify_set_firing_policy( +enum lttng_action_status lttng_action_notify_set_rate_policy( struct lttng_action *action, - const struct lttng_firing_policy *policy) + const struct lttng_rate_policy *policy) { enum lttng_action_status status; struct lttng_action_notify *notify_action; - struct lttng_firing_policy *copy = NULL; + struct lttng_rate_policy *copy = NULL; if (!action || !policy || !IS_NOTIFY_ACTION(action)) { status = LTTNG_ACTION_STATUS_INVALID; goto end; } - copy = lttng_firing_policy_copy(policy); + copy = lttng_rate_policy_copy(policy); if (!copy) { status = LTTNG_ACTION_STATUS_ERROR; goto end; @@ -176,8 +222,8 @@ enum lttng_action_status lttng_action_notify_set_firing_policy( notify_action = action_notify_from_action(action); - /* Free the previous firing policy .*/ - lttng_firing_policy_destroy(notify_action->policy); + /* Free the previous rate policy .*/ + lttng_rate_policy_destroy(notify_action->policy); /* Assign the policy. */ notify_action->policy = copy; @@ -185,13 +231,13 @@ enum lttng_action_status lttng_action_notify_set_firing_policy( copy = NULL; end: - lttng_firing_policy_destroy(copy); + lttng_rate_policy_destroy(copy); return status; } -enum lttng_action_status lttng_action_notify_get_firing_policy( +enum lttng_action_status lttng_action_notify_get_rate_policy( const struct lttng_action *action, - const struct lttng_firing_policy **policy) + const struct lttng_rate_policy **policy) { enum lttng_action_status status; const struct lttng_action_notify *notify_action;