summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/ss_logger_reader_writer_control.cpp
blob: 692cab8d00554808ee1082324725e18c3b29c633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * ss_logger_reader_writer_control.cpp
 */
#include "ss_logger_reader_writer_control.h"
#include <boost/bind.hpp>
#include <native_service/ns_sharedmem.h>
#include <native_service/ns_transmit_log.h>
#include <native_service/ns_logger_if.h>
#include <string>
#include "ss_logger_common.h"

#define LOGGERSERVICELOG_REMOTE_IP_PORT    3500
#define TRANSMIT_REMOTE_IP_PORT    3500

CReaderWriterControl::CReaderWriterControl()
    : m_pLoggerCfg(NULL) {  // LCOV_EXCL_BR_LINE 11:Unexpected branch
}

CReaderWriterControl::~CReaderWriterControl() {  // LCOV_EXCL_START 14:globle instance
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
}
// LCOV_EXCL_STOP

EFrameworkunifiedStatus CReaderWriterControl::Initialize(CLoggerCfg * f_pLoggerCfg) {
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  if (NULL != f_pLoggerCfg) {  // LCOV_EXCL_BR_LINE 200:As it is not always NULL
    this->m_pLoggerCfg = f_pLoggerCfg;

    l_eStatus = m_debugReaderWriter.Initialize(  // LCOV_EXCL_BR_LINE 11:Unexpected branch
        f_pLoggerCfg, ReaderWriter::eReaderWriterTypeMem, std::string(FRAMEWORKUNIFIEDLOG_SHAREDMEM_NAME),
        FRAMEWORKUNIFIEDLOG_SHAREDMEM_SIZE, ReaderWriter::eReaderWriterTypeUdp,
        std::string("169.254.80.9"), LOGGERSERVICELOG_REMOTE_IP_PORT, "", 0);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (eFrameworkunifiedStatusOK == l_eStatus) {  // LCOV_EXCL_BR_LINE 200:To ensure success
      l_eStatus = m_debugReaderWriter.Start(std::string("pdg.LogQueR"));
    }

    LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15:macro
        l_eStatus, "m_debugReaderWriter.Start(std::string(pdg.TransQueR)");


    l_eStatus = m_transmitReaderWriter.Initialize(  // LCOV_EXCL_BR_LINE 11:Unexpected branch
        f_pLoggerCfg, ReaderWriter::eReaderWriterTypeMem,
        std::string(TRANSMIT_LOG_SHAREDMEM_NAME), TRANSMIT_LOG_SHAREDMEM_SIZE,
        ReaderWriter::eReaderWriterTypeUdp, std::string("169.254.80.9"),
        TRANSMIT_REMOTE_IP_PORT, "", 0);  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    if (eFrameworkunifiedStatusOK == l_eStatus) {    // LCOV_EXCL_BR_LINE 6:it can not be fail
      l_eStatus = m_transmitReaderWriter.Start(std::string("pdg.TransQueR"));  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    }

    LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15:macro
        l_eStatus, "m_transmitReaderWriter.Start(std::string(pdg.TransQueR)");


    l_eStatus = m_performanceReaderWriter.Initialize(  // LCOV_EXCL_BR_LINE 11:Unexpected branch
        f_pLoggerCfg, ReaderWriter::eReaderWriterTypeQueue, std::string("/NSplog"), 0,
        ReaderWriter::eReaderWriterTypeFile, std::string(PERFORMANCE_LOG_PATH_FN),
        f_pLoggerCfg->m_performanceLogMaxFileSize, std::string("169.254.80.9"),
        0);  // LCOV_EXCL_BR_LINE 11:except,C++ STL

    if (eFrameworkunifiedStatusOK == l_eStatus) {    // LCOV_EXCL_BR_LINE 6:it can not be fail
      l_eStatus = m_performanceReaderWriter.Start(
          std::string("pdg.PerformQueR"));  // LCOV_EXCL_BR_LINE 11:except,C++ STL
    }

    LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15:macro
        l_eStatus,
        "m_performanceReaderWriter.Start(std::string(pdg.PerformQueR)");


    this->m_pLoggerCfg->AddLoggingParamCB(
        boost::bind(&CReaderWriterControl::UpdateLoggingParams, this, _1));
  }
  return (l_eStatus);
}

EFrameworkunifiedStatus CReaderWriterControl::UpdateLoggingParams(void* param) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  l_eStatus = this->m_debugReaderWriter.UpdateLoggingParameters();
  LOG_STATUS_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15:macro
                        "this->m_debugReaderWriter.UpdateLoggingParameters()");

  l_eStatus = this->m_transmitReaderWriter.UpdateLoggingParameters();
  LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15:macro
      l_eStatus, "this->m_transmitReaderWriter.UpdateLoggingParameters()");

  l_eStatus = this->m_performanceReaderWriter.UpdateLoggingParameters();
  LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 15:macro
      l_eStatus,
      "this->m_performanceReaderWriter."
      "UpdateLoggingParameters()");

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus);
  return (l_eStatus);
}

EFrameworkunifiedStatus CReaderWriterControl::FlushCache(EReaderWriterType f_type) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
  switch (f_type) {  // LCOV_EXCL_BR_LINE 8: eReaderWriterLogDebug and eReaderWriterLogInvalid can not be called
    // LCOV_EXCL_START 8: dead code
    case eReaderWriterLogDebug:
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      l_eStatus = this->m_debugReaderWriter.FlushCache(
          std::string(DEBUG_LOG_PATH_FN));
      LOG_STATUS_IF_ERRORED(
          l_eStatus, "this->m_debugReaderWriter.FlushCache(DEBUG_LOG_PATH_FN)");
      break;
    // LCOV_EXCL_STOP
    case eReaderWriterLogTransmit:
      l_eStatus = this->m_transmitReaderWriter.FlushCache(
          std::string(TRANSMIT_LOG_PATH_FN));
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "this->m_debugReaderWriter.FlushCache(TRANSMIT_LOG_PATH_FN)");
      break;

    case eReaderWriterLogPerformance:
      l_eStatus = this->m_performanceReaderWriter.FlushCache(
          std::string(PERFORMANCE_LOG_PATH_FN));
      LOG_STATUS_IF_ERRORED(
          l_eStatus,
          "this->m_debugReaderWriter.FlushCache(PERFORMANCE_LOG_PATH_FN)");
      break;
    // LCOV_EXCL_START 8: dead code
    case eReaderWriterLogInvalid:
    default:
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      break;
    // LCOV_EXCL_STOP
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "- : %d", l_eStatus);
  return (l_eStatus);
}