source: trunk/packages/xen-3.1/xen-3.1/tools/libxen/src/xen_vif_metrics.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 4.9 KB
Line 
1/*
2 * Copyright (c) 2006-2007, XenSource Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
17 */
18
19
20#include <stddef.h>
21#include <stdlib.h>
22
23#include "xen_internal.h"
24#include <xen/api/xen_common.h>
25#include <xen/api/xen_vif_metrics.h>
26
27
28XEN_FREE(xen_vif_metrics)
29XEN_SET_ALLOC_FREE(xen_vif_metrics)
30XEN_ALLOC(xen_vif_metrics_record)
31XEN_SET_ALLOC_FREE(xen_vif_metrics_record)
32XEN_ALLOC(xen_vif_metrics_record_opt)
33XEN_RECORD_OPT_FREE(xen_vif_metrics)
34XEN_SET_ALLOC_FREE(xen_vif_metrics_record_opt)
35
36
37static const struct_member xen_vif_metrics_record_struct_members[] =
38    {
39        { .key = "uuid",
40          .type = &abstract_type_string,
41          .offset = offsetof(xen_vif_metrics_record, uuid) },
42        { .key = "io_read_kbs",
43          .type = &abstract_type_float,
44          .offset = offsetof(xen_vif_metrics_record, io_read_kbs) },
45        { .key = "io_write_kbs",
46          .type = &abstract_type_float,
47          .offset = offsetof(xen_vif_metrics_record, io_write_kbs) },
48        { .key = "last_updated",
49          .type = &abstract_type_datetime,
50          .offset = offsetof(xen_vif_metrics_record, last_updated) }
51    };
52
53const abstract_type xen_vif_metrics_record_abstract_type_ =
54    {
55       .typename = STRUCT,
56       .struct_size = sizeof(xen_vif_metrics_record),
57       .member_count =
58           sizeof(xen_vif_metrics_record_struct_members) / sizeof(struct_member),
59       .members = xen_vif_metrics_record_struct_members
60    };
61
62
63void
64xen_vif_metrics_record_free(xen_vif_metrics_record *record)
65{
66    if (record == NULL)
67    {
68        return;
69    }
70    free(record->handle);
71    free(record->uuid);
72    free(record);
73}
74
75
76bool
77xen_vif_metrics_get_record(xen_session *session, xen_vif_metrics_record **result, xen_vif_metrics vif_metrics)
78{
79    abstract_value param_values[] =
80        {
81            { .type = &abstract_type_string,
82              .u.string_val = vif_metrics }
83        };
84
85    abstract_type result_type = xen_vif_metrics_record_abstract_type_;
86
87    *result = NULL;
88    XEN_CALL_("VIF_metrics.get_record");
89
90    if (session->ok)
91    {
92       (*result)->handle = xen_strdup_((*result)->uuid);
93    }
94
95    return session->ok;
96}
97
98
99bool
100xen_vif_metrics_get_by_uuid(xen_session *session, xen_vif_metrics *result, char *uuid)
101{
102    abstract_value param_values[] =
103        {
104            { .type = &abstract_type_string,
105              .u.string_val = uuid }
106        };
107
108    abstract_type result_type = abstract_type_string;
109
110    *result = NULL;
111    XEN_CALL_("VIF_metrics.get_by_uuid");
112    return session->ok;
113}
114
115
116bool
117xen_vif_metrics_get_io_read_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics)
118{
119    abstract_value param_values[] =
120        {
121            { .type = &abstract_type_string,
122              .u.string_val = vif_metrics }
123        };
124
125    abstract_type result_type = abstract_type_float;
126
127    XEN_CALL_("VIF_metrics.get_io_read_kbs");
128    return session->ok;
129}
130
131
132bool
133xen_vif_metrics_get_io_write_kbs(xen_session *session, double *result, xen_vif_metrics vif_metrics)
134{
135    abstract_value param_values[] =
136        {
137            { .type = &abstract_type_string,
138              .u.string_val = vif_metrics }
139        };
140
141    abstract_type result_type = abstract_type_float;
142
143    XEN_CALL_("VIF_metrics.get_io_write_kbs");
144    return session->ok;
145}
146
147
148bool
149xen_vif_metrics_get_last_updated(xen_session *session, time_t *result, xen_vif_metrics vif_metrics)
150{
151    abstract_value param_values[] =
152        {
153            { .type = &abstract_type_string,
154              .u.string_val = vif_metrics }
155        };
156
157    abstract_type result_type = abstract_type_datetime;
158
159    XEN_CALL_("VIF_metrics.get_last_updated");
160    return session->ok;
161}
162
163
164bool
165xen_vif_metrics_get_all(xen_session *session, struct xen_vif_metrics_set **result)
166{
167
168    abstract_type result_type = abstract_type_string_set;
169
170    *result = NULL;
171    xen_call_(session, "VIF_metrics.get_all", NULL, 0, &result_type, result);
172    return session->ok;
173}
174
175
176bool
177xen_vif_metrics_get_uuid(xen_session *session, char **result, xen_vif_metrics vif_metrics)
178{
179    abstract_value param_values[] =
180        {
181            { .type = &abstract_type_string,
182              .u.string_val = vif_metrics }
183        };
184
185    abstract_type result_type = abstract_type_string;
186
187    *result = NULL;
188    XEN_CALL_("VIF_metrics.get_uuid");
189    return session->ok;
190}
Note: See TracBrowser for help on using the repository browser.