]> git.tdb.fi Git - gldbg.git/commitdiff
Add gldBreak callback to gldecoder
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Nov 2010 15:03:17 +0000 (15:03 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 24 Nov 2010 15:03:17 +0000 (15:03 +0000)
Add a callback for otherwise unhandled functions

source/gldecoder.c
source/gldecoder.funcs.t
source/gldecoder.struct.t
source/glprint.c
source/tracer.cpp

index f5540c09077930b0a1875031610df71008642dbb..81b1a43c128b8f3ddba292f86cc883dff2c9ff17 100644 (file)
@@ -44,17 +44,14 @@ int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len)
 
        packet_read_short(pkt, (short *)&func);
 
-       if(dec)
-       {
-               int ret = 0;
-
-               if(func&0x8000)
-                       ret = decode_gldfunc(dec, func, pkt);
-               else
-                       ret = decode_func(dec, func, pkt);
-               if(ret<0)
-                       return -1;
-       }
+       int ret = 0;
+
+       if(func&0x8000)
+               ret = decode_gldfunc(dec, func, pkt);
+       else
+               ret = decode_func(dec, func, pkt);
+       if(ret<0)
+               return -1;
 
        return len;
 }
@@ -70,6 +67,18 @@ static void decode_gldError(GlDecoder *dec, GlPacket *pkt)
        packet_read_int(pkt, (int *)&code);
        if(dec->gldError)
                dec->gldError(dec->user_data, code);
+       else if(dec->unhandled)
+               dec->unhandled(dec->user_data, FUNC_GLDERROR);
+}
+
+static void decode_gldBreak(GlDecoder *dec, GlPacket *pkt)
+{
+       unsigned short func;
+       packet_read_short(pkt, (short *)&func);
+       if(dec->gldBreak)
+               dec->gldBreak(dec->user_data, func);
+       else if(dec->unhandled)
+               dec->unhandled(dec->user_data, FUNC_GLDBREAK);
 }
 
 static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt)
@@ -77,6 +86,7 @@ static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt)
        switch(func)
        {
        case FUNC_GLDERROR: decode_gldError(dec, pkt); break;
+       case FUNC_GLDBREAK: decode_gldBreak(dec, pkt); break;
        default: return -1;
        }
        return 0;
index d4433aa6e9d942d79eee538530a19f820a64f138..98add0427b637cd3fdce12107f49e8e8cd5b7bc4 100644 (file)
@@ -24,6 +24,8 @@ if ret.ctype!="void":
 for p in params:
        w(', p_%s', p.name)
 wl(');')
+wl('   else if(dec->unhandled)')
+wl('           dec->unhandled(dec->user_data, FUNC_%s);', func.name.upper())
 wl('   return 0;')
 wl('}')
 :static int decode_func(GlDecoder *dec, unsigned short func, GlPacket *pkt)
index 5b46acafaf2ce13942b461a2ebeea3af72112f10..cc146ccec71a817edc3aa5eb4fd687f911e66361 100644 (file)
@@ -10,4 +10,6 @@ for p in params:
        w(', %s', p.ctype)
 wl(');')
 :      void (*gldError)(void *, GLenum);
+:      void (*gldBreak)(void *, unsigned short);
+:      void (*unhandled)(void *, unsigned short);
 :} GlDecoder;
index 8dacdb338b1834765dcb25554835cea5fb31343e..e90c0e3d6eb6445ce88de453e88b615b6aba14c4 100644 (file)
@@ -24,6 +24,7 @@ typedef struct sGlPrintData
 static void init_print(GlDecoder *);
 static void glprint_free(void *);
 static void print_gldError(void *, GLenum);
+static void print_unhandled(void *, unsigned short);
 
 GlDecoder *glprint_new(char *buffer, unsigned bufsize)
 {
@@ -45,6 +46,7 @@ GlDecoder *glprint_new(char *buffer, unsigned bufsize)
 
        init_print(dec);
        dec->gldError = print_gldError;
+       dec->unhandled = print_unhandled;
 
        return dec;
 }
@@ -136,3 +138,9 @@ static void print_gldError(void *user_data, GLenum code)
        GlPrintData *gpd = (GlPrintData *)user_data;
        snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode"));
 }
+
+static void print_unhandled(void *user_data, unsigned short func)
+{
+       GlPrintData *gpd = (GlPrintData *)user_data;
+       gpd->buffer[0] = 0;
+}
index 8aa12de25fd629b362c4b4eaaae3af4e3708ac85..9f703f1e673cd7a78d90dbebc084b3bbb9c4b435 100644 (file)
@@ -54,7 +54,11 @@ void Tracer::decode(const char *data, unsigned len)
 
        int ret = glprint->decode(data, len);
        if(ret>=0)
-               IO::print(*out, "%s\n", glprint->get_buffer());
+       {
+               const char *buf = glprint->get_buffer();
+               if(buf[0])
+                       IO::print(*out, "%s\n", buf);
+       }
 }
 
 void Tracer::cmd_trace(const string &args)