LCOV - code coverage report
Current view: top level - shared - dlt_user_shared.c (source / functions) Coverage Total Hit
Test: dlt_final_coverage.info Lines: 82.0 % 50 41
Test Date: 2025-06-10 07:37:20 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              : #include <poll.h>
      73              : 
      74              : #include <sys/uio.h> /* writev() */
      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        11833 : int dlt_user_check_userheader(DltUserHeader *userheader)
      97              : {
      98        11833 :     if (userheader == 0)
      99              :         return -1;
     100              : 
     101        23666 :     return (userheader->pattern[0] == 'D') &&
     102        11833 :            (userheader->pattern[1] == 'U') &&
     103        23666 :            (userheader->pattern[2] == 'H') &&
     104        11833 :            (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              :     struct pollfd pfd;
     136           51 :     pfd.fd = handle;
     137           51 :     pfd.events = POLLOUT;
     138              : 
     139           51 :     if (poll(&pfd, 1, DLT_WRITEV_TIMEOUT_MS) < 0) {
     140              :         return DLT_RETURN_ERROR;
     141              :     }
     142              : 
     143           51 :     if (pfd.revents & POLLOUT) {
     144           51 :         return dlt_user_log_out2(handle, ptr1, len1, ptr2, len2);
     145              :     } else {
     146              :         return DLT_RETURN_ERROR;
     147              :     }
     148              : }
     149              : 
     150         6375 : DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
     151              : {
     152              :     struct iovec iov[3];
     153              :     uint32_t bytes_written;
     154              : 
     155         6375 :     if (handle < 0)
     156              :         /* Invalid handle */
     157              :         return DLT_RETURN_ERROR;
     158              : 
     159         5857 :     iov[0].iov_base = ptr1;
     160         5857 :     iov[0].iov_len = len1;
     161         5857 :     iov[1].iov_base = ptr2;
     162         5857 :     iov[1].iov_len = len2;
     163         5857 :     iov[2].iov_base = ptr3;
     164         5857 :     iov[2].iov_len = len3;
     165              : 
     166         5857 :     bytes_written = (uint32_t) writev(handle, iov, 3);
     167              : 
     168         5857 :     if (bytes_written != (len1 + len2 + len3)) {
     169            2 :         switch (errno) {
     170              :         case ETIMEDOUT:
     171              :         {
     172              :             return DLT_RETURN_PIPE_ERROR;     /* ETIMEDOUT - connect timeout */
     173              :             break;
     174              :         }
     175              :         case EBADF:
     176              :         {
     177              :             return DLT_RETURN_PIPE_ERROR;     /* EBADF - handle not open */
     178              :             break;
     179              :         }
     180              :         case EPIPE:
     181              :         {
     182              :             return DLT_RETURN_PIPE_ERROR;     /* EPIPE - pipe error */
     183              :             break;
     184              :         }
     185            0 :         case EAGAIN:
     186              :         {
     187            0 :             return DLT_RETURN_PIPE_FULL;     /* EAGAIN - data could not be written */
     188              :             break;
     189              :         }
     190              :         default:
     191              :         {
     192              :             break;
     193              :         }
     194              :         }
     195              : 
     196              :         return DLT_RETURN_ERROR;
     197              :     }
     198              : 
     199              :     return DLT_RETURN_OK;
     200              : }
     201              : 
     202            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)
     203              : {
     204            0 :     if (handle < 0)
     205              :         /* Invalid handle */
     206              :         return DLT_RETURN_ERROR;
     207              : 
     208              :     struct pollfd pfd;
     209            0 :     pfd.fd = handle;
     210            0 :     pfd.events = POLLOUT;
     211              : 
     212            0 :     if (poll(&pfd, 1, DLT_WRITEV_TIMEOUT_MS) < 0) {
     213              :         return DLT_RETURN_ERROR;
     214              :     }
     215              : 
     216            0 :     if (pfd.revents & POLLOUT) {
     217            0 :         return dlt_user_log_out3(handle, ptr1, len1, ptr2, len2, ptr3, len3);
     218              :     } else {
     219              :         return DLT_RETURN_ERROR;
     220              :     }
     221              : }
        

Generated by: LCOV version 2.0-1