Exemplo n.º 1
0
static void task_do_run(XmlTag *tag, XmlTag **ans, gboolean run)
{
	DEFINE_XTV(XTV_TASK_ID);

	struct mbb_task *task;
	guint id;

	MBB_XTV_CALL(&id);

	mbb_plock_reader_lock();

	on_final { mbb_plock_reader_unlock(); }

	task = mbb_task_get(id);
	if (task == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_TASK);

	g_mutex_lock(task->mutex);
	if (task->run == run) final {
		g_mutex_unlock(task->mutex);
		*ans = mbb_xml_msg_error(
			"task is already %s", run ? "run" : "stop"
		);
	}

	task->run = run;
	if (run) mbb_task_resume(task);
	g_mutex_unlock(task->mutex);

	mbb_plock_reader_unlock();
}
Exemplo n.º 2
0
static void task_cancel(XmlTag *tag, XmlTag **ans)
{
	DEFINE_XTV(XTV_TASK_ID);

	struct mbb_task *task;
	guint id;

	MBB_XTV_CALL(&id);

	mbb_plock_reader_lock();

	on_final { mbb_plock_reader_unlock(); }

	task = mbb_task_get(id);
	if (task == NULL) final
		*ans = mbb_xml_msg(MBB_MSG_UNKNOWN_TASK);

	task->cancel = TRUE;
	g_mutex_lock(task->mutex);
	if (task->run == FALSE) {
		task->run = TRUE;
		mbb_task_resume(task);
	}
	g_mutex_unlock(task->mutex);

	mbb_plock_reader_unlock();
}
Exemplo n.º 3
0
gboolean mbb_session_has(gint sid)
{
	gboolean ret = FALSE;

	mbb_plock_reader_lock();

	if (ht != NULL && g_hash_table_lookup(ht, GINT_TO_POINTER(sid)) != NULL)
		ret = TRUE;

	mbb_plock_reader_unlock();

	return ret;
}