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/reader/queue_reader.h"
25 namespace ReaderWriter {
26 CQueueReader::CQueueReader()
28 m_queName("") { // LCOV_EXCL_BR_LINE 11:except,C++ STL
31 CQueueReader::~CQueueReader() {
37 EFrameworkunifiedStatus CQueueReader::Initialize(CLoggerCfg* f_pLoggerCfg,
38 std::string f_name, UI_32 f_maxSize) {
39 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
40 if (f_pLoggerCfg != NULL) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API
41 this->m_pLoggerCfg = f_pLoggerCfg;
42 // Check for invalid name
43 if (f_name.length() != 0) { // LCOV_EXCL_BR_LINE 6:it can not be 0
45 l_eStatus = this->Open();
48 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
52 EFrameworkunifiedStatus CQueueReader::Open(void) {
53 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
55 if (-1 != m_handle) { // LCOV_EXCL_BR_LINE 6:Because m_handle is always -1
56 // Queue already opened, no action required.
57 l_eStatus = eFrameworkunifiedStatusOK;
58 } else if (m_queName.length() != 0) { // LCOV_EXCL_BR_LINE 6:Because m_queName is not always an empty string
59 const UI_32 MAX_MESSAGES_STORED_IN_QUEUE = 512;
60 struct mq_attr mqattr;
62 mqattr.mq_maxmsg = MAX_MESSAGES_STORED_IN_QUEUE;
63 mqattr.mq_msgsize = MAX_QUEUE_MSG_SIZE;
65 this->m_handle = mq_open(m_queName.c_str(), O_RDONLY | O_CREAT, 0666,
67 if (-1 != m_handle) { // LCOV_EXCL_BR_LINE 5:mq_open cannot be passed because it cannot be turned mock
68 l_eStatus = eFrameworkunifiedStatusOK;
71 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
75 BOOL CQueueReader::IsOpen(void) {
76 return (-1 != m_handle) ? TRUE : FALSE; // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set
79 EFrameworkunifiedStatus CQueueReader::Read(UI_8* f_data, UI_32 f_length,
81 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
83 if (this->m_handle != -1) { // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set
84 if (f_length <= MAX_QUEUE_MSG_SIZE) { // LCOV_EXCL_BR_LINE 6:Because the applicable variable cannot be changed from the external API
85 f_bytesRead = static_cast<SI_32>(mq_receive(this->m_handle, reinterpret_cast<char *>(f_data),
86 (size_t) MAX_QUEUE_MSG_SIZE, NULL));
88 if ((0 <= f_bytesRead) && ((UI_32) f_bytesRead <= f_length)) { // LCOV_EXCL_BR_LINE 6:Because the condition cannot be set
89 l_eStatus = eFrameworkunifiedStatusOK;
96 void CQueueReader::Close(void) {
97 if (this->m_handle != -1) { // LCOV_EXCL_BR_LINE 200: m_handle is aways not -1
98 (void) mq_close(this->m_handle);
101 } // namespace ReaderWriter