command queue; not really used yet
This commit is contained in:
parent
57a7eb7a0c
commit
1b1d5bbfa9
|
@ -0,0 +1,71 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains interface to the command queue stuff
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef CMD_H__28542C9B_7CB8_40F8_BBB6_DCE13CBB1E7F__INCLUDED
|
||||
#define CMD_H__28542C9B_7CB8_40F8_BBB6_DCE13CBB1E7F__INCLUDED
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define LADISH_COMMAND_STATE_PREPARE 0
|
||||
#define LADISH_COMMAND_STATE_PENDING 1
|
||||
#define LADISH_COMMAND_STATE_WAITING 2
|
||||
#define LADISH_COMMAND_STATE_DONE 3
|
||||
|
||||
struct ladish_command
|
||||
{
|
||||
struct list_head siblings;
|
||||
|
||||
unsigned int state;
|
||||
bool cancel;
|
||||
|
||||
void * context;
|
||||
bool (* run)(void * context);
|
||||
void (* destructor)(void * context);
|
||||
};
|
||||
|
||||
struct ladish_cqueue
|
||||
{
|
||||
bool cancel;
|
||||
struct list_head queue;
|
||||
};
|
||||
|
||||
void ladish_cqueue_init(struct ladish_cqueue * queue_ptr);
|
||||
void ladish_cqueue_run(struct ladish_cqueue * queue_ptr);
|
||||
void ladish_cqueue_cancel(struct ladish_cqueue * queue_ptr);
|
||||
bool ladish_cqueue_add_command(struct ladish_cqueue * queue_ptr, struct ladish_command * command_ptr);
|
||||
void ladish_cqueue_uninit(struct ladish_cqueue * queue_ptr);
|
||||
|
||||
void * ladish_command_new(size_t size);
|
||||
|
||||
bool ladish_command_new_studio(const char * studio_name);
|
||||
bool ladish_command_load_studio(const char * studio_name);
|
||||
bool ladish_command_rename_studio(const char * studio_name);
|
||||
bool ladish_command_save_studio(void);
|
||||
bool ladish_command_start_studio(void);
|
||||
bool ladish_command_stop_studio(void);
|
||||
bool ladish_command_unload_studio(void);
|
||||
|
||||
#endif /* #ifndef CMD_H__28542C9B_7CB8_40F8_BBB6_DCE13CBB1E7F__INCLUDED */
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "load studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_load_studio(const char * studio_name)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "new studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_new_studio(const char * studio_name)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "rename studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_rename_studio(const char * studio_name)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "save studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_save_studio(void)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "start studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_start_studio(void)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "stop studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_stop_studio(void)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains implementation of the "unload studio" command
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
bool ladish_command_unload_studio(void)
|
||||
{
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
/* -*- Mode: C ; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* LADI Session Handler (ladish)
|
||||
*
|
||||
* Copyright (C) 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
||||
*
|
||||
**************************************************************************
|
||||
* This file contains interface to the command queue
|
||||
**************************************************************************
|
||||
*
|
||||
* LADI Session Handler is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LADI Session Handler is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LADI Session Handler. If not, see <http://www.gnu.org/licenses/>
|
||||
* or write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "cmd.h"
|
||||
|
||||
void ladish_cqueue_init(struct ladish_cqueue * queue_ptr)
|
||||
{
|
||||
queue_ptr->cancel = false;
|
||||
INIT_LIST_HEAD(&queue_ptr->queue);
|
||||
}
|
||||
|
||||
void ladish_cqueue_run(struct ladish_cqueue * queue_ptr)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
struct ladish_command * cmd_ptr;
|
||||
|
||||
loop:
|
||||
if (list_empty(&queue_ptr->queue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
node_ptr = queue_ptr->queue.next;
|
||||
cmd_ptr = list_entry(node_ptr, struct ladish_command, siblings);
|
||||
|
||||
ASSERT(cmd_ptr->run != NULL);
|
||||
ASSERT(cmd_ptr->state == LADISH_COMMAND_STATE_PENDING || cmd_ptr->state == LADISH_COMMAND_STATE_WAITING);
|
||||
|
||||
if (!cmd_ptr->run(cmd_ptr->context))
|
||||
{
|
||||
ladish_cqueue_uninit(queue_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cmd_ptr->state)
|
||||
{
|
||||
case LADISH_COMMAND_STATE_DONE:
|
||||
break;
|
||||
case LADISH_COMMAND_STATE_WAITING:
|
||||
return;
|
||||
default:
|
||||
log_error("unexpected cmd state %u after run()", cmd_ptr->state);
|
||||
ASSERT_NO_PASS;
|
||||
ladish_cqueue_uninit(queue_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
list_del(node_ptr);
|
||||
|
||||
if (cmd_ptr->destructor != NULL)
|
||||
{
|
||||
cmd_ptr->destructor(cmd_ptr->context);
|
||||
}
|
||||
|
||||
free(cmd_ptr);
|
||||
|
||||
if (queue_ptr->cancel && list_empty(&queue_ptr->queue));
|
||||
{
|
||||
queue_ptr->cancel = false;
|
||||
}
|
||||
|
||||
goto loop;
|
||||
}
|
||||
|
||||
void ladish_cqueue_cancel(struct ladish_cqueue * queue_ptr)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
struct ladish_command * cmd_ptr;
|
||||
|
||||
if (list_empty(&queue_ptr->queue))
|
||||
{ /* nothing to cancel */
|
||||
return;
|
||||
}
|
||||
|
||||
node_ptr = queue_ptr->queue.prev;
|
||||
cmd_ptr = list_entry(node_ptr, struct ladish_command, siblings);
|
||||
if (cmd_ptr->state != LADISH_COMMAND_STATE_WAITING)
|
||||
{
|
||||
ladish_cqueue_uninit(queue_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* clear all commands except currently waiting one */
|
||||
while (queue_ptr->queue.next != queue_ptr->queue.prev)
|
||||
{
|
||||
node_ptr = queue_ptr->queue.prev;
|
||||
list_del(node_ptr);
|
||||
|
||||
cmd_ptr = list_entry(node_ptr, struct ladish_command, siblings);
|
||||
|
||||
if (cmd_ptr->destructor != NULL)
|
||||
{
|
||||
cmd_ptr->destructor(cmd_ptr->context);
|
||||
}
|
||||
|
||||
free(cmd_ptr);
|
||||
}
|
||||
|
||||
queue_ptr->cancel = true;
|
||||
cmd_ptr->cancel = true;
|
||||
ladish_cqueue_run(queue_ptr);
|
||||
}
|
||||
|
||||
bool ladish_cqueue_add_command(struct ladish_cqueue * queue_ptr, struct ladish_command * cmd_ptr)
|
||||
{
|
||||
ASSERT(cmd_ptr->run != NULL);
|
||||
|
||||
if (queue_ptr->cancel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
list_add_tail(&cmd_ptr->siblings, &queue_ptr->queue);
|
||||
ladish_cqueue_run(queue_ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ladish_cqueue_uninit(struct ladish_cqueue * queue_ptr)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
struct ladish_command * cmd_ptr;
|
||||
|
||||
while (!list_empty(&queue_ptr->queue))
|
||||
{
|
||||
node_ptr = queue_ptr->queue.next;
|
||||
list_del(node_ptr);
|
||||
|
||||
cmd_ptr = list_entry(node_ptr, struct ladish_command, siblings);
|
||||
|
||||
if (cmd_ptr->destructor != NULL)
|
||||
{
|
||||
cmd_ptr->destructor(cmd_ptr->context);
|
||||
}
|
||||
|
||||
free(cmd_ptr);
|
||||
}
|
||||
|
||||
queue_ptr->cancel = false;
|
||||
}
|
||||
|
||||
void * ladish_command_new(size_t size)
|
||||
{
|
||||
struct ladish_command * cmd_ptr;
|
||||
|
||||
ASSERT(size >= sizeof(struct ladish_command));
|
||||
|
||||
cmd_ptr = malloc(size);
|
||||
if (cmd_ptr == NULL)
|
||||
{
|
||||
log_error("malloc failed to allocate command with size %zu", size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmd_ptr->state = LADISH_COMMAND_STATE_PREPARE;
|
||||
cmd_ptr->cancel = false;
|
||||
|
||||
cmd_ptr->context = cmd_ptr;
|
||||
cmd_ptr->run = NULL;
|
||||
cmd_ptr->destructor = NULL;
|
||||
|
||||
return cmd_ptr;
|
||||
}
|
|
@ -439,6 +439,8 @@ bool studio_init(void)
|
|||
goto jack_graph_destroy;
|
||||
}
|
||||
|
||||
ladish_cqueue_init(&g_studio.cmd_queue);
|
||||
|
||||
if (!jack_proxy_init(
|
||||
on_jack_server_started,
|
||||
on_jack_server_stopped,
|
||||
|
@ -470,6 +472,8 @@ void studio_uninit(void)
|
|||
|
||||
studio_clear(false);
|
||||
|
||||
ladish_cqueue_uninit(&g_studio.cmd_queue);
|
||||
|
||||
free(g_studios_dir);
|
||||
|
||||
log_info("studio object destroy");
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "../jack_proxy.h"
|
||||
#include "../dbus/error.h"
|
||||
#include "jack_dispatch.h"
|
||||
#include "cmd.h"
|
||||
|
||||
#define JACK_CONF_MAX_ADDRESS_SIZE 1024
|
||||
|
||||
|
@ -59,6 +60,7 @@ struct studio
|
|||
|
||||
dbus_object_path dbus_object;
|
||||
|
||||
struct ladish_cqueue cmd_queue;
|
||||
struct list_head event_queue;
|
||||
|
||||
char * name;
|
||||
|
|
8
wscript
8
wscript
|
@ -209,6 +209,14 @@ def build(bld):
|
|||
'studio_jack_conf.c',
|
||||
'studio_load.c',
|
||||
'studio_save.c',
|
||||
'cmd_load_studio.c',
|
||||
'cmd_new_studio.c',
|
||||
'cmd_rename_studio.c',
|
||||
'cmd_save_studio.c',
|
||||
'cmd_start_studio.c',
|
||||
'cmd_stop_studio.c',
|
||||
'cmd_unload_studio.c',
|
||||
'cqueue.c',
|
||||
]:
|
||||
daemon.source.append(os.path.join("daemon", source))
|
||||
|
||||
|
|
Loading…
Reference in New Issue