diff options
Diffstat (limited to 'src/log')
-rw-r--r-- | src/log/RBACoverageLog.cpp | 357 | ||||
-rw-r--r-- | src/log/RBACoverageLog.hpp | 118 | ||||
-rw-r--r-- | src/log/RBAILogCollector.cpp | 26 | ||||
-rw-r--r-- | src/log/RBAILogCollector.hpp | 47 | ||||
-rw-r--r-- | src/log/RBALog.cpp | 43 | ||||
-rw-r--r-- | src/log/RBALog.hpp | 51 | ||||
-rw-r--r-- | src/log/RBALogManager.cpp | 863 | ||||
-rw-r--r-- | src/log/RBALogManager.hpp | 232 |
8 files changed, 1737 insertions, 0 deletions
diff --git a/src/log/RBACoverageLog.cpp b/src/log/RBACoverageLog.cpp new file mode 100644 index 0000000..ca64f14 --- /dev/null +++ b/src/log/RBACoverageLog.cpp @@ -0,0 +1,357 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Coverage Log class definition file + */ + +#include <algorithm> +#include <sstream> +#include "RBACoverageLog.hpp" + +#include "RBAExpression.hpp" +#include "RBALog.hpp" +#include "RBAAbstractConstraint.hpp" +#include "RBAConstraintImpl.hpp" +#include "RBAILogCollector.hpp" +#include "RBAExpressionType.hpp" +#include "RBAConstraintInfo.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +const std::string RBACoverageLog::SEP = ","; +const std::string RBACoverageLog::EXP_SEP = "\t"; +const std::string RBACoverageLog::START = "START"; +const std::string RBACoverageLog::END = "END"; +const std::string RBACoverageLog::EXPRESSION = "EXPRESSION"; +const std::string RBACoverageLog::CONSTRAINT = "Constraint"; +const std::string RBACoverageLog::RULE = "Rule"; + +/** + * Add request log in one line + * + * @param message log message + */ +void +RBACoverageLog::addRequestLogLine(const std::string& message) +{ + notify("#Request#" + message); +} + +/** + * Add allocate setting log in one line + * + * @param message log + */ +void +RBACoverageLog::addPrevResultLogLine(const std::string& message) +{ + notify("#PrevResult#" + message); +} + +/** + * Add result log in one line + * + * @param message + */ +void +RBACoverageLog::addResultLogLine(const std::string& message) +{ + notify("#Result#" + message); +} + +void +RBACoverageLog::addStartLogLine(const std::string& log) +{ + notify(log); +} + +void +RBACoverageLog::addCoverageLogCollector(RBAILogCollector* collector) +{ + collectors_.insert(collector); +} + +void +RBACoverageLog::removeCoverageLogCollector(RBAILogCollector* collector) +{ + auto it = std::find(collectors_.begin(), collectors_.end(), collector); + if(it != collectors_.end()) { + collectors_.erase(it); + } +} + +/** + * Add "Constraint" log in one line + * + * @param message + */ +void +RBACoverageLog::addConstraintLogLine(const std::string& message) +{ + notify("#Constraint#" + message); +} + +/** + * Add "Constraint" start log + * + * @param constraint + */ +void +RBACoverageLog::addConstraintStartLog(const RBAAbstractConstraint* element) +{ + std::string isRuntime = "t"; + std::string eleName = element->getElementName(); + if(element->isConstraint()) { + const RBAConstraintImpl* constraint + = dynamic_cast<const RBAConstraintImpl*>(element); + if(!constraint->isRuntime()) { + isRuntime = "f"; + } + } + addConstraintLogLine(START + SEP + eleName + SEP + isRuntime); +} + +/** + * Add "Constraint" finish log + * + * @param constraint + */ +void +RBACoverageLog::addConstraintEndLog(const RBAAbstractConstraint* element) +{ + addConstraintLogLine(END); +} + +/** + * Add "Constraint expression" execution log + * + * @param expressionText + * @param result + */ +void +RBACoverageLog::addConstraintExpressionLog( + const std::string& expressionText, RBAExecuteResult result) +{ + std::string resultMsg; + if (RBAExecuteResult::TRUE == result) { + resultMsg = "t"; + } else if (RBAExecuteResult::FALSE == result) { + resultMsg = "f"; + } else if (RBAExecuteResult::EXE == result) { + resultMsg = "e"; + } else if (RBAExecuteResult::NOTEXE == result) { + resultMsg = "ne"; + } else { + resultMsg = "skip"; + } + addConstraintLogLine( + EXPRESSION + EXP_SEP + getHierarchy() + EXP_SEP + expressionText + EXP_SEP + + resultMsg); +} + +/** + * Add "Constraint expression" execution log (For Action) + * + * @param expressionText + */ +void +RBACoverageLog::addConstraintExpressionLog(const std::string& expressionText) +{ + addConstraintLogLine(EXPRESSION + EXP_SEP + + getHierarchy() + EXP_SEP + + expressionText); +} + +/** + * Add request cancellation log in one line + * + * @param message + */ +void +RBACoverageLog::addCanceledRequestLogLine(const std::string& message) +{ + notify("#CanceledRequest#" + message); +} + +/** + * Add constraint structure log in one line + * + * @param message + */ +void +RBACoverageLog::addHierarchyOfConstraintLogLine(const std::string& message) +{ + notify("#HierarchyOfConstraint#" + message); +} + +/** + * Add constraint structure start log in one line + * + * @param message + */ +void + +RBACoverageLog:: +addHierarchyOfConstraintStartLog(const RBAAbstractConstraint* element) +{ + std::string isRuntime = "t"; + std::string type = CONSTRAINT; + std::string eleName = element->getElementName(); + if(element->isConstraint()) { + const RBAConstraintImpl* constraint + = dynamic_cast<const RBAConstraintImpl*>(element); + if(!constraint->isRuntime()) { + isRuntime = "f"; + } + } + else if(element->isRule()) { + type = RULE; + } + addHierarchyOfConstraintLogLine(START + SEP + + eleName + SEP + + isRuntime + SEP + type); +} + +/** + * Add constraint structure finish log + * + * @param constraint + */ +void +RBACoverageLog::addHierarchyOfConstraintEndLog(const RBAAbstractConstraint* element) +{ + std::string eleName = element->getElementName(); + addHierarchyOfConstraintLogLine(END + SEP + eleName); +} + +/** + * Add constraint structure execution log + * + * @param expressionText + * @param result + */ +void +RBACoverageLog:: +addHierarchyOfConstraintExpressionLog(const std::string& expressionText, + const RBAExpression* expression) +{ + addHierarchyOfConstraintLogLine(EXPRESSION + EXP_SEP + + getHierarchy() + EXP_SEP + + expressionText + EXP_SEP + + getExpressionType(expression)); +} + +// --------------------------------------------------------- +// Hierarchical information of constraint log for coverage +// --------------------------------------------------------- + +/** + * Initialize the constraint hierarchy + */ +void +RBACoverageLog::initConstraintHierarchy() +{ + hierarchys_.clear(); +} + +/** + * Returns the constraint hierarchy as a string + * + * @return + */ +std::string +RBACoverageLog::getHierarchy() const +{ + std::ostringstream oss; + + std::string pre; + int32_t i=0; + for(std::string now : hierarchys_) { + if((i != 0) && (pre[0] != '#')) { + // If it is the first time and it is not treated as multiple operators, + // add split identifier + oss << "#"; + } + pre = now; + if(now[0] == '#') { + now = now.substr(1, now.length()); + } + oss << now; + i++; + } + + return oss.str(); +} + +/** + * Add constraint hierarchy + * + * @param data + * @return + */ +bool +RBACoverageLog::addHierarchy(const std::string& data) +{ + hierarchys_.push_back(data); + return true; +} + +/** + * Remove constraint hierarchy + * + * @param data + * @return + */ +void +RBACoverageLog::removeHierarchy() +{ + hierarchys_.pop_back(); +} + +/** + * Returns the type string of the expression + * to be output to the hierarchical log + * + * @param expression + * @return + */ +std::string +RBACoverageLog::getExpressionType(const RBAExpression* expression) const +{ + switch(expression->getUnderlyingType()) { + case RBAExpressionType::BOOLEAN: + return "boolean"; + case RBAExpressionType::ACTION: + case RBAExpressionType::SET_OF_ACTION: + return "action"; + default: + return "unknown"; + } +} + +void +RBACoverageLog::notify(const std::string& log) +{ + for(RBAILogCollector* collector : collectors_) { + collector->log(log); + } +} +#endif + +} diff --git a/src/log/RBACoverageLog.hpp b/src/log/RBACoverageLog.hpp new file mode 100644 index 0000000..11e3695 --- /dev/null +++ b/src/log/RBACoverageLog.hpp @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Coverage Log class + */ + +#ifndef RBACOVERAGELOG_HPP +#define RBACOVERAGELOG_HPP + +#include <vector> +#include <set> +#include "RBAILogCollector.hpp" +#include "RBAExecuteResult.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +class RBALog; +class RBAExpression; +class RBAAbstractConstraint; + +class DLL_EXPORT RBACoverageLog +{ +public: + RBACoverageLog()=default; + RBACoverageLog(const RBACoverageLog&)=delete; + RBACoverageLog(const RBACoverageLog&&)=delete; + RBACoverageLog& operator=(const RBACoverageLog&)=delete; + RBACoverageLog& operator=(const RBACoverageLog&&)=delete; + virtual ~RBACoverageLog()=default; + +public: + void addRequestLogLine(const std::string& message); + void addPrevResultLogLine(const std::string& message); + void addResultLogLine(const std::string& message); + void addStartLogLine(const std::string& log); + void addCoverageLogCollector(RBAILogCollector* collector); + void removeCoverageLogCollector(RBAILogCollector* collector); + void addConstraintLogLine(const std::string& message); + void addConstraintStartLog(const RBAAbstractConstraint* element); + void addConstraintEndLog(const RBAAbstractConstraint* element); + void addConstraintExpressionLog(const std::string& expressionText, + const RBAExecuteResult result); + void addConstraintExpressionLog(const std::string& expressionText); + void addCanceledRequestLogLine(const std::string& message); + void addHierarchyOfConstraintLogLine(const std::string& message); + void addHierarchyOfConstraintStartLog(const RBAAbstractConstraint* element); + void addHierarchyOfConstraintEndLog(const RBAAbstractConstraint* element); + void addHierarchyOfConstraintExpressionLog(const std::string& expressionText, + const RBAExpression* expression); + void initConstraintHierarchy(); + std::string getHierarchy() const; + bool addHierarchy(const std::string& data); + void removeHierarchy(); + std::string getExpressionType(const RBAExpression* expression) const; + +public: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + // Delimiters other than constraint expression lines + const static std::string SEP; + // Delimiters of constraint expression line (Tab) + const static std::string EXP_SEP; + const static std::string START; + const static std::string END; + const static std::string EXPRESSION; + const static std::string CONSTRAINT; + const static std::string RULE; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +private: + std::string createLog(std::vector<RBALog*> logs); + void notify(const std::string& log); + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + std::vector<std::string> hierarchys_; // Constraint hierarchy (x#y#z format) + std::set<RBAILogCollector*> collectors_; + std::vector<RBALog*> requestLogs_; + std::vector<RBALog*> resultLogs_; + std::vector<RBALog*> constraintLogs; + std::vector<RBALog*> canceledRequestLogs_; + + // Constraint structure log for finding the denominator of + // constraint coverage. The constraint log is different + // because it also has the execution result. + std::vector<RBALog*> hierarchyOfConstraintLogs_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +}; +#endif + +} +#endif diff --git a/src/log/RBAILogCollector.cpp b/src/log/RBAILogCollector.cpp new file mode 100644 index 0000000..d9765f0 --- /dev/null +++ b/src/log/RBAILogCollector.cpp @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + + /** + * Log collector interface class definition file + */ + +#include "RBAILogCollector.hpp" + +namespace rba +{ + +} diff --git a/src/log/RBAILogCollector.hpp b/src/log/RBAILogCollector.hpp new file mode 100644 index 0000000..b873912 --- /dev/null +++ b/src/log/RBAILogCollector.hpp @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + + /** + * Log collector interface class + */ + +#ifndef RBAILOGCOLLECTOR_HPP +#define RBAILOGCOLLECTOR_HPP + +#include <string> +#include "RBADllExport.hpp" + +namespace rba +{ + +class DLL_EXPORT RBAILogCollector +{ +protected: + RBAILogCollector()=default; + RBAILogCollector(const RBAILogCollector&)=delete; + RBAILogCollector(const RBAILogCollector&&)=delete; + RBAILogCollector& operator=(const RBAILogCollector&)=delete; + RBAILogCollector& operator=(const RBAILogCollector&&)=delete; + virtual ~RBAILogCollector()=default; + +public: + virtual void log(const std::string& logLine)=0; + +}; + +} + +#endif diff --git a/src/log/RBALog.cpp b/src/log/RBALog.cpp new file mode 100644 index 0000000..917ee57 --- /dev/null +++ b/src/log/RBALog.cpp @@ -0,0 +1,43 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Log class definition file + */ + +#include "RBALog.hpp" + +namespace rba { + +RBALog::RBALog(const std::int32_t level, const std::string& log) + : level_{level} + , log_{log} +{ +} + +int32_t +RBALog::getLevel() const +{ + return level_; +} + +const std::string& +RBALog::getLog() const +{ + return log_; +} + +} diff --git a/src/log/RBALog.hpp b/src/log/RBALog.hpp new file mode 100644 index 0000000..d0d44ee --- /dev/null +++ b/src/log/RBALog.hpp @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Log class + */ + +#ifndef RBALOG_HPP +#define RBALOG_HPP + +#include <string> + +namespace rba +{ + +class RBALog +{ +public: + RBALog(const std::int32_t level, const std::string& log); + RBALog(const RBALog&)=delete; + RBALog(const RBALog&&)=delete; + RBALog& operator=(const RBALog&)=delete; + RBALog& operator=(const RBALog&&)=delete; + virtual ~RBALog()=default; + +public: + int32_t getLevel() const; + const std::string& getLog() const; + +private: + int32_t level_; + std::string log_; + +}; + +} + +#endif diff --git a/src/log/RBALogManager.cpp b/src/log/RBALogManager.cpp new file mode 100644 index 0000000..cb1bd83 --- /dev/null +++ b/src/log/RBALogManager.cpp @@ -0,0 +1,863 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Log manager class definition file + */ + +#include <sstream> +#include <bitset> +#include "RBALogManager.hpp" +#include "RBALog.hpp" + +namespace rba +{ + +#ifdef RBA_USE_LOG +RBALogManager* RBALogManager::instance_=nullptr; + +const std::string RBALogManager::STR_TRUE = "true"; +const std::string RBALogManager::STR_FALSE = "false"; +std::string RBALogManager::indent_ = ""; + +RBALogManager::RBALogManager() +{ +} + +// +// Static method +// + +void +RBALogManager::setLogManager(RBALogManager* logManager) +{ + instance_ = logManager; +} + +RBALogManager* +RBALogManager::getLogManager() +{ + return instance_; +} + +void +RBALogManager::setType(std::uint16_t logType) +{ + if(instance_) { + instance_->setTypeImpl(logType); + } +} + +void +RBALogManager::setEnable(std::uint16_t logType, bool sw) +{ + if(instance_) { + instance_->setEnableImpl(logType, sw); + } +} + +void +RBALogManager::init(int32_t level) +{ + if(instance_) { + instance_->initImpl(level); + } +} + +void +RBALogManager::requestLogLine(const std::string& message) +{ + if(instance_) { + instance_->requestLogLineImpl(message); + } +} + +void +RBALogManager::resultLogLine(const std::string& message) +{ + if(instance_) { + instance_->resultLogLineImpl(message); + } +} + +void +RBALogManager::arbitrateAreaLogLine(const std::string& message) +{ + if(instance_) { + instance_->arbitrateAreaLogLineImpl(message); + } +} + +void +RBALogManager::arbitrateContentLogLine(const std::string& message) +{ + if(instance_) { + instance_->arbitrateContentLogLineImpl(message); + } +} + +void +RBALogManager::arbitrateConstraintLogLine(const std::string& message) +{ + if(instance_) { + instance_->arbitrateConstraintLogLineImpl(message); + } +} + +void +RBALogManager::arbitrateConstraintLogicLogLine(const std::string& message) +{ + if(instance_) { + instance_->arbitrateConstraintLogicLogLineImpl(message); + } +} + +void +RBALogManager::allConstraintLogLine(const std::string& message) +{ + if(instance_) { + instance_->allConstraintLogLineImpl(message); + } +} + +void +RBALogManager::cancelRequestLogLine(const std::string& message) +{ + if(instance_) { + instance_->cancelRequestLogLineImpl(message); + } +} + +std::string +RBALogManager::getArbitrateLog() +{ + if(instance_) { + return instance_->getArbitrateLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getAllConstraintLog() +{ + if(instance_) { + return instance_->getAllConstraintLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getCheckAllConstraintLog() +{ + if(instance_) { + return instance_->getCheckAllConstraintLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getRequestLog() +{ + if(instance_) { + return instance_->getRequestLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getPreviousResultLog() +{ + if(instance_) { + return instance_->getPreviousResultLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getResultLog() +{ + if(instance_) { + return instance_->getResultLogImpl(); + } + else { + return ""; + } +} + +std::string +RBALogManager::getCancelRequestLog() +{ + if(instance_) { + return instance_->getCancelRequestLogImpl(); + } + else { + return ""; + } +} + +void +RBALogManager::coverageRequestLogLine(const std::string& message) +{ + if(instance_) { + instance_->coverageRequestLogLineImpl(message); + } +} + +void +RBALogManager::coveragePrevResultLogLine(const std::string& message) +{ + if(instance_) { + instance_->coveragePrevResultLogLineImpl(message); + } +} + +void +RBALogManager::coverageResultLogLine(const std::string& message) +{ + if(instance_) { + instance_->coverageResultLogLineImpl(message); + } +} + +void +RBALogManager::coverageConstraintStartLog(const RBAAbstractConstraint* constraint) +{ + if(instance_) { + instance_->coverageConstraintStartLogImpl(constraint); + } +} + +void +RBALogManager::coverageConstraintEndLog(const RBAAbstractConstraint* constraint) +{ + if(instance_) { + instance_->coverageConstraintEndLogImpl(constraint); + } +} + +void +RBALogManager::coverageConstraintExpressionLog( + const std::string& expressionText, RBAExecuteResult result) { + if (instance_) { + instance_->coverageConstraintExpressionLogImpl(expressionText, result); + } +} + +void +RBALogManager:: +coverageConstraintExpressionLog(const std::string& expressionText) +{ + if(instance_) { + instance_->coverageConstraintExpressionLogImpl(expressionText); + } +} + +void +RBALogManager::coverageCanceledRequestLogLine(const std::string& message) +{ + if(instance_) { + instance_->coverageCanceledRequestLogLineImpl(message); + } +} + +void +RBALogManager::addStartLogLine(const std::string& log) +{ + if(instance_) { + instance_->addStartLogLineImpl(log); + } +} + +void +RBALogManager::addCoverageLogCollector(RBAILogCollector* collector) +{ + coverageLog_.addCoverageLogCollector(collector); +} + +void +RBALogManager::removeCoverageLogCollector(RBAILogCollector* collector) +{ + coverageLog_.removeCoverageLogCollector(collector); +} + +void +RBALogManager::coverageHierarchyOfConstraintLogLine(const std::string& message) +{ + if(instance_) { + instance_->coverageHierarchyOfConstraintLogLineImpl(message); + } +} + +void +RBALogManager:: +coverageHierarchyOfConstraintStartLog(const RBAAbstractConstraint* constraint) +{ + if(instance_) { + instance_->coverageHierarchyOfConstraintStartLogImpl(constraint); + } +} + +void +RBALogManager:: +coverageHierarchyOfConstraintEndLog(const RBAAbstractConstraint* constraint) +{ + if(instance_) { + instance_->coverageHierarchyOfConstraintEndLogImpl(constraint); + } +} + +void +RBALogManager:: +coverageHierarchyOfConstraintExpressionLog(const std::string& expressionText, + RBAExpression* expression) +{ + if(instance_) { + instance_->coverageHierarchyOfConstraintExpressionLogImpl(expressionText, + expression); + + } +} + +void +RBALogManager::initConstraintHierarchy() +{ + if(instance_) { + instance_->initConstraintHierarchyImpl(); + } +} + +bool RBALogManager::addHierarchy(const std::string& data) +{ +{ + if(instance_) { + return instance_->addHierarchyImpl(data); + } + else { + return true; + } +} +} + +void RBALogManager::removeHierarchy() +{ + if(instance_) { + instance_->removeHierarchyImpl(); + } +} + +// +// Private method +// + +void +RBALogManager::setTypeImpl(std::uint16_t logType) +{ + execType_ = logType; +} + +void +RBALogManager::setEnableImpl(std::uint16_t logType, bool sw) +{ + if(sw) { + requestType_ |= logType; + } else { + requestType_ &= ~logType; + } +} + +/** + * initialize log + */ +void +RBALogManager::initImpl(int32_t level) +{ + level_ = level; + requestLogs_.clear(); + previousResultLogs_.clear(); + resultLogs_.clear(); + cancelLogs_.clear(); + checkAllConstraintsLogs_.clear(); + allConstraintLogs_.clear(); + arbitrateLogs_.clear(); +} + +/** + * Output request information log in one line + * @param message + */ +void +RBALogManager::requestLogLineImpl(const std::string& message) +{ + if((TYPE_REQUEST & requestType_) != 0U) { + requestLogs_.push_back(std::make_shared<RBALog>(1, indent_ + message)); + } +} + +/** + * Ouput result information log in one line + * @param message + */ +void +RBALogManager::resultLogLineImpl(const std::string& message) +{ + if((TYPE_RESULT & requestType_ & execType_) != 0U) { + resultLogs_.push_back(std::make_shared<RBALog>(1, indent_ + message)); + } + if((TYPE_PREVIOUS_RESULT & requestType_ & execType_) != 0U) { + previousResultLogs_.push_back(std::make_shared<RBALog>(1, indent_ + message)); + } +} + +/** + * Ouput Area arbitration information log in one line + * @param message + */ +void +RBALogManager::arbitrateAreaLogLineImpl(const std::string& message) +{ + if((TYPE_ARBITRATE & requestType_) != 0U) { + arbitrateLogs_.push_back(std::make_shared<RBALog>(2, indent_ + message)); + } +} + +/** + * Ouput Content arbitration information log in one line + * @param message + */ +void +RBALogManager::arbitrateContentLogLineImpl(const std::string& message) +{ + if((TYPE_ARBITRATE & requestType_) != 0U) { + arbitrateLogs_.push_back(std::make_shared<RBALog>(2, indent_ + message)); + } +} + +/** + * Ouput Constraint confirmation information log in one line + * @param message + */ +void +RBALogManager::arbitrateConstraintLogLineImpl(const std::string& message) +{ + if((TYPE_ARBITRATE & requestType_ & execType_) != 0U) { + arbitrateLogs_.push_back(std::make_shared<RBALog>(3, indent_ + message)); + } + if((TYPE_CHECK_ALL_CONSTRAINTS & requestType_ & execType_) != 0U) { + checkAllConstraintsLogs_.push_back(std::make_shared<RBALog>(3, indent_ + message)); + } + if((TYPE_CANCEL_REQUEST & requestType_ & execType_) != 0U) { + cancelLogs_.push_back(std::make_shared<RBALog>(3, indent_ + message)); + } +} + +/** + * Ouput Constraint logic information log in one line + * @param message + */ +void +RBALogManager::arbitrateConstraintLogicLogLineImpl(const std::string& message) +{ + if((TYPE_ARBITRATE & requestType_ & execType_) != 0U) { + arbitrateLogs_.push_back(std::make_shared<RBALog>(4, indent_ + message)); + } + if((TYPE_CHECK_ALL_CONSTRAINTS & requestType_ & execType_) != 0U) { + checkAllConstraintsLogs_.push_back(std::make_shared<RBALog>(4, indent_ + message)); + } + if((TYPE_CANCEL_REQUEST & requestType_ & execType_) != 0U) { + cancelLogs_.push_back(std::make_shared<RBALog>(4, indent_ + message)); + } +} + +/** + * Ouput all Constraint check log in one line + * @param message + */ +void +RBALogManager::allConstraintLogLineImpl(const std::string& message) +{ + if((TYPE_ALL_CONSTRAINTS & requestType_) != 0U) { + allConstraintLogs_.push_back(std::make_shared<RBALog>(0, indent_ + message)); + } +} + +/** + * Ouput Request cancel log in one line + * @param message + */ +void +RBALogManager::cancelRequestLogLineImpl(const std::string& message) +{ + if((TYPE_CANCEL_REQUEST & requestType_) != 0U) { + cancelLogs_.push_back(std::make_shared<RBALog>(2, indent_ + message)); + } +} + +/** + * Get the string of arbitration log below the set level + * @return + */ +std::string +RBALogManager::getArbitrateLogImpl() +{ + std::ostringstream oss; + for(auto it=arbitrateLogs_.begin(); it!=arbitrateLogs_.end(); it++) { + if(it->get()->getLevel() <= level_) { + oss << it->get()->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get all constraints log + * @return + */ +std::string +RBALogManager::getAllConstraintLogImpl() +{ + std::ostringstream oss; + for(auto it=allConstraintLogs_.begin(); it!=allConstraintLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get check all constraints log + * @return + */ +std::string +RBALogManager::getCheckAllConstraintLogImpl() +{ + std::ostringstream oss; + for(auto it=checkAllConstraintsLogs_.begin(); + it!=checkAllConstraintsLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get request log + * @return + */ +std::string +RBALogManager::getRequestLogImpl() +{ + std::ostringstream oss; + for(auto it=requestLogs_.begin(); it!=requestLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get previous result log + * @return + */ +std::string +RBALogManager::getPreviousResultLogImpl() +{ + std::ostringstream oss; + for(auto it=previousResultLogs_.begin(); + it!=previousResultLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get result log + * @return + */ +std::string +RBALogManager::getResultLogImpl() +{ + std::ostringstream oss; + for(auto it=resultLogs_.begin(); it!=resultLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +/** + * get rule log + * @return + */ +std::string +RBALogManager::getCancelRequestLogImpl() +{ + std::ostringstream oss; + for(auto it=cancelLogs_.begin(); it!=cancelLogs_.end(); it++) { + RBALog* log = it->get(); + if(log->getLevel() <= level_) { + oss << log->getLog() << std::endl; + } + } + + return oss.str(); +} + +// ------------------------------ +// Log information for coverage +// ------------------------------ +/** + * Add request log for coverage in one line + * @param message + */ +void +RBALogManager::coverageRequestLogLineImpl(const std::string& message) +{ + coverageLog_.addRequestLogLine(message); +} + +/** + * Add Allocate setting log for coverage in one line + * @param message + */ +void +RBALogManager::coveragePrevResultLogLineImpl(const std::string& message) +{ + coverageLog_.addPrevResultLogLine(message); +} + +/** + * Add result log for coverage in one line + * @param message + */ +void +RBALogManager::coverageResultLogLineImpl(const std::string& message) +{ + coverageLog_.addResultLogLine(message); +} + +/** + * Add Constraint start log for coverage + * @param constraint + */ +void +RBALogManager::coverageConstraintStartLogImpl(const RBAAbstractConstraint* constraint) +{ + if ((execType_ == TYPE_ARBITRATE) || + (execType_ == TYPE_CANCEL_REQUEST) || + (execType_ == TYPE_NOTHING)) { + coverageLog_.addConstraintStartLog(constraint); + } +} + +/** + * Add Constraint finish log for coverage + * @param constraint + */ +void +RBALogManager::coverageConstraintEndLogImpl(const RBAAbstractConstraint* constraint) +{ + if ((execType_ == TYPE_ARBITRATE) || + (execType_ == TYPE_CANCEL_REQUEST) || + (execType_ == TYPE_NOTHING)) { + coverageLog_.addConstraintEndLog(constraint); + } +} + +/** + * Add Constraint execution log for coverage + * @param expressionText + * @param result + */ +void +RBALogManager::coverageConstraintExpressionLogImpl( + const std::string& expressionText, RBAExecuteResult result) +{ + if ((execType_ == TYPE_ARBITRATE) || + (execType_ == TYPE_CANCEL_REQUEST) || + (execType_ == TYPE_NOTHING)) { + coverageLog_.addConstraintExpressionLog(expressionText, result); + } +} + +/** + * Add action constraint execution log for coverage + * @param expressionText + */ +void +RBALogManager:: +coverageConstraintExpressionLogImpl(const std::string& expressionText) +{ + coverageLog_.addConstraintExpressionLog(expressionText); +} + +/** + * Add request cancellation log for coverage in one line + * @param message + */ +void +RBALogManager::coverageCanceledRequestLogLineImpl(const std::string& message) +{ + coverageLog_.addCanceledRequestLogLine(message); +} + +/** + * add start log line + * @param log + */ +void +RBALogManager::addStartLogLineImpl(const std::string& log) +{ + coverageLog_.addStartLogLine(log); +} + +/** + * Add Constraint structure log for coverage in one line + * @param message + */ +void +RBALogManager::coverageHierarchyOfConstraintLogLineImpl(const std::string& message) +{ + coverageLog_.addHierarchyOfConstraintLogLine(message); +} + +/** + * Add Constraint structure start log for coverage + * @param constraint + */ +void +RBALogManager:: +coverageHierarchyOfConstraintStartLogImpl(const RBAAbstractConstraint* constraint) +{ + coverageLog_.addHierarchyOfConstraintStartLog(constraint); +} + +/** + * Add Constraint structure finish log for coverage + * @param constraint + */ +void +RBALogManager:: +coverageHierarchyOfConstraintEndLogImpl(const RBAAbstractConstraint* constraint) +{ + coverageLog_.addHierarchyOfConstraintEndLog(constraint); +} + +/** + * Add Constraint structure formula log for coverage + * @param expressionText + * @param expression + */ +void +RBALogManager:: +coverageHierarchyOfConstraintExpressionLogImpl(const std::string& expressionText, + const RBAExpression* expression) +{ + coverageLog_.addHierarchyOfConstraintExpressionLog(expressionText, + expression); +} + +// ---------------------------------------------------------- +// Hierarchical information of constraint log for coverage +// ---------------------------------------------------------- +/** + * Initilize hierarchical structure of constraint + */ +void +RBALogManager::initConstraintHierarchyImpl() +{ + coverageLog_.initConstraintHierarchy(); +} + +/** + * Add hierarchical structure of constraint + * @param data + * @return + */ +bool +RBALogManager::addHierarchyImpl(const std::string& data) +{ + if ((execType_ == TYPE_ARBITRATE) || + (execType_ == TYPE_CANCEL_REQUEST) || + (execType_ == TYPE_NOTHING)) { + return coverageLog_.addHierarchy(data); + } else { + return false; + } +} + +/** + * Remove hierarchical structure of constraint + * @param data + * @return + */ +void +RBALogManager::removeHierarchyImpl() +{ + if ((execType_ == TYPE_ARBITRATE) || + (execType_ == TYPE_CANCEL_REQUEST) || + (execType_ == TYPE_NOTHING)) { + coverageLog_.removeHierarchy(); + } +} + +const std::string& +RBALogManager::boolToString(const bool value) +{ + if (value == true) { + return STR_TRUE; + } else { + return STR_FALSE; + } +} + +void +RBALogManager::setIndent(std::int32_t nest) +{ + indent_ = ""; + for (std::int32_t i = 0; i < nest; ++i) { + indent_ += " "; + } +} +#endif + +} diff --git a/src/log/RBALogManager.hpp b/src/log/RBALogManager.hpp new file mode 100644 index 0000000..a8f2427 --- /dev/null +++ b/src/log/RBALogManager.hpp @@ -0,0 +1,232 @@ +/** + * Copyright (c) 2019 DENSO 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. + */ + +/** + * Log manager class header file + */ + +#ifndef RBALOGMANAGER_HPP +#define RBALOGMANAGER_HPP + +#include <memory> +#include "RBACoverageLog.hpp" + +#ifdef RBA_USE_LOG + +namespace rba +{ + +class DLL_EXPORT RBALogManager +{ +public: + RBALogManager(); + RBALogManager(const RBALogManager&)=delete; + RBALogManager(const RBALogManager&&)=delete; + RBALogManager& operator=(const RBALogManager&)=delete; + RBALogManager& operator=(const RBALogManager&&)=delete; + virtual ~RBALogManager()=default; + + // Interefae for RBA Tool + static void init(int32_t level); + void addCoverageLogCollector(RBAILogCollector* collector); + void removeCoverageLogCollector(RBAILogCollector* collector); + static void addStartLogLine(const std::string& log); + static void coverageHierarchyOfConstraintLogLine(const std::string& message); + static void setLogManager(RBALogManager* logManager); + static RBALogManager* getLogManager(); + static void setEnable(std::uint16_t logType, bool sw=true); + + // Interface private to the outside of RBA + static void setType(std::uint16_t logType); + static void requestLogLine(const std::string& message); + static void resultLogLine(const std::string& message); + static void arbitrateAreaLogLine(const std::string& message); + static void arbitrateContentLogLine(const std::string& message); + static void arbitrateConstraintLogLine(const std::string& message); + static void arbitrateConstraintLogicLogLine(const std::string& message); + static void allConstraintLogLine(const std::string& message); + static void cancelRequestLogLine(const std::string& message); + static std::string getArbitrateLog(); + static std::string getAllConstraintLog(); + static std::string getCheckAllConstraintLog(); + static std::string getRequestLog(); + static std::string getPreviousResultLog(); + static std::string getResultLog(); + static std::string getCancelRequestLog(); + static void coverageRequestLogLine(const std::string& message); + static void coveragePrevResultLogLine(const std::string& message); + static void coverageResultLogLine(const std::string& message); + static void coverageConstraintStartLog(const RBAAbstractConstraint* constraint); + static void coverageConstraintEndLog(const RBAAbstractConstraint* constraint); + static void coverageConstraintExpressionLog(const std::string& expressionText, + RBAExecuteResult result); + static void coverageConstraintExpressionLog(const std::string& expressionText); + static void coverageCanceledRequestLogLine(const std::string& message); + static void coverageHierarchyOfConstraintStartLog(const RBAAbstractConstraint* constraint); + static void coverageHierarchyOfConstraintEndLog(const RBAAbstractConstraint* constraint); + static void coverageHierarchyOfConstraintExpressionLog(const std::string& expressionText, + RBAExpression* expression); + static void initConstraintHierarchy(); + static bool addHierarchy(const std::string& data); + static void removeHierarchy(); + static const std::string& boolToString(const bool value); + static void setIndent(std::int32_t nest); + +private: + void setTypeImpl(std::uint16_t logType); + void setEnableImpl(std::uint16_t logType, bool sw=true); + void initImpl(int32_t level); + void requestLogLineImpl(const std::string& message); + void resultLogLineImpl(const std::string& message); + void arbitrateAreaLogLineImpl(const std::string& message); + void arbitrateContentLogLineImpl(const std::string& message); + void arbitrateConstraintLogLineImpl(const std::string& message); + void arbitrateConstraintLogicLogLineImpl(const std::string& message); + void allConstraintLogLineImpl(const std::string& message); + void cancelRequestLogLineImpl(const std::string& message); + std::string getArbitrateLogImpl(); + std::string getAllConstraintLogImpl(); + std::string getCheckAllConstraintLogImpl(); + std::string getRequestLogImpl(); + std::string getPreviousResultLogImpl(); + std::string getResultLogImpl(); + std::string getCancelRequestLogImpl(); + void coverageRequestLogLineImpl(const std::string& message); + void coveragePrevResultLogLineImpl(const std::string& message); + void coverageResultLogLineImpl(const std::string& message); + void coverageConstraintStartLogImpl(const RBAAbstractConstraint* constraint); + void coverageConstraintEndLogImpl(const RBAAbstractConstraint* constraint); + void coverageConstraintExpressionLogImpl(const std::string& expressionText, + RBAExecuteResult result); + void coverageConstraintExpressionLogImpl(const std::string& expressionText); + void coverageCanceledRequestLogLineImpl(const std::string& message); + void addStartLogLineImpl(const std::string& log); + void coverageHierarchyOfConstraintLogLineImpl(const std::string& message); + void coverageHierarchyOfConstraintStartLogImpl(const RBAAbstractConstraint* constraint); + void coverageHierarchyOfConstraintEndLogImpl(const RBAAbstractConstraint* constraint); + void coverageHierarchyOfConstraintExpressionLogImpl(const std::string& expressionText, + const RBAExpression* expression); + void initConstraintHierarchyImpl(); + bool addHierarchyImpl(const std::string& data); + void removeHierarchyImpl(); + +public: + const static std::uint16_t TYPE_NOTHING =0x0000U; + const static std::uint16_t TYPE_ALL_CONSTRAINTS =0x0001U; + const static std::uint16_t TYPE_REQUEST =0x0002U; + const static std::uint16_t TYPE_PREVIOUS_RESULT =0x0004U; + const static std::uint16_t TYPE_ARBITRATE =0x0008U; + const static std::uint16_t TYPE_CANCEL_REQUEST =0x0010U; + const static std::uint16_t TYPE_CHECK_ALL_CONSTRAINTS =0x0020U; + const static std::uint16_t TYPE_RESULT =0x0080U; + /* + * Used when implementing log output feature in C++. + * Currebtly, the file is output on the RBATool side + * when TYPE_SAVE_LOG is on, so this information is not referenced. + */ + const static std::uint16_t TYPE_SAVE_LOG = 0x0100U; + +private: +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4251) +#endif + const static std::string STR_TRUE; + const static std::string STR_FALSE; + static RBALogManager* instance_; + static std::string indent_; + std::vector<std::shared_ptr<RBALog>> requestLogs_; + std::vector<std::shared_ptr<RBALog>> previousResultLogs_; + std::vector<std::shared_ptr<RBALog>> resultLogs_; + std::vector<std::shared_ptr<RBALog>> cancelLogs_; + std::vector<std::shared_ptr<RBALog>> checkAllConstraintsLogs_; + int32_t level_ = 0; + std::uint16_t requestType_ = RBALogManager::TYPE_NOTHING; + std::uint16_t execType_ = RBALogManager::TYPE_NOTHING; + std::vector<std::shared_ptr<RBALog>> allConstraintLogs_; + std::vector<std::shared_ptr<RBALog>> arbitrateLogs_; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + RBACoverageLog coverageLog_; + +}; + +} + +// @Deviation (PRE00-CPP,Rule-16_0_4,Rule-16_2_1) +// [Contents that deviate from the rules] +// Function-like macros shall not be defined. +// [Explanation that there is no problem even if it deviates from the rules] +// Do not modify because it will cause processing load +// if it is not a function macro +#define LOG_initConstraintHierarchy() \ + rba::RBALogManager::initConstraintHierarchy() +#define LOG_removeHierarchy() \ + rba::RBALogManager::removeHierarchy() +#define LOG_coverageHierarchyOfConstraintStartLog(log) \ + rba::RBALogManager::coverageHierarchyOfConstraintStartLog(log) +#define LOG_coverageHierarchyOfConstraintEndLog(log) \ + rba::RBALogManager::coverageHierarchyOfConstraintEndLog(log) +#define LOG_addCoverageLogCollector(collector) \ + rba::RBALogManager::addCoverageLogCollector(collector) +#define LOG_addHierarchy(log) \ + rba::RBALogManager::addHierarchy(log) +#define LOG_allConstraintLogLine(log) \ + rba::RBALogManager::allConstraintLogLine(log) +#define LOG_arbitrateAreaLogLine(log) \ + rba::RBALogManager::arbitrateAreaLogLine(log) +#define LOG_arbitrateConstraintLogLine(log) \ + rba::RBALogManager::arbitrateConstraintLogLine(log) +#define LOG_arbitrateConstraintLogicLogLine(log) \ + rba::RBALogManager::arbitrateConstraintLogicLogLine(log) +#define LOG_coverageConstraintExpressionLog(log, flag) \ + rba::RBALogManager::coverageConstraintExpressionLog(log, flag) +#define LOG_coverageConstraintExpressionLog2(log) \ + rba::RBALogManager::coverageConstraintExpressionLog(log) +#define LOG_coverageConstraintStartLog(constraint) \ + rba::RBALogManager::coverageConstraintStartLog(constraint) +#define LOG_coverageConstraintEndLog(constraint) \ + rba::RBALogManager::coverageConstraintEndLog(constraint) +#else +#define LOG_initConstraintHierarchy() do{} while(false) +#define LOG_removeHierarchy() do{} while(false) +#define LOG_coverageHierarchyOfConstraintStartLog(log) do{} while(false) +#define LOG_coverageHierarchyOfConstraintEndLog(log) do{} while(false) +#define LOG_addCoverageLogCollector(collector) do{} while(false) +#define LOG_addHierarchy(log) do{} while(false) +#define LOG_allConstraintLogLine(log) do{} while(false) +#define LOG_arbitrateAreaLogLine(log) do{} while(false) +#define LOG_arbitrateConstraintLogLine(log) do{} while(false) +#define LOG_arbitrateConstraintLogicLogLine(log) do{} while(false) +#define LOG_coverageConstraintExpressionLog(log, flag) do{} while(false) +#define LOG_coverageConstraintExpressionLog2(log) do{} while(false) +#define LOG_coverageConstraintStartLog(constraint) do{} while(false) +#define LOG_coverageConstraintEndLog(constraint) do{} while(false) +#endif + +// class method +#ifdef RBA_USE_LOG +#define LOG_getSymbol() getSymbol() +#define LOG_getExpressionText() getExpressionText() +#define LOG_getCoverageExpressionText() getCoverageExpressionText() +#else +#define LOG_getSymbol() std::string("") +#define LOG_getExpressionText() std::string("") +#define LOG_getCoverageExpressionText() std::string("") +#endif + +#endif |