[3877] | 1 | //error.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 |
---|
| 5 | * |
---|
| 6 | * This file is part of libroar a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #include "libroar.h" |
---|
| 37 | |
---|
| 38 | int roar_err_int(struct roar_error_frame * frame) { |
---|
| 39 | if ( frame == NULL ) |
---|
| 40 | return -1; |
---|
| 41 | |
---|
| 42 | memset(frame, 0, sizeof(struct roar_error_frame)); |
---|
| 43 | |
---|
| 44 | frame->cmd = -1; |
---|
| 45 | frame->ra_errno = -1; |
---|
| 46 | frame->ra_suberrno = -1; |
---|
| 47 | frame->p_errno = -1; |
---|
| 48 | |
---|
| 49 | return 0; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void * roar_err_buildmsg(struct roar_message * mes, struct roar_error_frame * frame) { |
---|
| 53 | int16_t * d; |
---|
| 54 | |
---|
| 55 | if ( mes == NULL || frame == NULL ) |
---|
| 56 | return NULL; |
---|
| 57 | |
---|
| 58 | memset(mes, 0, sizeof(struct roar_message)); |
---|
| 59 | |
---|
| 60 | d = (int16_t*)mes->data; |
---|
| 61 | |
---|
| 62 | mes->datalen = 8 + frame->datalen; |
---|
| 63 | frame->data = &(mes->data[8]); |
---|
| 64 | |
---|
| 65 | mes->data[0] = 0; // version. |
---|
| 66 | mes->data[1] = frame->cmd; |
---|
| 67 | mes->data[2] = frame->ra_errno; |
---|
| 68 | mes->data[3] = frame->ra_suberrno; |
---|
| 69 | d[2] = ROAR_HOST2NET16(frame->p_errno); |
---|
| 70 | d[3] = ROAR_HOST2NET16(frame->flags); |
---|
| 71 | |
---|
| 72 | return frame->data; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | int roar_err_parsemsg(struct roar_message * mes, struct roar_error_frame * frame) { |
---|
| 76 | int16_t * d; |
---|
| 77 | |
---|
| 78 | if ( mes == NULL || frame == NULL ) |
---|
| 79 | return -1; |
---|
| 80 | |
---|
| 81 | d = (int16_t*)mes->data; |
---|
| 82 | |
---|
| 83 | if ( mes->datalen < 8 ) |
---|
| 84 | return -1; |
---|
| 85 | |
---|
| 86 | if ( mes->data[0] != 0 ) |
---|
| 87 | return -1; |
---|
| 88 | |
---|
| 89 | frame->cmd = mes->data[1]; |
---|
| 90 | frame->ra_errno = mes->data[2]; |
---|
| 91 | frame->ra_suberrno = mes->data[3]; |
---|
| 92 | frame->p_errno = ROAR_NET2HOST16(d[2]); |
---|
| 93 | frame->flags = ROAR_NET2HOST16(d[3]); |
---|
| 94 | |
---|
| 95 | frame->datalen = mes->datalen - 8; |
---|
| 96 | frame->data = &(mes->data[8]); |
---|
| 97 | |
---|
| 98 | return 0; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | //ll |
---|