Commit b9b351ba authored by Bernhard Link's avatar Bernhard Link

some more work towards generic event support

parent f3bacb47
......@@ -39,7 +39,8 @@ END
EVENT Generic
1 extension CARD8
4 length UINT32
32 data LISTofCARD8
8 evtype CARD16
10 data LISTofCARD8
END
EOF
......@@ -1366,26 +1366,43 @@ static inline void free_expectedreplylist(struct expectedreply *r) {
}
}
static inline const struct request *find_extension_request(struct connection *c,unsigned char req,unsigned char subreq,const char **extension) {
static inline const struct extension *find_extension_by_opcode(struct connection *c, unsigned char req) {
struct usedextension *u;
struct unknownextension *e;
for( u = c->usedextensions; u != NULL ; u = u->next ) {
if( req != u->major_opcode )
continue;
*extension = u->extension->name;
if( subreq < u->extension->numsubrequests )
return u->extension->subrequests + subreq;
else
return NULL;
return u->extension;
}
return NULL;
}
static inline const char *find_unknown_extension(struct connection *c, unsigned char req) {
struct unknownextension *e;
for( e = c->unknownextensions ; e != NULL ; e = e->next ) {
if( req == e->major_opcode ) {
*extension = e->name;
break;
return e->name;
}
}
return NULL;
}
static inline const struct request *find_extension_request(struct connection *c,unsigned char req,unsigned char subreq,const char **extension) {
const struct extension *e;
const char *name;
e = find_extension_by_opcode(c, req);
if( e != NULL ) {
*extension = e->name;
if( subreq < e->numsubrequests )
return e->subrequests + subreq;
else
return NULL;
}
name = find_unknown_extension(c, req);
if( name != NULL )
*extension = name;
return NULL;
}
......@@ -1709,6 +1726,31 @@ void parse_server(struct connection *c) {
const struct event *events;
size_t num_events;
void print_generic_event(struct connection *c, const unsigned char *buffer, const struct event *event) {
unsigned long stackvalues[30];
struct stack stack;
stack.base = stackvalues;
stack.num = 30;
stack.ofs = 0;
uint8_t opcode = getCARD8(1);
const struct extension *extension;
extension = find_extension_by_opcode(c, opcode);
if( extension != NULL ) {
fprintf(out, "%s(%hhu) ", extension->name, opcode);
// TODO: get description from format...
print_parameters(c, buffer, 32, event->parameters, false, &stack);
} else {
const char *name = find_unknown_extension(c, opcode);
if( name != NULL ) {
fprintf(out, "%s(%hhu) ", name, opcode);
} else {
fprintf(out, "unknown extension %hhu ", opcode);
}
print_parameters(c, buffer, 32, event->parameters, false, &stack);
}
}
static void print_event(struct connection *c,const unsigned char *buffer) {
const struct event *event;
uint8_t code = getCARD8(0);
......@@ -1742,7 +1784,11 @@ static void print_event(struct connection *c,const unsigned char *buffer) {
} else
event = &events[code];
fprintf(out,"%s(%hhu) ",event->name,code);
if( event->handler == NULL ) {
print_parameters(c,buffer,32,event->parameters,false,&stack);
} else {
event->handler(c, buffer, event);
}
}
const struct extension *extensions;
......@@ -1760,4 +1806,3 @@ const struct extension *find_extension(const uint8_t *name,size_t len) {
return NULL;
}
......@@ -5,9 +5,11 @@ struct constant {
unsigned long value;
const char *name;
};
struct event;
typedef bool request_func(struct connection*,bool,bool,struct expectedreply *);
typedef void reply_func(struct connection*,bool*,bool*,int,void*);
typedef void event_func(struct connection *, const unsigned char *, const struct event *);
struct request {
const char *name;
......@@ -20,6 +22,7 @@ struct request {
struct event {
const char *name;
const struct parameter *parameters;
event_func *handler;
};
struct extension {
......@@ -134,10 +137,12 @@ extern size_t num_extensions;
extern const struct parameter *unexpected_reply;
extern const struct parameter *setup_parameters;
bool requestQueryExtension(struct connection *c, bool pre, bool bigrequest UNUSED, struct expectedreply *reply);
bool requestInternAtom(struct connection *c, bool pre, bool bigrequest UNUSED, struct expectedreply *reply);
void replyListFontsWithInfo(struct connection *c,bool *ignore,bool *dontremove,int datatype UNUSED,void *data UNUSED);
void replyQueryExtension(struct connection *c,bool *ignore UNUSED,bool *dontremove UNUSED,int datatype,void *data);
void replyInternAtom(struct connection *c,bool *ignore UNUSED,bool *dontremove UNUSED,int datatype UNUSED,void *data);
/* special handlers, for the SPECIAL requests/events */
extern request_func requestQueryExtension;
extern request_func requestInternAtom;
extern reply_func replyListFontsWithInfo;
extern reply_func replyQueryExtension;
extern reply_func replyInternAtom;
extern event_func print_generic_event;
#endif
......@@ -2351,7 +2351,7 @@ static const struct event *finalize_events(struct parser *parser, struct namespa
ns->name);
parser->error = true;
} else if( strcmp(es[i].name, "Generic") == 0 ) {
// TODO: ...
es[i].handler = print_generic_event;
} else {
fprintf(stderr, "No specials available for '%s::%s'!\n",
ns->name, es[i].name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment