1 // u/* -*- Mode: C++ ; c-basic-offset: 4 -*- */
3 JACK control API implementation
5 Copyright (C) 2008 Nedko Arnaudov
6 Copyright (C) 2008 Grame
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; version 2 of the License.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 #include "driver_interface.h"
38 #include "JackError.h"
39 #include "JackServer.h"
41 #include "JackTools.h"
42 #include "JackControlAPI.h"
43 #include "JackLockedEngine.h"
44 #include "JackConstants.h"
45 #include "JackDriverLoader.h"
46 #include "JackServerGlobals.h"
56 class JackServer
* engine
;
58 /* string, server name */
59 union jackctl_parameter_value name
;
60 union jackctl_parameter_value default_name
;
62 /* bool, whether to be "realtime" */
63 union jackctl_parameter_value realtime
;
64 union jackctl_parameter_value default_realtime
;
67 union jackctl_parameter_value realtime_priority
;
68 union jackctl_parameter_value default_realtime_priority
;
70 /* bool, whether to exit once all clients have closed their connections */
71 union jackctl_parameter_value temporary
;
72 union jackctl_parameter_value default_temporary
;
74 /* bool, whether to be verbose */
75 union jackctl_parameter_value verbose
;
76 union jackctl_parameter_value default_verbose
;
78 /* int32_t, msecs; if zero, use period size. */
79 union jackctl_parameter_value client_timeout
;
80 union jackctl_parameter_value default_client_timeout
;
82 /* uint32_t, clock source type */
83 union jackctl_parameter_value clock_source
;
84 union jackctl_parameter_value default_clock_source
;
86 /* uint32_t, max port number */
87 union jackctl_parameter_value port_max
;
88 union jackctl_parameter_value default_port_max
;
91 union jackctl_parameter_value replace_registry
;
92 union jackctl_parameter_value default_replace_registry
;
94 /* bool, synchronous or asynchronous engine mode */
95 union jackctl_parameter_value sync
;
96 union jackctl_parameter_value default_sync
;
101 jack_driver_desc_t
* desc_ptr
;
106 struct jackctl_internal
108 jack_driver_desc_t
* desc_ptr
;
113 struct jackctl_parameter
116 const char * short_description
;
117 const char * long_description
;
118 jackctl_param_type_t type
;
120 union jackctl_parameter_value
* value_ptr
;
121 union jackctl_parameter_value
* default_value_ptr
;
123 union jackctl_parameter_value value
;
124 union jackctl_parameter_value default_value
;
125 struct jackctl_driver
* driver_ptr
;
127 jack_driver_param_constraint_desc_t
* constraint_ptr
;
131 struct jackctl_parameter
*
132 jackctl_add_parameter(
133 JSList
** parameters_list_ptr_ptr
,
135 const char * short_description
,
136 const char * long_description
,
137 jackctl_param_type_t type
,
138 union jackctl_parameter_value
* value_ptr
,
139 union jackctl_parameter_value
* default_value_ptr
,
140 union jackctl_parameter_value value
,
141 jack_driver_param_constraint_desc_t
* constraint_ptr
= NULL
)
143 struct jackctl_parameter
* parameter_ptr
;
145 parameter_ptr
= (struct jackctl_parameter
*)malloc(sizeof(struct jackctl_parameter
));
146 if (parameter_ptr
== NULL
)
148 jack_error("Cannot allocate memory for jackctl_parameter structure.");
152 parameter_ptr
->name
= name
;
153 parameter_ptr
->short_description
= short_description
;
154 parameter_ptr
->long_description
= long_description
;
155 parameter_ptr
->type
= type
;
156 parameter_ptr
->is_set
= false;
158 if (value_ptr
== NULL
)
160 value_ptr
= ¶meter_ptr
->value
;
163 if (default_value_ptr
== NULL
)
165 default_value_ptr
= ¶meter_ptr
->default_value
;
168 parameter_ptr
->value_ptr
= value_ptr
;
169 parameter_ptr
->default_value_ptr
= default_value_ptr
;
171 *value_ptr
= *default_value_ptr
= value
;
173 parameter_ptr
->driver_ptr
= NULL
;
174 parameter_ptr
->id
= 0;
175 parameter_ptr
->constraint_ptr
= constraint_ptr
;
177 *parameters_list_ptr_ptr
= jack_slist_append(*parameters_list_ptr_ptr
, parameter_ptr
);
179 return parameter_ptr
;
187 jackctl_free_driver_parameters(
188 struct jackctl_driver
* driver_ptr
)
190 JSList
* next_node_ptr
;
192 while (driver_ptr
->parameters
)
194 next_node_ptr
= driver_ptr
->parameters
->next
;
195 free(driver_ptr
->parameters
->data
);
196 free(driver_ptr
->parameters
);
197 driver_ptr
->parameters
= next_node_ptr
;
203 jackctl_add_driver_parameters(
204 struct jackctl_driver
* driver_ptr
)
208 union jackctl_parameter_value jackctl_value
;
209 jackctl_param_type_t jackctl_type
;
210 struct jackctl_parameter
* parameter_ptr
;
211 jack_driver_param_desc_t
* descriptor_ptr
;
213 for (i
= 0 ; i
< driver_ptr
->desc_ptr
->nparams
; i
++)
215 descriptor_ptr
= driver_ptr
->desc_ptr
->params
+ i
;
217 switch (descriptor_ptr
->type
)
219 case JackDriverParamInt
:
220 jackctl_type
= JackParamInt
;
221 jackctl_value
.i
= descriptor_ptr
->value
.i
;
223 case JackDriverParamUInt
:
224 jackctl_type
= JackParamUInt
;
225 jackctl_value
.ui
= descriptor_ptr
->value
.ui
;
227 case JackDriverParamChar
:
228 jackctl_type
= JackParamChar
;
229 jackctl_value
.c
= descriptor_ptr
->value
.c
;
231 case JackDriverParamString
:
232 jackctl_type
= JackParamString
;
233 strcpy(jackctl_value
.str
, descriptor_ptr
->value
.str
);
235 case JackDriverParamBool
:
236 jackctl_type
= JackParamBool
;
237 jackctl_value
.b
= descriptor_ptr
->value
.i
;
240 jack_error("Unknown driver parameter type %i", (int)descriptor_ptr
->type
);
245 parameter_ptr
= jackctl_add_parameter(
246 &driver_ptr
->parameters
,
247 descriptor_ptr
->name
,
248 descriptor_ptr
->short_desc
,
249 descriptor_ptr
->long_desc
,
254 descriptor_ptr
->constraint
);
256 if (parameter_ptr
== NULL
)
261 parameter_ptr
->driver_ptr
= driver_ptr
;
262 parameter_ptr
->id
= descriptor_ptr
->character
;
268 jackctl_free_driver_parameters(driver_ptr
);
273 /* destroy jack_driver_param_desc_t list created by jackctl_create_param_list() */
275 jackctl_destroy_param_list(
289 /* for drivers and internals are configured through jack_driver_param_t JSList */
290 /* this function creates such list from a jackctl_parameter list */
293 jackctl_create_param_list(
294 const JSList
* paramlist
,
295 JSList
** retparamlist
)
297 jackctl_parameter
* param_ptr
;
298 jack_driver_param_t
* retparam_ptr
;
300 *retparamlist
= NULL
;
301 while (paramlist
!= NULL
)
303 param_ptr
= (jackctl_parameter
*)paramlist
->data
;
304 if (param_ptr
->is_set
)
306 /* jack_info("setting driver parameter %p ...", parameter_ptr); */
307 retparam_ptr
= (jack_driver_param_t
*)malloc(sizeof(jack_driver_param_t
));
308 if (retparam_ptr
== NULL
)
310 jack_error ("Allocation of jack_driver_param_t structure failed");
314 retparam_ptr
->character
= param_ptr
->id
;
316 switch (param_ptr
->type
)
319 retparam_ptr
->value
.i
= param_ptr
->value_ptr
->i
;
322 retparam_ptr
->value
.ui
= param_ptr
->value_ptr
->ui
;
325 retparam_ptr
->value
.c
= param_ptr
->value_ptr
->c
;
327 case JackParamString
:
328 strcpy(retparam_ptr
->value
.str
, param_ptr
->value_ptr
->str
);
331 retparam_ptr
->value
.i
= param_ptr
->value_ptr
->b
;
334 jack_error("Unknown parameter type %i", (int)param_ptr
->type
);
339 *retparamlist
= jack_slist_append(*retparamlist
, retparam_ptr
);
342 paramlist
= paramlist
->next
;
350 jackctl_destroy_param_list(*retparamlist
);
355 jackctl_drivers_load(
356 struct jackctl_server
* server_ptr
)
358 struct jackctl_driver
* driver_ptr
;
360 JSList
*descriptor_node_ptr
;
362 descriptor_node_ptr
= jack_drivers_load(NULL
);
363 if (descriptor_node_ptr
== NULL
)
365 jack_error("Could not find any drivers in driver directory!");
369 while (descriptor_node_ptr
!= NULL
)
371 driver_ptr
= (struct jackctl_driver
*)malloc(sizeof(struct jackctl_driver
));
372 if (driver_ptr
== NULL
)
374 jack_error("Memory allocation of jackctl_driver structure failed.");
378 driver_ptr
->desc_ptr
= (jack_driver_desc_t
*)descriptor_node_ptr
->data
;
379 driver_ptr
->parameters
= NULL
;
380 driver_ptr
->infos
= NULL
;
382 if (!jackctl_add_driver_parameters(driver_ptr
))
384 assert(driver_ptr
->parameters
== NULL
);
389 server_ptr
->drivers
= jack_slist_append(server_ptr
->drivers
, driver_ptr
);
392 node_ptr
= descriptor_node_ptr
;
393 descriptor_node_ptr
= descriptor_node_ptr
->next
;
402 jackctl_server_free_drivers(
403 struct jackctl_server
* server_ptr
)
405 JSList
* next_node_ptr
;
406 struct jackctl_driver
* driver_ptr
;
408 while (server_ptr
->drivers
)
410 next_node_ptr
= server_ptr
->drivers
->next
;
411 driver_ptr
= (struct jackctl_driver
*)server_ptr
->drivers
->data
;
413 jackctl_free_driver_parameters(driver_ptr
);
414 free(driver_ptr
->desc_ptr
->params
);
415 free(driver_ptr
->desc_ptr
);
418 free(server_ptr
->drivers
);
419 server_ptr
->drivers
= next_node_ptr
;
424 jackctl_internals_load(
425 struct jackctl_server
* server_ptr
)
427 struct jackctl_internal
* internal_ptr
;
429 JSList
*descriptor_node_ptr
;
431 descriptor_node_ptr
= jack_internals_load(NULL
);
432 if (descriptor_node_ptr
== NULL
)
434 jack_error("Could not find any internals in driver directory!");
438 while (descriptor_node_ptr
!= NULL
)
440 internal_ptr
= (struct jackctl_internal
*)malloc(sizeof(struct jackctl_internal
));
441 if (internal_ptr
== NULL
)
443 jack_error("Memory allocation of jackctl_driver structure failed.");
447 internal_ptr
->desc_ptr
= (jack_driver_desc_t
*)descriptor_node_ptr
->data
;
448 internal_ptr
->parameters
= NULL
;
449 internal_ptr
->refnum
= -1;
451 if (!jackctl_add_driver_parameters((struct jackctl_driver
*)internal_ptr
))
453 assert(internal_ptr
->parameters
== NULL
);
458 server_ptr
->internals
= jack_slist_append(server_ptr
->internals
, internal_ptr
);
461 node_ptr
= descriptor_node_ptr
;
462 descriptor_node_ptr
= descriptor_node_ptr
->next
;
471 jackctl_server_free_internals(
472 struct jackctl_server
* server_ptr
)
474 JSList
* next_node_ptr
;
475 struct jackctl_internal
* internal_ptr
;
477 while (server_ptr
->internals
)
479 next_node_ptr
= server_ptr
->internals
->next
;
480 internal_ptr
= (struct jackctl_internal
*)server_ptr
->internals
->data
;
482 jackctl_free_driver_parameters((struct jackctl_driver
*)internal_ptr
);
483 free(internal_ptr
->desc_ptr
->params
);
484 free(internal_ptr
->desc_ptr
);
487 free(server_ptr
->internals
);
488 server_ptr
->internals
= next_node_ptr
;
494 jackctl_server_free_parameters(
495 struct jackctl_server
* server_ptr
)
497 JSList
* next_node_ptr
;
499 while (server_ptr
->parameters
)
501 next_node_ptr
= server_ptr
->parameters
->next
;
502 free(server_ptr
->parameters
->data
);
503 free(server_ptr
->parameters
);
504 server_ptr
->parameters
= next_node_ptr
;
510 struct jackctl_sigmask
515 static jackctl_sigmask sigmask
;
517 static void signal_handler(int signum
)
519 printf("Jack main caught signal %d\n", signum
);
520 (void) signal(SIGINT
, SIG_DFL
);
521 SetEvent(sigmask
.wait_event
);
525 jackctl_setup_signals(
528 if ((sigmask
.wait_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
)) == NULL
) {
529 jack_error("CreateEvent fails err = %ld", GetLastError());
533 (void) signal(SIGINT
, signal_handler
);
534 (void) signal(SIGABRT
, signal_handler
);
535 (void) signal(SIGTERM
, signal_handler
);
540 void jackctl_wait_signals(jackctl_sigmask_t
* signals
)
542 if (WaitForSingleObject(signals
->wait_event
, INFINITE
) != WAIT_OBJECT_0
) {
543 jack_error("WaitForSingleObject fails err = %ld", GetLastError());
549 struct jackctl_sigmask
554 static jackctl_sigmask sigmask
;
558 signal_handler(int sig
)
560 /* this is used by the child (active) process, but it never
561 gets called unless we are already shutting down after
565 snprintf(buf
, sizeof(buf
), "Received signal %d during shutdown (ignored)\n", sig
);
568 SERVER_EXPORT jackctl_sigmask_t
*
569 jackctl_setup_signals(
573 struct sigaction action
;
576 /* ensure that we are in our own process group so that
577 kill (SIG, -pgrp) does the right thing.
582 pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS
, NULL
);
586 POSIX says that signals are delivered like this:
588 * if a thread has blocked that signal, it is not
589 a candidate to receive the signal.
590 * of all threads not blocking the signal, pick
591 one at random, and deliver the signal.
593 this means that a simple-minded multi-threaded program can
594 expect to get POSIX signals delivered randomly to any one
597 here, we block all signals that we think we might receive
598 and want to catch. all "child" threads will inherit this
599 setting. if we create a thread that calls sigwait() on the
600 same set of signals, implicitly unblocking all those
601 signals. any of those signals that are delivered to the
602 process will be delivered to that thread, and that thread
603 alone. this makes cleanup for a signal-driven exit much
604 easier, since we know which thread is doing it and more
605 importantly, we are free to call async-unsafe functions,
606 because the code is executing in normal thread context
607 after a return from sigwait().
610 sigemptyset(&sigmask
.signals
);
611 sigaddset(&sigmask
.signals
, SIGHUP
);
612 sigaddset(&sigmask
.signals
, SIGINT
);
613 sigaddset(&sigmask
.signals
, SIGQUIT
);
614 sigaddset(&sigmask
.signals
, SIGPIPE
);
615 sigaddset(&sigmask
.signals
, SIGTERM
);
616 sigaddset(&sigmask
.signals
, SIGUSR1
);
617 sigaddset(&sigmask
.signals
, SIGUSR2
);
619 /* all child threads will inherit this mask unless they
620 * explicitly reset it
623 pthread_sigmask(SIG_BLOCK
, &sigmask
.signals
, 0);
625 /* install a do-nothing handler because otherwise pthreads
626 behaviour is undefined when we enter sigwait.
629 sigfillset(&allsignals
);
630 action
.sa_handler
= signal_handler
;
631 action
.sa_mask
= allsignals
;
632 action
.sa_flags
= SA_RESTART
|SA_RESETHAND
;
634 for (i
= 1; i
< NSIG
; i
++)
636 if (sigismember (&sigmask
.signals
, i
))
638 sigaction(i
, &action
, 0);
646 jackctl_wait_signals(jackctl_sigmask_t
* sigmask
)
652 #if defined(sun) && !defined(__sun__) // SUN compiler only, to check
653 sigwait(&sigmask
->signals
);
655 sigwait(&sigmask
->signals
, &sig
);
657 fprintf(stderr
, "Jack main caught signal %d\n", sig
);
661 //jack_dump_configuration(engine, 1);
675 if (sig
!= SIGSEGV
) {
676 // unblock signals so we can see them during shutdown.
677 // this will help prod developers not to lose sight of
678 // bugs that cause segfaults etc. during shutdown.
679 sigprocmask(SIG_UNBLOCK
, &sigmask
->signals
, 0);
685 jack_driver_param_constraint_desc_t
*
686 get_realtime_priority_constraint()
688 jack_driver_param_constraint_desc_t
* constraint_ptr
;
691 if (!jack_get_thread_realtime_priority_range(&min
, &max
))
696 //jack_info("realtime priority range is (%d,%d)", min, max);
698 constraint_ptr
= (jack_driver_param_constraint_desc_t
*)calloc(1, sizeof(jack_driver_param_value_enum_t
));
699 if (constraint_ptr
== NULL
)
701 jack_error("Cannot allocate memory for jack_driver_param_constraint_desc_t structure.");
704 constraint_ptr
->flags
= JACK_CONSTRAINT_FLAG_RANGE
;
706 constraint_ptr
->constraint
.range
.min
.i
= min
;
707 constraint_ptr
->constraint
.range
.max
.i
= max
;
709 return constraint_ptr
;
712 SERVER_EXPORT jackctl_server_t
* jackctl_server_create(
713 bool (* on_device_acquire
)(const char * device_name
),
714 void (* on_device_release
)(const char * device_name
))
716 struct jackctl_server
* server_ptr
;
717 union jackctl_parameter_value value
;
719 server_ptr
= (struct jackctl_server
*)malloc(sizeof(struct jackctl_server
));
720 if (server_ptr
== NULL
)
722 jack_error("Cannot allocate memory for jackctl_server structure.");
726 server_ptr
->drivers
= NULL
;
727 server_ptr
->internals
= NULL
;
728 server_ptr
->parameters
= NULL
;
729 server_ptr
->engine
= NULL
;
731 strcpy(value
.str
, JACK_DEFAULT_SERVER_NAME
);
732 if (jackctl_add_parameter(
733 &server_ptr
->parameters
,
735 "Server name to use.",
739 &server_ptr
->default_name
,
742 goto fail_free_parameters
;
746 if (jackctl_add_parameter(
747 &server_ptr
->parameters
,
749 "Whether to use realtime mode.",
750 "Use realtime scheduling. This is needed for reliable low-latency performance. On most systems, it requires JACK to run with special scheduler and memory allocation privileges, which may be obtained in several ways. On Linux you should use PAM.",
752 &server_ptr
->realtime
,
753 &server_ptr
->default_realtime
,
756 goto fail_free_parameters
;
760 if (jackctl_add_parameter(
761 &server_ptr
->parameters
,
763 "Scheduler priority when running in realtime mode.",
766 &server_ptr
->realtime_priority
,
767 &server_ptr
->default_realtime_priority
,
769 get_realtime_priority_constraint()) == NULL
)
771 goto fail_free_parameters
;
775 if (jackctl_add_parameter(
776 &server_ptr
->parameters
,
778 "Exit once all clients have closed their connections.",
781 &server_ptr
->temporary
,
782 &server_ptr
->default_temporary
,
785 goto fail_free_parameters
;
789 if (jackctl_add_parameter(
790 &server_ptr
->parameters
,
795 &server_ptr
->verbose
,
796 &server_ptr
->default_verbose
,
799 goto fail_free_parameters
;
803 if (jackctl_add_parameter(
804 &server_ptr
->parameters
,
806 "Client timeout limit in milliseconds.",
809 &server_ptr
->client_timeout
,
810 &server_ptr
->default_client_timeout
,
813 goto fail_free_parameters
;
817 if (jackctl_add_parameter(
818 &server_ptr
->parameters
,
820 "Clocksource type : c(ycle) | h(pet) | s(ystem).",
823 &server_ptr
->clock_source
,
824 &server_ptr
->default_clock_source
,
827 goto fail_free_parameters
;
831 if (jackctl_add_parameter(
832 &server_ptr
->parameters
,
834 "Maximum number of ports.",
837 &server_ptr
->port_max
,
838 &server_ptr
->default_port_max
,
841 goto fail_free_parameters
;
845 if (jackctl_add_parameter(
846 &server_ptr
->parameters
,
848 "Replace shared memory registry.",
851 &server_ptr
->replace_registry
,
852 &server_ptr
->default_replace_registry
,
855 goto fail_free_parameters
;
859 if (jackctl_add_parameter(
860 &server_ptr
->parameters
,
862 "Use server synchronous mode.",
866 &server_ptr
->default_sync
,
869 goto fail_free_parameters
;
872 JackServerGlobals::on_device_acquire
= on_device_acquire
;
873 JackServerGlobals::on_device_release
= on_device_release
;
875 if (!jackctl_drivers_load(server_ptr
))
877 goto fail_free_parameters
;
880 /* Allowed to fail */
881 jackctl_internals_load(server_ptr
);
885 fail_free_parameters
:
886 jackctl_server_free_parameters(server_ptr
);
894 SERVER_EXPORT
void jackctl_server_destroy(jackctl_server
*server_ptr
)
897 jackctl_server_free_drivers(server_ptr
);
898 jackctl_server_free_internals(server_ptr
);
899 jackctl_server_free_parameters(server_ptr
);
904 SERVER_EXPORT
const JSList
* jackctl_server_get_drivers_list(jackctl_server
*server_ptr
)
906 return (server_ptr
) ? server_ptr
->drivers
: NULL
;
909 SERVER_EXPORT
bool jackctl_server_stop(jackctl_server
*server_ptr
)
912 server_ptr
->engine
->Stop();
919 SERVER_EXPORT
bool jackctl_server_close(jackctl_server
*server_ptr
)
922 server_ptr
->engine
->Close();
923 delete server_ptr
->engine
;
925 /* clean up shared memory and files from this server instance */
926 jack_log("Cleaning up shared memory");
930 jack_log("Cleaning up files");
932 JackTools::CleanupFiles(server_ptr
->name
.str
);
934 jack_log("Unregistering server `%s'", server_ptr
->name
.str
);
936 jack_unregister_server(server_ptr
->name
.str
);
938 server_ptr
->engine
= NULL
;
946 SERVER_EXPORT
const JSList
* jackctl_server_get_parameters(jackctl_server
*server_ptr
)
948 return (server_ptr
) ? server_ptr
->parameters
: NULL
;
953 jackctl_server
*server_ptr
,
954 jackctl_driver
*driver_ptr
)
956 JSList
* paramlist
= NULL
;
960 if (!server_ptr
|| !driver_ptr
) {
964 int rc
= jack_register_server(server_ptr
->name
.str
, server_ptr
->replace_registry
.b
);
968 jack_error("`%s' server already active", server_ptr
->name
.str
);
971 jack_error("Too many servers already active");
974 jack_error("No access to shm registry");
978 jack_log("Server `%s' registered", server_ptr
->name
.str
);
980 /* clean up shared memory and files from any previous
981 * instance of this server name */
983 JackTools::CleanupFiles(server_ptr
->name
.str
);
985 if (!server_ptr
->realtime
.b
&& server_ptr
->client_timeout
.i
== 0) {
986 server_ptr
->client_timeout
.i
= 500; /* 0.5 sec; usable when non realtime. */
989 /* check port max value before allocating server */
990 if (server_ptr
->port_max
.ui
> PORT_NUM_MAX
) {
991 jack_error("Jack server started with too much ports %d (when port max can be %d)", server_ptr
->port_max
.ui
, PORT_NUM_MAX
);
995 /* get the engine/driver started */
996 server_ptr
->engine
= new JackServer(
998 server_ptr
->temporary
.b
,
999 server_ptr
->client_timeout
.i
,
1000 server_ptr
->realtime
.b
,
1001 server_ptr
->realtime_priority
.i
,
1002 server_ptr
->port_max
.ui
,
1003 server_ptr
->verbose
.b
,
1004 (jack_timer_type_t
)server_ptr
->clock_source
.ui
,
1005 server_ptr
->name
.str
);
1006 if (server_ptr
->engine
== NULL
)
1008 jack_error("Failed to create new JackServer object");
1009 goto fail_unregister
;
1012 if (!jackctl_create_param_list(driver_ptr
->parameters
, ¶mlist
)) goto fail_delete
;
1013 rc
= server_ptr
->engine
->Open(driver_ptr
->desc_ptr
, paramlist
);
1014 jackctl_destroy_param_list(paramlist
);
1017 jack_error("JackServer::Open failed with %d", rc
);
1023 } catch (std::exception e
) {
1024 jack_error("jackctl_server_open error...");
1025 jackctl_destroy_param_list(paramlist
);
1029 delete server_ptr
->engine
;
1030 server_ptr
->engine
= NULL
;
1033 jack_log("Cleaning up shared memory");
1037 jack_log("Cleaning up files");
1039 JackTools::CleanupFiles(server_ptr
->name
.str
);
1041 jack_log("Unregistering server `%s'", server_ptr
->name
.str
);
1043 jack_unregister_server(server_ptr
->name
.str
);
1050 jackctl_server_start(
1051 jackctl_server
*server_ptr
)
1056 int rc
= server_ptr
->engine
->Start();
1057 bool result
= rc
>= 0;
1060 jack_error("JackServer::Start() failed with %d", rc
);
1066 SERVER_EXPORT
const char * jackctl_driver_get_name(jackctl_driver
*driver_ptr
)
1068 return (driver_ptr
) ? driver_ptr
->desc_ptr
->name
: NULL
;
1071 SERVER_EXPORT jackctl_driver_type_t
jackctl_driver_get_type(jackctl_driver
*driver_ptr
)
1073 return (driver_ptr
) ? (jackctl_driver_type_t
)driver_ptr
->desc_ptr
->type
: (jackctl_driver_type_t
)0;
1076 SERVER_EXPORT
const JSList
* jackctl_driver_get_parameters(jackctl_driver
*driver_ptr
)
1078 return (driver_ptr
) ? driver_ptr
->parameters
: NULL
;
1081 SERVER_EXPORT jack_driver_desc_t
* jackctl_driver_get_desc(jackctl_driver
*driver_ptr
)
1083 return (driver_ptr
) ? driver_ptr
->desc_ptr
: NULL
;
1086 SERVER_EXPORT
const char * jackctl_parameter_get_name(jackctl_parameter
*parameter_ptr
)
1088 return (parameter_ptr
) ? parameter_ptr
->name
: NULL
;
1091 SERVER_EXPORT
const char * jackctl_parameter_get_short_description(jackctl_parameter
*parameter_ptr
)
1093 return (parameter_ptr
) ? parameter_ptr
->short_description
: NULL
;
1096 SERVER_EXPORT
const char * jackctl_parameter_get_long_description(jackctl_parameter
*parameter_ptr
)
1098 return (parameter_ptr
) ? parameter_ptr
->long_description
: NULL
;
1101 SERVER_EXPORT
bool jackctl_parameter_has_range_constraint(jackctl_parameter
*parameter_ptr
)
1103 return (parameter_ptr
) ? (parameter_ptr
->constraint_ptr
!= NULL
&& (parameter_ptr
->constraint_ptr
->flags
& JACK_CONSTRAINT_FLAG_RANGE
) != 0) : false;
1106 SERVER_EXPORT
bool jackctl_parameter_has_enum_constraint(jackctl_parameter
*parameter_ptr
)
1108 return (parameter_ptr
) ? (parameter_ptr
->constraint_ptr
!= NULL
&& (parameter_ptr
->constraint_ptr
->flags
& JACK_CONSTRAINT_FLAG_RANGE
) == 0): false;
1111 SERVER_EXPORT
uint32_t jackctl_parameter_get_enum_constraints_count(jackctl_parameter
*parameter_ptr
)
1113 if (!parameter_ptr
) {
1117 if (!jackctl_parameter_has_enum_constraint(parameter_ptr
))
1122 return parameter_ptr
->constraint_ptr
->constraint
.enumeration
.count
;
1125 SERVER_EXPORT
union jackctl_parameter_value
jackctl_parameter_get_enum_constraint_value(jackctl_parameter
*parameter_ptr
, uint32_t index
)
1127 jack_driver_param_value_t
* value_ptr
;
1128 union jackctl_parameter_value jackctl_value
;
1130 if (!parameter_ptr
) {
1131 memset(&jackctl_value
, 0, sizeof(jackctl_value
));
1132 return jackctl_value
;
1135 value_ptr
= ¶meter_ptr
->constraint_ptr
->constraint
.enumeration
.possible_values_array
[index
].value
;
1137 switch (parameter_ptr
->type
)
1140 jackctl_value
.i
= value_ptr
->i
;
1143 jackctl_value
.ui
= value_ptr
->ui
;
1146 jackctl_value
.c
= value_ptr
->c
;
1148 case JackParamString
:
1149 strcpy(jackctl_value
.str
, value_ptr
->str
);
1152 jack_error("Bad driver parameter type %i (enum constraint)", (int)parameter_ptr
->type
);
1156 return jackctl_value
;
1159 SERVER_EXPORT
const char * jackctl_parameter_get_enum_constraint_description(jackctl_parameter
*parameter_ptr
, uint32_t index
)
1161 return (parameter_ptr
) ? parameter_ptr
->constraint_ptr
->constraint
.enumeration
.possible_values_array
[index
].short_desc
: NULL
;
1164 SERVER_EXPORT
void jackctl_parameter_get_range_constraint(jackctl_parameter
*parameter_ptr
, union jackctl_parameter_value
* min_ptr
, union jackctl_parameter_value
* max_ptr
)
1166 if (!parameter_ptr
|| !min_ptr
|| !max_ptr
) {
1170 switch (parameter_ptr
->type
)
1173 min_ptr
->i
= parameter_ptr
->constraint_ptr
->constraint
.range
.min
.i
;
1174 max_ptr
->i
= parameter_ptr
->constraint_ptr
->constraint
.range
.max
.i
;
1177 min_ptr
->ui
= parameter_ptr
->constraint_ptr
->constraint
.range
.min
.ui
;
1178 max_ptr
->ui
= parameter_ptr
->constraint_ptr
->constraint
.range
.max
.ui
;
1181 jack_error("Bad driver parameter type %i (range constraint)", (int)parameter_ptr
->type
);
1186 SERVER_EXPORT
bool jackctl_parameter_constraint_is_strict(jackctl_parameter_t
* parameter_ptr
)
1188 return (parameter_ptr
) ? (parameter_ptr
->constraint_ptr
!= NULL
&& (parameter_ptr
->constraint_ptr
->flags
& JACK_CONSTRAINT_FLAG_STRICT
) != 0) : false;
1191 SERVER_EXPORT
bool jackctl_parameter_constraint_is_fake_value(jackctl_parameter_t
* parameter_ptr
)
1193 return (parameter_ptr
) ? (parameter_ptr
->constraint_ptr
!= NULL
&& (parameter_ptr
->constraint_ptr
->flags
& JACK_CONSTRAINT_FLAG_FAKE_VALUE
) != 0) : false;
1196 SERVER_EXPORT jackctl_param_type_t
jackctl_parameter_get_type(jackctl_parameter
*parameter_ptr
)
1198 return (parameter_ptr
) ? parameter_ptr
->type
: (jackctl_param_type_t
)0;
1201 SERVER_EXPORT
char jackctl_parameter_get_id(jackctl_parameter_t
* parameter_ptr
)
1203 return (parameter_ptr
) ? parameter_ptr
->id
: 0;
1206 SERVER_EXPORT
bool jackctl_parameter_is_set(jackctl_parameter
*parameter_ptr
)
1208 return (parameter_ptr
) ? parameter_ptr
->is_set
: false;
1211 SERVER_EXPORT
union jackctl_parameter_value
jackctl_parameter_get_value(jackctl_parameter
*parameter_ptr
)
1213 if (parameter_ptr
) {
1214 return *parameter_ptr
->value_ptr
;
1216 union jackctl_parameter_value jackctl_value
;
1217 memset(&jackctl_value
, 0, sizeof(jackctl_value
));
1218 return jackctl_value
;
1222 SERVER_EXPORT
bool jackctl_parameter_reset(jackctl_parameter
*parameter_ptr
)
1224 if (!parameter_ptr
) {
1228 if (!parameter_ptr
->is_set
)
1233 parameter_ptr
->is_set
= false;
1235 *parameter_ptr
->value_ptr
= *parameter_ptr
->default_value_ptr
;
1240 SERVER_EXPORT
bool jackctl_parameter_set_value(jackctl_parameter
*parameter_ptr
, const union jackctl_parameter_value
* value_ptr
)
1242 if (!parameter_ptr
|| !value_ptr
) {
1246 parameter_ptr
->is_set
= true;
1247 *parameter_ptr
->value_ptr
= *value_ptr
;
1252 SERVER_EXPORT
union jackctl_parameter_value
jackctl_parameter_get_default_value(jackctl_parameter
*parameter_ptr
)
1254 if (parameter_ptr
) {
1255 return *parameter_ptr
->default_value_ptr
;
1257 union jackctl_parameter_value jackctl_value
;
1258 memset(&jackctl_value
, 0, sizeof(jackctl_value
));
1259 return jackctl_value
;
1263 // Internals clients
1265 SERVER_EXPORT
const JSList
* jackctl_server_get_internals_list(jackctl_server
*server_ptr
)
1267 return (server_ptr
) ? server_ptr
->internals
: NULL
;
1270 SERVER_EXPORT
const char * jackctl_internal_get_name(jackctl_internal
*internal_ptr
)
1272 return (internal_ptr
) ? internal_ptr
->desc_ptr
->name
: NULL
;
1275 SERVER_EXPORT
const JSList
* jackctl_internal_get_parameters(jackctl_internal
*internal_ptr
)
1277 return (internal_ptr
) ? internal_ptr
->parameters
: NULL
;
1280 SERVER_EXPORT
bool jackctl_server_load_internal(
1281 jackctl_server
* server_ptr
,
1282 jackctl_internal
* internal
)
1284 if (!server_ptr
|| !internal
) {
1289 if (server_ptr
->engine
!= NULL
) {
1291 if (!jackctl_create_param_list(internal
->parameters
, ¶mlist
)) return false;
1292 server_ptr
->engine
->InternalClientLoad2(internal
->desc_ptr
->name
, internal
->desc_ptr
->name
, paramlist
, JackNullOption
, &internal
->refnum
, -1, &status
);
1293 jackctl_destroy_param_list(paramlist
);
1294 return (internal
->refnum
> 0);
1300 SERVER_EXPORT
bool jackctl_server_unload_internal(
1301 jackctl_server
* server_ptr
,
1302 jackctl_internal
* internal
)
1304 if (!server_ptr
|| !internal
) {
1309 if (server_ptr
->engine
!= NULL
&& internal
->refnum
> 0) {
1310 // Client object is internally kept in JackEngine, and will be deallocated in InternalClientUnload
1311 return ((server_ptr
->engine
->GetEngine()->InternalClientUnload(internal
->refnum
, &status
)) == 0);
1317 SERVER_EXPORT
bool jackctl_server_add_slave(jackctl_server
* server_ptr
, jackctl_driver
* driver_ptr
)
1319 if (server_ptr
&& server_ptr
->engine
) {
1320 if (server_ptr
->engine
->IsRunning()) {
1321 jack_error("Cannot add a slave in a running server");
1325 if (!jackctl_create_param_list(driver_ptr
->parameters
, ¶mlist
)) return false;
1326 JackDriverInfo
* info
= server_ptr
->engine
->AddSlave(driver_ptr
->desc_ptr
, paramlist
);
1327 jackctl_destroy_param_list(paramlist
);
1329 driver_ptr
->infos
= jack_slist_append(driver_ptr
->infos
, info
);
1340 SERVER_EXPORT
bool jackctl_server_remove_slave(jackctl_server
* server_ptr
, jackctl_driver
* driver_ptr
)
1342 if (server_ptr
&& server_ptr
->engine
) {
1343 if (server_ptr
->engine
->IsRunning()) {
1344 jack_error("Cannot remove a slave from a running server");
1347 if (driver_ptr
->infos
) {
1348 JackDriverInfo
* info
= (JackDriverInfo
*)driver_ptr
->infos
->data
;
1350 driver_ptr
->infos
= jack_slist_remove(driver_ptr
->infos
, info
);
1351 server_ptr
->engine
->RemoveSlave(info
);
1363 SERVER_EXPORT
bool jackctl_server_switch_master(jackctl_server
* server_ptr
, jackctl_driver
* driver_ptr
)
1365 if (server_ptr
&& server_ptr
->engine
) {
1367 if (!jackctl_create_param_list(driver_ptr
->parameters
, ¶mlist
)) return false;
1368 bool ret
= (server_ptr
->engine
->SwitchMaster(driver_ptr
->desc_ptr
, paramlist
) == 0);
1369 jackctl_destroy_param_list(paramlist
);