Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_ProtocolContext.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 #include "C_ProtocolContext.hpp"
00021 
00022 #include "GeneratorError.h"
00023 #include "BufferUtils.hpp"
00024 
00025 #include <cstdlib> // for strtoul
00026 #include "GeneratorTrace.hpp"
00027 
00028 
00029 
00030 C_ProtocolContext::C_ProtocolContext(int P_nb_values) {
00031 
00032   m_nb_values = P_nb_values ;
00033 
00034   ALLOC_TABLE(m_ctxt_val_table, 
00035               T_pCtxtValue,
00036               sizeof(T_CtxtValue),
00037               m_nb_values);
00038 
00039   reset_ctxt_values() ;
00040 
00041   m_end_ctxt_counter = false;
00042 }
00043 
00044 
00045 void C_ProtocolContext::reset_ctxt_values(int P_index) {
00046 
00047   int L_i ;
00048 
00049   for(L_i = P_index ; L_i < m_nb_values ; L_i++) {
00050     m_ctxt_val_table[L_i].m_ctxt_value.m_type = E_TYPE_NUMBER ;
00051     m_ctxt_val_table[L_i].m_ctxt_value.m_id   = L_i ;
00052     m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number = 0 ;
00053     m_ctxt_val_table[L_i].m_ctxt_position.m_id_field = -1 ;
00054     m_ctxt_val_table[L_i].m_ctxt_position.m_position_ptr = NULL ;
00055   }
00056 }
00057 
00058 C_ProtocolContext::~C_ProtocolContext() {
00059   FREE_TABLE(m_ctxt_val_table);
00060   m_end_ctxt_counter = false;
00061 }
00062 
00063 
00064 void C_ProtocolContext::start_ctxt_value(int P_ctxt_id,
00065                                          int P_size) {
00066   m_ctxt_val_table[P_ctxt_id].m_ctxt_value.m_value.m_val_number = P_size ;
00067 }
00068 
00069 
00070 void C_ProtocolContext::update_ctxt_values(int P_nbCtx,
00071                                            int *P_idTable, 
00072                                            int P_size) {
00073 
00074   int L_i ;
00075 
00076   for (L_i = 0 ; L_i < P_nbCtx; L_i++) {
00077     m_ctxt_val_table[P_idTable[L_i]].m_ctxt_value.m_value.m_val_number += P_size ;
00078   }
00079 }
00080 
00081 
00082 int C_ProtocolContext::update_ctxt_values_decode(int P_nbCtx,
00083                                                  int *P_idTable, 
00084                                                  int P_size) {
00085   int L_ret = 0 ;
00086   int L_i       ;
00087 
00088   for (L_i = 0 ; L_i < P_nbCtx; L_i++) {
00089     m_ctxt_val_table[P_idTable[L_i]].m_ctxt_value.m_value.m_val_number 
00090       -= P_size ;
00091     
00092     if (m_ctxt_val_table[P_idTable[L_i]].m_ctxt_value.m_value.m_val_number 
00093         < 0) {
00094       L_ret = -1 ;
00095       break;
00096     }
00097   }
00098 
00099   return (L_ret);
00100 }
00101 
00102 
00103 void C_ProtocolContext::update_ctxt_values(int P_id,
00104                                            int P_size) {
00105   m_ctxt_val_table[P_id].m_ctxt_value.m_value.m_val_number += P_size ;
00106 }
00107 
00108 
00109 void C_ProtocolContext::update_ctxt_position(int P_id, T_pPositionValue P_position_value) {
00110   m_ctxt_val_table[P_id].m_ctxt_position.m_id_field     =  P_position_value->m_id_field;
00111   m_ctxt_val_table[P_id].m_ctxt_position.m_position_ptr = P_position_value->m_position_ptr;
00112 }
00113 
00114 
00115 unsigned long C_ProtocolContext::get_counter_ctxt(int P_ctxt_id) {
00116   return(m_ctxt_val_table[P_ctxt_id].m_ctxt_value.m_value.m_val_number);
00117 }
00118 
00119 
00120 bool C_ProtocolContext::end_counter_ctxt() {
00121 
00122   int L_i ;
00123 
00124   for (L_i=1; L_i < m_nb_values; L_i++) {
00125     m_end_ctxt_counter = (m_ctxt_val_table[L_i].m_ctxt_value.m_value.m_val_number
00126                           == 0) ;
00127     if (!m_end_ctxt_counter) break ;
00128   }
00129   return (m_end_ctxt_counter);
00130 }

Generated on Wed Mar 7 14:44:53 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002