LCOV - code coverage report
Current view: top level - shared - dlt_user_shared.c (source / functions) Coverage Total Hit
Test: dlt_final_coverage.info Lines: 80.8 % 52 42
Test Date: 2025-03-25 20:53:42 Functions: 83.3 % 6 5

            Line data    Source code
       1              : /*
       2              :  * SPDX license identifier: MPL-2.0
       3              :  *
       4              :  * Copyright (C) 2011-2015, BMW AG
       5              :  *
       6              :  * This file is part of COVESA Project DLT - Diagnostic Log and Trace.
       7              :  *
       8              :  * This Source Code Form is subject to the terms of the
       9              :  * Mozilla Public License (MPL), v. 2.0.
      10              :  * If a copy of the MPL was not distributed with this file,
      11              :  * You can obtain one at http://mozilla.org/MPL/2.0/.
      12              :  *
      13              :  * For further information see http://www.covesa.org/.
      14              :  */
      15              : 
      16              : /*!
      17              :  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de>
      18              :  *
      19              :  * \copyright Copyright © 2011-2015 BMW AG. \n
      20              :  * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
      21              :  *
      22              :  * \file dlt_user_shared.c
      23              :  */
      24              : 
      25              : 
      26              : /*******************************************************************************
      27              : **                                                                            **
      28              : **  SRC-MODULE: dlt_user_shared.c                                             **
      29              : **                                                                            **
      30              : **  TARGET    : linux                                                         **
      31              : **                                                                            **
      32              : **  PROJECT   : DLT                                                           **
      33              : **                                                                            **
      34              : **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
      35              : **              Markus Klein                                                  **
      36              : **                                                                            **
      37              : **  PURPOSE   :                                                               **
      38              : **                                                                            **
      39              : **  REMARKS   :                                                               **
      40              : **                                                                            **
      41              : **  PLATFORM DEPENDANT [yes/no]: yes                                          **
      42              : **                                                                            **
      43              : **  TO BE CHANGED BY USER [yes/no]: no                                        **
      44              : **                                                                            **
      45              : *******************************************************************************/
      46              : 
      47              : /*******************************************************************************
      48              : **                      Author Identity                                       **
      49              : ********************************************************************************
      50              : **                                                                            **
      51              : ** Initials     Name                       Company                            **
      52              : ** --------     -------------------------  ---------------------------------- **
      53              : **  aw          Alexander Wenzel           BMW                                **
      54              : **  mk          Markus Klein               Fraunhofer ESK                     **
      55              : *******************************************************************************/
      56              : 
      57              : /*******************************************************************************
      58              : **                      Revision Control History                              **
      59              : *******************************************************************************/
      60              : 
      61              : /*
      62              :  * $LastChangedRevision: 1670 $
      63              :  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
      64              :  * $LastChangedBy$
      65              :  * Initials    Date         Comment
      66              :  * aw          13.01.2010   initial
      67              :  */
      68              : 
      69              : #include <sys/stat.h>
      70              : #include <fcntl.h>
      71              : #include <errno.h>
      72              : 
      73              : #include <sys/uio.h> /* writev() */
      74              : #include <sys/time.h> /* timeval */
      75              : 
      76              : #include "dlt_user_shared.h"
      77              : #include "dlt_user_shared_cfg.h"
      78              : 
      79         6809 : DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype)
      80              : {
      81         6809 :     if (userheader == 0)
      82              :         return DLT_RETURN_ERROR;
      83              : 
      84         6809 :     if (mtype <= 0)
      85              :         return DLT_RETURN_ERROR;
      86              : 
      87         6809 :     userheader->pattern[0] = 'D';
      88         6809 :     userheader->pattern[1] = 'U';
      89         6809 :     userheader->pattern[2] = 'H';
      90         6809 :     userheader->pattern[3] = 1;
      91         6809 :     userheader->message = mtype;
      92              : 
      93         6809 :     return DLT_RETURN_OK;
      94              : }
      95              : 
      96        11835 : int dlt_user_check_userheader(DltUserHeader *userheader)
      97              : {
      98        11835 :     if (userheader == 0)
      99              :         return -1;
     100              : 
     101        23670 :     return (userheader->pattern[0] == 'D') &&
     102        11835 :            (userheader->pattern[1] == 'U') &&
     103        23670 :            (userheader->pattern[2] == 'H') &&
     104        11835 :            (userheader->pattern[3] == 1);
     105              : }
     106              : 
     107          432 : DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2)
     108              : {
     109              :     struct iovec iov[2];
     110              :     uint32_t bytes_written;
     111              : 
     112          432 :     if (handle < 0)
     113              :         /* Invalid handle */
     114              :         return DLT_RETURN_ERROR;
     115              : 
     116           94 :     iov[0].iov_base = ptr1;
     117           94 :     iov[0].iov_len = len1;
     118           94 :     iov[1].iov_base = ptr2;
     119           94 :     iov[1].iov_len = len2;
     120              : 
     121           94 :     bytes_written = (uint32_t) writev(handle, iov, 2);
     122              : 
     123           94 :     if (bytes_written != (len1 + len2))
     124              :         return DLT_RETURN_ERROR;
     125              : 
     126              :     return DLT_RETURN_OK;
     127              : }
     128              : 
     129           51 : DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2)
     130              : {
     131           51 :     if (handle < 0)
     132              :         /* Invalid handle */
     133              :         return DLT_RETURN_ERROR;
     134              : 
     135              :     fd_set fds;
     136          867 :     FD_ZERO(&fds);
     137           51 :     FD_SET(handle, &fds);
     138              : 
     139           51 :     struct timeval tv = { DLT_WRITEV_TIMEOUT_SEC, DLT_WRITEV_TIMEOUT_USEC };
     140           51 :     if (select(handle+1, NULL, &fds, NULL, &tv) < 0) {
     141              :         return DLT_RETURN_ERROR;
     142              :     }
     143              : 
     144           51 :     if (FD_ISSET(handle, &fds)) {
     145           51 :         return dlt_user_log_out2(handle, ptr1, len1, ptr2, len2);
     146              :     } else {
     147              :         return DLT_RETURN_ERROR;
     148              :     }
     149              : }
     150              : 
     151         6375 : DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
     152              : {
     153              :     struct iovec iov[3];
     154              :     uint32_t bytes_written;
     155              : 
     156         6375 :     if (handle < 0)
     157              :         /* Invalid handle */
     158              :         return DLT_RETURN_ERROR;
     159              : 
     160         5858 :     iov[0].iov_base = ptr1;
     161         5858 :     iov[0].iov_len = len1;
     162         5858 :     iov[1].iov_base = ptr2;
     163         5858 :     iov[1].iov_len = len2;
     164         5858 :     iov[2].iov_base = ptr3;
     165         5858 :     iov[2].iov_len = len3;
     166              : 
     167         5858 :     bytes_written = (uint32_t) writev(handle, iov, 3);
     168              : 
     169         5858 :     if (bytes_written != (len1 + len2 + len3)) {
     170            2 :         switch (errno) {
     171              :         case ETIMEDOUT:
     172              :         {
     173              :             return DLT_RETURN_PIPE_ERROR;     /* ETIMEDOUT - connect timeout */
     174              :             break;
     175              :         }
     176              :         case EBADF:
     177              :         {
     178              :             return DLT_RETURN_PIPE_ERROR;     /* EBADF - handle not open */
     179              :             break;
     180              :         }
     181              :         case EPIPE:
     182              :         {
     183              :             return DLT_RETURN_PIPE_ERROR;     /* EPIPE - pipe error */
     184              :             break;
     185              :         }
     186            0 :         case EAGAIN:
     187              :         {
     188            0 :             return DLT_RETURN_PIPE_FULL;     /* EAGAIN - data could not be written */
     189              :             break;
     190              :         }
     191              :         default:
     192              :         {
     193              :             break;
     194              :         }
     195              :         }
     196              : 
     197              :         return DLT_RETURN_ERROR;
     198              :     }
     199              : 
     200              :     return DLT_RETURN_OK;
     201              : }
     202              : 
     203            0 : DltReturnValue dlt_user_log_out3_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
     204              : {
     205            0 :     if (handle < 0)
     206              :         /* Invalid handle */
     207              :         return DLT_RETURN_ERROR;
     208              : 
     209              :     fd_set fds;
     210            0 :     FD_ZERO(&fds);
     211            0 :     FD_SET(handle, &fds);
     212              : 
     213            0 :     struct timeval tv = { DLT_WRITEV_TIMEOUT_SEC, DLT_WRITEV_TIMEOUT_USEC };
     214            0 :     if (select(handle+1, NULL, &fds, NULL, &tv) < 0) {
     215              :         return DLT_RETURN_ERROR;
     216              :     }
     217              : 
     218            0 :     if (FD_ISSET(handle, &fds)) {
     219            0 :         return dlt_user_log_out3(handle, ptr1, len1, ptr2, len2, ptr3, len3);
     220              :     } else {
     221              :         return DLT_RETURN_ERROR;
     222              :     }
     223              : }
        

Generated by: LCOV version 2.0-1