Re-organized sub-directory by category
[staging/basesystem.git] / service / system / logger_service / server / src / 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 <string>
23 #include <new>
24 #include <iostream>
25 #include "readerWriter/writer/writer.h"
26 #include "readerWriter/writer/file_writer.h"
27 #include "readerWriter/writer/udp_writer.h"
28 #include "readerWriter/writer/udp_file_writer.h"
29 #include "readerWriter/writer/cached_file_writer.h"
30
31 namespace ReaderWriter {
32
33 CWriter::CWriter()
34     : m_pLoggerCfg(NULL) {
35 }
36
37 CWriter::~CWriter() {
38 }
39
40 CWriter* CWriter::OpenWriter(CLoggerCfg* f_pLoggerCfg, EReaderType f_type,
41                              std::string f_Name1, UI_32 f_size1,
42                              std::string f_Name2, UI_32 f_size2) {
43   CWriter* l_ret = NULL;
44   if ((f_Name1.length() != 0) && (f_pLoggerCfg != NULL)) {  // LCOV_EXCL_BR_LINE 200:As it is always TRUE
45     switch (f_type) {// LCOV_EXCL_BR_LINE 200:As it must be eReaderWriterTypeQueue or eReaderWriterTypeMem
46       case eReaderWriterTypeFile:
47         l_ret = new (std::nothrow) CCachedFileWriter();  // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new
48         break;
49
50       case eReaderWriterTypeUdp:
51         l_ret = new (std::nothrow) CUdpWriter();  // LCOV_EXCL_BR_LINE 5:Cannot pass because it cannot be new
52         break;
53       case eReaderWriterTypeUdpAndFile:  // LCOV_EXCL_START 8:dead code
54         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
55         if (f_Name2.length() != 0) {
56           l_ret = new (std::nothrow) CUdpFileWriter();
57         }
58       // LCOV_EXCL_STOP
59       default:
60         break;
61     }
62   }
63   if (NULL != l_ret) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
64     if (eFrameworkunifiedStatusOK  != l_ret->Initialize(f_pLoggerCfg, f_Name1, f_size1, f_Name2, f_size2)) {
65       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Open Writer Failed");
66       delete (l_ret);
67       l_ret = NULL;
68     }
69   }
70
71   return l_ret;
72 }
73
74 EFrameworkunifiedStatus CWriter::FlushCache(void) {  // LCOV_EXCL_START 8:Base class virtual functions
75   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
76   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Default function called!");
77   return (eFrameworkunifiedStatusOK);
78 }
79 // LCOV_EXCL_STOP
80
81 EFrameworkunifiedStatus CWriter::UpdateLoggingParameters(void) {
82   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Default function called!");
83   return (eFrameworkunifiedStatusOK);
84 }
85 }  // namespace ReaderWriter
86