File: ipmi_fru_info.cpp

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 (225 lines) | stat: -rw-r--r-- 4,753 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
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
/*
 * ipmi_fru_info.cpp
 *
 * Copyright (c) 2004 by FORCE Computers.
 * Copyright (c) 2005 by ESO Technologies.
 *
 * 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.
 *
 * Authors:
 *     Thomas Kanngieser <thomas.kanngieser@fci.com>
 *     Pierre Sangouard  <psangouard@eso-tech.com>
 */

extern "C" {
#include "SaHpiAtca.h"
}

#include <assert.h>
#include "ipmi_fru_info.h"


SaHpiEntityTypeT
MapAtcaSiteTypeToEntity( tIpmiAtcaSiteType type )
{
  static SaHpiEntityTypeT et[] = 
  {
    SAHPI_ENT_PHYSICAL_SLOT,
    SaHpiEntityTypeT(ATCAHPI_ENT_POWER_ENTRY_MODULE_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_SHELF_FRU_DEVICE_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_SHELF_MANAGER_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_FAN_TRAY_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_FAN_FILTER_TRAY_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_ALARM_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_AMC_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_PMC_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_RTM_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_SHELF_MANAGER_SLOT),
    SaHpiEntityTypeT(ATCAHPI_ENT_POWER_ENTRY_MODULE_SLOT)
  };

  if ( type >= eIpmiAtcaSiteTypeUnknown )
     {
       return SAHPI_ENT_UNKNOWN;
     }

  return et[type];
}


cIpmiFruInfo::cIpmiFruInfo( unsigned int addr, unsigned int fru_id,
			    SaHpiEntityTypeT entity, unsigned int slot,
			    tIpmiAtcaSiteType site, unsigned int properties )
  : m_addr( addr ), m_fru_id( fru_id ),
    m_slot( slot ), m_entity( entity ),
    m_site( site ), m_properties( properties )
{
}


cIpmiFruInfo::~cIpmiFruInfo()
{
}


cIpmiEntityPath 
cIpmiFruInfo::CreateEntityPath( const cIpmiEntityPath &top,
				const cIpmiEntityPath &bottom )
{
  cIpmiEntityPath middle;

  middle.SetEntry( 0, m_entity, m_slot );
  middle.AppendRoot( 1 );

  cIpmiEntityPath ep = bottom;
  ep += middle;
  ep += top;

  return ep;
}


cIpmiFruInfoContainer::cIpmiFruInfoContainer()
  : m_fru_info( 0 )
{
}


cIpmiFruInfoContainer::~cIpmiFruInfoContainer()
{
  while( m_fru_info )
     {
       cIpmiFruInfo *fi = (cIpmiFruInfo *)m_fru_info->data;
       m_fru_info = g_list_remove( m_fru_info, fi );
       delete fi;
     }
}


cIpmiFruInfo *
cIpmiFruInfoContainer::FindFruInfo( unsigned int addr, unsigned int fru_id ) const
{
  for( GList *list = m_fru_info; list; list = g_list_next( list ) )
     {
       cIpmiFruInfo *fi = (cIpmiFruInfo *)list->data;

       if ( fi->Address() == addr
	    && fi->FruId() == fru_id )
	    return fi;
     }

  return 0;
}


bool
cIpmiFruInfoContainer::AddFruInfo( cIpmiFruInfo *fru_info )
{
  if ( FindFruInfo( fru_info->Address(), fru_info->FruId() ) )
     {
       return false;
     }

  m_fru_info = g_list_append( m_fru_info, fru_info );

  return true;
}


bool
cIpmiFruInfoContainer::RemFruInfo( cIpmiFruInfo *fru_info )
{
  for( GList *list = m_fru_info; list; list = g_list_next( list ) )
     {
       cIpmiFruInfo *fi = (cIpmiFruInfo *)list->data;

       if ( fi == fru_info )
	  {
	    m_fru_info = g_list_remove( m_fru_info, fru_info );
	    delete fru_info;

	    return true;
	  }
     }

  return false;
}


cIpmiFruInfo *
cIpmiFruInfoContainer::NewFruInfo( unsigned int addr, unsigned int fru_id,
				   SaHpiEntityTypeT entity, unsigned int slot,
                                   tIpmiAtcaSiteType site, unsigned int properties )
{
  assert( fru_id == 0 );

  cIpmiFruInfo *fi = FindFruInfo( addr, fru_id );

  if ( fi )
       return fi;

  fi = new cIpmiFruInfo( addr, fru_id, entity, slot, site, properties );

  if ( !AddFruInfo( fi ) )
     {
       delete fi;

       return 0;
     }

  return fi;
}

cIpmiFruInfo *
cIpmiFruInfoContainer::NewFruInfo( unsigned int addr, unsigned int fru_id )
{
  assert( fru_id != 0 );

  cIpmiFruInfo *fi = FindFruInfo( addr, fru_id );

  if ( fi )
       return fi;

  cIpmiFruInfo *fi0 = FindFruInfo( addr, 0 );

  assert ( fi0 != NULL );

  fi = new cIpmiFruInfo( addr, fru_id, fi0->Entity(), fi0->Slot(), fi0->Site(), 0 );

  if ( !AddFruInfo( fi ) )
     {
       delete fi;

       return 0;
     }

  return fi;
}


unsigned int
cIpmiFruInfoContainer::GetFreeSlotForOther( unsigned int addr )
{
    return addr;
#if 0
  unsigned int slot = 0;

  for( GList *list = m_fru_info; list; list = g_list_next( list ) )
     {
       cIpmiFruInfo *fi = (cIpmiFruInfo *)list->data;

       if ( fi->Address() != addr || fi->Entity() )
            continue;

       if ( slot < fi->Slot() )
            slot = fi->Slot();
     }

  return slot + 1;
#endif
}