aboutsummaryrefslogtreecommitdiff
path: root/user-notification.h
blob: df2390c7d695aae8d84b7c12d7ea2b57428b8de6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once

#include <tllist.h>

#include "macros.h"

enum user_notification_kind {
    USER_NOTIFICATION_DEPRECATED,
    USER_NOTIFICATION_WARNING,
    USER_NOTIFICATION_ERROR,
};

struct user_notification {
    enum user_notification_kind kind;
    char *text;
};

typedef tll(struct user_notification) user_notifications_t;

static inline void
user_notifications_free(user_notifications_t *notifications)
{
    tll_foreach(*notifications, it)
        free(it->item.text);
    tll_free(*notifications);
}

static inline void
user_notification_add(user_notifications_t *notifications,
    enum user_notification_kind kind, char *text)
{
    struct user_notification notification = {
        .kind = kind,
        .text = text
    };
    tll_push_back(*notifications, notification);
}

void user_notification_add_fmt(user_notifications_t *notifications,
                           enum user_notification_kind kind,
                           const char *fmt, ...) PRINTF(3);