• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(std::shared_ptr<NapiMmsPduHelper>),std::shared_ptr<NapiMmsPduHelper> helper)25 bool NapiMmsPduHelper::Run(void (*func)(std::shared_ptr<NapiMmsPduHelper>), std::shared_ptr<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<ffrt::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<ffrt::mutex> lock(mtx_);
43     if (cv_.wait_for(lock, std::chrono::seconds(timeoutSecond)) == ffrt::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     std::unique_lock<ffrt::mutex> lock(mtx_);
68     datashareHelper_ = datashareHelper;
69 }
70 
GetPduFileName()71 std::string NapiMmsPduHelper::GetPduFileName()
72 {
73     return pduFileName_;
74 }
75 
GetStoreFileName()76 std::string NapiMmsPduHelper::GetStoreFileName()
77 {
78     return storeFileName_;
79 }
80 
GetDbUrl()81 std::string NapiMmsPduHelper::GetDbUrl()
82 {
83     return dbUrl_;
84 }
85 
GetDataShareHelper()86 std::shared_ptr<DataShare::DataShareHelper> NapiMmsPduHelper::GetDataShareHelper()
87 {
88     std::unique_lock<ffrt::mutex> lock(mtx_);
89     return datashareHelper_;
90 }
91 } // namespace Telephony
92 } // namespace OHOS
93