oop - C++ nonmember accessing member functions -


i'm working different team on project. other team constructing gui, which, gui frameworks inheritance driven. on other hand, code on side ('bottom end', guess 1 say) c (though believe it's technically c++ via msvc2010 toolchain w/o "treat c" flag.

both modules (ui , this) must compiled separately , linked together.

problem: need has popped bottom end call redraw function on gui side data given it. here things go bad. how can call set of member functions, 1 w/ complex dependencies? if try include window header, there's inheritance list gui stuff mile long, bottom end isn't build against complex gui libs...i can't forward declare way out because need call function on window?

now major communication design flaw, though we're in bad position right major restructuring isn't option.

questions:

  1. how should have been organized bottom end contact top redraw, going ball of c code ball of c++ node.

  2. what can circumvent issue?

the way can think of sort of communication class...but don't see how won't run same issue need built against both gui , bottom end?

if need call single function, or small subset of functions, callback best bet. if you're dealing member function, can still call pointer member function , pointer object in question. see this answer details on doing that. however, mean requiring include entire mile-long list of dependencies gui code.

edit: after thought, callback few functions without needing include dependencies gui code. example:

in gui code somewhere...

int dofooinbar(int arg1, const char *arg2){     return myform.childcontainer.childbox.childbutton.bar.dofoo( arg1, arg2 ); } 

now in guicallbacks.hpp...

int dofooinbar(int arg1, const char *arg2); 

you include guicallbacks.hpp , call dofooinbar() anywhere in c code. issue method need make new function every callback want use.

a more general method of accomplishing such task in bulk via passing messages. cross-platform method doing involves communication object, have mentioned. wouldn't encounter build issues if provide mechanism obtaining pointer shared communication object naming mechanism. small example be:

class commobj{ public:     struct message{         uint32_t type;         uint32_t flags;         std::string title;         std::string contents;         ... //maybe union here or instead     }; private:     static map<std::string, commobj*> internalobjects;     std::deque<message> messages;     std::string myname; public:     commobj(const char *name); //registers object in map     ~commobj(); //unregisters object in map     void pushmessage( uint32_t type, uint32_t flags, const char *title, const char *contents, ...);     message getmessage();     bool hasmessages();     static commobj *getobjbyname(const char *name);     static bool objwithnameexists(); }; 

obviously can make more c-like version, in c++ clarity. implementation details exercise reader.

with code, may build both backend , frontend against object, , can run check on both sides of code see if commobj name "backend->gui" has been made yet. if not, make it. able start communicating object grabbing pointer getobjbyname("backend->gui"); continuously poll object see if there new messages. can have object gui post messages backend too, perhaps named "gui->backend", or build bi-directionality object itself.

an alternative method use socket communication / shared file descriptors. read , write data socket other side pick up. basic signalling, may simple way accomplish need, if don't need complex. simple send() call socket descriptor need signal other side of code.

do aware using sockets cause slowdowns if used incredibly heavily. depends on underlying implementation, sockets on localhost slower raw function calls. aren't going need interlocked signalling in tight loop though, should fine either method. when slower, mean it's maybe 50 microseconds vs 5 microseconds. it's not worry situations, aware of. on flipside, if gui code running in different thread backend code, want mutex communications object before posting/reading messages, wouldn't needed shared file descriptor. mutexes/semaphors bring own baggage along deal with.

using communications object 1 gave outline allow automatic marshaling of types, might interested in. granted, write object marshaling socket too, @ point might use shared object.

i hope project ends going smoothly.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -