dahdi_debug.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Written by Oron Peled <oron@actcom.co.il>
  3. * Copyright (C) 2004-2006, Xorcom
  4. *
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  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.
  16. *
  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.
  20. *
  21. */
  22. #include <linux/version.h>
  23. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  24. # warning "This module is tested only with 2.6 kernels"
  25. #endif
  26. #include <linux/kernel.h>
  27. #include <linux/errno.h>
  28. #include <linux/module.h>
  29. #include <dahdi/kernel.h>
  30. #include "dahdi_debug.h"
  31. #include "xdefs.h"
  32. static const char rcsid[] = "$Id$";
  33. #define P_(x) [ x ] = { .value = x, .name = #x, }
  34. static struct {
  35. int value;
  36. char *name;
  37. } poll_names[] = {
  38. P_(POLLIN),
  39. P_(POLLPRI),
  40. P_(POLLOUT),
  41. P_(POLLERR),
  42. P_(POLLHUP),
  43. P_(POLLNVAL),
  44. P_(POLLRDNORM),
  45. P_(POLLRDBAND),
  46. P_(POLLWRNORM),
  47. P_(POLLWRBAND),
  48. P_(POLLMSG),
  49. P_(POLLREMOVE)
  50. };
  51. #undef P_
  52. void dump_poll(int debug, const char *msg, int poll)
  53. {
  54. int i;
  55. for(i = 0; i < ARRAY_SIZE(poll_names); i++) {
  56. if(poll & poll_names[i].value)
  57. DBG(GENERAL, "%s: %s\n", msg, poll_names[i].name);
  58. }
  59. }
  60. void alarm2str(int alarm, char *buf, int buflen)
  61. {
  62. char *p = buf;
  63. int left = buflen;
  64. int i;
  65. int n;
  66. if(!alarm) {
  67. snprintf(buf, buflen, "NONE");
  68. return;
  69. }
  70. memset(buf, 0, buflen);
  71. for(i = 0; i < 8; i++) {
  72. if(left && (alarm & BIT(i))) {
  73. n = snprintf(p, left, "%s,", alarmbit2str(i));
  74. p += n;
  75. left -= n;
  76. }
  77. }
  78. if(p > buf) /* kill last comma */
  79. *(p - 1) = '\0';
  80. }
  81. EXPORT_SYMBOL(dump_poll);
  82. EXPORT_SYMBOL(alarm2str);