MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / _sr_session_source_add

Function _sr_session_source_add

libsigrok4DSL/session.c:337–382  ·  view source on GitHub ↗

* Add an event source for a file descriptor. * * @param pollfd The GPollFD. * @param timeout Max time to wait before the callback is called, ignored if 0. * @param cb Callback function to add. Must not be NULL. * @param cb_data Data for the callback function. Can be NULL. * @param poll_object TODO. * * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or * SR_ERR_MALL

Source from the content-addressed store, hash-verified

335 * SR_ERR_MALLOC upon memory allocation errors.
336 */
337static int _sr_session_source_add(GPollFD *pollfd, int timeout,
338 sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi, gintptr poll_object)
339{
340 struct source *new_sources, *s;
341 GPollFD *new_pollfds;
342
343 if (!cb) {
344 sr_err("%s: cb was NULL", __func__);
345 return SR_ERR_ARG;
346 }
347 if (session == NULL){
348 sr_err("_sr_session_source_add(), session is null.");
349 return SR_ERR_CALL_STATUS;
350 }
351
352 /* Note: cb_data can be NULL, that's not a bug. */
353
354 new_pollfds = g_try_realloc(session->pollfds,
355 sizeof(GPollFD) * (session->num_sources + 1));
356 if (!new_pollfds) {
357 sr_err("%s: new_pollfds malloc failed", __func__);
358 return SR_ERR_MALLOC;
359 }
360
361 new_sources = g_try_realloc(session->sources, sizeof(struct source) *
362 (session->num_sources + 1));
363 if (!new_sources) {
364 sr_err("%s: new_sources malloc failed", __func__);
365 return SR_ERR_MALLOC;
366 }
367
368 new_pollfds[session->num_sources] = *pollfd;
369 s = &new_sources[session->num_sources++];
370 s->timeout = timeout;
371 s->cb = cb;
372 s->cb_data = sdi;
373 s->poll_object = poll_object;
374 session->pollfds = new_pollfds;
375 session->sources = new_sources;
376
377 if (timeout != session->source_timeout && timeout > 0
378 && (session->source_timeout == -1 || timeout < session->source_timeout))
379 session->source_timeout = timeout;
380
381 return SR_OK;
382}
383
384/**
385 * Add an event source for a file descriptor.

Callers 3

sr_session_source_addFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected