ucserial.cc

Go to the documentation of this file.
00001 /*
00002  *  ucserial.cc - Serialization of usecode objects
00003  *
00004  *  Copyright (C) 2002  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifdef HAVE_CONFIG_H
00022 #  include <config.h>
00023 #endif
00024 
00025 #include "servemsg.h"
00026 #include "ucserial.h"
00027 #include "useval.h"
00028 #include "utils.h"
00029 #include "debugmsg.h"
00030 
00031 /*
00032 
00033 /*
00034  *  Read/write out data common to all objects.
00035  *
00036  *  Output: 1 if successful, else 0.
00037  */
00038 
00039 template <class Serial> 
00040 void Stack_frame_io
00041   (
00042   Serial& io,
00043   int& functionid,
00044   int& ip,
00045   int& call_chain,
00046   int& call_depth,
00047   int& eventid,
00048   int& caller_item,
00049   int& num_args,
00050   int& num_vars
00051   )
00052 {
00053   unsigned char c = (unsigned char)Exult_server::dbg_stackframe;
00054   io << c << functionid << ip << call_chain << call_depth
00055      << eventid << caller_item << num_args << num_vars;
00056   // locals!
00057 }
00058 
00059 int Stack_frame_out
00060   (
00061   int fd,       // Socket.
00062   int functionid,
00063   int ip,
00064   int call_chain,
00065   int call_depth,
00066   int eventid,
00067   int caller_item,
00068   int num_args,
00069   int num_vars, 
00070   Usecode_value* locals
00071   )
00072 {
00073   static unsigned char buf[Exult_server::maxlength];
00074   unsigned char *ptr = &buf[0];
00075   Serial_out io(ptr);
00076   Stack_frame_io<Serial_out>(io, functionid, ip, call_chain, call_depth,
00077                  eventid, caller_item, num_args, num_vars);
00078 
00079   int remaining = Exult_server::maxlength - (ptr - buf);
00080   for (int i = 0; i < num_args + num_vars; i++) {
00081     int vallen = locals[i].save(ptr, remaining);
00082     // error checking...
00083     ptr += vallen;
00084     remaining -= vallen;
00085   }
00086 
00087   return Exult_server::Send_data(fd, Exult_server::usecode_debugging, 
00088                    buf, ptr - buf);
00089   // locals!
00090 }
00091 
00092 
00093 bool Stack_frame_in
00094   (
00095   unsigned char *data,    // Data that was read.
00096   int datalen,      // Length of data.
00097   int& functionid,
00098   int& ip,
00099   int& call_chain,
00100   int& call_depth,
00101   int& eventid,
00102   int& caller_item,
00103   int& num_args,
00104   int& num_vars,
00105   Usecode_value*& locals
00106   )
00107 {
00108   unsigned char *ptr = data;
00109   Serial_in io(ptr);
00110   Stack_frame_io<Serial_in>(io, functionid, ip, call_chain, call_depth,
00111                 eventid, caller_item, num_args, num_vars);
00112 
00113   int remaining = datalen - (ptr - data);
00114   locals = new Usecode_value[num_args + num_vars];
00115   for (int i = 0; i < num_args + num_vars; i++) {
00116     unsigned char *tmpptr = ptr;
00117     locals[i].restore(ptr, remaining);
00118     // error checking...
00119     remaining -= (ptr - tmpptr);
00120   }
00121 
00122 
00123   return (ptr - data) == datalen;
00124   // locals!
00125 }

Generated on Mon Jul 9 14:42:52 2007 for ExultEngine by  doxygen 1.5.1