Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_DataDecode.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_DataDecode.hpp"
00021 #include "Utils.hpp"
00022 
00023 #include <cstring>
00024 
00025 #define SOCKET_ERROR(l,m) iostream_error << m << iostream_endl << iostream_flush
00026 #ifdef DEBUG_MODE
00027 #define SOCKET_DEBUG(l,m) iostream_error << m << iostream_endl << iostream_flush
00028 #else
00029 #define SOCKET_DEBUG(l,m)
00030 #endif
00031 
00032 C_DataDecode::C_DataDecode(size_t P_buf_size) {
00033   SOCKET_DEBUG(0, "C_DataDecode::C_DataDecode (" 
00034             << P_buf_size << ")");
00035   m_segm_size = 0 ;
00036   m_buf_size = P_buf_size;
00037   ALLOC_TABLE(m_buffer,
00038               unsigned char*,
00039               sizeof(unsigned char),
00040               m_buf_size);
00041 }
00042 
00043 C_DataDecode::~C_DataDecode() {
00044   SOCKET_DEBUG(0, "C_DataDecode::~C_DataDecode ()");
00045   m_segm_size = 0 ;
00046   FREE_TABLE(m_buffer);
00047   m_buf_size = 0 ;
00048 }
00049 
00050 void C_DataDecode::init () {
00051   SOCKET_DEBUG(0, "C_DataDecode::init ()");
00052   m_segm_size = 0 ;
00053 }
00054 
00055 void C_DataDecode::reset_buffer() {
00056   SOCKET_DEBUG(0, "C_DataDecode::reset_buffer ()");
00057   m_segm_size = 0 ;
00058 }
00059 
00060 unsigned char *C_DataDecode::get_buffer (unsigned char* P_buf, 
00061                                          size_t       * P_pSize) {
00062 
00063   size_t L_final_size = (*P_pSize) ;
00064 
00065   SOCKET_DEBUG(0, "C_DataDecode::get_buffer (" 
00066             << (void*)&P_buf[0] << "," << *P_pSize << ")");
00067 
00068   SOCKET_DEBUG(0, "C_DataDecode::get_buffer() segment = " << m_segm_size);
00069 
00070   
00071   L_final_size += m_segm_size;
00072   if (L_final_size <= m_buf_size) {
00073     memcpy (m_buffer+m_segm_size, P_buf, *P_pSize);
00074     m_segm_size = 0 ;
00075     *P_pSize = L_final_size ;
00076   } else {
00077     // error
00078     *P_pSize = 0 ;
00079   }
00080 
00081   SOCKET_DEBUG(0, "C_DataDecode::get_buffer () return " 
00082             << &m_buffer);
00083 
00084   return (m_buffer);
00085 }
00086 
00087 int           C_DataDecode::set_buffer (unsigned char* P_buf, 
00088                                          size_t         P_size) {
00089   int L_ret = 0 ;
00090   SOCKET_DEBUG(0, "C_DataDecode::set_buffer (" 
00091             << &P_buf[0] << "," << P_size << ")");
00092 
00093   if (P_size <= m_buf_size) {
00094     memmove(m_buffer, P_buf, P_size);
00095     m_segm_size = P_size ;
00096   } else {
00097     SOCKET_ERROR(E_GEN_FATAL_ERROR, "session maximum size buffer=" << m_buf_size << " data=" << P_size);
00098     L_ret = -1 ;
00099   }
00100   return (L_ret);
00101 }

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