lundi 18 mai 2020

Designing class for handling multiple communication protocols handling

I am developing a C++ application which should handle multiple communication protocols (Ethernet, Serial, etc.). Each of the communication protocols is handled as a specific class. In order to expose as little as possible information about the internal structure and organization of the said classes and protocols, I would like to somehow wrap all of this functionality and provide somewhat generic API for sending data over a selected protocol.

Basically, what API should provide (the parameters are not restricted to this, but is the general idea):

bool sendData(uint8_t* buffer, const size_t& bufferSize);

void receiveData(uint8_t* dataBuffer, size_t& bufferSize);

What is the best way to create a generic API for the said functionality, and if possible involve some design pattern?

Regards.

Aucun commentaire:

Enregistrer un commentaire