jack1 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.

113 lines
2.4KB

  1. /*
  2. Copyright (C) 2013 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include <stdio.h>
  16. #include <stdint.h>
  17. #include <jack/types.h>
  18. #include <jack/uuid.h>
  19. #include "internal.h"
  20. static pthread_mutex_t uuid_lock = PTHREAD_MUTEX_INITIALIZER;
  21. static uint32_t uuid_cnt = 0;
  22. enum JackUUIDType {
  23. JackUUIDPort = 0x1,
  24. JackUUIDClient = 0x2
  25. };
  26. jack_uuid_t
  27. jack_client_uuid_generate ()
  28. {
  29. jack_uuid_t uuid = JackUUIDClient;
  30. pthread_mutex_lock (&uuid_lock);
  31. uuid = (uuid << 32) | ++uuid_cnt;
  32. pthread_mutex_unlock (&uuid_lock);
  33. return uuid;
  34. }
  35. jack_uuid_t
  36. jack_port_uuid_generate (uint32_t port_id)
  37. {
  38. jack_uuid_t uuid = JackUUIDPort;
  39. uuid = (uuid << 32) | (port_id + 1);
  40. return uuid;
  41. }
  42. uint32_t
  43. jack_uuid_to_index (jack_uuid_t u)
  44. {
  45. return (u & 0xffff) - 1;
  46. }
  47. int
  48. jack_uuid_empty (jack_uuid_t u)
  49. {
  50. return (u == 0);
  51. }
  52. int
  53. jack_uuid_compare (jack_uuid_t a, jack_uuid_t b)
  54. {
  55. if (a == b) {
  56. return 0;
  57. }
  58. if (a < b) {
  59. return -1;
  60. }
  61. return 1;
  62. }
  63. void
  64. jack_uuid_copy (jack_uuid_t* dst, jack_uuid_t src)
  65. {
  66. *dst = src;
  67. }
  68. void
  69. jack_uuid_clear (jack_uuid_t* u)
  70. {
  71. *u = 0;
  72. }
  73. void
  74. jack_uuid_unparse (jack_uuid_t u, char b[JACK_UUID_STRING_SIZE])
  75. {
  76. snprintf (b, JACK_UUID_STRING_SIZE, "%" PRIu64, u);
  77. }
  78. int
  79. jack_uuid_parse (const char *b, jack_uuid_t* u)
  80. {
  81. if (sscanf (b, "%" PRIu64, u) == 1) {
  82. if (*u < (0x1LL << 32)) {
  83. /* has not type bits set - not legal */
  84. return -1;
  85. }
  86. return 0;
  87. }
  88. return -1;
  89. }