File: statd.cc

package info (click to toggle)
glcpu 1.0.1-6.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 136 kB
  • ctags: 64
  • sloc: cpp: 592; makefile: 77; sh: 16
file content (58 lines) | stat: -rw-r--r-- 1,730 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/** Copyright (c) 2000 Jakob Borg
 **
 ** This file implements a small daemon to be run from inetd.
 **
 ** 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 2 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, write to the Free Software
 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 **
 ** $Id: statd.cc,v 1.11 2000/10/22 20:03:43 jb Exp $
 **/

#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int NCPU = 1;
extern const int HISTORY = 20;

extern vector<int>* get_cpu_percent();

/**
 ** When user says DATA, return an array of bytes of the form <n> n*<data>,
 ** that is first the number of data streams, then the raw data.
 ** This data is then smoothed by glcpu before plotting.
 **/

int main()
{
	while (true && cin.good()) {
                // if user disconnects w/o saying QUIT, we will get !cin.good()
		vector<int>* data = get_cpu_percent();
		string foo;
		cin >> foo;
		if (foo == "DATA") {
			cout << data->size() << " ";
			for (unsigned i = 0; i < data->size(); i++) {
				cout << (*data)[i] << " ";
			}
			cout << endl;
		} else if (foo == "QUIT")
			return 0;
		else
			cout << foo << "?" << endl;
	}
	return 0;
}