Deduce type of void in pure C

191 views Asked by At

Well, I have callback which is arisen when I get HTTP response on HTTP GET request. The prototype of this callback is the following (async programming, could be arised at any time):

// I use Ecore_Con_Url library from EFL framework
Eina_Bool _pt_url_data_cb(void *data, int type, void *event_info)

and this callback can contains data in event_info in JSON format, or pure data. This depends on the what is in void* data. Well, there are two ways to avoid of this pure design:

  • Use two callbacks. If we expect to get pure data - register callback like _pt_url_pure_cb, if we expect data in JSON format register _pt_url_json_cb. But lack of this method is that we have to register/unregister callbacks at runtime. And they are arised when we get some HTTP response with data, doesn't matter in which form they are. I think we could get big problems with this solution.

For example:

// Expect HTTP response as pure data
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _pt_url_pure_cb, data);
return;

// _pt_url_pure_cb wasn't yet called
// Expect HTTP response in JSON format

ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _pt_url_json_cb, data);
...
// Will be called with pure data
_pt_url_json_cb()
  • The second approach is to somehow identify type of void* data and depending on it parse event_info as pure or JSON data. Well, how I could do that with any possible approaches?

Note: What I mean by pure and JSON data? pure - like binary file or any other file which should not be parsed, just download all bytes and save them on the file system. JSON should be parsed and can contain http identifiers to these pure data.

0

There are 0 answers