File: new_sim_annunciator.cpp

package info (click to toggle)
openhpi 3.6.1-2.2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 25,544 kB
  • ctags: 25,275
  • sloc: ansic: 202,885; cpp: 63,639; java: 16,472; cs: 15,161; python: 11,884; makefile: 4,872; perl: 1,529; sh: 371; xml: 36; asm: 13
file content (411 lines) | stat: -rw-r--r-- 10,943 bytes parent folder | download | duplicates (4)
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/** 
 * @file    new_sim_annunciator.cpp
 *
 * The file includes a class for annunciator handling:\n
 * NewSimulatorAnnunciator
 * 
 * @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.
 * 
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>

#include "new_sim_domain.h"
#include "new_sim_annunciator.h"
#include "new_sim_announcement.h"
#include "new_sim_entity.h"


/**
 * Constructor
 **/
NewSimulatorAnnunciator::NewSimulatorAnnunciator( NewSimulatorResource *res )
  : NewSimulatorRdr( res, SAHPI_ANNUNCIATOR_RDR ), 
    m_mode( SAHPI_ANNUNCIATOR_MODE_SHARED ),
    m_ann_id( 0 ) {
    	
   memset( &m_ann_rec, 0, sizeof( SaHpiAnnunciatorRecT ));
}


/**
 * Full qualified constructor to fill an object with the parsed data
 **/
NewSimulatorAnnunciator::NewSimulatorAnnunciator( NewSimulatorResource *res,
                                        SaHpiRdrT rdr )
  : NewSimulatorRdr( res, SAHPI_ANNUNCIATOR_RDR, rdr.Entity, rdr.IsFru, rdr.IdString ),
    m_mode( SAHPI_ANNUNCIATOR_MODE_SHARED ),
    m_ann_id( 0 ) {

   memcpy(&m_ann_rec, &rdr.RdrTypeUnion.AnnunciatorRec, sizeof( SaHpiAnnunciatorRecT ));
}
  
                      
/**
 * Destructor
 **/
NewSimulatorAnnunciator::~NewSimulatorAnnunciator()
{
}


/** 
 * Dump the Annunciator information
 * 
 * @param dump Address of the log
 * 
 **/
void NewSimulatorAnnunciator::Dump( NewSimulatorLog &dump ) const {
  char str[256];
  IdString().GetAscii( str, 256 );

  dump << "Annunciator: " << m_ann_rec.AnnunciatorNum << " " << str << "\n";
  dump << "Announcements: " << "\n";
  for (int i= 0; i < m_anns.Num(); i++) {
      m_anns[i]->Dump( dump );
  }
}


/**
 * A rdr structure is filled with the data
 * 
 * This method is called by method NewSimulatorRdr::Populate().
 * 
 * @param resource Address of resource structure
 * @param rdr Address of rdr structure
 * 
 * @return true
 **/
bool NewSimulatorAnnunciator::CreateRdr( SaHpiRptEntryT &resource, SaHpiRdrT &rdr ) {
  
  if ( NewSimulatorRdr::CreateRdr( resource, rdr ) == false )
       return false;

  // Annunciator record
  memcpy(&rdr.RdrTypeUnion.AnnunciatorRec, &m_ann_rec, sizeof(SaHpiAnnunciatorRecT));

  return true;
}


/**
 * Find announcement by announcement pointer
 * 
 * @param ann pointer on the announcement to be found 
 * @return return the same pointer if it could be found successfully 
 **/
NewSimulatorAnnouncement *NewSimulatorAnnunciator::FindAnnouncement( NewSimulatorAnnouncement *ann ) {
	
   for( int i = 0; i < m_anns.Num(); i++ ) {
      NewSimulatorAnnouncement *a = m_anns[i];
      if ( a == ann ) return ann;
   }

   return 0;
}


/**
 * Add an announcement to the array if it isn't already included in the array
 * 
 * @param ann pointer to announcement to be added
 * @return bool if successful 
 **/ 
bool NewSimulatorAnnunciator::AddAnnouncement( NewSimulatorAnnouncement *ann ) {
	
   if ( FindAnnouncement( ann ) ) {
      return false;
   }
   
   if (ann->EntryId() > m_ann_id)
      m_ann_id = ann->EntryId();
      
   m_anns.Add( ann );

   return true;
}


/**
 * The annunciator data is copied into the internal record structer
 * 
 * @param ann_data Record to be copied into the internal structure
 **/ 
void NewSimulatorAnnunciator::SetData( SaHpiAnnunciatorRecT ann_data ) {
	
   memcpy( &m_ann_rec, &ann_data, sizeof( SaHpiAnnunciatorRecT ));   
}


// Official HPI functions
 
 /**
 * HPI function saHpiAnnunciatorGetNext()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param severity of announcement to get
 * @param uackOnly flag if only unacknowledge announcement should be returned
 * @param ann address to announcement structure where the announcement should be copied to
 * 
 * @return HPI return code
 **/    
SaErrorT NewSimulatorAnnunciator::GetNextAnnouncement( SaHpiSeverityT severity, 
                                                       SaHpiBoolT uackOnly, 
                                                       SaHpiAnnouncementT &ann ) {
   SaHpiEntryIdT num;
   SaHpiTimeT    time;
   NewSimulatorAnnouncement *a;
   bool found = false;
   
   if (&ann == NULL)
      return SA_ERR_HPI_INVALID_PARAMS;

   if (m_anns.Num() == 0)
      return SA_ERR_HPI_NOT_PRESENT;

   if (ann.EntryId == SAHPI_FIRST_ENTRY) {
      a = m_anns[0];
      num = a->EntryId();
      time = a->TimeStamp();
      found = true;
   } else {
      num = ann.EntryId;
      time = ann.Timestamp;
   }
   
   for (int i = 0; i < m_anns.Num(); i++) {
      a = m_anns[i];
      
      // Be aware that the previos Announcement can already be deleted
      if (( a->EntryId() > num ) && ( a->TimeStamp() >= time )) {
         found = true;
      }
      
      if (found) {
        // If we have found the previous announcement, we have to check the criteria	
      	if ( (severity == SAHPI_ALL_SEVERITIES) ||
      	      (severity == a->Severity()) ) {
      	
      	   if ( (uackOnly == SAHPI_TRUE) &&
      	         !a->IsAcknowledge() ) {
      	         	
      	      memcpy( &ann, &a->AnnRec(), sizeof( SaHpiAnnouncementT ));
      	      return SA_OK;
      	      
      	   } else if (uackOnly == SAHPI_FALSE) {

      	      memcpy( &ann, &a->AnnRec(), sizeof( SaHpiAnnouncementT ));
      	      return SA_OK;
      	   }
      	}

      } else {
         // Find the previous announciator
         if ( a->EntryId() == num ) {
            if ( a->TimeStamp() == time ) {
            	   found = true;
            } else {
            	   return SA_ERR_HPI_INVALID_DATA;
            }
         }
      }
   }
         
   return SA_ERR_HPI_NOT_PRESENT;
}


/**
 * HPI function saHpiAnnunciatorGet()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param num announcement id 
 * @param ann address to Announcement structure where the announcement should be copied to
 * 
 * @return HPI return code
 **/   
SaErrorT NewSimulatorAnnunciator::GetAnnouncement( SaHpiEntryIdT num, SaHpiAnnouncementT &ann ) {
   
   if ((&ann == NULL) ||
        (num == SAHPI_FIRST_ENTRY) ||
        (num == SAHPI_LAST_ENTRY))
      return SA_ERR_HPI_INVALID_PARAMS;
   
   for (int i = 0; i < m_anns.Num(); i++) {
   	  NewSimulatorAnnouncement *a = m_anns[i];
      
      if ( a->EntryId() == num ) {
      	memcpy( &ann, &a->AnnRec(), sizeof( SaHpiAnnouncementT ));
      	return SA_OK;
      } 
   }
   
   return SA_ERR_HPI_NOT_PRESENT;
}
/**
 * HPI function saHpiAnnunciatorAcknowledge()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param num announcement id to be acknowledged
 * @param severity everity of announcements to be acknowledged
 * 
 * @return HPI return code
 **/ 
SaErrorT NewSimulatorAnnunciator::SetAcknowledge( SaHpiEntryIdT num, SaHpiSeverityT severity) {
   
   for (int i = 0; i < m_anns.Num(); i++) {
      NewSimulatorAnnouncement *ann = m_anns[i];
      
      if (num != SAHPI_ENTRY_UNSPECIFIED) {
         if ( ann->EntryId() == num ) {
         	ann->SetAcknowledge( true );
            return SA_OK;
         }
      } else {
      	if ( (severity == SAHPI_ALL_SEVERITIES) ||
      	     (severity == ann->Severity()) ) 
      	   ann->SetAcknowledge( true );
      }
   }
   
   if (num != SAHPI_ENTRY_UNSPECIFIED)
      return SA_ERR_HPI_NOT_PRESENT;
      
   return SA_OK;
   
}
/**
 * HPI function saHpiAnnunciatorAdd()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param ann announcement to be added
 * 
 * @return HPI return code
 **/ 
SaErrorT NewSimulatorAnnunciator::AddAnnouncement( SaHpiAnnouncementT &ann ) {
      
   if (&ann == NULL)
      return SA_ERR_HPI_INVALID_PARAMS;
      
   if (m_mode == SAHPI_ANNUNCIATOR_MODE_AUTO)
      return SA_ERR_HPI_READ_ONLY;

   ann.AddedByUser = SAHPI_TRUE;
   oh_gettimeofday(&ann.Timestamp);
   ann.EntryId = ValidEntryId();
   
   NewSimulatorAnnouncement *ann_obj = new NewSimulatorAnnouncement( ann );
   if ( ann_obj == NULL)
      return SA_ERR_HPI_OUT_OF_SPACE;
   
   m_anns.Add( ann_obj );
   
   return SA_OK;
}


/**
 * HPI function saHpiAnnunciatorDelete()
 * 
 * See also the description of the function inside the specification or header file.
 * 
 * @param num entryId of announcement to be deleted
 * @param severity severity of announcements to be deleted
 * 
 * @return HPI return code
 **/ 
SaErrorT NewSimulatorAnnunciator::DeleteAnnouncement( SaHpiEntryIdT &num, 
                                                      SaHpiSeverityT &severity) {
   
   if (m_mode == SAHPI_ANNUNCIATOR_MODE_AUTO)
      return SA_ERR_HPI_READ_ONLY;
   
   for (int i = m_anns.Num() - 1; i >= 0; i--) {
      NewSimulatorAnnouncement *ann = m_anns[i];
      
      if (num != SAHPI_ENTRY_UNSPECIFIED) {
         if ( ann->EntryId() == num ) {
            m_anns.Rem( i );
            return SA_OK;
         }
      } else {
      	if ( (severity == SAHPI_ALL_SEVERITIES) ||
      	     (severity == ann->Severity()) ) 
      	   m_anns.Rem( i );
      }
   }
   
   if (num != SAHPI_ENTRY_UNSPECIFIED)
      return SA_ERR_HPI_NOT_PRESENT;
      
   return SA_OK;
}


/**
 * HPI function saHpiAnnunciatorModeGet()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param mode address of return value
 * 
 * @return HPI return code
 **/
SaErrorT NewSimulatorAnnunciator::GetMode( SaHpiAnnunciatorModeT &mode ) {
    
    if (&mode == NULL)
       return SA_ERR_HPI_INVALID_PARAMS;
    
    mode = m_mode;

    return SA_OK;
}


/**
 * HPI function saHpiAnnunciatorModeSet()
 * 
 * See also the description of the function inside the specification or header file.
 * Copying the internal reading values (if a read is allowed).
 * 
 * @param mode to be set
 * 
 * @return HPI return code
 **/
SaErrorT NewSimulatorAnnunciator::SetMode( SaHpiAnnunciatorModeT mode ) {
    
   if ( m_ann_rec.ModeReadOnly == SAHPI_TRUE)
       return SA_ERR_HPI_READ_ONLY;

   if ((mode != SAHPI_ANNUNCIATOR_MODE_AUTO) &&
        (mode !=  SAHPI_ANNUNCIATOR_MODE_USER) &&
        (mode != SAHPI_ANNUNCIATOR_MODE_SHARED))
      return SA_ERR_HPI_INVALID_PARAMS;
      
   m_mode = mode;

   return SA_OK;
}