98 uint32_t sol_flags = 0;
100 if (gpoll_events & G_IO_IN) sol_flags |= SOL_FD_FLAGS_IN;
101 if (gpoll_events & G_IO_OUT) sol_flags |= SOL_FD_FLAGS_OUT;
102 if (gpoll_events & G_IO_PRI) sol_flags |= SOL_FD_FLAGS_PRI;
103 if (gpoll_events & G_IO_ERR) sol_flags |= SOL_FD_FLAGS_ERR;
104 if (gpoll_events & G_IO_HUP) sol_flags |= SOL_FD_FLAGS_HUP;
105 if (gpoll_events & G_IO_NVAL) sol_flags |= SOL_FD_FLAGS_NVAL;
113 gushort glib_flags = 0;
115 if (sol_flags & SOL_FD_FLAGS_IN) glib_flags |= G_IO_IN;
116 if (sol_flags & SOL_FD_FLAGS_OUT) glib_flags |= G_IO_OUT;
117 if (sol_flags & SOL_FD_FLAGS_PRI) glib_flags |= G_IO_PRI;
118 if (sol_flags & SOL_FD_FLAGS_ERR) glib_flags |= G_IO_ERR;
119 if (sol_flags & SOL_FD_FLAGS_HUP) glib_flags |= G_IO_HUP;
120 if (sol_flags & SOL_FD_FLAGS_NVAL) glib_flags |= G_IO_NVAL;
130 for (i = 0; i < mdata->
n_poll; i++) {
131 GPollFD *gpfd = mdata->
fds + i;
176 if (gpfd && gpfd->events == h->
events)
180 SOL_DBG(
"glib fd=%d, changed events %#x -> %#x", h->
fd, h->
events, gpfd->events);
182 SOL_DBG(
"glib fd=%d is not needed anymore", h->
fd);
188 for (i = 0; i < (uint16_t)mdata->
n_poll; i++) {
189 const GPollFD *gpfd = mdata->
fds + i;
206 h->
watch = sol_fd_add(gpfd->fd,
217 sol_fd_del(h->
watch);
227 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
228 gboolean r = g_main_context_acquire(ctx);
232 SOL_WRN(
"couldn't acquire glib's context.");
240 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
242 g_main_context_release(ctx);
245 static inline unsigned int
248 unsigned int left_zeros;
252 if ((left_zeros = __builtin_clz(u - 1)) < 1)
254 return 1 << ((
sizeof(u) * 8) - left_zeros);
262 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
269 ready = g_main_context_prepare(ctx, &mdata->
max_prio);
279 mdata->
n_poll = g_main_context_query(ctx,
283 if (req_n_fds == mdata->
n_fds)
289 tmp = realloc(mdata->
fds, byte_size);
292 memset(tmp, 0, byte_size);
295 mdata->
fds = (GPollFD *)tmp;
296 mdata->
n_fds = req_n_fds;
328 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
334 ready = g_main_context_check(ctx,
347 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
352 g_main_context_dispatch(ctx);
362 GMainContext *ctx = g_source_get_context(&mdata->
gsource);
373 g_source_destroy(&mdata->
gsource);
374 g_source_unref(&mdata->
gsource);
376 g_main_context_unref(ctx);
383 #ifndef SOL_NO_API_VERSION
403 if (g_main_depth()) {
404 SOL_DBG(
"already running with glib");
408 ctx = g_main_context_default();
416 gsource = g_main_context_find_source_by_user_data(ctx, (
void *)
sol_init);
423 g_source_set_callback(gsource,
426 id = g_source_attach(gsource, ctx);
440 g_main_context_ref(ctx);
441 SOL_DBG(
"glib's mainloop is now integrated");
445 failed_mainloop_source:
446 g_source_destroy(gsource);
448 g_source_unref(gsource);
449 SOL_WRN(
"failed to integrate glib's mainloop");
static GSourceFuncs _sol_glib_integration_gsource_funcs
Source callbacks needed for the integration of the mainloops.
Definition: sol-glib-integration.h:59
static struct _sol_glib_integration_fd_handler * _sol_glib_integration_source_fd_handler_data_find(struct _sol_glib_integration_source_data *mdata, int fd)
Definition: sol-glib-integration.h:140
uint16_t api_version
must match SOL_MAINLOOP_SOURCE_TYPE_API_VERSION at runtime.
Definition: sol-mainloop.h:673
#define SOL_DBG(fmt,...)
Logs a message with debug level.
Definition: sol-log.h:671
#define SOL_NULL_CHECK(ptr,...)
Convenience macro to check for NULL pointer.
Definition: sol-log.h:223
int sol_init(void)
Initializes the Soletta library.
static uint32_t _sol_glib_integration_gpoll_events_to_fd_flags(gushort gpoll_events)
Definition: sol-glib-integration.h:96
static bool _sol_glib_integration_source_get_next_timeout(void *data, struct timespec *ts)
Definition: sol-glib-integration.h:311
#define SOL_PTR_VECTOR_FOREACH_IDX(vector, itrvar, idx)
Macro to iterate over the pointer vector easily.
Definition: sol-vector.h:672
static void sol_ptr_vector_clear(struct sol_ptr_vector *pv)
Delete all elements from the vector.
Definition: sol-vector.h:642
static void _sol_glib_integration_source_fd_handlers_adjust(struct _sol_glib_integration_source_data *mdata)
Definition: sol-glib-integration.h:166
#define SOL_WRN(fmt,...)
Logs a message with warning level.
Definition: sol-log.h:645
gushort events
Definition: sol-glib-integration.h:75
gint max_prio
Definition: sol-glib-integration.h:92
int sol_util_size_mul(size_t op1, size_t op2, size_t *out)
Multiply two values checking for overflow.
Structure representing the type of a source of mainloop events.
Definition: sol-mainloop.h:667
static void _sol_glib_integration_source_dispose(void *data)
Definition: sol-glib-integration.h:358
Definition: sol-glib-integration.h:85
static unsigned int _sol_glib_integration_align_power2(unsigned int u)
Definition: sol-glib-integration.h:246
int fd
Definition: sol-glib-integration.h:74
GSource gsource
Definition: sol-glib-integration.h:86
static gboolean _sol_glib_integration_gsource_check(GSource *source)
Definition: sol-glib-integration.h:45
static const struct sol_mainloop_source_type _sol_glib_integration_source_type
Source type to integrate the mainloops (see sol_mainloop_source_type)
Definition: sol-glib-integration.h:382
Definition: sol-glib-integration.h:71
These routines are used for Soletta logging.
static bool sol_glib_integration(void)
Definition: sol-glib-integration.h:394
struct sol_ptr_vector handlers
Definition: sol-glib-integration.h:87
static gboolean _sol_glib_integration_gsource_dispatch(GSource *source, GSourceFunc cb, gpointer user_data)
Definition: sol-glib-integration.h:51
static bool _sol_glib_integration_source_acquire(struct _sol_glib_integration_source_data *mdata)
Definition: sol-glib-integration.h:225
static bool _sol_glib_integration_source_prepare(void *data)
Definition: sol-glib-integration.h:258
static bool _sol_glib_integration_source_check(void *data)
Definition: sol-glib-integration.h:324
static FILE * fd
Definition: download.c:28
static bool _sol_glib_integration_on_source_fd(void *data, int fd, uint32_t active_flags)
Definition: sol-glib-integration.h:154
static struct sol_timeout * timeout
Definition: browse.c:36
gint n_fds
Definition: sol-glib-integration.h:89
struct sol_mainloop_source sol_mainloop_source
Structure of a Source of mainloop events.
Definition: sol-mainloop.h:762
gint timeout
Definition: sol-glib-integration.h:91
static int sol_ptr_vector_del(struct sol_ptr_vector *pv, uint16_t i)
Remove the pointer of index i from the vector.
Definition: sol-vector.h:541
struct _sol_glib_integration_source_data * mdata
Definition: sol-glib-integration.h:73
static gushort _sol_glib_integration_fd_flags_to_gpoll_events(uint32_t sol_flags)
Definition: sol-glib-integration.h:111
static void _sol_glib_integration_fd_handler_del(struct _sol_glib_integration_fd_handler *h)
Definition: sol-glib-integration.h:79
struct sol_fd * watch
Definition: sol-glib-integration.h:72
static void sol_ptr_vector_init(struct sol_ptr_vector *pv)
Initializes a sol_ptr_vector structure.
Definition: sol-vector.h:326
static GPollFD * _sol_glib_integration_source_gpollfd_find(struct _sol_glib_integration_source_data *mdata, int fd)
Definition: sol-glib-integration.h:126
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers...
Definition: sol-vector.h:310
static void _sol_glib_integration_source_release(struct _sol_glib_integration_source_data *mdata)
Definition: sol-glib-integration.h:238
#define SOL_NULL_CHECK_GOTO(ptr, label)
Convenience macro to check for NULL pointer and jump to a given label.
Definition: sol-log.h:262
static struct timespec sol_util_timespec_from_msec(int msec)
Create a struct timespec from milliseconds.
Definition: sol-util.h:195
#define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx)
Macro to iterate over the pointer vector easily in the reverse order.
Definition: sol-vector.h:701
These are routines that Soletta provides for its vector implementation.
static gboolean _sol_glib_integration_gsource_cb(gpointer user_data)
Definition: sol-glib-integration.h:66
#define SOL_INT_CHECK_GOTO(var, exp, label)
Similar to SOL_INT_CHECK but jumping to label instead of returning.
Definition: sol-log.h:345
#define SOL_MAINLOOP_SOURCE_TYPE_API_VERSION
Compile time API version to be checked during runtime.
Definition: sol-mainloop.h:669
GPollFD * fds
Definition: sol-glib-integration.h:88
gint n_poll
Definition: sol-glib-integration.h:90
struct sol_mainloop_source * sol_mainloop_add_source(const struct sol_mainloop_source_type *type, const void *data)
Create a new source of events to the main loop.
static gboolean _sol_glib_integration_gsource_prepare(GSource *source, gint *timeout)
Definition: sol-glib-integration.h:39
These routines are used for Soletta's mainloop manipulation.
int sol_ptr_vector_append(struct sol_ptr_vector *pv, const void *ptr)
Append a pointer to the end of the vector.
static void _sol_glib_integration_source_dispatch(void *data)
Definition: sol-glib-integration.h:343