-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmpiOSBase_Service.c
185 lines (153 loc) · 6.07 KB
/
cmpiOSBase_Service.c
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
/*
* cmpiOSBase_Service.c
*
* (C) Copyright IBM Corp. 2002, 2004
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
* CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
*
* You can obtain a current copy of the Common Public License from
* http://oss.software.ibm.com/developerworks/opensource/license-cpl.html
*
* Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
* Contributors: Heidi Neumann <heidineu@de.ibm.com>
*
* Interface Type : Common Manageability Programming Interface ( CMPI )
*
* Description:
* This is the factory implementation for creating instances of CIM
* class Linux_Service.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cmpidt.h"
#include "cmpimacs.h"
#include "cmpiOSBase_Common.h"
#include "OSBase_Common.h"
#include "cmpiOSBase_Service.h"
/* ---------------------------------------------------------------------------*/
/* private declarations */
/* ---------------------------------------------------------------------------*/
/* ---------------------------------------------------------------------------*/
/* Factory functions */
/* ---------------------------------------------------------------------------*/
/* ---------- method to create a CMPIObjectPath of Linux_Service -------------*/
CMPIObjectPath * _makePath_Service( const CMPIBroker * _broker,
const CMPIContext * ctx,
const CMPIObjectPath * ref,
LXS_Service * lxssvc,
CMPIStatus * rc) {
CMPIObjectPath * op = NULL;
_OSBASE_TRACE(2,("--- _makePath_Service() called"));
/* the sblim-cmpi-base package offers some tool methods to get common
* system data
*/
if( !get_system_name() ) {
CMSetStatusWithChars( _broker, rc,
CMPI_RC_ERR_FAILED, "no host name found" );
_OSBASE_TRACE(2,("--- _makePath_Service() failed : %s",CMGetCharPtr(rc->msg)));
goto exit;
}
op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)),
_ClassName, rc );
if( CMIsNullObject(op) ) {
CMSetStatusWithChars( _broker, rc,
CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." );
_OSBASE_TRACE(2,("--- _makePath_Service() failed : %s",CMGetCharPtr(rc->msg)));
goto exit;
}
CMAddKey(op, "SystemCreationClassName", CSCreationClassName, CMPI_chars);
CMAddKey(op, "SystemName", get_system_name(), CMPI_chars);
CMAddKey(op, "CreationClassName", _ClassName, CMPI_chars);
CMAddKey(op, "Name", lxssvc->svName, CMPI_chars);
exit:
_OSBASE_TRACE(2,("--- _makePath_Service() exited"));
return op;
}
/* ----------- method to create a CMPIInstance of Linux_Service --------------*/
CMPIInstance * _makeInst_Service( const CMPIBroker * _broker,
const CMPIContext * ctx,
const CMPIObjectPath * ref,
const char ** properties,
LXS_Service * lxssvc,
CMPIStatus * rc) {
CMPIObjectPath * op = NULL;
CMPIInstance * ci = NULL;
const char ** keys = NULL;
int keyCount = 0;
_OSBASE_TRACE(2,("--- _makeInst_Service() called"));
/* the sblim-cmpi-base package offers some tool methods to get common
* system data
*/
if( !get_system_name() ) {
CMSetStatusWithChars( _broker, rc,
CMPI_RC_ERR_FAILED, "no host name found" );
_OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg)));
goto exit;
}
op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)),
_ClassName, rc );
if( CMIsNullObject(op) ) {
CMSetStatusWithChars( _broker, rc,
CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." );
_OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg)));
goto exit;
}
ci = CMNewInstance( _broker, op, rc);
if( CMIsNullObject(ci) ) {
CMSetStatusWithChars( _broker, rc,
CMPI_RC_ERR_FAILED, "Create CMPIInstance failed." );
_OSBASE_TRACE(2,("--- _makeInst_Service() failed : %s",CMGetCharPtr(rc->msg)));
goto exit;
}
/* set property filter */
keys = calloc(5,sizeof(char*));
keys[0] = strdup("SystemCreationClassName");
keys[1] = strdup("SystemName");
keys[2] = strdup("CreationClassName");
keys[3] = strdup("Name");
CMSetPropertyFilter(ci,properties,keys);
for( ;keys[keyCount]!=NULL;keyCount++) { free((char*)keys[keyCount]); }
free(keys);
CMSetProperty( ci, "SystemCreationClassName", CSCreationClassName, CMPI_chars );
CMSetProperty( ci, "SystemName", get_system_name(), CMPI_chars );
CMSetProperty( ci, "CreationClassName", _ClassName, CMPI_chars );
CMSetProperty( ci, "Name", lxssvc->svName, CMPI_chars );
CMSetProperty( ci, "Caption", "Linux (/etc/init.d) Service", CMPI_chars);
CMSetProperty( ci, "Description", "Instances of this class represents the /etc/init.d managed Services.", CMPI_chars);
CMSetProperty( ci, "Status", lxssvc->svStatus, CMPI_chars);
CMSetProperty( ci, "Started", (CMPIValue*)&(lxssvc->svStarted), CMPI_boolean);
exit:
_OSBASE_TRACE(2,("--- _makeInst_Service() exited"));
return ci;
}
/* ---------------------------------------------------------------------------*/
void serviceDup(LXS_Service *old, LXS_Service *new)
{
if (old==NULL || new==NULL)
return;
if (old->svName) {
free(old->svName);
free(old->svCCname);
free(old->svSystemname);
free(old->svSystemCCname);
free(old->svStatus);
}
old->svName=strdup(new->svName);
old->svCCname=strdup(new->svCCname);
old->svSystemname=strdup(new->svSystemname);
old->svSystemCCname=strdup(new->svSystemCCname);
old->svStatus=strdup(new->svStatus);
old->svStarted=new->svStarted;
}
int serviceChanged(LXS_Service *old, LXS_Service *new)
{
return strcmp(old->svStatus,new->svStatus) ||
old->svStarted != new->svStarted;
}
/* ---------------------------------------------------------------------------*/
/* end of cmpiOSBase_Service.c */
/* ---------------------------------------------------------------------------*/