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