mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +00:00
convert user objects to callbacks.{print,free}
This commit is contained in:
parent
b4aa2328d7
commit
82d6d349ba
@ -65,7 +65,7 @@ ibm = ibm.c ibm.h smapi.c smapi.h
|
|||||||
mpd = mpd.c mpd.h libmpdclient.c libmpdclient.h
|
mpd = mpd.c mpd.h libmpdclient.c libmpdclient.h
|
||||||
moc = moc.c moc.h
|
moc = moc.c moc.h
|
||||||
xmms2 = xmms2.c xmms2.h
|
xmms2 = xmms2.c xmms2.h
|
||||||
linux = linux.c linux.h top.c top.h users.c sony.c sony.h i8k.c i8k.h
|
linux = linux.c linux.h top.c top.h users.c users.h sony.c sony.h i8k.c i8k.h
|
||||||
solaris = solaris.c
|
solaris = solaris.c
|
||||||
freebsd = freebsd.c freebsd.h
|
freebsd = freebsd.c freebsd.h
|
||||||
netbsd = netbsd.c netbsd.h
|
netbsd = netbsd.c netbsd.h
|
||||||
|
18
src/conky.c
18
src/conky.c
@ -1273,24 +1273,6 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
DO_JUMP;
|
DO_JUMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef __linux__
|
|
||||||
OBJ(user_names) {
|
|
||||||
snprintf(p, p_max_size, "%s", cur->users.names);
|
|
||||||
}
|
|
||||||
OBJ(user_terms) {
|
|
||||||
snprintf(p, p_max_size, "%s", cur->users.terms);
|
|
||||||
}
|
|
||||||
OBJ(user_times) {
|
|
||||||
snprintf(p, p_max_size, "%s", cur->users.times);
|
|
||||||
}
|
|
||||||
OBJ(user_time) {
|
|
||||||
update_user_time(obj->data.s);
|
|
||||||
snprintf(p, p_max_size, "%s", cur->users.ctime);
|
|
||||||
}
|
|
||||||
OBJ(user_number) {
|
|
||||||
snprintf(p, p_max_size, "%d", cur->users.number);
|
|
||||||
}
|
|
||||||
#endif /* __linux__ */
|
|
||||||
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
#if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
||||||
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
|| defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
|
||||||
OBJ(apm_adapter) {
|
OBJ(apm_adapter) {
|
||||||
|
@ -307,10 +307,6 @@ extern int cpu_separate;
|
|||||||
* instances of the same text object */
|
* instances of the same text object */
|
||||||
extern struct information info;
|
extern struct information info;
|
||||||
|
|
||||||
/* defined in users.c */
|
|
||||||
void update_users(void);
|
|
||||||
void update_user_time(char *tty);
|
|
||||||
|
|
||||||
/* defined in conky.c */
|
/* defined in conky.c */
|
||||||
extern double current_update_time, last_update_time, update_interval;
|
extern double current_update_time, last_update_time, update_interval;
|
||||||
|
|
||||||
|
37
src/core.c
37
src/core.c
@ -63,6 +63,7 @@
|
|||||||
#include "tailhead.h"
|
#include "tailhead.h"
|
||||||
#include "timeinfo.h"
|
#include "timeinfo.h"
|
||||||
#include "top.h"
|
#include "top.h"
|
||||||
|
#include "users.h"
|
||||||
|
|
||||||
#ifdef NCURSES
|
#ifdef NCURSES
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
@ -1047,11 +1048,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
obj->callbacks.print = &print_uptime;
|
obj->callbacks.print = &print_uptime;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
END OBJ(user_names, &update_users)
|
END OBJ(user_names, &update_users)
|
||||||
|
obj->callbacks.print = &print_user_names;
|
||||||
|
obj->callbacks.free = &free_user_names;
|
||||||
END OBJ(user_times, &update_users)
|
END OBJ(user_times, &update_users)
|
||||||
|
obj->callbacks.print = &print_user_times;
|
||||||
|
obj->callbacks.free = &free_user_times;
|
||||||
END OBJ_ARG(user_time, 0, "user time needs a console name as argument")
|
END OBJ_ARG(user_time, 0, "user time needs a console name as argument")
|
||||||
obj->data.s = strndup(arg, text_buffer_size);
|
obj->data.s = strndup(arg, text_buffer_size);
|
||||||
|
obj->callbacks.print = &print_user_time;
|
||||||
|
obj->callbacks.free = &free_user_time;
|
||||||
END OBJ(user_terms, &update_users)
|
END OBJ(user_terms, &update_users)
|
||||||
|
obj->callbacks.print = &print_user_terms;
|
||||||
|
obj->callbacks.free = &free_user_terms;
|
||||||
END OBJ(user_number, &update_users)
|
END OBJ(user_number, &update_users)
|
||||||
|
obj->callbacks.print = &print_user_number;
|
||||||
END OBJ(gw_iface, &update_gateway_info)
|
END OBJ(gw_iface, &update_gateway_info)
|
||||||
obj->callbacks.print = &print_gateway_iface;
|
obj->callbacks.print = &print_gateway_iface;
|
||||||
END OBJ(gw_ip, &update_gateway_info)
|
END OBJ(gw_ip, &update_gateway_info)
|
||||||
@ -1885,33 +1895,6 @@ void free_text_objects(struct text_object *root, int internal)
|
|||||||
free_top(obj, internal);
|
free_top(obj, internal);
|
||||||
break;
|
break;
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
case OBJ_user_names:
|
|
||||||
if (info.users.names) {
|
|
||||||
free(info.users.names);
|
|
||||||
info.users.names = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OBJ_user_terms:
|
|
||||||
if (info.users.terms) {
|
|
||||||
free(info.users.terms);
|
|
||||||
info.users.terms = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OBJ_user_times:
|
|
||||||
if (info.users.times) {
|
|
||||||
free(info.users.times);
|
|
||||||
info.users.times = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case OBJ_user_time:
|
|
||||||
if (info.users.ctime) {
|
|
||||||
free(info.users.ctime);
|
|
||||||
info.users.ctime = 0;
|
|
||||||
}
|
|
||||||
if (data.s) {
|
|
||||||
free(data.s);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#ifdef MPD
|
#ifdef MPD
|
||||||
case OBJ_mpd_title:
|
case OBJ_mpd_title:
|
||||||
case OBJ_mpd_artist:
|
case OBJ_mpd_artist:
|
||||||
|
69
src/users.c
69
src/users.c
@ -129,7 +129,7 @@ static void users_alloc(struct information *ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_user_time(char *tty)
|
static void update_user_time(char *tty)
|
||||||
{
|
{
|
||||||
struct information *current_info = &info;
|
struct information *current_info = &info;
|
||||||
char temp[BUFLEN] = "";
|
char temp[BUFLEN] = "";
|
||||||
@ -222,3 +222,70 @@ void update_users(void)
|
|||||||
strncpy(current_info->users.times, "broken", text_buffer_size);
|
strncpy(current_info->users.times, "broken", text_buffer_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_user_names(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
snprintf(p, p_max_size, "%s", info.users.names);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_user_terms(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
snprintf(p, p_max_size, "%s", info.users.terms);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_user_times(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
snprintf(p, p_max_size, "%s", info.users.times);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_user_time(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
update_user_time(obj->data.s);
|
||||||
|
snprintf(p, p_max_size, "%s", info.users.ctime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_user_number(struct text_object *obj, char *p, int p_max_size)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
snprintf(p, p_max_size, "%d", info.users.number);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_user_names(struct text_object *obj)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
if (info.users.names) {
|
||||||
|
free(info.users.names);
|
||||||
|
info.users.names = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_user_terms(struct text_object *obj)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
if (info.users.terms) {
|
||||||
|
free(info.users.terms);
|
||||||
|
info.users.terms = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_user_times(struct text_object *obj)
|
||||||
|
{
|
||||||
|
(void)obj;
|
||||||
|
if (info.users.times) {
|
||||||
|
free(info.users.times);
|
||||||
|
info.users.times = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_user_time(struct text_object *obj)
|
||||||
|
{
|
||||||
|
if (info.users.ctime) {
|
||||||
|
free(info.users.ctime);
|
||||||
|
info.users.ctime = 0;
|
||||||
|
}
|
||||||
|
if (obj->data.s)
|
||||||
|
free(obj->data.s);
|
||||||
|
}
|
||||||
|
47
src/users.h
Normal file
47
src/users.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
||||||
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
||||||
|
*
|
||||||
|
* Conky, a system monitor, based on torsmo
|
||||||
|
*
|
||||||
|
* Any original torsmo code is licensed under the BSD license
|
||||||
|
*
|
||||||
|
* All code written since the fork of torsmo is licensed under the GPL
|
||||||
|
*
|
||||||
|
* Please see COPYING for details
|
||||||
|
*
|
||||||
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
||||||
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
||||||
|
* (see AUTHORS)
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _USERS_H
|
||||||
|
#define _USERS_H
|
||||||
|
|
||||||
|
void update_users(void);
|
||||||
|
|
||||||
|
void print_user_names(struct text_object *, char *, int);
|
||||||
|
void print_user_terms(struct text_object *, char *, int);
|
||||||
|
void print_user_times(struct text_object *, char *, int);
|
||||||
|
void print_user_time(struct text_object *, char *, int);
|
||||||
|
void print_user_number(struct text_object *, char *, int);
|
||||||
|
|
||||||
|
void free_user_names(struct text_object *);
|
||||||
|
void free_user_terms(struct text_object *);
|
||||||
|
void free_user_times(struct text_object *);
|
||||||
|
void free_user_time(struct text_object *);
|
||||||
|
|
||||||
|
#endif /* _USERS_H */
|
Loading…
Reference in New Issue
Block a user