| 1 |
/* |
| 2 |
* Written by Oron Peled <[email protected]> |
| 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 |
#include <linux/kernel.h> |
| 24 |
#include <linux/errno.h> |
| 25 |
#include <linux/module.h> |
| 26 |
#include <dahdi/kernel.h> |
| 27 |
#include "dahdi_debug.h" |
| 28 |
#include "xdefs.h" |
| 29 |
|
| 30 |
static const char rcsid[] = "$Id$"; |
| 31 |
|
| 32 |
#define P_(x) [ x ] = { .value = x, .name = #x, } |
| 33 |
static struct { |
| 34 |
int value; |
| 35 |
char *name; |
| 36 |
} poll_names[] = { |
| 37 |
P_(POLLIN), P_(POLLPRI), P_(POLLOUT), P_(POLLERR), P_(POLLHUP), |
| 38 |
P_(POLLNVAL), P_(POLLRDNORM), P_(POLLRDBAND), P_(POLLWRNORM), |
| 39 |
P_(POLLWRBAND), P_(POLLMSG), P_(POLLREMOVE) |
| 40 |
}; |
| 41 |
|
| 42 |
#undef P_ |
| 43 |
|
| 44 |
void dump_poll(int debug, const char *msg, int poll) |
| 45 |
{ |
| 46 |
int i; |
| 47 |
|
| 48 |
for (i = 0; i < ARRAY_SIZE(poll_names); i++) { |
| 49 |
if (poll & poll_names[i].value) |
| 50 |
DBG(GENERAL, "%s: %s\n", msg, poll_names[i].name); |
| 51 |
} |
| 52 |
} |
| 53 |
EXPORT_SYMBOL(dump_poll); |
| 54 |
|
| 55 |
void alarm2str(int alarm, char *buf, int buflen) |
| 56 |
{ |
| 57 |
char *p = buf; |
| 58 |
int left = buflen; |
| 59 |
int i; |
| 60 |
int n; |
| 61 |
|
| 62 |
if (!alarm) { |
| 63 |
snprintf(buf, buflen, "NONE"); |
| 64 |
return; |
| 65 |
} |
| 66 |
memset(buf, 0, buflen); |
| 67 |
for (i = 0; i < 8; i++) { |
| 68 |
if (left && (alarm & BIT(i))) { |
| 69 |
n = snprintf(p, left, "%s,", alarmbit2str(i)); |
| 70 |
p += n; |
| 71 |
left -= n; |
| 72 |
} |
| 73 |
} |
| 74 |
if (p > buf) /* kill last comma */ |
| 75 |
*(p - 1) = '\0'; |
| 76 |
} |
| 77 |
EXPORT_SYMBOL(alarm2str); |