1/**
2 * \file
3 * \brief
4 */
5
6/*
7 * Copyright (c) 2010, ETH Zurich and Mircosoft Corporation.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include "internal.h"
16
17struct list {
18    coreid_t id;
19    struct boot_perfmon_binding *b;
20    struct list *next;
21};
22
23struct relations {
24    struct list *head;
25};
26
27errval_t relations_new(struct relations **retrel)
28{
29    // Allocate
30    struct relations *r = malloc(sizeof(struct relations));
31    if (!r) {
32        return LIB_ERR_MALLOC_FAIL;
33    }
34
35    // Initialize
36    r->head = NULL;
37
38    *retrel = r;
39    return SYS_ERR_OK;
40
41}
42
43errval_t relations_add(struct relations *r, coreid_t id,
44                       struct boot_perfmon_binding *b)
45{
46    // Allocate
47    struct list *list = malloc(sizeof(struct list));
48    if (!list) {
49        return LIB_ERR_MALLOC_FAIL;
50    }
51
52    // Initialize
53    list->id = id;
54    list->b = b;
55
56    // Add to the head of list
57    list->next = r->head;
58    r->head = list;
59
60    return SYS_ERR_OK;
61}
62
63errval_t relations_get(struct relations *r, coreid_t id,
64                       struct boot_perfmon_binding **b)
65{
66    struct list *walk = r->head;
67    while (walk) {
68        if (walk->id == id) {
69            *b = walk->b;
70            return SYS_ERR_OK;
71        }
72        walk = walk->next;
73    }
74
75    USER_PANIC("relations_get: item not found");
76}
77
78errval_t relations_iterate(struct relations *r, void *st,
79                           relations_iterator_fn func)
80{
81    errval_t err;
82
83    struct list *walk = r->head;
84    while (walk) {
85        err = func(st, walk->id, walk->b);
86        if (err_is_fail(err)) {
87            return err;
88        }
89        walk = walk->next;
90    }
91
92    return SYS_ERR_OK;
93}
94
95int relations_count(struct relations *r)
96{
97    int count = 0;
98
99    struct list *walk = r->head;
100    while (walk) {
101        count++;
102        walk = walk->next;
103    }
104
105    return count;
106}
107
108errval_t relations_remove(struct relations *r, coreid_t id)
109{
110    USER_PANIC("NYI");
111}
112