Changeset 115

Show
Ignore:
Timestamp:
05/16/07 17:57:31 (2 years ago)
Author:
dsmith
Message:

fixed error message reporting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libcwiid/connect.c

    r112 r115  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * remove error_pipe init and destruct 
     20 * 
    1821 *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * rewrite for API overhaul 
     
    5962        struct wiimote *wiimote = NULL; 
    6063        struct sockaddr_l2 remote_addr; 
    61         char mesg_pipe_init = 0, status_pipe_init = 0, error_pipe_init = 0, 
    62              rw_pipe_init = 0, state_mutex_init = 0, rw_mutex_init = 0, 
    63              rpt_mutex_init = 0, router_thread_init = 0, status_thread_init = 0; 
     64        char mesg_pipe_init = 0, status_pipe_init = 0, rw_pipe_init = 0, 
     65             state_mutex_init = 0, rw_mutex_init = 0, rpt_mutex_init = 0, 
     66             router_thread_init = 0, status_thread_init = 0; 
    6467        void *pthread_ret; 
    6568 
     
    136139        } 
    137140        status_pipe_init = 1; 
    138         if (pipe(wiimote->error_pipe)) { 
    139                 cwiid_err(wiimote, "Pipe creation error (error pipe)"); 
    140                 goto ERR_HND; 
    141         } 
    142         error_pipe_init = 1; 
    143141        if (pipe(wiimote->rw_pipe)) { 
    144142                cwiid_err(wiimote, "Pipe creation error (rw pipe)"); 
     
    248246                        } 
    249247                } 
    250                 if (error_pipe_init) { 
    251                         if (close(wiimote->error_pipe[0]) || 
    252                           close(wiimote->error_pipe[1])) { 
    253                                 cwiid_err(wiimote, "Pipe close error (error pipe)"); 
    254                         } 
    255                 } 
    256248                if (rw_pipe_init) { 
    257249                        if (close(wiimote->rw_pipe[0]) || close(wiimote->rw_pipe[1])) { 
     
    329321                cwiid_err(wiimote, "Pipe close error (status pipe)"); 
    330322        } 
    331         if (close(wiimote->error_pipe[0]) || close(wiimote->error_pipe[1])) { 
    332                 cwiid_err(wiimote, "Pipe close error (error pipe)"); 
    333         } 
    334323        if (close(wiimote->rw_pipe[0]) || close(wiimote->rw_pipe[1])) { 
    335324                cwiid_err(wiimote, "Pipe close error (rw pipe)"); 
  • trunk/libcwiid/cwiid_internal.h

    r112 r115  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * remove error_pipe 
     20 *  * add struct mesg_array to process_error 
     21 * 
    1822 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * added timestamp to mesg_array 
     
    176180        int mesg_pipe[2]; 
    177181        int status_pipe[2]; 
    178         int error_pipe[2]; 
    179182        int rw_pipe[2]; 
    180183        struct cwiid_state state; 
     
    208211 
    209212/* process.c */ 
    210 int process_error(struct wiimote *, ssize_t); 
     213int process_error(struct wiimote *, ssize_t, struct mesg_array *); 
    211214int process_status(struct wiimote *, const unsigned char *, 
    212215                   struct mesg_array *); 
  • trunk/libcwiid/process.c

    r101 r115  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * process_err adds error_mesg to mesg_array 
     20 * 
    1821 *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * created for API overhaul (moved from old event.c) 
     
    2326#include "cwiid_internal.h" 
    2427 
    25 int process_error(struct wiimote *wiimote, ssize_t len
    26 { 
    27         struct cwiid_error_mesg error_mesg; 
    28         int ret = 0; 
    29  
    30         error_mesg.type = CWIID_MESG_ERROR; 
     28int process_error(struct wiimote *wiimote, ssize_t len, struct mesg_array *ma
     29{ 
     30        struct cwiid_error_mesg *error_mesg; 
     31 
     32        error_mesg = &ma->array[ma->count++].error_mesg; 
     33        error_mesg->type = CWIID_MESG_ERROR; 
    3134        if (len == 0) { 
    32                 error_mesg.error = CWIID_ERROR_DISCONNECT; 
     35                error_mesg->error = CWIID_ERROR_DISCONNECT; 
    3336        } 
    3437        else { 
    35                 error_mesg.error = CWIID_ERROR_COMM; 
    36         } 
    37  
    38         if (write(wiimote->error_pipe[1], &error_mesg, sizeof error_mesg) 
    39           != sizeof error_mesg) { 
    40                 cwiid_err(wiimote, "Error pipe write error"); 
    41                 ret = -1; 
     38                error_mesg->error = CWIID_ERROR_COMM; 
    4239        } 
    4340 
    4441        if (cancel_rw(wiimote)) { 
    4542                cwiid_err(wiimote, "RW cancel error"); 
    46                 ret = -1; 
    47         } 
    48  
    49         return ret; 
     43        } 
     44 
     45        return 0; 
    5046} 
    5147 
  • trunk/libcwiid/thread.c

    r112 r115  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * send error_mesg from process_error 
     20 * 
    1821 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * added timestamp to message array 
     
    6871                /* Read packet */ 
    6972                len = read(wiimote->int_socket, buf, READ_BUF_LEN); 
     73                ma.count = 0; 
     74                if (clock_gettime(CLOCK_REALTIME, &ma.timestamp)) { 
     75                        if (print_clock_err) { 
     76                                cwiid_err(wiimote, "clock_gettime error"); 
     77                                print_clock_err = 0; 
     78                        } 
     79                } 
     80                err = 0; 
    7081                if ((len == -1) || (len == 0)) { 
    71                         process_error(wiimote, len); 
     82                        process_error(wiimote, len, &ma); 
     83                        write_mesg_array(wiimote, &ma); 
    7284                        /* Quit! */ 
    7385                        break; 
     
    7890                                cwiid_err(wiimote, "Invalid packet type"); 
    7991                        } 
    80                         ma.count = 0; 
    81                         if (clock_gettime(CLOCK_REALTIME, &ma.timestamp)) { 
    82                                 if (print_clock_err) { 
    83                                         cwiid_err(wiimote, "clock_gettime error"); 
    84                                         print_clock_err = 0; 
    85                                 } 
    86                         } 
    87                         err = 0; 
    8892 
    8993                        /* Main switch */ 
     
    155159                                } 
    156160                                if (wiimote->flags & CWIID_FLAG_MESG_IFC) { 
    157                                         if (write_mesg_array(wiimote, &ma)) { 
    158                                                 /* prints its own errors */ 
    159                                         } 
     161                                        /* prints its own errors */ 
     162                                        write_mesg_array(wiimote, &ma); 
    160163                                } 
    161164                        }