Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / systemservice / logger_service / server / src / udp_file_writer.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SS_LoggerService
19 /// \brief    TODO
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include "readerWriter/writer/udp_file_writer.h"
23 #include "readerWriter/writer/file_writer.h"
24 #include "readerWriter/writer/cached_file_writer.h"
25
26 namespace ReaderWriter {
27
28 // LCOV_EXCL_START 8:dead code
29 CUdpFileWriter::CUdpFileWriter()
30     : m_pUdpWriter(NULL),
31       m_pFileWriter(NULL),
32       m_pLoggerCfg(NULL),
33       m_ipAddress(""),
34       m_port(0),
35       m_FileName(""),
36       m_FileSize(0) {
37   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
38 }
39 // LCOV_EXCL_STOP
40
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;
46   }
47   if (this->m_pUdpWriter != NULL) {
48     delete (this->m_pUdpWriter);
49     this->m_pUdpWriter = NULL;
50   }
51 }
52 // LCOV_EXCL_STOP
53
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;
66     m_port = f_size2;
67     m_FileName = f_Name1;
68     m_FileSize = f_size1;
69     EFrameworkunifiedStatus l_eStatus1 = this->m_pUdpWriter->Initialize(m_pLoggerCfg,
70                                                            m_ipAddress, m_port,
71                                                            "", 0);
72     EFrameworkunifiedStatus l_eStatus2 = this->m_pFileWriter->Initialize(m_pLoggerCfg,
73                                                             m_FileName,
74                                                             m_FileSize, "", 0);
75     l_eStatus =
76         ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
77             eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
78     if (l_eStatus == eFrameworkunifiedStatusOK) {
79       l_eStatus = this->Open();
80     }
81   } else {
82     l_eStatus = eFrameworkunifiedStatusNullPointer;
83   }
84   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
85   return (l_eStatus);
86 }
87 // LCOV_EXCL_STOP
88
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();
95     l_eStatus =
96         ((l_eStatus1 != eFrameworkunifiedStatusOK) || (eFrameworkunifiedStatusOK != l_eStatus2)) ?
97             eFrameworkunifiedStatusFail : eFrameworkunifiedStatusOK;
98   }
99
100   return (l_eStatus);
101 }
102 // LCOV_EXCL_STOP
103
104 BOOL CUdpFileWriter::IsOpen(void) {  // LCOV_EXCL_START 8:dead code
105   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
106   BOOL l_ret = FALSE;
107   if ((this->m_pUdpWriter != NULL) && (this->m_pFileWriter != NULL)) {
108     l_ret = (m_pUdpWriter->IsOpen() && m_pFileWriter->IsOpen());
109   }
110   return l_ret;
111 }
112 // LCOV_EXCL_STOP
113
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.");
122   }
123
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.");
127   } else {
128     l_eStatus = eFrameworkunifiedStatusFail;
129   }
130   return (l_eStatus);
131 }
132 // LCOV_EXCL_STOP
133
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;
140   }
141   if (this->m_pUdpWriter != NULL) {
142     this->m_pUdpWriter->Close();
143     delete (this->m_pUdpWriter);
144     this->m_pUdpWriter = NULL;
145   }
146 }
147 // LCOV_EXCL_STOP
148
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());
152 }
153 // LCOV_EXCL_STOP
154
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());
158 }
159 }  // namespace ReaderWriter
160
161 // LCOV_EXCL_STOP