Merge branch 'collectd-4.4' into collectd-4.5
[collectd.git] / src / xmms.c
1 /**
2  * collectd - src/xmms.c
3  * Copyright (C) 2007  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #include "collectd.h"
23 #include "plugin.h"
24 #include "common.h"
25
26 #include <xmms/xmmsctrl.h>
27
28 static gint xmms_session;
29
30 static void cxmms_submit (const char *type, gauge_t value)
31 {
32         value_t values[1];
33         value_list_t vl = VALUE_LIST_INIT;
34
35         values[0].gauge = value;
36
37         vl.values = values;
38         vl.values_len = 1;
39         vl.time = time (NULL);
40         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
41         sstrncpy (vl.plugin, "xmms", sizeof (vl.plugin));
42         sstrncpy (vl.type, type, sizeof (vl.type));
43
44         plugin_dispatch_values (&vl);
45 } /* void cxmms_submit */
46
47 int cxmms_read (void)
48 {
49   gint rate;
50   gint freq;
51   gint nch;
52
53   if (!xmms_remote_is_running (xmms_session))
54     return (0);
55
56   xmms_remote_get_info (xmms_session, &rate, &freq, &nch);
57
58   if ((freq == 0) || (nch == 0))
59     return (-1);
60
61   cxmms_submit ("bitrate", rate);
62   cxmms_submit ("frequency", freq);
63
64   return (0);
65 } /* int read */
66
67 void module_register (void)
68 {
69   plugin_register_read ("xmms", cxmms_read);
70 } /* void module_register */
71
72 /*
73  * vim: shiftwidth=2:softtabstop=2:textwidth=78
74  */