0

I am developing a software that has its core, plugins and GUI modularly separated. I load the modules dynamically on demand.

I need to determine which kind of inter-communication would be best suited for a software modularized this way so the different parts can exchange events and information, considering that the plugins or a GUI using a different toolkit would eventually be developed by third parties.

For now I have considered to simply load the symbols from the shared objects and work with them knowing their types and functions signatures. I have also considered using an IPC like DBus but I am not sure if this would be overkill or totally unnecessary.

Being cross-platform is not much of a concern right now but it might be in the future.

What are the pros and cons of one vs the other? are there any other solutions to consider which I have not found about?

1 Answers1

1

IPC is overkill for components loaded in-process. All the extra annotations concerning size of buffers and direction of copy are unnecessary when the caller and callee can share pointers directly.

If you ever want to move to Windows, consider that the shared libraries might have different allocators and different class layout. The best thing to do is export a factory function, return a pointer to an interface (abstract class having only pure virtual member functions and no data, the data and implementations are all in a subclass), and let the object free itself (one of the virtual member functions destroys it).

For an example, you can look at COM IUnknown. You don't need all the complexity of interface queries and so on, but using pure virtual functions and reference counting is a very flexible, very scalable, and extremely portable pattern.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720