summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/udp_file_writer.cpp
blob: ce04ae00225d0e028daa360a81b233b00f4fd1a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_SS_LoggerService
/// \brief    TODO
///
///////////////////////////////////////////////////////////////////////////////
#include "readerWriter/writer/udp_file_writer.h"
#include "readerWriter/writer/file_writer.h"
#include "readerWriter/writer/cached_file_writer.h"

namespace ReaderWriter {

// LCOV_EXCL_START 8:dead code
CUdpFileWriter::CUdpFileWriter()
    : m_pUdpWriter(NULL),
      m_pFileWriter(NULL),
      m_pLoggerCfg(NULL),
      m_ipAddress(""),
      m_port(0),
      m_FileName(""),
      m_FileSize(0) {
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
}
// LCOV_EXCL_STOP

CUdpFileWriter::~CUdpFileWriter() {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  if (this->m_pFileWriter != NULL) {
    delete (this->m_pFileWriter);
    this->m_pFileWriter = NULL;
  }
  if (this->m_pUdpWriter != NULL) {
    delete (this->m_pUdpWriter);
    this->m_pUdpWriter = NULL;
  }
}
// LCOV_EXCL_STOP

// LCOV_EXCL_START 8:dead code
EFrameworkunifiedStatus CUdpFileWriter::Initialize(CLoggerCfg* f_pLoggerCfg,
                                      std::string f_Name1, UI_32 f_size1,
                                      std::string f_Name2, UI_32 f_size2) {
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  if ((NULL == this->m_pFileWriter) && (NULL == this->m_pUdpWriter)
      && (NULL != f_pLoggerCfg)) {
    this->m_pFileWriter = new (std::nothrow) CCachedFileWriter();
    this->m_pUdpWriter = new (std::nothrow) CUdpWriter();
    m_pLoggerCfg = f_pLoggerCfg;
    m_ipAddress = f_Name2;
    m_port = f_size2;
    m_FileName = f_Name1;
    m_FileSize = f_size1;
    EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Initialize(m_pLoggerCfg,
                                                           m_ipAddress, m_port,
                                                           "", 0);
    EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Initialize(m_pLoggerCfg,
                                                            m_FileName,
                                                            m_FileSize, "", 0);
    l_eStatus =
        ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
            eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
    if (l_eStatus == eFrameworkunifiedStatusOK) {
      l_eStatus = this->Open();
    }
  } else {
    l_eStatus = eFrameworkunifiedStatusNullPointer;
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
  return (l_eStatus);
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CUdpFileWriter::Open(void) {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  if ((NULL != this->m_pFileWriter) && (NULL != this->m_pUdpWriter)) {
    EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Open();
    EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Open();
    l_eStatus =
        ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
            eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
  }

  return (l_eStatus);
}
// LCOV_EXCL_STOP

BOOL CUdpFileWriter::IsOpen(void) {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  BOOL l_ret = FALSE;
  if ((this->m_pUdpWriter != NULL) && (this->m_pFileWriter != NULL)) {
    l_ret = (m_pUdpWriter->IsOpen() && m_pFileWriter->IsOpen());
  }
  return l_ret;
}
// LCOV_EXCL_STOP

// LCOV_EXCL_START 8:dead code
EFrameworkunifiedStatus CUdpFileWriter::Write(UI_8* f_data, UI_32 f_length,
                                 SI_32& f_bytesWritten) {
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  if ((NULL != this->m_pUdpWriter)) {
    l_eStatus = this->m_pUdpWriter->Write(f_data, f_length, f_bytesWritten);
    LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pUdpWriter->Write() failed.");
  }

  if ((NULL != this->m_pFileWriter)) {
    l_eStatus = this->m_pFileWriter->Write(f_data, f_length, f_bytesWritten);
    LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pFileWriter->Write() failed.");
  } else {
    l_eStatus = eFrameworkunifiedStatusFail;
  }
  return (l_eStatus);
}
// LCOV_EXCL_STOP

void CUdpFileWriter::Close() {    // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  if (this->m_pFileWriter != NULL) {
    this->m_pFileWriter->Close();
    delete (this->m_pFileWriter);
    this->m_pFileWriter = NULL;
  }
  if (this->m_pUdpWriter != NULL) {
    this->m_pUdpWriter->Close();
    delete (this->m_pUdpWriter);
    this->m_pUdpWriter = NULL;
  }
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CUdpFileWriter::FlushCache(void) {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  return (this->m_pFileWriter->FlushCache());
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CUdpFileWriter::UpdateLoggingParameters(void) {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  return (this->m_pUdpWriter->UpdateLoggingParameters());
}
}  // namespace ReaderWriter

// LCOV_EXCL_STOP