Remove unused directories and files in video_in_hal
[staging/basesystem.git] / systemservice / logger_service / server / src / cached_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/cached_file_writer.h"
23 #include <native_service/frameworkunified_types.h>
24
25 namespace ReaderWriter {
26
27 CCachedFileWriter::CCachedFileWriter() {
28   std::memset(this->m_buffer, 0, CACHED_BLOCK_SIZE);
29   m_index = 0u;
30 }
31
32 CCachedFileWriter::~CCachedFileWriter() {
33 }
34
35 EFrameworkunifiedStatus CCachedFileWriter::Write(UI_8* f_data, UI_32 f_length,
36                                     SI_32& f_bytesWritten) {
37   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
38   // length check
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();
42     }
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.");
47       FRAMEWORKUNIFIEDLOG(
48           ZONE_ERR,
49           __FUNCTION__,
50           " Error. Length(%d) bigger than cache. Will dump memory to core and ignore data. ",
51           f_length);
52       // LCOV_EXCL_STOP
53     } else {
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;
57     }
58   } else {
59     l_eStatus = eFrameworkunifiedStatusFail;
60   }
61
62   return (l_eStatus);
63 }
64
65 EFrameworkunifiedStatus CCachedFileWriter::FlushCache(void) {
66   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
67   SI_32 l_written = 0;
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;
74     l_written = 0;
75   }
76   this->m_index = 0;
77   return l_eStatus;
78 }
79 }  // namespace ReaderWriter