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.

165 lines
4.3KB

  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. #include <jack/metadata.h>
  25. #include <jack/uuid.h>
  26. jack_client_t *client;
  27. static void signal_handler(int sig)
  28. {
  29. jack_client_close(client);
  30. fprintf(stderr, "signal received, exiting ...\n");
  31. exit(0);
  32. }
  33. static void
  34. port_rename_callback (jack_port_id_t port, const char* old_name, const char* new_name, void* arg)
  35. {
  36. printf ("Port %d renamed from %s to %s\n", port, old_name, new_name);
  37. }
  38. static void
  39. port_callback (jack_port_id_t port, int yn, void* arg)
  40. {
  41. printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
  42. }
  43. static void
  44. connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
  45. {
  46. printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
  47. }
  48. static void
  49. client_callback (const char* client, int yn, void* arg)
  50. {
  51. printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
  52. }
  53. static int
  54. graph_callback (void* arg)
  55. {
  56. printf ("Graph reordered\n");
  57. return 0;
  58. }
  59. static void
  60. propchange (jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg)
  61. {
  62. char buf[JACK_UUID_STRING_SIZE];
  63. const char* action = "";
  64. switch (change) {
  65. case PropertyCreated:
  66. action = "created";
  67. break;
  68. case PropertyChanged:
  69. action = "changed";
  70. break;
  71. case PropertyDeleted:
  72. action = "deleted";
  73. break;
  74. }
  75. if (jack_uuid_empty (subject)) {
  76. printf ("All properties changed!\n");
  77. } else {
  78. jack_uuid_unparse (subject, buf);
  79. if (key) {
  80. printf ("key [%s] for %s %s\n", key, buf, action);
  81. } else {
  82. printf ("all keys for %s %s\n", buf, action);
  83. }
  84. }
  85. }
  86. int
  87. main (int argc, char *argv[])
  88. {
  89. jack_options_t options = JackNullOption;
  90. jack_status_t status;
  91. if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
  92. fprintf (stderr, "jack_client_open() failed, "
  93. "status = 0x%2.0x\n", status);
  94. if (status & JackServerFailed) {
  95. fprintf (stderr, "Unable to connect to JACK server\n");
  96. }
  97. return 1;
  98. }
  99. if (jack_set_port_registration_callback (client, port_callback, NULL)) {
  100. fprintf (stderr, "cannot set port registration callback\n");
  101. return 1;
  102. }
  103. if (jack_set_port_rename_callback (client, port_rename_callback, NULL)) {
  104. fprintf (stderr, "cannot set port registration callback\n");
  105. return 1;
  106. }
  107. if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
  108. fprintf (stderr, "cannot set port connect callback\n");
  109. return 1;
  110. }
  111. if (jack_set_client_registration_callback (client, client_callback, NULL)) {
  112. fprintf (stderr, "cannot set client registration callback\n");
  113. return 1;
  114. }
  115. if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
  116. fprintf (stderr, "cannot set graph order registration callback\n");
  117. return 1;
  118. }
  119. if (jack_set_property_change_callback (client, propchange, NULL)) {
  120. fprintf (stderr, "cannot set property change callback\n");
  121. return 1;
  122. }
  123. if (jack_activate (client)) {
  124. fprintf (stderr, "cannot activate client");
  125. return 1;
  126. }
  127. #ifndef WIN32
  128. signal(SIGINT, signal_handler);
  129. signal(SIGQUIT, signal_handler);
  130. signal(SIGHUP, signal_handler);
  131. #endif
  132. signal(SIGABRT, signal_handler);
  133. signal(SIGTERM, signal_handler);
  134. #ifdef WIN32
  135. Sleep(INFINITE);
  136. #else
  137. sleep (-1);
  138. #endif
  139. exit (0);
  140. }