--- /dev/null
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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 _GNU_SOURCE 1
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "decision_made_event.h"
+
+static int allocate_dm_event(struct faultd_event_type *type,
+ void *data, struct faultd_event **ev)
+{
+ struct decision_made_event *dm_ev;
+ struct dm_event_data *dm_ev_data = data;
+ int ret;
+
+ dm_ev = malloc(sizeof(*dm_ev));
+ if (!dm_ev)
+ return -ENOMEM;
+
+ ret = faultd_event_init(type, &dm_ev->event);
+ if (ret)
+ goto free_dm_ev;
+
+ dm_ev->who_made = strdup(dm_ev_data->who_made);
+ dm_ev->action = strdup(dm_ev_data->action);
+
+ if (!dm_ev->who_made || !dm_ev->action) {
+ ret = -ENOMEM;
+ goto cleanup_strs;
+ }
+
+ dm_ev->action_data = dm_ev_data->action_data;
+ dm_ev->action_data_release = dm_ev_data->action_data_release;
+
+ dm_ev->reason = dm_ev_data->reason;
+ faultd_event_ref(dm_ev->reason);
+
+ *ev = &dm_ev->event;
+ return 0;
+cleanup_strs:
+ free(dm_ev->who_made);
+ free(dm_ev->action);
+
+ faultd_event_cleanup(&dm_ev->event);
+free_dm_ev:
+ free(dm_ev);
+
+ return ret;
+}
+
+static void dm_event_release(struct faultd_event *ev)
+{
+ struct decision_made_event *dm_ev =
+ to_decision_made_event(ev);
+
+ free(dm_ev->who_made);
+ free(dm_ev->action);
+ if (dm_ev->action_data_release)
+ dm_ev->action_data_release(dm_ev->action_data);
+ faultd_event_unref(dm_ev->reason);
+ faultd_event_cleanup(&dm_ev->event);
+ free(dm_ev);
+}
+
+static char *dm_event_to_string(struct faultd_event *ev)
+{
+ struct decision_made_event *dm_ev =
+ to_decision_made_event(ev);
+ char *str;
+ int ret;
+
+ /* TODO print action data? */
+ ret = asprintf(&str, "Decision Made Event:"
+ " Who made: %s"
+ " Action: %s",
+ dm_ev->who_made,
+ dm_ev->action);
+
+ return ret > 0 ? str : NULL;
+}
+
+static struct faultd_event_type decision_made_event_type = {
+ .name = DECISION_MADE_EVENT_ID,
+ .default_ops = {
+ .to_string = dm_event_to_string,
+ .release = dm_event_release,
+ },
+ .allocate_event = allocate_dm_event,
+ .node = LIST_HEAD_INIT(decision_made_event_type.node),
+};
+
+FAULTD_EVENT_TYPE_REGISTER(decision_made_event_type, decision_made_et)
--- /dev/null
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * 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 FAULTD_DECISION_MADE_EVENT_H
+#define FAULTD_DECISION_MADE_EVENT_H
+
+#include <time.h>
+
+#include "action.h"
+#include "event.h"
+#include "common.h"
+
+#define DECISION_MADE_EVENT_ID "decision_made"
+
+struct decision_made_event {
+ struct faultd_event event;
+ struct faultd_event *reason;
+ char *who_made;
+ char *action;
+ void *action_data;
+ void (*action_data_release)(void *);
+ /* TODO: what more do we need? */
+};
+
+struct dm_event_data {
+ /* This is referenced by dm event */
+ struct faultd_event *reason;
+ /* Strings are deep copied */
+ char *who_made;
+ char *action;
+ /* Action data is shallow copied */
+ void *action_data;
+ void (*action_data_release)(void *);
+};
+
+#define to_decision_made_event(EVENT) \
+ container_of(EVENT, struct decision_made_event, event)
+
+#endif /* FAULTD_DECISION_MADE_EVENT_H */