debugger.cpp

Go to the documentation of this file.
00001 #ifndef DEBUGGER_IMPLEMENTATION_FILE
00002 #define DEBUGGER_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : debugger                                                          *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "debugger.h"
00019 #include "win_ext.rh"
00020 
00021 #include <basis/convert_utf.h>
00022 #include <basis/function.h>
00023 #include <basis/istring.h>
00024 #include <basis/packable.h>
00025 #include <basis/portable.h>
00026 
00027 debugger::debugger(void *recipient, synchronicity synch,
00028     line_ending ending, time_stamp_method stamp)
00029 : log_base(),
00030   _recipient(recipient),
00031   _synch(synch),
00032   _stamp(stamp)
00033 {
00034   eol(ending);
00035 }
00036 
00037 debugger::~debugger() {}
00038 
00039 const u_int &debugger::EVENT()
00040 {
00041 #ifdef __WIN32__
00042   // this string is used to register a unique windows message that is used
00043   // for communication between the debugger object and a debugger object.
00044   const char *DEBUG_UNIQUIFIER = "dbg_interprocess_event";
00045   static u_int ev = RegisterWindowMessage(to_unicode_temp(DEBUG_UNIQUIFIER));
00046 #else
00047   static u_int ev = 0;
00048 #endif
00049   return ev;
00050 }
00051 
00052 outcome debugger::log(u_int string_table_id, void *instance, int filter)
00053 {
00054 #ifdef __WIN32__
00055   return log(portable::rc_string(string_table_id,
00056       (application_instance)instance), filter);
00057 #else
00058   if (string_table_id || instance || filter) {}
00059   return common::NOT_IMPLEMENTED;
00060 #endif
00061 }
00062 
00063 void *debugger::recipient() const { return _recipient; }
00064 
00065 byte_array *debugger::create_debug_message(const istring &info,
00066     line_ending ending, int filter, time_stamp_method stamp)
00067 {
00068   // the format for the debugging info structure is:
00069   //    short ending;  // how to end the line.
00070   //    int filter;  // what filter to apply.
00071   //    byte message[];  // the actual message as a packed istring.
00072 
00073   byte_array *to_send = new byte_array;
00074   basis::attach(*to_send, short(ending));
00075   basis::attach(*to_send, filter);
00076   istring real_info;
00077   if (info.t() && (stamp == ADD_STAMP) )
00078     real_info = timestamp(true, true);
00079   real_info += info;
00080   real_info.pack(*to_send);
00081   return to_send;
00082 }
00083 
00084 istring debugger::crack_debug_message(void *lparam,
00085     line_ending &ending, int &filter)
00086 {
00087   // the message to print is extracted from the global chunk.
00088   byte_array *received = (byte_array *)lparam;
00089   // snag the ending.
00090   short the_end;
00091   basis::detach(*received, the_end);
00092   ending = line_ending(the_end);
00093   // grab the filter.
00094   basis::detach(*received, filter);
00095   // and finally, the data.
00096   istring to_return;
00097   to_return.unpack(*received);
00098   WHACK(received);  // get rid of the storage.
00099   return to_return;
00100 }
00101 
00102 outcome debugger::log(const istring &info, int filter)
00103 {
00104   // break out if there's no window to send to (we've done the stream and file
00105   // printing already).
00106   if (!_recipient) return common::BAD_INPUT;
00107 #ifdef __WIN32__
00108   if (!IsWindow((HWND)_recipient)) {
00109     // this handle is no longer valid.
00110     _recipient = NIL;
00111     return common::BAD_INPUT;
00112   }
00113   HGLOBAL holder = create_debug_message(info, eol(), filter, _stamp);
00114   // send the info.
00115   if (_synch == immediate)
00116     ::SendMessage((window_handle)_recipient, debugger::EVENT(), 0,
00117         (LPARAM)holder);
00118   else
00119     ::PostMessage((window_handle)_recipient, debugger::EVENT(), 0,
00120         (LPARAM)holder);
00121   return common::OKAY;
00122 #else
00123   if (!info || filter) {}
00124   return common::NOT_IMPLEMENTED;
00125 #endif
00126 }
00127 
00128 
00129 #endif //DEBUGGER_IMPLEMENTATION_FILE
00130 

Generated on Fri Sep 5 04:28:33 2008 for HOOPLE Libraries by  doxygen 1.5.1