void *cb_data;
};
-/* There can currently only be one session at a time. */
-/* 'sr_current_session' is not static, it's used elsewhere (via 'extern'). */
-struct sr_session *sr_current_session;
-
/**
* Create a new session.
* Currently, there can be only one session at a time within the same process.
*
* @since 0.4.0
*/
-SR_API int sr_session_new(struct sr_session **session)
+SR_API int sr_session_new(struct sr_session **new_session)
{
- if (sr_current_session) {
- sr_err("%s: session already exists", __func__);
- return SR_ERR_BUG;
- }
+ struct sr_session *session;
- sr_current_session = g_malloc0(sizeof(struct sr_session));
+ session = g_malloc0(sizeof(struct sr_session));
- sr_current_session->source_timeout = -1;
- sr_current_session->running = FALSE;
- sr_current_session->abort_session = FALSE;
- g_mutex_init(&sr_current_session->stop_mutex);
+ session->source_timeout = -1;
+ session->running = FALSE;
+ session->abort_session = FALSE;
+ g_mutex_init(&session->stop_mutex);
- *session = sr_current_session;
+ *new_session = session;
return SR_OK;
}
g_free(session);
- if (session == sr_current_session)
- sr_current_session = NULL;
-
return SR_OK;
}
* @retval SR_OK Success.
* @retval SR_ERR Error occured.
*/
-static int sr_session_iteration(gboolean block)
+static int sr_session_iteration(struct sr_session *session, gboolean block)
{
- struct sr_session *session = sr_current_session;
unsigned int i;
int ret;
} else {
/* Real sources, use g_poll() main loop. */
while (session->num_sources)
- sr_session_iteration(TRUE);
+ sr_session_iteration(session, TRUE);
}
return SR_OK;
return SR_ERR_ARG;
}
- for (l = sr_current_session->datafeed_callbacks; l; l = l->next) {
+ for (l = sdi->session->datafeed_callbacks; l; l = l->next) {
if (sr_log_loglevel_get() >= SR_LOG_DBG)
datafeed_dump(packet);
cb_struct = l->data;