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 //////////////////////////////////////////////////////////////////////////////////////////////////
19 /// \brief <INSERT INFO HERE>.
21 //////////////////////////////////////////////////////////////////////////////////////////////////
25 #include <native_service/frameworkunified_thread_priority.h>
26 #include <native_service/ns_logger_if.h>
32 const_cast<PSTR>("thrd"),
36 namespace frameworkunified {
39 CFrameworkunifiedThreadPriorities::TThreadPriorityList CFrameworkunifiedThreadPriorities::ms_mapThreadPritories;
41 //////////////////////////////////////////
43 //////////////////////////////////////////
44 CFrameworkunifiedThreadPriorities::CFrameworkunifiedThreadPriorities() { // LCOV_EXCL_START 200:only use static function of this class
45 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
49 //////////////////////////////////////////
51 //////////////////////////////////////////
52 CFrameworkunifiedThreadPriorities::~CFrameworkunifiedThreadPriorities() { // LCOV_EXCL_START 200:only use static function of this class
53 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
57 //////////////////////////////////////////
59 //////////////////////////////////////////
60 SI_32 CFrameworkunifiedThreadPriorities::GetPriority(const std::string &f_cThreadName) {
61 SI_32 l_si32Prio = FRAMEWORKUNIFIED_PRIORITY_NOT_FOUND;
62 ThreadPrioMapIter iter = ms_mapThreadPritories.find(f_cThreadName);
63 if (iter != ms_mapThreadPritories.end() && (FRAMEWORKUNIFIED_PRIORITY_NOT_FOUND == l_si32Prio)) {
64 l_si32Prio = iter->second;
70 //////////////////////////////////////////
72 //////////////////////////////////////////
73 EFrameworkunifiedStatus CFrameworkunifiedThreadPriorities::AddPriority(const std::string &f_cThreadName, SI_32 f_si32Priority) {
74 ms_mapThreadPritories[f_cThreadName] = f_si32Priority;
75 return eFrameworkunifiedStatusOK;
78 //////////////////////////////////////////
80 //////////////////////////////////////////
81 VOID CFrameworkunifiedThreadPriorities::PrintPriorites() { // LCOV_EXCL_START 7: debug code
82 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
83 ThreadPrioMapIter iter = ms_mapThreadPritories.begin();
84 for (; iter != ms_mapThreadPritories.end(); iter++) {
85 std::string name = iter->first;
86 FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "Thread name: %s Priority: %d", name.data(), iter->second);
91 //////////////////////////////////////////
92 // ParseThreadArguments
93 //////////////////////////////////////////
94 EFrameworkunifiedStatus CFrameworkunifiedThreadPriorities::ParseThreadArguments(PCHAR f_cArgumentValue) {
95 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
101 if (NULL != f_cArgumentValue) {
102 l_cOptions = f_cArgumentValue;
103 FRAMEWORKUNIFIEDLOG(ZONE_NS_DIS, __FUNCTION__, "args of -p: %s", l_cOptions); // LCOV_EXCL_BR_LINE 15:marco defined in "native_service/ns_logger_if.h"
105 while (*l_cOptions != '\0' && (eFrameworkunifiedStatusOK == l_eStatus)) {
106 switch (getsubopt(&l_cOptions, priopts, &l_cValue)) {
108 if (l_cValue == NULL) {
109 l_eStatus = eFrameworkunifiedStatusFail;
111 std::string l_cName("");
112 std::string l_cPriority(""); // LCOV_EXCL_BR_LINE 11: except branch
113 int at = static_cast<int>(frameworkunified::framework::args::name);
115 l_cData = strtok_r(l_cValue, ":", &saveptr); // NOLINT (readability/nolint)
116 while (NULL != l_cData) {
118 case frameworkunified::framework::args::name:
121 case frameworkunified::framework::args::priority:
122 l_cPriority = l_cData;
128 if (!l_cName.empty() && !l_cPriority.empty()) {
129 frameworkunified::framework::CFrameworkunifiedThreadPriorities::AddPriority(l_cName, atoi(l_cPriority.data()));
130 at = static_cast<int>(frameworkunified::framework::args::name);
137 l_cData = strtok_r(NULL, ":", &saveptr); // NOLINT (readability/nolint)
143 l_eStatus = eFrameworkunifiedStatusFail;
152 } // namespace framework
153 }; // namespace frameworkunified