1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "dm_ability_manager.h" 17 18 #include "semaphore.h" 19 20 #include "constants.h" 21 #include "device_manager_log.h" 22 23 namespace OHOS { 24 namespace DistributedHardware { 25 IMPLEMENT_SINGLE_INSTANCE(DmAbilityManager); 26 GetAbilityRole()27AbilityRole DmAbilityManager::GetAbilityRole() 28 { 29 return mAbilityStatus_; 30 } 31 StartAbility(AbilityRole role)32AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) 33 { 34 // not support for L1 yet, do nothing. jsut save status and role 35 mAbilityStatus_ = role; 36 mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; 37 return mStatus_; 38 } 39 waitForTimeout(uint32_t timeout_s)40void DmAbilityManager::waitForTimeout(uint32_t timeout_s) 41 { 42 struct timespec ts; 43 clock_gettime(CLOCK_REALTIME, &ts); 44 ts.tv_sec += timeout_s; 45 sem_timedwait(&mSem_, &ts); 46 } 47 StartAbilityDone()48void DmAbilityManager::StartAbilityDone() 49 { 50 mStatus_ = AbilityStatus::ABILITY_STATUS_SUCCESS; 51 sem_post(&mSem_); 52 } 53 } 54 } 55