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 "avdtp_ctrl.h"
17 #include "avdtp_l2cap.h"
18 #include "btm/btm_thread.h"
19 #include "btstack.h"
20 #include "event.h"
21 #include "log.h"
22 #include "module.h"
23
24 void AvdtStartup(void *context);
25 void AvdtShutdown(void *context);
26
AVDT_Init()27 static void AVDT_Init()
28 {
29 LOG_DEBUG("[AVDT]%{public}s:", __func__);
30 return;
31 }
32
AVDT_Cleanup()33 static void AVDT_Cleanup()
34 {
35 LOG_DEBUG("[AVDT]%{public}s:", __func__);
36 return;
37 }
38
AVDT_Startup()39 static void AVDT_Startup()
40 {
41 LOG_INFO("[AVDT] %{public}s", __func__);
42 /* Create queue resource */
43 if (BTM_CreateProcessingQueue(PROCESSING_QUEUE_ID_AVDTP, BTM_PROCESSING_QUEUE_SIZE_DEFAULT)) {
44 return;
45 }
46 Event *event = EventCreate(true);
47 if (!AvdtAsyncProcess(AvdtStartup, event)) {
48 EventWait(event, WAIT_TIME);
49 }
50 EventDelete(event);
51 return;
52 }
53
AvdtStartup(void * context)54 void AvdtStartup(void *context)
55 {
56 Event *event = (Event *)context;
57 AvdtControlBlockInit();
58 /* regist psm */
59 if (L2CIF_RegisterService(AVDT_PSM, (L2capService *)&G_AVDT_L2C_APPL, NULL, NULL)) {
60 LOG_DEBUG("[AVDT]%{public}s:L2CIF_RegisterService failed! ", __func__);
61 }
62 EventSet(event);
63 return;
64 }
65
AVDT_Shutdown()66 static void AVDT_Shutdown()
67 {
68 LOG_INFO("[AVDT] %{public}s", __func__);
69 Event *event = EventCreate(true);
70 if (!AvdtAsyncProcess(AvdtShutdown, event)) {
71 EventWait(event, WAIT_TIME);
72 }
73 EventDelete(event);
74 return;
75 }
76
AvdtShutdown(void * context)77 void AvdtShutdown(void *context)
78 {
79 Event *event = (Event *)context;
80 L2CIF_DeregisterService(AVDT_PSM, NULL);
81 AvdtSigDealloc();
82 AvdtTransChDeallocAll();
83 /* Delete queue resource */
84 BTM_DeleteProcessingQueue(PROCESSING_QUEUE_ID_AVDTP);
85 EventSet(event);
86 return;
87 }
88
89 static Module g_avdtp = {
90 .name = MODULE_NAME_AVDTP,
91 .init = AVDT_Init,
92 .startup = AVDT_Startup,
93 .shutdown = AVDT_Shutdown,
94 .cleanup = AVDT_Cleanup,
95 .dependencies = {MODULE_NAME_L2CAP, MODULE_NAME_GAP},
96 };
97
98 MODULE_DECL(g_avdtp)
99