File: new_sim_rdr.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 (138 lines) | stat: -rw-r--r-- 3,505 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
/** 
 * @file    new_sim_rdr.cpp
 *
 * The file includes an abstract class for rdr types:\n
 * NewSimulatorRdr
 * 
 * @author  Lars Wetzel <larswetzel@users.sourceforge.net>
 * @version 0.2
 * @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 "new_sim_rdr.h"
#include "new_sim_entity.h"
#include "new_sim_resource.h"
#include "new_sim_domain.h"

/**
 * Constructor
 **/
NewSimulatorRdr::NewSimulatorRdr( NewSimulatorResource *res, SaHpiRdrTypeT type )
                : m_resource( 0 ), m_type( type ), m_populate( false ) {
}


/**
 * Full qualified constructor
 **/
NewSimulatorRdr::NewSimulatorRdr( NewSimulatorResource *res, 
                                  SaHpiRdrTypeT type, 
                                  SaHpiEntityPathT entity, 
                                  SaHpiBoolT isFru, 
                                  SaHpiTextBufferT idString)
 : m_resource( 0 ), 
   m_type( type ),
   m_entity_path( entity ),
   m_is_fru( isFru ),
   m_id_string( idString ),
   m_populate( false ) {
}


/**
 * Destructor
 **/
NewSimulatorRdr::~NewSimulatorRdr() {}


/** 
 * Return a pointer on the own domain
 * 
 * @return pointer on NewSimulatorDomain
 **/
NewSimulatorDomain *NewSimulatorRdr::Domain() { 
	return m_resource->Domain();
}


/**
 * A rdr structure is filled with the internally data
 * 
 * This method is called by method NewSimulatorRdr::Populate().
 * 
 * @param resource Address of resource structure
 * @param rdr Address of rdr structure
 * 
 * @return true
 **/
bool NewSimulatorRdr::CreateRdr( SaHpiRptEntryT &resource, SaHpiRdrT &rdr ) {
   rdr.RecordId = m_record_id;
   rdr.RdrType  = m_type;
   rdr.Entity   = m_entity_path;
   rdr.IdString = m_id_string;

   return true;
}

/**
 * Add the Rdr to the rptcache 
 * 
 * In this function the object is added to the rptcache by calling oh_add_rdr and
 * afterwards append on the given list.
 * 
 * @param list Pointer on GSList
 * @return success
 **/
bool NewSimulatorRdr::Populate(GSList **list) {

   if ( m_populate )
      return true;

   // find resource
   SaHpiRptEntryT *resource = Domain()->FindResource( Resource()->ResourceId() );

   if ( !resource ) {
      stdlog << "Resource not found: Can't populate RDR !\n";
      return false;
   }

   // create rdr
   SaHpiRdrT *rdr = (SaHpiRdrT *)g_malloc0(sizeof(SaHpiRdrT));
   CreateRdr( *resource, *rdr );

   int rv = oh_add_rdr( Domain()->GetHandler()->rptcache,
                        resource->ResourceId,
                        rdr, this, 1 );

   if ( rv != 0 ) {
       stdlog << "Can't add RDR to plugin cache !\n";
       g_free( rdr );
       return false;
   }

   // assign the hpi record id to sensor, so we can find
   // the rdr for a given sensor.
   // the id comes from oh_add_rdr.
   RecordId() = rdr->RecordId;

   stdlog << "NewSimulatorRdr::Populate RDR for resource " << resource->ResourceId << " RDR " << RecordId() << "\n";
   *list = g_slist_append(*list, rdr);

   m_populate = true;

   return true;
}