diff options
author | Alan Coopersmith <alan.coopersmith@sun.com> | 2009-08-12 14:18:25 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@sun.com> | 2009-08-12 16:44:40 -0700 |
commit | 3199c6fb39f02b36a07ef65bf4b07d6ec340944d (patch) | |
tree | 59613bdf195e6f0490f672badd881372f2de9ac9 | |
parent | fccbbd6f3bdc090d2da9b32fdff2fd13679e2b78 (diff) | |
download | xscope-3199c6fb39f02b36a07ef65bf4b07d6ec340944d.tar.gz |
Convert extension decoding to function pointer tables
Each extension now registers it's own request, reply, event & error decoding
functions as needed in the central table, instead of a cascading block of
if/else statements to modify for each new extension added.
Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
-rw-r--r-- | bigreqscope.h | 2 | ||||
-rw-r--r-- | decode_bigreq.c | 9 | ||||
-rw-r--r-- | decode_lbx.c | 15 | ||||
-rw-r--r-- | decode_randr.c | 15 | ||||
-rw-r--r-- | decode_render.c | 18 | ||||
-rw-r--r-- | decode_shm.c | 15 | ||||
-rw-r--r-- | decode_wcp.c | 10 | ||||
-rw-r--r-- | extensions.c | 123 | ||||
-rw-r--r-- | extensions.h | 41 | ||||
-rw-r--r-- | lbxscope.h | 2 | ||||
-rw-r--r-- | randrscope.h | 3 | ||||
-rw-r--r-- | renderscope.h | 4 | ||||
-rw-r--r-- | shmscope.h | 4 | ||||
-rw-r--r-- | wcpscope.h | 3 |
14 files changed, 165 insertions, 99 deletions
diff --git a/bigreqscope.h b/bigreqscope.h index 0b182c0..00e9c08 100644 --- a/bigreqscope.h +++ b/bigreqscope.h @@ -13,8 +13,6 @@ #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char BIGREQRequest; - extern void BigreqEnable (FD fd, const unsigned char *buf); extern void BigreqEnableReply (FD fd, const unsigned char *buf); diff --git a/decode_bigreq.c b/decode_bigreq.c index be0d597..3b324e7 100644 --- a/decode_bigreq.c +++ b/decode_bigreq.c @@ -31,9 +31,9 @@ #include "bigreqscope.h" #include "extensions.h" -unsigned char BIGREQRequest; +static unsigned char BIGREQRequest; -void +static void bigreq_decode_req ( FD fd, const unsigned char *buf) @@ -51,7 +51,7 @@ bigreq_decode_req ( } } -void +static void bigreq_decode_reply ( FD fd, const unsigned char *buf, @@ -78,4 +78,7 @@ InitializeBIGREQ( p = DefineType(BIGREQREPLY, ENUMERATED, "BIGREQREPLY", (PrintProcType) PrintENUMERATED); DefineEValue (p, 0L, "BigreqEnable"); + + InitializeExtensionDecoder(BIGREQRequest, bigreq_decode_req, + bigreq_decode_reply); } diff --git a/decode_lbx.c b/decode_lbx.c index dd74657..90b9fd1 100644 --- a/decode_lbx.c +++ b/decode_lbx.c @@ -32,9 +32,10 @@ #include "lbxscope.h" #include "extensions.h" -unsigned char LBXRequest, LBXEvent, LBXError; +static unsigned char LBXRequest, LBXError; +unsigned char LBXEvent; /* exported for DecodeEvent in decode11.c */ -void +static void lbx_decode_req ( FD fd, const unsigned char *buf) @@ -70,7 +71,7 @@ lbx_decode_req ( } } -void +static void lbx_decode_reply ( FD fd, const unsigned char *buf, @@ -85,7 +86,7 @@ lbx_decode_reply ( } } -void +static void lbx_decode_error ( FD fd, const unsigned char *buf) @@ -100,7 +101,7 @@ lbx_decode_error ( } } -void +static void lbx_decode_event ( FD fd, const unsigned char *buf) @@ -149,4 +150,8 @@ InitializeLBX ( p = DefineType(LBXEVENT, ENUMERATED, "LBXEVENT", (PrintProcType) PrintENUMERATED); DefineEValue (p, 0L, "SwitchEvent"); DefineEValue (p, 1L, "CloseEvent"); + + InitializeExtensionDecoder(LBXRequest, lbx_decode_req, lbx_decode_reply); + InitializeExtensionErrorDecoder(LBXError, lbx_decode_error); + InitializeExtensionEventDecoder(LBXEvent, lbx_decode_event); } diff --git a/decode_randr.c b/decode_randr.c index b6a1ce3..7b5552a 100644 --- a/decode_randr.c +++ b/decode_randr.c @@ -32,9 +32,9 @@ #include "randrscope.h" #include "extensions.h" -unsigned char RANDRRequest, RANDRError, RANDREvent; +static unsigned char RANDRRequest, RANDRError, RANDREvent; -void +static void randr_decode_req ( FD fd, const unsigned char *buf) @@ -52,7 +52,7 @@ randr_decode_req ( } } -void +static void randr_decode_reply ( FD fd, const unsigned char *buf, @@ -65,7 +65,7 @@ randr_decode_reply ( } } -void +static void randr_decode_event ( FD fd, const unsigned char *buf) @@ -97,4 +97,11 @@ InitializeRANDR ( DefineEValue (p, 0L, "QueryVersion"); DefineEValue (p, 1L, "GetScreenInfo"); DefineEValue (p, 2L, "SetScreenConfig"); + + InitializeExtensionDecoder(RANDRRequest, randr_decode_req, + randr_decode_reply); + /* Not yet implemented: + InitializeExtensionErrorDecoder(RANDRError, randr_decode_error); */ + InitializeExtensionEventDecoder(RANDREvent, randr_decode_event); + } diff --git a/decode_render.c b/decode_render.c index e1f5c05..4035960 100644 --- a/decode_render.c +++ b/decode_render.c @@ -32,9 +32,11 @@ #include "renderscope.h" #include "extensions.h" -unsigned char RENDERRequest, RENDERError; +static unsigned char RENDERRequest, RENDERError; +#define RENDERNError 5 -void + +static void render_decode_req ( FD fd, const unsigned char *buf) @@ -75,7 +77,7 @@ render_decode_req ( } } -void +static void render_decode_reply ( FD fd, const unsigned char *buf, @@ -89,7 +91,7 @@ render_decode_reply ( } } -void +static void render_decode_error ( FD fd, const unsigned char *buf) @@ -235,6 +237,7 @@ InitializeRENDER ( const unsigned char *buf) { TYPE p; + int errcode; RENDERRequest = (unsigned char)(buf[9]); RENDERError = (unsigned char)(buf[11]); @@ -325,4 +328,11 @@ InitializeRENDER ( DefineType(POINTFIXED, BUILTIN, "POINTFIXED", PrintPOINTFIXED); DefineType(TRIANGLE, RECORD, "TRIANGLE", PrintTRIANGLE); DefineType(TRAPEZOID, RECORD, "TRAPEZOID", PrintTRAPEZOID); + + InitializeExtensionDecoder(RENDERRequest, render_decode_req, + render_decode_reply); + for (errcode = RENDERError; errcode < (RENDERError + RENDERNError) ; + errcode ++) { + InitializeExtensionErrorDecoder(errcode, render_decode_error); + } } diff --git a/decode_shm.c b/decode_shm.c index 938c770..ca48385 100644 --- a/decode_shm.c +++ b/decode_shm.c @@ -31,9 +31,9 @@ #include "shmscope.h" #include "extensions.h" -unsigned char MITSHMRequest, MITSHMError, MITSHMEvent; +static unsigned char MITSHMRequest, MITSHMError, MITSHMEvent; -void +static void mitshm_decode_req ( FD fd, const unsigned char *buf) @@ -53,7 +53,7 @@ mitshm_decode_req ( } } -void +static void mitshm_decode_reply ( FD fd, const unsigned char *buf, @@ -65,14 +65,14 @@ mitshm_decode_reply ( } } -void +static void mitshm_decode_event ( FD fd, const unsigned char *buf) { } -void +static void mitshm_decode_error ( FD fd, const unsigned char *buf) @@ -116,4 +116,9 @@ InitializeMITSHM ( p = DefineType(MITSHMEVENT, ENUMERATED, "MITSHMEVENT", (PrintProcType) PrintENUMERATED); DefineEValue (p, 0L, "CompletionEvent"); + + InitializeExtensionDecoder(MITSHMRequest, mitshm_decode_req, + mitshm_decode_reply); + InitializeExtensionErrorDecoder(MITSHMError, mitshm_decode_error); + InitializeExtensionEventDecoder(MITSHMEvent, mitshm_decode_event); } diff --git a/decode_wcp.c b/decode_wcp.c index fdb7664..1e37a95 100644 --- a/decode_wcp.c +++ b/decode_wcp.c @@ -32,9 +32,9 @@ #include "wcpscope.h" #include "extensions.h" -unsigned char WCPRequest, WCPError; +static unsigned char WCPRequest, WCPError; -void +static void wcp_decode_req ( FD fd, const unsigned char *buf) @@ -71,7 +71,7 @@ wcp_decode_req ( } } -void +static void wcp_decode_reply ( FD fd, const unsigned char *buf, @@ -89,7 +89,7 @@ wcp_decode_reply ( } } -void +static void wcp_decode_error ( FD fd, const unsigned char *buf) @@ -129,4 +129,6 @@ InitializeWCP ( p = DefineType(WCPREPLY, ENUMERATED, "WCPREPLY", (PrintProcType) PrintENUMERATED); DefineEValue (p, 0L, "QueryVersion"); + InitializeExtensionDecoder(WCPRequest, wcp_decode_req, wcp_decode_reply); + InitializeExtensionErrorDecoder(WCPError, wcp_decode_error); } diff --git a/extensions.c b/extensions.c index d053c06..cb75ef8 100644 --- a/extensions.c +++ b/extensions.c @@ -135,7 +135,7 @@ ProcessQueryExtensionReply(long seq, const unsigned char *buf) qe->event = buf[10]; qe->error = buf[11]; - ext_by_request[qe->request - EXTENSION_MIN] = qe; + ext_by_request[qe->request - EXTENSION_MIN_REQ] = qe; for (i = 0; decodable_extensions[i].name != NULL ; i++) { if (strcmp(qe->name, decodable_extensions[i].name) == 0) { @@ -160,21 +160,68 @@ ProcessQueryExtensionReply(long seq, const unsigned char *buf) } } +/* Decoding for specific/known extensions */ + +static extension_decode_req_ptr ExtensionRequestDecoder[NUM_EXTENSIONS]; +static extension_decode_reply_ptr ExtensionReplyDecoder[NUM_EXTENSIONS]; +static extension_decode_error_ptr ExtensionErrorDecoder[NUM_EXTENSIONS]; +static extension_decode_event_ptr ExtensionEventDecoder[NUM_EXT_EVENTS]; + +void +InitializeExtensionDecoder (int Request, extension_decode_req_ptr reqd, + extension_decode_reply_ptr repd) +{ + if ((Request > EXTENSION_MAX_REQ) || (Request < EXTENSION_MIN_REQ)) { + char errmsg[128]; + + snprintf(errmsg, sizeof(errmsg), "Failed to register decoder" + " for invalid extension request code %d.", Request); + warn(errmsg); + return; + } + ExtensionRequestDecoder[Request - EXTENSION_MIN_REQ] = reqd; + ExtensionReplyDecoder[Request - EXTENSION_MIN_REQ] = repd; +} + +void +InitializeExtensionErrorDecoder(int Error, extension_decode_error_ptr errd) +{ + if ((Error > EXTENSION_MAX_ERR) || (Error < EXTENSION_MIN_ERR)) { + char errmsg[128]; + + snprintf(errmsg, sizeof(errmsg), "Failed to register decoder" + " for invalid extension error code %d.", Error); + warn(errmsg); + return; + } + ExtensionErrorDecoder[Error - EXTENSION_MIN_ERR] = errd; +} + +void +InitializeExtensionEventDecoder(int Event, extension_decode_event_ptr evd) +{ + if ((Event > EXTENSION_MAX_EV) || (Event < EXTENSION_MIN_EV)) { + char errmsg[128]; + + snprintf(errmsg, sizeof(errmsg), "Failed to register decoder" + " for invalid extension event code %d.", Event); + warn(errmsg); + return; + } + ExtensionEventDecoder[Event - EXTENSION_MIN_EV] = evd; +} + void ExtensionRequest (FD fd, const unsigned char *buf, short Request) { - if (Request == LBXRequest) { - lbx_decode_req(fd, buf); - } else if (Request == WCPRequest) { - wcp_decode_req(fd, buf); - } else if (Request == RENDERRequest) { - render_decode_req(fd,buf); - } else if (Request == RANDRRequest) { - randr_decode_req(fd,buf); - } else if (Request == MITSHMRequest) { - mitshm_decode_req(fd,buf); - } else if (Request == BIGREQRequest) { - bigreq_decode_req(fd,buf); + extension_decode_req_ptr decode_req = NULL; + + if ((Request <= EXTENSION_MAX_REQ) && (Request >= EXTENSION_MIN_REQ)) { + decode_req = ExtensionRequestDecoder[Request - EXTENSION_MIN_REQ]; + } + + if (decode_req != NULL) { + decode_req(fd, buf); } else { ExtendedRequest(fd, buf); ReplyExpected(fd, Request); @@ -185,18 +232,14 @@ void ExtensionReply (FD fd, const unsigned char *buf, short Request, short RequestMinor) { - if (Request == LBXRequest) { - lbx_decode_reply(fd, buf, RequestMinor); - } else if (Request == WCPRequest) { - wcp_decode_reply(fd, buf, RequestMinor); - } else if (Request == RENDERRequest) { - render_decode_reply(fd, buf, RequestMinor); - } else if (Request == RANDRRequest) { - randr_decode_reply(fd, buf, RequestMinor); - } else if (Request == MITSHMRequest) { - mitshm_decode_reply(fd, buf, RequestMinor); - } else if (Request == BIGREQRequest) { - bigreq_decode_reply(fd, buf, RequestMinor); + extension_decode_reply_ptr decode_reply = NULL; + + if ((Request <= EXTENSION_MAX_REQ) && (Request >= EXTENSION_MIN_REQ)) { + decode_reply = ExtensionReplyDecoder[Request - EXTENSION_MIN_REQ]; + } + + if (decode_reply != NULL) { + decode_reply(fd, buf, RequestMinor); } else { warn("Extended reply opcode"); } @@ -205,14 +248,14 @@ ExtensionReply (FD fd, const unsigned char *buf, void ExtensionError (FD fd, const unsigned char *buf, short Error) { - if (Error == LBXError) { - lbx_decode_error(fd, buf); - } else if (Error == WCPError) { - wcp_decode_error(fd, buf); - } else if (Error >= RENDERError && Error < RENDERError + RENDERNError) { - render_decode_error(fd,buf); - } else if (Error == MITSHMError) { - mitshm_decode_error(fd, buf); + extension_decode_error_ptr decode_error = NULL; + + if ((Error <= EXTENSION_MAX_ERR) && (Error >= EXTENSION_MIN_ERR)) { + decode_error = ExtensionErrorDecoder[Error - EXTENSION_MIN_ERR]; + } + + if (decode_error != NULL) { + decode_error(fd, buf); } else { warn("Extended Error code"); } @@ -221,12 +264,14 @@ ExtensionError (FD fd, const unsigned char *buf, short Error) void ExtensionEvent (FD fd, const unsigned char *buf, short Event) { - if (Event == LBXEvent) { - lbx_decode_event (fd, buf); - } else if (Event == RANDREvent) { - randr_decode_event (fd, buf); - } else if (Event == MITSHMEvent) { - mitshm_decode_event (fd, buf); + extension_decode_event_ptr decode_event = NULL; + + if ((Event <= EXTENSION_MAX_EV) && (Event >= EXTENSION_MIN_EV)) { + decode_event = ExtensionEventDecoder[Event - EXTENSION_MIN_EV]; + } + + if (decode_event != NULL) { + decode_event(fd, buf); } else { warn("Extended Event code"); } diff --git a/extensions.h b/extensions.h index 18107e8..d93e013 100644 --- a/extensions.h +++ b/extensions.h @@ -32,9 +32,14 @@ #include "scope.h" -#define EXTENSION_MIN 128 /* lowest possible extension request code */ -#define EXTENSION_MAX 255 /* highest possible extension request code */ -#define NUM_EXTENSIONS 128 /* maximum possible number of extensions */ +#define EXTENSION_MIN_REQ 128 /* lowest possible extension request code */ +#define EXTENSION_MAX_REQ 255 /* highest possible extension request code */ +#define EXTENSION_MIN_EV 64 /* lowest possible extension event code */ +#define EXTENSION_MAX_EV 127 /* highest possible extension event code */ +#define EXTENSION_MIN_ERR 128 /* lowest possible extension error code */ +#define EXTENSION_MAX_ERR 255 /* highest possible extension error code */ +#define NUM_EXTENSIONS 128 /* maximum possible number of extensions */ +#define NUM_EXT_EVENTS 64 /* maximum possible number of extension events */ /* special processing in extensions.c to capture extension info */ extern void ProcessQueryExtensionRequest(long seq, const unsigned char *buf); @@ -48,20 +53,6 @@ extern void ExtensionEvent(FD fd, const unsigned char *buf, short Event); /* X11 Extension decoders in decode_*.c */ -#define extension_decode_prototypes(ext) \ - extern void ext##_decode_req (FD fd, const unsigned char *buf); \ - extern void ext##_decode_reply (FD fd, const unsigned char *buf, \ - short RequestMinor); \ - extern void ext##_decode_error (FD fd, const unsigned char *buf); \ - extern void ext##_decode_event (FD fd, const unsigned char *buf) - -extension_decode_prototypes(bigreq); -extension_decode_prototypes(lbx); -extension_decode_prototypes(mitshm); -extension_decode_prototypes(randr); -extension_decode_prototypes(render); -extension_decode_prototypes(wcp); - extern void InitializeBIGREQ (const unsigned char *buf); extern void InitializeLBX (const unsigned char *buf); extern void InitializeMITSHM (const unsigned char *buf); @@ -69,4 +60,20 @@ extern void InitializeRANDR (const unsigned char *buf); extern void InitializeRENDER (const unsigned char *buf); extern void InitializeWCP (const unsigned char *buf); +/* Called from Initialize* to register the extension-specific decoders */ + +typedef void (*extension_decode_req_ptr) (FD fd, const unsigned char *buf); +typedef void (*extension_decode_reply_ptr) (FD fd, const unsigned char *buf, + short RequestMinor); +typedef void (*extension_decode_error_ptr) (FD fd, const unsigned char *buf); +typedef void (*extension_decode_event_ptr) (FD fd, const unsigned char *buf); + +extern void InitializeExtensionDecoder (int Request, + extension_decode_req_ptr reqd, + extension_decode_reply_ptr repd); +extern void InitializeExtensionErrorDecoder(int Error, + extension_decode_error_ptr errd); +extern void InitializeExtensionEventDecoder(int Event, + extension_decode_event_ptr evd); + #endif /* XSCOPE_EXTENSIONS_H */ @@ -39,8 +39,6 @@ SOFTWARE. #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char LBXRequest; -extern unsigned char LBXError; extern unsigned char LBXEvent; extern void LbxQueryVersion (FD fd, const unsigned char *buf); diff --git a/randrscope.h b/randrscope.h index 5b63b06..efb0129 100644 --- a/randrscope.h +++ b/randrscope.h @@ -12,9 +12,6 @@ #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char RANDRRequest; -extern unsigned char RANDREvent; - extern void RandrQueryVersion (FD fd, const unsigned char *buf); extern void RandrQueryVersionReply (FD fd, const unsigned char *buf); extern void RandrGetScreenInfo (FD fd, const unsigned char *buf); diff --git a/renderscope.h b/renderscope.h index 201e339..f38224f 100644 --- a/renderscope.h +++ b/renderscope.h @@ -12,10 +12,6 @@ #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char RENDERRequest; -extern unsigned char RENDERError; -#define RENDERNError 5 - extern void RenderQueryVersion (FD fd, const unsigned char *buf); extern void RenderQueryVersionReply (FD fd, const unsigned char *buf); extern void RenderQueryPictFormats (FD fd, const unsigned char *buf); @@ -12,10 +12,6 @@ #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char MITSHMRequest; -extern unsigned char MITSHMError; -extern unsigned char MITSHMEvent; - extern void MitshmQueryVersion (FD fd, const unsigned char *buf); extern void MitshmQueryVersionReply (FD fd, const unsigned char *buf); extern void MitshmAttach (FD fd, const unsigned char *buf); @@ -37,9 +37,6 @@ #define printfield(a,b,c,d,e) if (Verbose > 1) PrintField(a,b,c,d,e) -extern unsigned char WCPRequest; -extern unsigned char WCPError; - extern void WcpQueryVersion (FD fd, const unsigned char *buf); extern void WcpQueryVersionReply (FD fd, const unsigned char *buf); extern void WcpPutImage (FD fd, const unsigned char *buf); |