File: sim_annunciators.c

package info (click to toggle)
openhpi 2.14.1-1.2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 20,380 kB
  • sloc: ansic: 187,087; cpp: 32,188; sh: 10,415; makefile: 4,467; perl: 1,529
file content (173 lines) | stat: -rw-r--r-- 5,567 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
/*      -*- 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_annunciator(struct oh_handler_state *state,
                                struct oh_event *e,
                                struct sim_annunciator * myannun) {
        SaHpiRdrT *rdr;
        struct simAnnunciatorInfo *info = NULL;
        int i;
	SaErrorT error = SA_OK;

        rdr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT));
        // set up res_rdr
        rdr->RdrType = SAHPI_ANNUNCIATOR_RDR;
        memcpy(&rdr->RdrTypeUnion.AnnunciatorRec,
               &myannun->annun, sizeof(SaHpiAnnunciatorRecT));
        oh_init_textbuffer(&rdr->IdString);
        oh_append_textbuffer(&rdr->IdString, myannun->comment);

        // get the entity path
        rdr->Entity = e->resource.ResourceEntity;

        // save the announcements for the annunciator
        for (i = 0; myannun->announs[i].EntryId != 0; i++) {
                if (info == NULL) {
                        info = (struct simAnnunciatorInfo *)g_malloc0(sizeof(struct simAnnunciatorInfo));
                        // set the default mode value
                        info->mode = SAHPI_ANNUNCIATOR_MODE_SHARED;
                        // set up the announcement list
                        info->announs = oh_announcement_create();
                        if (info->announs == NULL) {
                                return SA_ERR_HPI_OUT_OF_SPACE;
                        }
                }
                /* fix the resource id for the announcement */
                myannun->announs[i].StatusCond.ResourceId = e->resource.ResourceId;

                oh_announcement_append(info->announs, &myannun->announs[i]);
        }

        /* everything ready so inject the rdr */
	error = sim_inject_rdr(state, e, rdr, info);
        if (error) {
                g_free(rdr);
                g_free(info);
        }

        return error;
}


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

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

        return 0;
}


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

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

        return 0;
}


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

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

        return 0;
}


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

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

        return 0;
}


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

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

        return 0;
}