When Bluetoothd initializing, it will load plugins in /usr/lib/bluetooth/plugins by default. Actually, most of bluetooth profiles are implemented as plugins in BlueZ.
In plugin.h, it defines:
struct bluetooth_plugin_desc {
const char *name;
int (*init) (void);
void (*exit) (void);
};#define BLUETOOTH_PLUGIN_DEFINE(name,init,exit) \
struct bluetooth_plugin_desc bluetooth_plugin_desc = { \
name, init, exit \
};
It means that if you want to implement a plugin, just try to implement to callback functions: init and exit. All other communctions should be communicated with socket or IO channel.
Search macro BLUETOOTH_PLUGIN_DEFINE, you will find:
- BLUETOOTH_PLUGIN_DEFINE(“audio”, audio_init, audio_exit)
- BLUETOOTH_PLUGIN_DEFINE(“input”, input_init, input_exit)
- BLUETOOTH_PLUGIN_DEFINE(“network”, network_init, network_exit)
- BLUETOOTH_PLUGIN_DEFINE(“echo”, echo_init, echo_exit)
- BLUETOOTH_PLUGIN_DEFINE(“storage”, storage_init, storage_exit) //no implementation actually
- BLUETOOTH_PLUGIN_DEFINE(“serial”, serial_init, serial_exit)
Implement on serial plugin
- Connect to dbus system bus;
- btd_register_adapter_driver(&serial_proxy_driver);
- btd_register_device_driver(&serial_port_driver);
- communicate others with socket and dbus;
Implement on echo
- Communicate RFCOMM with socket;
- Use IO channel for internal event;
Implement on audio
- Connect to Dbus system bus;
- Load audio.conf;
- According to settings, start headset, audio gateway, sink, source, control service;
- Register device drivers;
Implement on input
It is similar with audio.