C
Chris
I wrote a lib for a p2p network that implements the protocol and queue
handling, etc. works fine.
The main class in the library is called Client and contains (among many
others) a run() method, which
does queue processing and runs for ever. When an inbound message is
received a switch is used to call an approriate processXYZMsg
function.
I now want to create a gui and console front ends for it and am trying
to figure out the code design.
I had originally planned (badly) that each gui would be derived from
Client, and therefore
be able to override eg processLoginReplyMsg() with their own methods.
As the run() method of Client blocks this idea sucks and is embarassing
I now think i should really have 2 threads, one for the Client and one
for the ui.
My question is this. As i can't override the processXYZ functions how
should i handle interaction between the Client lib and the gui?
One though i had was to pass function pointers as arguments to the Client
eg client.setProcessLoginReplyMsgFunction(some_callback_function);
Although in reality i would probably pass in some sort of map containing
all the function pointers in to the constructor of Client.
Any advice welcome on the best approach to this.
Thanks
Chris
handling, etc. works fine.
The main class in the library is called Client and contains (among many
others) a run() method, which
does queue processing and runs for ever. When an inbound message is
received a switch is used to call an approriate processXYZMsg
function.
I now want to create a gui and console front ends for it and am trying
to figure out the code design.
I had originally planned (badly) that each gui would be derived from
Client, and therefore
be able to override eg processLoginReplyMsg() with their own methods.
As the run() method of Client blocks this idea sucks and is embarassing
I now think i should really have 2 threads, one for the Client and one
for the ui.
My question is this. As i can't override the processXYZ functions how
should i handle interaction between the Client lib and the gui?
One though i had was to pass function pointers as arguments to the Client
eg client.setProcessLoginReplyMsgFunction(some_callback_function);
Although in reality i would probably pass in some sort of map containing
all the function pointers in to the constructor of Client.
Any advice welcome on the best approach to this.
Thanks
Chris