bluez5: use callback table in hsp/hfp backends

This commit is contained in:
Pauli Virtanen 2021-03-18 21:48:10 +02:00 committed by Wim Taymans
parent 18eccf4289
commit e18df4e344
5 changed files with 210 additions and 142 deletions

View file

@ -553,6 +553,48 @@ static inline enum spa_bt_transport_state spa_bt_transport_state_from_string(con
return SPA_BT_TRANSPORT_STATE_IDLE;
}
struct spa_bt_backend_implementation {
#define SPA_VERSION_BT_BACKEND_IMPLEMENTATION 0
uint32_t version;
int (*free) (void *data);
int (*register_profiles) (void *data);
int (*unregister_profiles) (void *data);
int (*unregistered) (void *data);
int (*add_filters) (void *data);
};
struct spa_bt_backend {
struct spa_callbacks impl;
};
#define spa_bt_backend_set_implementation(b,_impl,_data) \
(b)->impl = SPA_CALLBACKS_INIT(_impl, _data)
#define spa_bt_backend_impl(b,m,v,...) \
({ \
int res = -ENOTSUP; \
if (b) \
spa_callbacks_call_res(&(b)->impl, \
struct spa_bt_backend_implementation, \
res, m, v, ##__VA_ARGS__); \
res; \
})
#define spa_bt_backend_free(b) spa_bt_backend_impl(b, free, 0)
#define spa_bt_backend_register_profiles(b) spa_bt_backend_impl(b, register_profiles, 0)
#define spa_bt_backend_unregister_profiles(b) spa_bt_backend_impl(b, unregister_profiles, 0)
#define spa_bt_backend_unregistered(b) spa_bt_backend_impl(b, unregistered, 0)
#define spa_bt_backend_add_filters(b) spa_bt_backend_impl(b, add_filters, 0)
static inline struct spa_bt_backend *dummy_backend_new(struct spa_bt_monitor *monitor,
void *dbus_connection,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
return NULL;
}
#ifdef HAVE_BLUEZ_5_BACKEND_NATIVE
struct spa_bt_backend *backend_native_new(struct spa_bt_monitor *monitor,
@ -560,20 +602,8 @@ struct spa_bt_backend *backend_native_new(struct spa_bt_monitor *monitor,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support);
void backend_native_free(struct spa_bt_backend *backend);
void backend_native_register_profiles(struct spa_bt_backend *backend);
void backend_native_unregister_profiles(struct spa_bt_backend *backend);
#else
static inline struct spa_bt_backend *backend_native_new(struct spa_bt_monitor *monitor,
void *dbus_connection,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support) {
return NULL;
}
static inline void backend_native_free(struct spa_bt_backend *backend) {}
static inline void backend_native_register_profiles(struct spa_bt_backend *backend) {}
static inline void backend_native_unregister_profiles(struct spa_bt_backend *backend) {}
#define backend_native_new dummy_backend_new
#endif
#define OFONO_SERVICE "org.ofono"
@ -583,20 +613,8 @@ struct spa_bt_backend *backend_ofono_new(struct spa_bt_monitor *monitor,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support);
void backend_ofono_free(struct spa_bt_backend *backend);
int backend_ofono_register(struct spa_bt_backend *backend);
void backend_ofono_add_filters(struct spa_bt_backend *backend);
#else
static inline struct spa_bt_backend *backend_ofono_new(struct spa_bt_monitor *monitor,
void *dbus_connection,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support) {
return NULL;
}
static inline void backend_ofono_free(struct spa_bt_backend *backend) {}
static inline int backend_ofono_register(struct spa_bt_backend *backend) { return -ENOTSUP; }
static inline void backend_ofono_add_filters(struct spa_bt_backend *backend) {}
#define backend_ofono_new dummy_backend_new
#endif
#define HSPHFPD_SERVICE "org.hsphfpd"
@ -606,22 +624,8 @@ struct spa_bt_backend *backend_hsphfpd_new(struct spa_bt_monitor *monitor,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support);
void backend_hsphfpd_free(struct spa_bt_backend *backend);
int backend_hsphfpd_register(struct spa_bt_backend *backend);
void backend_hsphfpd_unregistered(struct spa_bt_backend *backend);
void backend_hsphfpd_add_filters(struct spa_bt_backend *backend);
#else
static inline struct spa_bt_backend *backend_hsphfpd_new(struct spa_bt_monitor *monitor,
void *dbus_connection,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support) {
return NULL;
}
static inline void backend_hsphfpd_free(struct spa_bt_backend *backend) {}
static inline int backend_hsphfpd_register(struct spa_bt_backend *backend) { return -ENOTSUP; }
static inline void backend_hsphfpd_unregistered(struct spa_bt_backend *backend) {}
static inline void backend_hsphfpd_add_filters(struct spa_bt_backend *backend) {}
#define backend_hsphfpd_new dummy_backend_new
#endif
#ifdef __cplusplus