5 * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 static GSList *drivers = NULL;
42 struct obex_service_driver *obex_service_driver_find(GSList *drivers,
43 const uint8_t *target, unsigned int target_size,
44 const uint8_t *who, unsigned int who_size)
48 for (l = drivers; l; l = l->next) {
49 struct obex_service_driver *driver = l->data;
51 /* who is optional, so only check for it if not NULL */
52 if (who != NULL && memncmp0(who, who_size, driver->who,
56 if (memncmp0(target, target_size, driver->target,
57 driver->target_size) == 0)
64 GSList *obex_service_driver_list(uint16_t services)
72 for (l = drivers; l && services; l = l->next) {
73 struct obex_service_driver *driver = l->data;
75 if (driver->service & services) {
76 list = g_slist_append(list, driver);
77 services &= ~driver->service;
84 int obex_service_driver_register(struct obex_service_driver *driver)
87 error("Invalid driver");
91 if (obex_service_driver_list(driver->service)) {
92 error("Permission denied: service %s already registered",
97 DBG("driver %p service %s registered", driver, driver->name);
99 /* Drivers that support who has priority */
101 drivers = g_slist_prepend(drivers, driver);
103 drivers = g_slist_append(drivers, driver);
108 void obex_service_driver_unregister(struct obex_service_driver *driver)
110 if (!g_slist_find(drivers, driver)) {
111 error("Unable to unregister: No such driver %p", driver);
115 DBG("driver %p service %s unregistered", driver, driver->name);
117 drivers = g_slist_remove(drivers, driver);