5 * Copyright (C) 2007-2010 Nokia Corporation
6 * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
43 #include "obex-priv.h"
46 #include "transport.h"
48 static GSList *servers = NULL;
50 static void init_server(uint16_t service, GSList *transports)
54 for (l = transports; l; l = l->next) {
55 struct obex_transport_driver *transport = l->data;
56 struct obex_server *server;
59 if (transport->service != 0 &&
60 (transport->service & service) == FALSE)
63 server = g_new0(struct obex_server, 1);
64 server->transport = transport;
65 server->drivers = obex_service_driver_list(service);
67 server->transport_data = transport->start(server, &err);
68 if (server->transport_data == NULL) {
69 DBG("Unable to start %s transport: %s (%d)",
70 transport->name, strerror(err), err);
75 servers = g_slist_prepend(servers, server);
79 int obex_server_init(void)
85 drivers = obex_service_driver_list(0);
86 if (drivers == NULL) {
87 DBG("No service driver registered");
91 transports = obex_transport_driver_list();
92 if (transports == NULL) {
93 DBG("No transport driver registered");
97 for (l = drivers; l; l = l->next) {
98 struct obex_service_driver *driver = l->data;
100 init_server(driver->service, transports);
106 void obex_server_exit(void)
110 for (l = servers; l; l = l->next) {
111 struct obex_server *server = l->data;
113 server->transport->stop(server->transport_data);
117 g_slist_free(servers);
122 struct obex_service_driver *obex_server_find_driver(
123 struct obex_server *server,
128 for (l = server->drivers; l; l = l->next) {
129 struct obex_service_driver *driver = l->data;
131 if (driver->channel == channel)
138 int obex_server_new_connection(struct obex_server *server, GIOChannel *io,
139 uint16_t tx_mtu, uint16_t rx_mtu)
141 return obex_session_start(io, tx_mtu, rx_mtu, server);