Remove unused directories and files in video_in_hal
[staging/basesystem.git] / nsframework / framework_unified / client / NS_FrameworkCore / src / frameworkunified_thread_priority.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
19 /// \brief <INSERT INFO HERE>.
20 ///
21 //////////////////////////////////////////////////////////////////////////////////////////////////
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <native_service/frameworkunified_thread_priority.h>
26 #include <native_service/ns_logger_if.h>
27
28 #include <string>
29
30 char *priopts[] = {
31 #define THREAD    0
32   const_cast<PSTR>("thrd"),
33   NULL
34 };
35
36 namespace frameworkunified {
37 namespace framework {
38
39 CFrameworkunifiedThreadPriorities::TThreadPriorityList CFrameworkunifiedThreadPriorities::ms_mapThreadPritories;
40
41 //////////////////////////////////////////
42 // Constructor
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
46 }
47 // LCOV_EXCL_STOP
48
49 //////////////////////////////////////////
50 // Destructor
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
54 }
55 // LCOV_EXCL_STOP
56
57 //////////////////////////////////////////
58 // GetPriority
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;
65   }
66
67   return l_si32Prio;
68 }
69
70 //////////////////////////////////////////
71 // AddPriority
72 //////////////////////////////////////////
73 EFrameworkunifiedStatus CFrameworkunifiedThreadPriorities::AddPriority(const std::string &f_cThreadName, SI_32 f_si32Priority) {
74   ms_mapThreadPritories[f_cThreadName] = f_si32Priority;
75   return eFrameworkunifiedStatusOK;
76 }
77
78 //////////////////////////////////////////
79 // PrintPriorites
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);
87   }
88 }
89 // LCOV_EXCL_STOP
90
91 //////////////////////////////////////////
92 // ParseThreadArguments
93 //////////////////////////////////////////
94 EFrameworkunifiedStatus CFrameworkunifiedThreadPriorities::ParseThreadArguments(PCHAR f_cArgumentValue) {
95   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
96   PCHAR l_cData = NULL;
97   PSTR l_cOptions;
98   PSTR l_cValue;
99   PCHAR saveptr;
100
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"
104
105     while (*l_cOptions != '\0' && (eFrameworkunifiedStatusOK == l_eStatus)) {
106       switch (getsubopt(&l_cOptions, priopts, &l_cValue)) {
107         case THREAD: {
108             if (l_cValue == NULL) {
109               l_eStatus = eFrameworkunifiedStatusFail;
110             } else {
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);
114
115               l_cData = strtok_r(l_cValue, ":", &saveptr);  // NOLINT  (readability/nolint)
116               while (NULL != l_cData) {
117                 switch (at) {
118                   case frameworkunified::framework::args::name:
119                     l_cName = l_cData;
120                     break;
121                   case frameworkunified::framework::args::priority:
122                     l_cPriority = l_cData;
123                     break;
124                   default:
125                     break;
126                 }
127
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);
131                   l_cName.clear();
132                   l_cPriority.clear();
133                 } else {
134                   at++;
135                 }
136
137                 l_cData = strtok_r(NULL, ":", &saveptr);  // NOLINT  (readability/nolint)
138               }
139             }
140             break;
141           }
142         default: {
143             l_eStatus = eFrameworkunifiedStatusFail;
144             break;
145           }
146       }
147     }
148   }
149   return l_eStatus;
150 }
151
152 }  //  namespace framework
153 };  //  namespace frameworkunified
154 ///  EOF
155
156