1 /*
2 * Copyright (c) 2022 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 #include "dm_thread.h"
16
17 namespace OHOS {
18 namespace DistributedHardware {
19 using funcstr = void (*)(std::map<std::string, std::shared_ptr<ISoftbusStateCallback>>, DmDeviceInfo);
20
21 funcstr DmThread::funcName_;
22 std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> DmThread::parameter1_ = {};
23 DmDeviceInfo DmThread::parameter2_;
24
DmThread(funcstr funcname,std::map<std::string,std::shared_ptr<ISoftbusStateCallback>> parameter1,DmDeviceInfo parameter2)25 DmThread::DmThread(funcstr funcname,\
26 std::map<std::string, std::shared_ptr<ISoftbusStateCallback>> parameter1,\
27 DmDeviceInfo parameter2)
28 {
29 funcName_ = funcname;
30 parameter1_ = parameter1;
31 parameter2_ = parameter2;
32 parameterGroup_.member1 = parameter1;
33 parameterGroup_.member2 = parameter2;
34 }
35
PthreadDeviceStart(void * parameterInfo)36 void* DmThread::PthreadDeviceStart(void* parameterInfo)
37 {
38 PthreadCallbackParameter *parameterStruct = static_cast<PthreadCallbackParameter *>(parameterInfo);
39 funcName_(parameterStruct->member1, parameterStruct->member2);
40 return nullptr;
41 }
42
DmCreatThread()43 void DmThread::DmCreatThread()
44 {
45 pthread_t tid;
46 pthread_attr_t attr;
47 pthread_attr_init(&attr);
48 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
49 pthread_create(&tid, &attr, PthreadDeviceStart, static_cast<void *>(¶meterGroup_));
50 }
51 } // namespace DistributedHardware
52 } // namespace OHOS
53