1 2 /* 3 * Copyright (c) 2024 Huawei Device Co., Ltd. 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 #include "qos.h" 17 #include "inner_api/qos.h" 18 #include <unistd.h> 19 #include <string> 20 #include <unordered_map> 21 22 static constexpr int ERROR_NUM = -1; 23 24 using namespace OHOS::QOS; 25 using namespace std; 26 OH_QoS_SetThreadQoS(QoS_Level level)27int OH_QoS_SetThreadQoS(QoS_Level level) 28 { 29 if (level < QOS_BACKGROUND || level > QOS_USER_INTERACTIVE) { 30 return ERROR_NUM; 31 } 32 return SetThreadQos(static_cast<QosLevel>(level)); 33 } 34 OH_QoS_ResetThreadQoS(void)35int OH_QoS_ResetThreadQoS(void) 36 { 37 return ResetThreadQos(); 38 } 39 OH_QoS_GetThreadQoS(QoS_Level * level)40int OH_QoS_GetThreadQoS(QoS_Level *level) 41 { 42 if (level == nullptr) { 43 return ERROR_NUM; 44 } 45 QosLevel qosLevel; 46 int ret = GetThreadQos(qosLevel); 47 if (ret < 0) { 48 return ERROR_NUM; 49 } 50 if (static_cast<int>(qosLevel) < QoS_Level::QOS_BACKGROUND || 51 static_cast<int>(qosLevel) > QoS_Level::QOS_USER_INTERACTIVE) { 52 return ERROR_NUM; 53 } 54 *level = static_cast<QoS_Level>(qosLevel); 55 return 0; 56 }