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
|
/* This file is part of cmpiLinux_FanProvider.
*
* cmpiLinux_FanProvider 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 3 of the License, or
* (at your option) any later version.
*
* cmpiLinux_FanProvider 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 cmpiLinux_FanProvider. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef _XOPEN_SOURCE
//this is for strdup
#define _XOPEN_SOURCE 500
#endif
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <cmpi/cmpimacs.h>
#include <sblim/OSBase_Common.h>
#include <sblim/cmpiOSBase_Common.h>
#include "cmpiLinux_Fan.h"
static CMPIArray * _get_AccessibleFeatures(
CMPIBroker const *_broker,
CMPIStatus *rc,
struct cim_fan const *sptr)
{
int index = 0;
uint16_t value = 1;
unsigned int i = 1;
CMPIArray *res = CMNewArray(_broker, 8, CMPI_uint16, rc);
if (!res) {
CMSetStatusWithChars(_broker, rc, CMPI_RC_ERR_FAILED,
"CMNewArray(_broker, 8, CMPI_uint16, rc)");
_OSBASE_TRACE(2, ("--- _get_AccessibleFeatures failed: %s",
CMGetCharPtr(rc->msg)));
}else {
while (i <= CIM_FAN_AF_FEATURE_MAX) {
if (i & sptr->accessible_features) {
CMSetArrayElementAt(res, index++, (CMPIValue*)(&value),
CMPI_uint16);
}
++value;
i = i << 1;
}
}
return res;
}
CMPIObjectPath * _makePath_Fan(
CMPIBroker const *_broker,
CMPIContext const *ctx,
CMPIObjectPath const *cop,
struct cim_fan *sptr,
CMPIStatus *rc)
{
return _makePath_FanCommon(_ClassName, _broker, ctx, cop, sptr, rc);
}
CMPIInstance * _makeInst_Fan(
CMPIBroker const *_broker,
CMPIContext const *ctx,
CMPIObjectPath const *cop,
char const **properties,
struct cim_fan *sptr,
CMPIStatus *rc)
{
CMPIObjectPath *op;
CMPIInstance *ci;
CMPIValue val;
_OSBASE_TRACE(2, ("--- _makeInst_Fan() called"));
if (!(ci = _makeInst_FanCommon(_ClassName, _broker, ctx, cop, properties,
sptr, rc, &op))) {
return NULL;
}
// CoolingDevice
val.boolean = true;
CMSetProperty(ci, "ActiveCooling", &val, CMPI_boolean);
// CIM_Fan
// Linux_Fan
val.array = _get_AccessibleFeatures(_broker, rc, sptr);
if (!rc->rc) {
CMSetProperty(ci, "AccessibleFeatures", &val, CMPI_uint16A);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_MIN_SPEED) {
val.uint64 = (uint64_t) sptr->min_speed;
CMSetProperty(ci, "MinSpeed", &val, CMPI_uint64);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_MAX_SPEED) {
val.uint64 = (uint64_t) sptr->max_speed;
CMSetProperty(ci, "MaxSpeed", &val, CMPI_uint64);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_DIV) {
CMSetProperty(ci, "Divisor", &sptr->divisor, CMPI_uint32);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_PULSES) {
CMSetProperty(ci, "Pulses", &sptr->pulses, CMPI_uint32);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_BEEP) {
val.boolean = sptr->beep;
CMSetProperty(ci, "Beep", &val, CMPI_boolean);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_ALARM) {
CMSetProperty(ci, "Alarm", &sptr->alarm, CMPI_boolean);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_ALARM_MIN) {
CMSetProperty(ci, "MinAlarm", &sptr->alarm_min, CMPI_boolean);
}
if (!rc->rc && sptr->accessible_features & CIM_FAN_AF_ALARM_MAX) {
CMSetProperty(ci, "MaxAlarm", &sptr->alarm_max, CMPI_boolean);
}
_OSBASE_TRACE(2, ("--- _makeInst_Fan() exited"));
return ci;
}
|