2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SS_LoggerService
21 ///////////////////////////////////////////////////////////////////////////////
22 #include "readerWriter/writer/udp_file_writer.h"
23 #include "readerWriter/writer/file_writer.h"
24 #include "readerWriter/writer/cached_file_writer.h"
26 namespace ReaderWriter {
28 // LCOV_EXCL_START 8:dead code
29 CUdpFileWriter::CUdpFileWriter()
37 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
41 CUdpFileWriter::~CUdpFileWriter() { // LCOV_EXCL_START 8:dead code
42 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
43 if (this->m_pFileWriter != NULL) {
44 delete (this->m_pFileWriter);
45 this->m_pFileWriter = NULL;
47 if (this->m_pUdpWriter != NULL) {
48 delete (this->m_pUdpWriter);
49 this->m_pUdpWriter = NULL;
54 // LCOV_EXCL_START 8:dead code
55 EFrameworkunifiedStatus CUdpFileWriter::Initialize(CLoggerCfg* f_pLoggerCfg,
56 std::string f_Name1, UI_32 f_size1,
57 std::string f_Name2, UI_32 f_size2) {
58 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
59 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
60 if ((NULL == this->m_pFileWriter) && (NULL == this->m_pUdpWriter)
61 && (NULL != f_pLoggerCfg)) {
62 this->m_pFileWriter = new (std::nothrow) CCachedFileWriter();
63 this->m_pUdpWriter = new (std::nothrow) CUdpWriter();
64 m_pLoggerCfg = f_pLoggerCfg;
65 m_ipAddress = f_Name2;
69 EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Initialize(m_pLoggerCfg,
72 EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Initialize(m_pLoggerCfg,
76 ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
77 eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
78 if (l_eStatus == eFrameworkunifiedStatusOK) {
79 l_eStatus = this->Open();
82 l_eStatus = eFrameworkunifiedStatusNullPointer;
84 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
89 EFrameworkunifiedStatus CUdpFileWriter::Open(void) { // LCOV_EXCL_START 8:dead code
90 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
91 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
92 if ((NULL != this->m_pFileWriter) && (NULL != this->m_pUdpWriter)) {
93 EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Open();
94 EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Open();
96 ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
97 eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
104 BOOL CUdpFileWriter::IsOpen(void) { // LCOV_EXCL_START 8:dead code
105 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
107 if ((this->m_pUdpWriter != NULL) && (this->m_pFileWriter != NULL)) {
108 l_ret = (m_pUdpWriter->IsOpen() && m_pFileWriter->IsOpen());
114 // LCOV_EXCL_START 8:dead code
115 EFrameworkunifiedStatus CUdpFileWriter::Write(UI_8* f_data, UI_32 f_length,
116 SI_32& f_bytesWritten) {
117 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
118 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
119 if ((NULL != this->m_pUdpWriter)) {
120 l_eStatus = this->m_pUdpWriter->Write(f_data, f_length, f_bytesWritten);
121 LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pUdpWriter->Write() failed.");
124 if ((NULL != this->m_pFileWriter)) {
125 l_eStatus = this->m_pFileWriter->Write(f_data, f_length, f_bytesWritten);
126 LOG_STATUS_IF_ERRORED(l_eStatus, "this->m_pFileWriter->Write() failed.");
128 l_eStatus = eFrameworkunifiedStatusFail;
134 void CUdpFileWriter::Close() { // LCOV_EXCL_START 8:dead code
135 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
136 if (this->m_pFileWriter != NULL) {
137 this->m_pFileWriter->Close();
138 delete (this->m_pFileWriter);
139 this->m_pFileWriter = NULL;
141 if (this->m_pUdpWriter != NULL) {
142 this->m_pUdpWriter->Close();
143 delete (this->m_pUdpWriter);
144 this->m_pUdpWriter = NULL;
149 EFrameworkunifiedStatus CUdpFileWriter::FlushCache(void) { // LCOV_EXCL_START 8:dead code
150 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
151 return (this->m_pFileWriter->FlushCache());
155 EFrameworkunifiedStatus CUdpFileWriter::UpdateLoggingParameters(void) { // LCOV_EXCL_START 8:dead code
156 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
157 return (this->m_pUdpWriter->UpdateLoggingParameters());
159 } // namespace ReaderWriter