File: dmucs_msg.h

package info (click to toggle)
dmucs 0.6.1-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 3,220 kB
  • sloc: ansic: 5,053; sh: 3,557; cpp: 2,472; makefile: 63; perl: 26
file content (117 lines) | stat: -rwxr-xr-x 3,049 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#ifndef _DMUCS_PKT_H_
#define _DMUCS_PKT_H_

/*
 * dmucs_msg.h: definition of a DMUCS packet received by the DMUCS server.
 *
 * Copyright (C) 2005, 2006  Victor T. Norman
 *
 * 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
 */

#include "COSMIC/HDR/sockets.h"

enum dmucs_req_t {
    HOST_REQ,
    LOAD_AVERAGE_INFORM,
    STATUS_INFORM,
    MONITOR_REQ
};


/*
 * Format of packets that come in to the dmucs server:
 *
 * o host request:   "host <client IP address>
 * o load average:   "load <host IP address> <3 floating pt numbers>"
 * o status message: "status <host IP address> up|down [n <numCpus>]
 *		[p <powerIndex>]"
 * o monistor req:   "monitor <client IP address>"
 */

#include "dmucs_host.h"
#include "dmucs_dprop.h"

class DmucsMsg {
private:
protected:
    struct in_addr clientIp_;
    DmucsDprop dprop_;

    DmucsMsg(struct in_addr clientIp, DmucsDprop dprop) :
	clientIp_(clientIp), dprop_(dprop) {}

public:
    /* Factory Method: parseMsg */
    static DmucsMsg *parseMsg(Socket *sock, const char *buf);

    virtual void handle(Socket *sock, const char *buf) = 0;
};


class DmucsStatusMsg : public DmucsMsg
{
private:
    struct in_addr host_;
    host_status_t status_;
    int numCpus_;
    int powerIndex_;

public:
    DmucsStatusMsg(struct in_addr clientIp, struct in_addr host,
		   host_status_t status, DmucsDprop dprop) :
	DmucsMsg(clientIp, dprop), 
	host_(host), status_(status), numCpus_(1), powerIndex_(1) {}
    void handle(Socket *sock, const char *buf);
};


class DmucsLdAvgMsg : public DmucsMsg
{
private:
    struct in_addr host_;
    float ldAvg1_, ldAvg5_, ldAvg10_;

public:
    DmucsLdAvgMsg(struct in_addr clientIp, struct in_addr host,
		  float ldavg1, float ldavg5,
		  float ldavg10, DmucsDprop dprop) :
	DmucsMsg(clientIp, dprop), 
	host_(host), ldAvg1_(ldavg1), ldAvg5_(ldavg5), ldAvg10_(ldavg10) {}
    void handle(Socket *sock, const char *buf);
};


class DmucsHostReqMsg : public DmucsMsg
{
public:
    DmucsHostReqMsg(struct in_addr clientIp, DmucsDprop dprop) :
	DmucsMsg(clientIp, dprop) {}
    void handle(Socket *sock, const char *buf);
};


class DmucsMonitorReqMsg : public DmucsMsg
{
public:
    DmucsMonitorReqMsg(struct in_addr clientIp, DmucsDprop dprop) :
	DmucsMsg(clientIp, dprop) {};
    void handle(Socket *sock, const char *buf);
};


#define BUFSIZE 1024	// largest info we will read from the socket.

#endif