mercredi 23 septembre 2015

Getting data to outside from libwebsockets interface

I have made a simple libwebsockets server according to this link: http://ift.tt/WluCya. The name of the server module is WebsocketInterface.

Outside this server interface, in the same application, I have a class DataHandler, which needs to read some user-submitted information from the WebsocketInterface to control itself.

Inside the WebsocketInterface I can read the user input from void* in in the block case LWS_CALLBACK_RECEIVE: and it works fine.

My question is that what could be a proper and effective way to deliver this data to the class DataHandler?

My current solution is to use a singleton class, let's call it WebsocketMessenger. This class is included and instantiated by both modules, WebsocketInteface and DataHandler class. The WebsocketMessenger has a buffer where the WebsocketInterface writes the user input and where the DataHandler can read it from.

This singleton-based solution works in the way I want it to. However, I'm curious if there are other design patterns applicable to this situation. What would be your solution?

Aucun commentaire:

Enregistrer un commentaire