diff options
author | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-11 13:50:22 +0200 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2011-10-11 13:50:22 +0200 |
commit | 98280f75c07d574a2776558c4fec2797c2b21450 (patch) | |
tree | b2d943258a7c75ee3e3f798b79f37a61873297b8 /src | |
parent | 9585f876733b62fb29aaeb163f0f8c408765c9e3 (diff) | |
download | DLT-daemon-98280f75c07d574a2776558c4fec2797c2b21450.tar.gz |
Prepared alternative log over FIFO or SHM.
Diffstat (limited to 'src')
-rwxr-xr-x | src/daemon/dlt-daemon.c | 247 | ||||
-rwxr-xr-x | src/lib/dlt_user.c | 2 |
2 files changed, 135 insertions, 114 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 86315c6..0e52d3c 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1698,11 +1698,12 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDae int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) { - //int bytes_to_be_removed; + int bytes_to_be_removed=0; int j,sent,third_value; ssize_t ret; uint8_t rcv_buffer[10000]; int size; + DltUserHeader *userheader; static char text[DLT_DAEMON_TEXTSIZE]; @@ -1714,152 +1715,172 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo return -1; } + userheader = (DltUserHeader*) (daemon_local->receiver.buf); + //dlt_shm_status(&(daemon_local->dlt_shm)); - while ( (size = dlt_shm_copy(&(daemon_local->dlt_shm),rcv_buffer,10000)) > 0) - { - if (dlt_message_read(&(daemon_local->msg),rcv_buffer,size,0,verbose)==0) + while (1) + { + if(userheader->message == DLT_USER_MESSAGE_LOG_SHM) { + /* log message in SHM */ + if((size = dlt_shm_copy(&(daemon_local->dlt_shm),rcv_buffer,10000)) <= 0) + break; + if (dlt_message_read(&(daemon_local->msg),rcv_buffer,size,0,verbose)!=0) { + break; + dlt_log(LOG_ERR,"Can't read messages from shm\n"); + return -1; + } + bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); + if (daemon_local->msg.found_serialheader) + { + bytes_to_be_removed += sizeof(dltSerialHeader); + } + } + else { /* userheader->message == DLT_USER_MESSAGE_LOG */ + /* log message in FIFO */ + if(dlt_message_read(&(daemon_local->msg),(unsigned char*)daemon_local->receiver.buf+sizeof(DltUserHeader),daemon_local->receiver.bytesRcvd-sizeof(DltUserHeader),0,verbose)!=0) { + break; + dlt_log(LOG_ERR,"Can't read messages from receiver\n"); + return -1; + } ; + bytes_to_be_removed = sizeof(DltUserHeader); + } + + /* set overwrite ecu id */ + if (daemon_local->flags.evalue[0]) { - /* set overwrite ecu id */ - if (daemon_local->flags.evalue[0]) + /* Set header extra parameters */ + dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid ); + //msg.headerextra.seid = 0; + if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1) { - /* Set header extra parameters */ - dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid ); - //msg.headerextra.seid = 0; - if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1) - { - dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n"); - dlt_shm_remove(&(daemon_local->dlt_shm)); - return -1; - } - - /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ - daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; } - /* prepare storage header */ - if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) + /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + } + + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1) { - if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1) - { - dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); - dlt_shm_remove(&(daemon_local->dlt_shm)); - return -1; - } + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; } - else + } + else + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1) { - if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1) - { - dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); - dlt_shm_remove(&(daemon_local->dlt_shm)); - return -1; - } + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + dlt_shm_remove(&(daemon_local->dlt_shm)); + return -1; } + } - /* display message */ - if (daemon_local->flags.xflag) + /* display message */ + if (daemon_local->flags.xflag) + { + if (dlt_message_print_hex(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) { - if (dlt_message_print_hex(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) - { - dlt_log(LOG_ERR,"dlt_message_print_hex() failed!\n"); - } - } /* if */ - else if (daemon_local->flags.aflag) + dlt_log(LOG_ERR,"dlt_message_print_hex() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.aflag) + { + if (dlt_message_print_ascii(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_ascii() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.sflag) + { + if (dlt_message_print_header(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_header() failed!\n"); + } + /* print message header only */ + } /* if */ + + sent=0; + + /* write message to offline trace */ + if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) + { + dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize, + daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0); + sent = 1; + } + + /* look if TCP connection to client is available */ + for (j = 0;((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && (j <= daemon_local->fdmax); j++) + { + /* send to everyone! */ + if (FD_ISSET(j, &(daemon_local->master))) { - if (dlt_message_print_ascii(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + /* except the listener and ourselves */ + if (daemon_local->flags.yvalue!=0) { - dlt_log(LOG_ERR,"dlt_message_print_ascii() failed!\n"); + third_value = daemon_local->fdserial; } - } /* if */ - else if (daemon_local->flags.sflag) - { - if (dlt_message_print_header(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + else { - dlt_log(LOG_ERR,"dlt_message_print_header() failed!\n"); + third_value = daemon_local->sock; } - /* print message header only */ - } /* if */ - - sent=0; - /* write message to offline trace */ - if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) - { - dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize, - daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0); - sent = 1; - } - - /* look if TCP connection to client is available */ - for (j = 0;((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && (j <= daemon_local->fdmax); j++) - { - /* send to everyone! */ - if (FD_ISSET(j, &(daemon_local->master))) + if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) { - /* except the listener and ourselves */ - if (daemon_local->flags.yvalue!=0) - { - third_value = daemon_local->fdserial; - } - else + DLT_DAEMON_SEM_LOCK(); + + if (daemon_local->flags.lflag) { - third_value = daemon_local->sock; + send(j,dltSerialHeader,sizeof(dltSerialHeader),0); } - if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) - { - DLT_DAEMON_SEM_LOCK(); + send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); + send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); - if (daemon_local->flags.lflag) - { - send(j,dltSerialHeader,sizeof(dltSerialHeader),0); - } - - send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); - send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); + DLT_DAEMON_SEM_FREE(); - DLT_DAEMON_SEM_FREE(); + sent=1; + } /* if */ + else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue[0])) + { + DLT_DAEMON_SEM_LOCK(); - sent=1; - } /* if */ - else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue[0])) + if (daemon_local->flags.lflag) { - DLT_DAEMON_SEM_LOCK(); - - if (daemon_local->flags.lflag) - { - ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); - } + ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); + } - ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader)); - ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize); + ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader)); + ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize); - DLT_DAEMON_SEM_FREE(); + DLT_DAEMON_SEM_FREE(); - sent=1; - } - } /* if */ - } /* for */ + sent=1; + } + } /* if */ + } /* for */ - /* Message was not sent to client, so store it in client ringbuffer */ - if (sent==1 || (daemon->mode == DLT_USER_MODE_OFF)) - { - /* dlt message was sent, remove from buffer */ + /* Message was not sent to client, so store it in client ringbuffer */ + if (sent==1 || (daemon->mode == DLT_USER_MODE_OFF)) + { + if(userheader->message == DLT_USER_MESSAGE_LOG_SHM) { + /* dlt message was sent, remove from buffer if log message from shm */ dlt_shm_remove(&(daemon_local->dlt_shm)); - - } - else - { - /* dlt message was not sent, keep in buffer */ - break; - } - + } } else { - dlt_log(LOG_ERR,"Can't read messages from receiver\n"); - return -1; + /* dlt message was not sent, keep in buffer */ + break; } + } /* keep not read data in buffer */ diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 7886320..da4f9e4 100755 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -2031,7 +2031,7 @@ int dlt_user_log_send_log(DltContextData *log, int mtype) } /* also for Trace messages */ - if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG)==-1) + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_SHM)==-1) { return -1; } |