1 /*
2  * Copyright (C) 2023-2024 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 "napi_mms_pdu_helper.h"
17 
18 #include "tel_event_handler.h"
19 #include "telephony_log_wrapper.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 constexpr static const int32_t WAIT_TIME_SECOND = 30;
24 
Run(void (* func)(NapiMmsPduHelper &),NapiMmsPduHelper & helper)25 bool NapiMmsPduHelper::Run(void (*func)(NapiMmsPduHelper &), NapiMmsPduHelper &helper)
26     __attribute__((no_sanitize("cfi")))
27 {
28     TelFFRTUtils::Submit([&]() { func(helper); });
29     TELEPHONY_LOGI("Thread running");
30     return WaitForResult(WAIT_TIME_SECOND);
31 }
32 
NotifyAll()33 void NapiMmsPduHelper::NotifyAll()
34 {
35     std::unique_lock<std::mutex> lock(mtx_);
36     cv_.notify_all();
37     TELEPHONY_LOGI("Thread NotifyAll");
38 }
39 
WaitForResult(int32_t timeoutSecond)40 bool NapiMmsPduHelper::WaitForResult(int32_t timeoutSecond) __attribute__((no_sanitize("cfi")))
41 {
42     std::unique_lock<std::mutex> lock(mtx_);
43     if (cv_.wait_for(lock, std::chrono::seconds(timeoutSecond)) == std::cv_status::timeout) {
44         TELEPHONY_LOGI("Interface overtime");
45         return false;
46     }
47     return true;
48 }
49 
SetPduFileName(const std::string & pduFileName)50 void NapiMmsPduHelper::SetPduFileName(const std::string &pduFileName)
51 {
52     pduFileName_ = pduFileName;
53 }
54 
SetStoreFileName(const std::string & storeFileName)55 void NapiMmsPduHelper::SetStoreFileName(const std::string &storeFileName)
56 {
57     storeFileName_ = storeFileName;
58 }
59 
SetDbUrl(const std::string & dbUrl)60 void NapiMmsPduHelper::SetDbUrl(const std::string &dbUrl)
61 {
62     dbUrl_ = dbUrl;
63 }
64 
SetDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> & datashareHelper)65 void NapiMmsPduHelper::SetDataShareHelper(std::shared_ptr<DataShare::DataShareHelper> &datashareHelper)
66 {
67     datashareHelper_ = datashareHelper;
68 }
69 
GetPduFileName()70 std::string NapiMmsPduHelper::GetPduFileName()
71 {
72     return pduFileName_;
73 }
74 
GetStoreFileName()75 std::string NapiMmsPduHelper::GetStoreFileName()
76 {
77     return storeFileName_;
78 }
79 
GetDbUrl()80 std::string NapiMmsPduHelper::GetDbUrl()
81 {
82     return dbUrl_;
83 }
84 
GetDataShareHelper()85 std::shared_ptr<DataShare::DataShareHelper> NapiMmsPduHelper::GetDataShareHelper()
86 {
87     return datashareHelper_;
88 }
89 } // namespace Telephony
90 } // namespace OHOS
91