File: new_sim_file_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 (154 lines) | stat: -rw-r--r-- 4,688 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
/** 
 * @file    new_sim_file_rdr.cpp
 *
 * The file includes an abstract class for parsing the special rdr data:\n
 * NewSimulatorFileRdr
 * 
 * @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 <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <glib.h>
#include <SaHpi.h>

#include "new_sim_file_rdr.h"
#include "new_sim_file_util.h"

#include <oh_error.h>


 /**
 * Constructor
 **/
NewSimulatorFileRdr::NewSimulatorFileRdr(GScanner *scanner) 
   : NewSimulatorFileUtil ( scanner ),
     m_depth ( 0 ) {
                                          	
   memset( &m_rdr, 0, sizeof( SaHpiRdrT ));
}

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


/** 
 * Read a RDR section 
 *
 * Startpoint is token \c RDR_TOKEN_HANDLER. Endpoint is \c G_TOKEN_RIGHT_CURLY if 
 * no error occurs during parsing.\n
 * Depend on wich RDR type is read, some helper functions are called.
 * 
 * @return success bool
 *
 **/ 
bool NewSimulatorFileRdr::process_rdr_token( void ) {
   guint cur_token = g_scanner_get_next_token(m_scanner);
   char *rdrfield;
   NewSimulatorEntityPath ep;
   bool success = true;
   bool commonBlock = true;
   
   if (cur_token != G_TOKEN_LEFT_CURLY) {
   	  err("Processing parse configuration: Expected left curly token.");
      return false;
   }
   m_depth++;
   
   while ( commonBlock && success) {
      cur_token = g_scanner_get_next_token(m_scanner);
      
      switch (cur_token) {
         case G_TOKEN_EOF:  
            err("Processing parse rpt entry: File ends too early");
       	    success = false;
       	    break;

         case G_TOKEN_RIGHT_CURLY:
            m_depth--;
            break;
          
         case G_TOKEN_LEFT_CURLY:
            m_depth++;
            break;

         case RDR_DETAIL_TOKEN_HANDLER:
            commonBlock = false;
            break;
            
         case G_TOKEN_STRING:
            rdrfield = g_strdup(m_scanner->value.v_string);
            cur_token = g_scanner_get_next_token(m_scanner);
            if (cur_token != G_TOKEN_EQUAL_SIGN) {
               err("Processing parse rdr entry: Missing equal sign");
               success = false;
            }
         
            cur_token = g_scanner_get_next_token(m_scanner);
         
            if (!strcmp(rdrfield, "RecordId")) {
               // will be assigned by the daemon -> ignore it
         	   stdlog << "DBG: rdr - RecordId is ignored\n";
         	
            } else if (!strcmp(rdrfield, "RdrType")) {
         	   if (cur_token == G_TOKEN_INT) {
         	      m_rdr.RdrType = (SaHpiRdrTypeT) m_scanner->value.v_int;
         	      stdlog << "DBG: rdr - RdrType " << m_rdr.RdrType << "\n";
         	   } else {	
         	      err("Processing parse rpt entry: Wrong kind of RdrType");
         	   }
         	 
            } else if (!strcmp(rdrfield, "Entity")) {
            	   if (cur_token == G_TOKEN_LEFT_CURLY)
            	      success = process_entity( m_rdr.Entity );
            	   if ( !success )
            	      err("Error at parsing the entity path");
          	
            } else if (!strcmp(rdrfield, "IsFru")) {
               if (cur_token == G_TOKEN_INT) {
         	      m_rdr.IsFru = m_scanner->value.v_int;
         	      stdlog << "DBG: rdr - IsFru " << m_rdr.IsFru << "\n";
         	   
         	   } else {
         	   	  success = false;
         	      err("Processing parse rdr entry: Wrong kind of IsFru");
         	   }
         	
            } else if (!strcmp(rdrfield, "IdString")) {
               if ( cur_token == G_TOKEN_LEFT_CURLY ) {
               	  success = process_textbuffer( m_rdr.IdString );
                  stdlog << "DBG: IdString " << m_rdr.IdString << "\n";                  
               } else {
               	  success = false;
                  err("Processing parse rdr entry: Couldn't parse IdSting");
               }
         	
            } else {
               // Unknown Token 
               err("Processing parse rdr entry: Unknown Rdr field %s", rdrfield);
               success = false;	
            }
         
            break;

         default: 
            err("Processing parse rdr entry: Unknown token");
            success = false;
            break;
      }
   }
   return success;
}