119e95205Sopenharmony_ci/*
219e95205Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
319e95205Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
419e95205Sopenharmony_ci * you may not use this file except in compliance with the License.
519e95205Sopenharmony_ci * You may obtain a copy of the License at
619e95205Sopenharmony_ci *
719e95205Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
819e95205Sopenharmony_ci *
919e95205Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1019e95205Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1119e95205Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1219e95205Sopenharmony_ci * See the License for the specific language governing permissions and
1319e95205Sopenharmony_ci * limitations under the License.
1419e95205Sopenharmony_ci */
1519e95205Sopenharmony_ci
1619e95205Sopenharmony_ci#include "avdtp_ctrl.h"
1719e95205Sopenharmony_ci#include "avdtp_l2cap.h"
1819e95205Sopenharmony_ci#include "btm/btm_thread.h"
1919e95205Sopenharmony_ci#include "btstack.h"
2019e95205Sopenharmony_ci#include "event.h"
2119e95205Sopenharmony_ci#include "log.h"
2219e95205Sopenharmony_ci#include "module.h"
2319e95205Sopenharmony_ci
2419e95205Sopenharmony_civoid AvdtStartup(void *context);
2519e95205Sopenharmony_civoid AvdtShutdown(void *context);
2619e95205Sopenharmony_ci
2719e95205Sopenharmony_cistatic void AVDT_Init()
2819e95205Sopenharmony_ci{
2919e95205Sopenharmony_ci    LOG_DEBUG("[AVDT]%{public}s:", __func__);
3019e95205Sopenharmony_ci    return;
3119e95205Sopenharmony_ci}
3219e95205Sopenharmony_ci
3319e95205Sopenharmony_cistatic void AVDT_Cleanup()
3419e95205Sopenharmony_ci{
3519e95205Sopenharmony_ci    LOG_DEBUG("[AVDT]%{public}s:", __func__);
3619e95205Sopenharmony_ci    return;
3719e95205Sopenharmony_ci}
3819e95205Sopenharmony_ci
3919e95205Sopenharmony_cistatic void AVDT_Startup()
4019e95205Sopenharmony_ci{
4119e95205Sopenharmony_ci    LOG_INFO("[AVDT] %{public}s", __func__);
4219e95205Sopenharmony_ci    /* Create queue resource */
4319e95205Sopenharmony_ci    if (BTM_CreateProcessingQueue(PROCESSING_QUEUE_ID_AVDTP, BTM_PROCESSING_QUEUE_SIZE_DEFAULT)) {
4419e95205Sopenharmony_ci        return;
4519e95205Sopenharmony_ci    }
4619e95205Sopenharmony_ci    Event *event = EventCreate(true);
4719e95205Sopenharmony_ci    if (!AvdtAsyncProcess(AvdtStartup, event)) {
4819e95205Sopenharmony_ci        EventWait(event, WAIT_TIME);
4919e95205Sopenharmony_ci    }
5019e95205Sopenharmony_ci    EventDelete(event);
5119e95205Sopenharmony_ci    return;
5219e95205Sopenharmony_ci}
5319e95205Sopenharmony_ci
5419e95205Sopenharmony_civoid AvdtStartup(void *context)
5519e95205Sopenharmony_ci{
5619e95205Sopenharmony_ci    Event *event = (Event *)context;
5719e95205Sopenharmony_ci    AvdtControlBlockInit();
5819e95205Sopenharmony_ci    /* regist psm */
5919e95205Sopenharmony_ci    if (L2CIF_RegisterService(AVDT_PSM, (L2capService *)&G_AVDT_L2C_APPL, NULL, NULL)) {
6019e95205Sopenharmony_ci        LOG_DEBUG("[AVDT]%{public}s:L2CIF_RegisterService failed! ", __func__);
6119e95205Sopenharmony_ci    }
6219e95205Sopenharmony_ci    EventSet(event);
6319e95205Sopenharmony_ci    return;
6419e95205Sopenharmony_ci}
6519e95205Sopenharmony_ci
6619e95205Sopenharmony_cistatic void AVDT_Shutdown()
6719e95205Sopenharmony_ci{
6819e95205Sopenharmony_ci    LOG_INFO("[AVDT] %{public}s", __func__);
6919e95205Sopenharmony_ci    Event *event = EventCreate(true);
7019e95205Sopenharmony_ci    if (!AvdtAsyncProcess(AvdtShutdown, event)) {
7119e95205Sopenharmony_ci        EventWait(event, WAIT_TIME);
7219e95205Sopenharmony_ci    }
7319e95205Sopenharmony_ci    EventDelete(event);
7419e95205Sopenharmony_ci    return;
7519e95205Sopenharmony_ci}
7619e95205Sopenharmony_ci
7719e95205Sopenharmony_civoid AvdtShutdown(void *context)
7819e95205Sopenharmony_ci{
7919e95205Sopenharmony_ci    Event *event = (Event *)context;
8019e95205Sopenharmony_ci    L2CIF_DeregisterService(AVDT_PSM, NULL);
8119e95205Sopenharmony_ci    AvdtSigDealloc();
8219e95205Sopenharmony_ci    AvdtTransChDeallocAll();
8319e95205Sopenharmony_ci    /* Delete queue resource */
8419e95205Sopenharmony_ci    BTM_DeleteProcessingQueue(PROCESSING_QUEUE_ID_AVDTP);
8519e95205Sopenharmony_ci    EventSet(event);
8619e95205Sopenharmony_ci    return;
8719e95205Sopenharmony_ci}
8819e95205Sopenharmony_ci
8919e95205Sopenharmony_cistatic Module g_avdtp = {
9019e95205Sopenharmony_ci    .name = MODULE_NAME_AVDTP,
9119e95205Sopenharmony_ci    .init = AVDT_Init,
9219e95205Sopenharmony_ci    .startup = AVDT_Startup,
9319e95205Sopenharmony_ci    .shutdown = AVDT_Shutdown,
9419e95205Sopenharmony_ci    .cleanup = AVDT_Cleanup,
9519e95205Sopenharmony_ci    .dependencies = {MODULE_NAME_L2CAP, MODULE_NAME_GAP},
9619e95205Sopenharmony_ci};
9719e95205Sopenharmony_ci
9819e95205Sopenharmony_ciMODULE_DECL(g_avdtp)
99