File: sim_controls.c

package info (click to toggle)
openhpi 3.8.0-2.3
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 31,888 kB
  • sloc: ansic: 225,326; cpp: 63,687; java: 16,472; cs: 15,161; python: 11,884; sh: 11,508; makefile: 4,945; perl: 1,529; xml: 36; asm: 13
file content (186 lines) | stat: -rw-r--r-- 5,842 bytes parent folder | download | duplicates (8)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*      -*- linux-c -*-
 *
 * (C) Copyright IBM Corp. 2005, 2006
 *
 * 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.  This
 * file and program are licensed under a BSD style license.  See
 * the Copying file included with the OpenHPI distribution for
 * full licensing terms.
 *
 * Author(s):
 *        Christina Hernandez <hernanc@us.ibm.com>
 *        W. David Ashley <dashley@us.ibm.com>
 *	  Renier Morales <renier@openhpi.org>
 */


#include <sim_init.h>
#include <rpt_utils.h>


static SaErrorT new_control(struct oh_handler_state *state,
                            struct oh_event *e,
                            struct sim_control *mycontrol) {
        SaHpiRdrT *rdr = NULL;
        struct sim_control_info *info;
	SaErrorT error = SA_OK;

	if (!state || !e || !mycontrol) return SA_ERR_HPI_INVALID_PARAMS;

	rdr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT));
        // Copy information from rdr array to res_rdr
        rdr->RdrType = SAHPI_CTRL_RDR;
        memcpy(&rdr->RdrTypeUnion.CtrlRec, &mycontrol->control,
               sizeof(SaHpiCtrlRecT));

        oh_init_textbuffer(&rdr->IdString);
        oh_append_textbuffer(&rdr->IdString, mycontrol->comment);
        rdr->RecordId =
                oh_get_rdr_uid(SAHPI_CTRL_RDR, rdr->RdrTypeUnion.CtrlRec.Num);

	rdr->Entity = e->resource.ResourceEntity;

        //set up our private data
        info = (struct sim_control_info *)g_malloc(sizeof(struct sim_control_info));
        info->mode = mycontrol->mode;
	info->state.Type = rdr->RdrTypeUnion.CtrlRec.Type;
	switch (info->state.Type) {
		case SAHPI_CTRL_TYPE_DIGITAL:
			info->state.StateUnion.Digital = rdr->RdrTypeUnion.CtrlRec.TypeUnion.Digital.Default;
			break;
		case SAHPI_CTRL_TYPE_DISCRETE:
			info->state.StateUnion.Discrete = rdr->RdrTypeUnion.CtrlRec.TypeUnion.Discrete.Default;
			break;
		case SAHPI_CTRL_TYPE_ANALOG:
			info->state.StateUnion.Analog = rdr->RdrTypeUnion.CtrlRec.TypeUnion.Analog.Default;
			break;
		case SAHPI_CTRL_TYPE_STREAM:
			memcpy(&info->state.StateUnion.Stream, &rdr->RdrTypeUnion.CtrlRec.TypeUnion.Stream.Default, sizeof(SaHpiCtrlStateStreamT));
			break;
		case SAHPI_CTRL_TYPE_TEXT:
			memcpy(&info->state.StateUnion.Text, &rdr->RdrTypeUnion.CtrlRec.TypeUnion.Text.Default, sizeof(SaHpiCtrlStateTextT));
			break;
		case SAHPI_CTRL_TYPE_OEM:
			memcpy(&info->state.StateUnion.Oem, &rdr->RdrTypeUnion.CtrlRec.TypeUnion.Oem.Default, sizeof(SaHpiCtrlStateOemT));
			break;
		default:
			err("Bad Error: Unrecognized control type.");
	}

        // everything ready so add the rdr and extra info to the rptcache
	error = sim_inject_rdr(state, e, rdr, info);
        if (error) {
                g_free(rdr);
                g_free(info);
        }

        return error;
}


SaErrorT sim_discover_chassis_controls(struct oh_handler_state *state,
                                       struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_chassis_controls[i].index != 0) {
                rc = new_control(state, e, &sim_chassis_controls[i]);
                if (rc) {
                        err("Error %d returned when adding chassis control", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d chassis controls injected", j, i);

        return 0;
}


SaErrorT sim_discover_cpu_controls(struct oh_handler_state *state,
                                   struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_cpu_controls[i].index != 0) {
                rc = new_control(state, e, &sim_cpu_controls[i]);
                if (rc) {
                        err("Error %d returned when adding cpu control", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d cpu controls injected", j, i);

        return 0;
}


SaErrorT sim_discover_dasd_controls(struct oh_handler_state *state,
                                    struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_dasd_controls[i].index != 0) {
                rc = new_control(state, e, &sim_dasd_controls[i]);
                if (rc) {
                        err("Error %d returned when adding dasd control", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d dasd controls injected", j, i);

        return 0;
}


SaErrorT sim_discover_hs_dasd_controls(struct oh_handler_state *state,
                                       struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_hs_dasd_controls[i].index != 0) {
                rc = new_control(state, e, &sim_hs_dasd_controls[i]);
                if (rc) {
                        err("Error %d returned when adding hs dasd control", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d hs dasd controls injected", j, i);

        return 0;
}


SaErrorT sim_discover_fan_controls(struct oh_handler_state *state,
                                   struct oh_event *e) {
        SaErrorT rc;
        int i = 0;
        int j = 0;

        while (sim_fan_controls[i].index != 0) {
                rc = new_control(state, e, &sim_fan_controls[i]);
                if (rc) {
                        err("Error %d returned when adding fan control", rc);
                } else {
                        j++;
                }
                i++;
        }
        dbg("%d of %d fan controls injected", j, i);

        return 0;
}