source: trunk/third/libgtop/lib/parameter.c @ 20897

Revision 20897, 3.0 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20896, which included commits to RCS files with non-trunk default branches.
Line 
1/* $Id: parameter.c,v 1.1.1.2 2004-10-03 04:59:47 ghudson Exp $ */
2
3/* Copyright (C) 1998-99 Martin Baulig
4   This file is part of LibGTop 1.0.
5
6   Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
7
8   LibGTop is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License,
11   or (at your option) any later version.
12
13   LibGTop is distributed in the hope that it will be useful, but WITHOUT
14   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16   for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with LibGTop; see the file COPYING. If not, write to the
20   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21   Boston, MA 02111-1307, USA.
22*/
23
24#include <glibtop.h>
25#include <glibtop/parameter.h>
26
27#define _write_data(ptr,size)   \
28        if ((data_ptr == NULL) || (data_size < size)) return -size; \
29        if (ptr == NULL) { char * const p = data_ptr; *p = '\0'; return 1; } \
30        memcpy (data_ptr, ptr, size);   \
31        return size;
32
33#define _check_data(size)       \
34        if ((data_ptr == NULL) || (data_size != size)) { \
35                glibtop_warn_r (server, "glibtop_set_parameter (%d): " \
36                                "Expected %lu bytes but got %lu.", \
37                                parameter, size, data_size); \
38                return; \
39        }
40
41#define _strlen(ptr)    (ptr ? strlen (ptr) : 0)
42
43size_t
44glibtop_get_parameter_l (glibtop *server, const unsigned parameter,
45                         void *data_ptr, size_t data_size)
46{
47        switch (parameter) {
48        case GLIBTOP_PARAM_METHOD:
49                _write_data (&server->method,
50                             sizeof (server->method));
51        case GLIBTOP_PARAM_FEATURES:
52                _write_data (&server->features,
53                             sizeof (server->features));
54        case GLIBTOP_PARAM_COMMAND:
55                _write_data (server->server_command,
56                             _strlen(server->server_command));
57        case GLIBTOP_PARAM_HOST:
58                _write_data (server->server_host,
59                             _strlen(server->server_host));
60        case GLIBTOP_PARAM_PORT:
61                _write_data (&server->server_port,
62                             sizeof (server->server_port));
63        case GLIBTOP_PARAM_ERROR_METHOD:
64                _write_data (&server->error_method,
65                             sizeof (server->error_method));
66        case GLIBTOP_PARAM_REQUIRED:
67                _write_data (&server->required,
68                             sizeof (server->required));
69        }
70
71        return 0;
72}
73
74void
75glibtop_set_parameter_l (glibtop *server, const unsigned parameter,
76                         const void *data_ptr, size_t data_size)
77{
78        switch (parameter) {
79        case GLIBTOP_PARAM_METHOD:
80                _check_data (sizeof (server->method));
81                memcpy (&server->method, data_ptr, data_size);
82                break;
83        case GLIBTOP_PARAM_FEATURES:
84                /* You should not be allowed to set this field. */
85                glibtop_warn_r (server, "glibtop_set_parameter (%d): " \
86                                "Cannot modify read-only value.",
87                                parameter);
88                break;
89        case GLIBTOP_PARAM_ERROR_METHOD:
90                _check_data (sizeof (server->error_method));
91                memcpy (&server->error_method, data_ptr, data_size);
92                break;
93        case GLIBTOP_PARAM_REQUIRED:
94                _check_data (sizeof (server->required));
95                memcpy (&server->required, data_ptr, data_size);
96                break;
97        }
98}
Note: See TracBrowser for help on using the repository browser.