diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-01-22 01:58:13 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-01-22 01:58:13 +0000 |
commit | d0d4a040f4a2d2c4582f1761cc526b970649a2ac (patch) | |
tree | 0b628b0d91f582eeface474736c34d985251a284 | |
parent | 493ec449cf22b725252c86863f801a191afdbde8 (diff) |
Unregister service record on shutdown
-rw-r--r-- | daemon/echo.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/daemon/echo.c b/daemon/echo.c index 066d6706..996d0804 100644 --- a/daemon/echo.c +++ b/daemon/echo.c @@ -45,6 +45,9 @@ static GMainLoop *main_loop = NULL; +static sdp_session_t *sdp_session = NULL; +static sdp_record_t *sdp_record = NULL; + static gboolean session_event(GIOChannel *chan, GIOCondition cond, gpointer data) { unsigned char buf[672]; @@ -125,28 +128,26 @@ static GIOChannel *setup_rfcomm(uint8_t channel) static int setup_sdp(uint8_t channel) { - sdp_session_t *session; - sdp_record_t *record; sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto; uuid_t root_uuid, l2cap, rfcomm, spp; sdp_profile_desc_t profile[1]; sdp_list_t *proto[2]; - session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); - if (!session) { + sdp_session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); + if (!sdp_session) { error("Connection to SDP server failed"); return -1; } - record = sdp_record_alloc(); - if (!record) { + sdp_record = sdp_record_alloc(); + if (!sdp_record) { error("Allocation of service record failed"); return -1; } sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(NULL, &root_uuid); - sdp_set_browse_groups(record, root); + sdp_set_browse_groups(sdp_record, root); sdp_uuid16_create(&l2cap, L2CAP_UUID); proto[0] = sdp_list_append(NULL, &l2cap); @@ -158,27 +159,26 @@ static int setup_sdp(uint8_t channel) apseq = sdp_list_append(apseq, proto[1]); aproto = sdp_list_append(NULL, apseq); - sdp_set_access_protos(record, aproto); + sdp_set_access_protos(sdp_record, aproto); sdp_uuid16_create(&spp, SERIAL_PORT_SVCLASS_ID); svclass = sdp_list_append(NULL, &spp); - sdp_set_service_classes(record, svclass); + sdp_set_service_classes(sdp_record, svclass); sdp_uuid16_create(&profile[0].uuid, SERIAL_PORT_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(NULL, &profile[0]); - sdp_set_profile_descs(record, pfseq); + sdp_set_profile_descs(sdp_record, pfseq); - sdp_set_info_attr(record, "Echo service", NULL, NULL); + sdp_set_info_attr(sdp_record, "Echo service", NULL, NULL); - if (sdp_record_register(session, record, 0) < 0) { + if (sdp_record_register(sdp_session, sdp_record, 0) < 0) { error("Registration of service record failed"); - sdp_record_free(record); + sdp_record_free(sdp_record); + sdp_record = NULL; return -1; } - sdp_record_free(record); - return 0; } @@ -232,6 +232,13 @@ int main(int argc, char *argv[]) dbus_connection_unref(system_bus); + if (sdp_record) { + if (sdp_record_unregister(sdp_session, sdp_record) < 0) + sdp_record_free(sdp_record); + } + + sdp_close(sdp_session); + g_main_loop_unref(main_loop); info("Exit"); |