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/cached_file_writer.h"
23 #include <native_service/frameworkunified_types.h>
25 namespace ReaderWriter {
27 CCachedFileWriter::CCachedFileWriter() {
28 std::memset(this->m_buffer, 0, CACHED_BLOCK_SIZE);
32 CCachedFileWriter::~CCachedFileWriter() {
35 EFrameworkunifiedStatus CCachedFileWriter::Write(UI_8* f_data, UI_32 f_length,
36 SI_32& f_bytesWritten) {
37 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
39 if (f_data != NULL) { // LCOV_EXCL_BR_LINE 200: f_data can not be null
40 if ((this->m_index + f_length) > CACHED_BLOCK_SIZE) { // LCOV_EXCL_BR_LINE 200: data size can not over 4*1024
41 l_eStatus = this->FlushCache();
43 if (f_length > CACHED_BLOCK_SIZE) { // LCOV_EXCL_BR_LINE 200: data size can not over 4*1024
44 // LCOV_EXCL_START 200: data size can not over 4*1024
45 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
46 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Possible memory corruption.");
50 " Error. Length(%d) bigger than cache. Will dump memory to core and ignore data. ",
54 (void) std::memcpy(&this->m_buffer[this->m_index], f_data, f_length);
55 this->m_index += f_length;
56 f_bytesWritten = f_length;
59 l_eStatus = eFrameworkunifiedStatusFail;
65 EFrameworkunifiedStatus CCachedFileWriter::FlushCache(void) {
66 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
68 SI_32 l_writtenTotal = 0;
69 while (((l_writtenTotal >= 0) && ((UI_32) l_writtenTotal < this->m_index))
70 && (eFrameworkunifiedStatusOK == l_eStatus)) {
71 l_eStatus = this->WriteData(&this->m_buffer[l_writtenTotal],
72 this->m_index - l_writtenTotal, l_written);
73 l_writtenTotal += l_written;
79 } // namespace ReaderWriter