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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
/**
* @file new_sim_resource.cpp
*
* The file includes a class for handling resources:
* NewSimulatorResource
*
* @author Lars Wetzel <larswetzel@users.sourceforge.net>
* @version 0.1
* @date 2010
*
* 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.
*
* The new Simulator plugin is adapted from the ipmidirect plugin.
* Thanks to \n
* Thomas Kanngieser <thomas.kanngieser@fci.com>\n
* Pierre Sangouard <psangouard@eso-tech.com>
*
**/
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <assert.h>
#include "new_sim_resource.h"
#include "new_sim_domain.h"
/**
* Constructor
**/
NewSimulatorResource::NewSimulatorResource( NewSimulatorDomain *domain )
: m_domain( domain ),
m_hotswap( this ),
m_is_fru( false ),
m_oem( 0 ),
m_current_control_id( 0 ),
m_populate( false ) {
for( int i = 0; i < 256; i++ ) m_sensor_num[i] = -1;
m_power_state = SAHPI_POWER_OFF;
memset( &m_rpt_entry, 0, sizeof( SaHpiRptEntryT ));
m_hotswap_indicator = SAHPI_HS_INDICATOR_OFF;
m_reset_state = SAHPI_RESET_DEASSERT;
}
/**
* Destructor
**/
NewSimulatorResource::~NewSimulatorResource() {}
/**
* Return the domain to which the resource is mapped
*
* @return pointer on domain
**/
NewSimulatorDomain *NewSimulatorResource::Domain() const {
return m_domain;
}
/**
* @deprecated Create a Sensor number
*
* @param num sensor number
* @return sensor number to be used in HPI
**/
int NewSimulatorResource::CreateSensorNum( SaHpiSensorNumT num ) {
int v = num;
if ( m_sensor_num[v] != -1 ) {
for( int i = 0xff; i >= 0; i-- )
if ( m_sensor_num[i] == -1 ) {
v = i;
break;
}
if ( m_sensor_num[v] != -1 ) {
assert( 0 );
return -1;
}
}
m_sensor_num[v] = num;
return v;
}
/**
* Set the resource information
*
* @param resinfo resource information to be set in the resource
**/
void NewSimulatorResource::SetResourceInfo( SaHpiResourceInfoT resinfo ) {
memcpy( &m_rpt_entry.ResourceInfo, &resinfo, sizeof( SaHpiResourceInfoT ) );
}
/**
* Destroy the resource and clean up
*
* @return success
**/
bool NewSimulatorResource::Destroy() {
SaHpiRptEntryT *rptentry;
stdlog << "removing resource: " << m_entity_path << ").\n";
while( Num() ) {
NewSimulatorRdr *rdr = GetRdr( 0 );
RemRdr( rdr );
delete rdr;
}
rptentry = oh_get_resource_by_id( Domain()->GetHandler()->rptcache, m_rpt_entry.ResourceId );
if ( !rptentry ) {
stdlog << "Can't find resource in plugin cache !\n";
} else {
// create remove event
oh_event *e = (oh_event *)g_malloc0( sizeof( oh_event ) );
// remove sensors only if resource is FRU
if ( rptentry->ResourceCapabilities & SAHPI_CAPABILITY_FRU ) {
e->event.EventType = SAHPI_ET_HOTSWAP;
if (e->resource.ResourceCapabilities & SAHPI_CAPABILITY_MANAGED_HOTSWAP) {
e->event.EventDataUnion.HotSwapEvent.HotSwapState = SAHPI_HS_STATE_NOT_PRESENT;
e->event.EventDataUnion.HotSwapEvent.PreviousHotSwapState = SAHPI_HS_STATE_NOT_PRESENT;
} else {
e->event.EventDataUnion.HotSwapEvent.HotSwapState = SAHPI_HS_STATE_NOT_PRESENT;
e->event.EventDataUnion.HotSwapEvent.PreviousHotSwapState = SAHPI_HS_STATE_ACTIVE;
}
} else {
e->event.EventType = SAHPI_ET_RESOURCE;
e->event.EventDataUnion.ResourceEvent.ResourceEventType = SAHPI_RESE_RESOURCE_FAILURE;
rptentry->ResourceFailed = SAHPI_TRUE;
}
e->event.Source = rptentry->ResourceId;
oh_gettimeofday(&e->event.Timestamp);
e->event.Severity = rptentry->ResourceSeverity;
e->resource = *rptentry;
stdlog << "NewSimulatorResource::Destroy OH_ET_RESOURCE_DEL Event resource " << m_rpt_entry.ResourceId << "\n";
Domain()->AddHpiEvent( e );
// remove resource from local cache
int rv = oh_remove_resource( Domain()->GetHandler()->rptcache, m_rpt_entry.ResourceId );
if ( rv != 0 ) {
stdlog << "Can't remove resource from plugin cache !\n";
}
}
m_domain->RemResource( this );
delete this;
return true;
}
/**
* Find a rdr entry with the correct type and number
*
* @param type type of rdr entry
* @param num number of rdr entry
*
* @return pointer on the rdr object
**/
NewSimulatorRdr *NewSimulatorResource::FindRdr( SaHpiRdrTypeT type, unsigned int num) {
for( int i = 0; i < NumRdr(); i++ ) {
NewSimulatorRdr *r = GetRdr( i );
if ( r->Type() == type && r->Num() == num )
return r;
}
return 0;
}
/**
* Add a rdr entry
*
* @param rdr pointer on the rdr to be added
* @return success
**/
bool NewSimulatorResource::AddRdr( NewSimulatorRdr *rdr ) {
stdlog << "adding rdr: " << rdr->EntityPath();
stdlog << " " << rdr->Num();
stdlog << " " << rdr->IdString() << "\n";
// set resource
rdr->Resource() = this;
// add rdr to resource
Add( rdr );
return true;
}
/**
* Remove a rdr entry
*
* @param rdr pointer on the rdr to be deleted
* @return success
**/
bool NewSimulatorResource::RemRdr( NewSimulatorRdr *rdr ) {
int idx = Find( rdr );
if ( idx == -1 ) {
stdlog << "user requested removal of a control"
" from a resource, but the control was not there !\n";
return false;
}
Rem( idx );
return true;
}
/**
* Initialize a new resource
*
* @param entry address of RptEntry structure
* @return success
**/
bool NewSimulatorResource::Create( SaHpiRptEntryT &entry ) {
stdlog << "DBG: Resource::Create: " << m_entity_path << ".\n";
stdlog << "DBG: Should be checked\n";
entry.EntryId = 0;
// resource info
SaHpiResourceInfoT &info = entry.ResourceInfo;
memset( &info, 0, sizeof( SaHpiResourceInfoT ) );
entry.ResourceEntity = m_entity_path;
entry.ResourceId = oh_uid_from_entity_path( &entry.ResourceEntity );
entry.ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE;
// if ( m_sel )
// entry.ResourceCapabilities |= SAHPI_CAPABILITY_EVENT_LOG;
if ( m_is_fru == true ) {
entry.ResourceCapabilities |= SAHPI_CAPABILITY_FRU;
}
entry.HotSwapCapabilities = 0;
entry.ResourceSeverity = SAHPI_OK;
entry.ResourceFailed = SAHPI_FALSE;
entry.ResourceTag = ResourceTag();
return true;
}
/**
* Popolate the resource
*
* @return success
**/
bool NewSimulatorResource::Populate() {
stdlog << "DBG: Start Populate()\n";
if ( m_populate == false ) {
stdlog << "DBG: populate resource: " << EntityPath() << ".\n";
// Work with some rpt_entries
m_rpt_entry.ResourceTag = ResourceTag();
if (m_rpt_entry.ResourceCapabilities & SAHPI_CAPABILITY_FRU) {
m_is_fru = true;
} else {
m_is_fru = false;
}
struct oh_event *e = (struct oh_event *)g_malloc0( sizeof( struct oh_event ) );
// Get own ResourceId
e->resource.ResourceEntity = m_entity_path;
m_rpt_entry.ResourceEntity = m_entity_path;
m_rpt_entry.ResourceId = oh_uid_from_entity_path( &(e->resource.ResourceEntity) );
memcpy(&e->resource, &m_rpt_entry, sizeof (SaHpiRptEntryT));
// add the resource to the resource cache
int rv = oh_add_resource( Domain()->GetHandler()->rptcache,
&(e->resource), this, 1 );
if ( rv != 0 ) {
stdlog << "Can't add resource to plugin cache !\n";
g_free( e );
return false;
}
// find updated resource in plugin cache
SaHpiRptEntryT *resource = oh_get_resource_by_id( Domain()->GetHandler()->rptcache,
m_rpt_entry.ResourceId );
if (!resource) return false;
for( int i = 0; i < NumRdr(); i++ ) {
NewSimulatorRdr *rdr = GetRdr( i );
if ( rdr->Populate(&e->rdrs) == false ) return false;
}
m_hotswap.SetTimeouts( Domain()->InsertTimeout(), Domain()->ExtractTimeout());
// Update resource in event accordingly
memcpy(&e->resource, resource, sizeof (SaHpiRptEntryT));
stdlog << "NewSimulatorResource::Populate start the hotswap state transitions\n";
if ( m_hotswap.StartResource( e ) != SA_OK ) return false;
if ( ResourceCapabilities() & SAHPI_CAPABILITY_MANAGED_HOTSWAP )
if ( m_hotswap.ActionRequest( SAHPI_HS_ACTION_INSERTION ) != SA_OK )
stdlog << "ERR: ActionRequest returns an error\n";
m_populate = true;
}
return true;
}
/**
* Dump the information of the resource
*
* @param dump address of logfile
**/
void NewSimulatorResource::Dump( NewSimulatorLog &dump ) const {
dump << "Resource " << m_rpt_entry.ResourceId << " " << m_entity_path << "\n";
dump << " EntryId " << m_rpt_entry.EntryId << "\n";
dump << " ResourceId " << m_rpt_entry.ResourceId << "\n";
dump << " ResourceInfo\n";
dump << " ResourceRev " << m_rpt_entry.ResourceInfo.ResourceRev << "\n";
dump << " SpecificVer " << m_rpt_entry.ResourceInfo.SpecificVer << "\n";
dump << " DeviceSupport " << m_rpt_entry.ResourceInfo.DeviceSupport << "\n";
dump << " ManufacturerId " << m_rpt_entry.ResourceInfo.ManufacturerId << "\n";
dump << " ProductId " << m_rpt_entry.ResourceInfo.ProductId << "\n";
dump << " FirmwareMajorRev " << m_rpt_entry.ResourceInfo.FirmwareMajorRev << "\n";
dump << " FirmwareMinorRev " << m_rpt_entry.ResourceInfo.FirmwareMinorRev << "\n";
dump << " AuxFirmwareRev " << m_rpt_entry.ResourceInfo.AuxFirmwareRev << "\n";
dump << " ResourceEntity " << m_rpt_entry.ResourceEntity << "\n";
dump << " ResourceCapabilities " << m_rpt_entry.ResourceCapabilities << "\n";
dump << " HotSwapCapabilities " << m_rpt_entry.HotSwapCapabilities << "\n";
dump << " ResourceSeverity " << m_rpt_entry.ResourceSeverity << "\n";
dump << " ResourceFailed " << m_rpt_entry.ResourceFailed << "\n";
dump << " ResourceTag " << m_rpt_entry.ResourceTag << "\n";
dump << "------------------------\n";
}
|