jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
2.9KB

  1. /*
  2. Copyright (C) 2007 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include <stdio.h>
  16. #include <errno.h>
  17. #ifndef WIN32
  18. #include <unistd.h>
  19. #endif
  20. #include <string.h>
  21. #include <signal.h>
  22. #include <stdlib.h>
  23. #include <jack/jack.h>
  24. jack_client_t *client;
  25. static void signal_handler(int sig)
  26. {
  27. jack_client_close(client);
  28. fprintf(stderr, "signal received, exiting ...\n");
  29. exit(0);
  30. }
  31. static void
  32. port_callback (jack_port_id_t port, int yn, void* arg)
  33. {
  34. printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
  35. }
  36. static void
  37. connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
  38. {
  39. printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
  40. }
  41. static void
  42. client_callback (const char* client, int yn, void* arg)
  43. {
  44. printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
  45. }
  46. static int
  47. graph_callback (void* arg)
  48. {
  49. printf ("Graph reordered\n");
  50. return 0;
  51. }
  52. int
  53. main (int argc, char *argv[])
  54. {
  55. jack_options_t options = JackNullOption;
  56. jack_status_t status;
  57. if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
  58. fprintf (stderr, "jack_client_open() failed, "
  59. "status = 0x%2.0x\n", status);
  60. if (status & JackServerFailed) {
  61. fprintf (stderr, "Unable to connect to JACK server\n");
  62. }
  63. return 1;
  64. }
  65. if (jack_set_port_registration_callback (client, port_callback, NULL)) {
  66. fprintf (stderr, "cannot set port registration callback\n");
  67. return 1;
  68. }
  69. if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
  70. fprintf (stderr, "cannot set port connect callback\n");
  71. return 1;
  72. }
  73. if (jack_set_client_registration_callback (client, client_callback, NULL)) {
  74. fprintf (stderr, "cannot set client registration callback\n");
  75. return 1;
  76. }
  77. if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
  78. fprintf (stderr, "cannot set graph order registration callback\n");
  79. return 1;
  80. }
  81. if (jack_activate (client)) {
  82. fprintf (stderr, "cannot activate client");
  83. return 1;
  84. }
  85. #ifdef WIN32
  86. signal(SIGINT, signal_handler);
  87. signal(SIGABRT, signal_handler);
  88. signal(SIGTERM, signal_handler);
  89. #else
  90. signal(SIGQUIT, signal_handler);
  91. signal(SIGTERM, signal_handler);
  92. signal(SIGHUP, signal_handler);
  93. signal(SIGINT, signal_handler);
  94. #endif
  95. sleep (-1);
  96. exit (0);
  97. }