Skip to content

Commit

Permalink
obexd: remove obex_mime_type_driver::set_io_watch
Browse files Browse the repository at this point in the history
All the drivers use the default function, where the register function
modifies what should be a constant vtable.

Instead let's remove the indirection, export and use the function as
applicable.

Since we have set and reset, export both functions and cleanup the
users.
  • Loading branch information
evelikov-work authored and Vudentz committed Jan 19, 2024
1 parent a9393b2 commit 8e88f8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
12 changes: 2 additions & 10 deletions obexd/src/mimetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static struct io_watch *find_io_watch(void *object)
return NULL;
}

static void reset_io_watch(void *object)
void obex_object_reset_io_watch(void *object)
{
struct io_watch *watch;

Expand All @@ -85,16 +85,11 @@ static void reset_io_watch(void *object)
g_free(watch);
}

static int set_io_watch(void *object, obex_object_io_func func,
int obex_object_set_io_watch(void *object, obex_object_io_func func,
void *user_data)
{
struct io_watch *watch;

if (func == NULL) {
reset_io_watch(object);
return 0;
}

watch = find_io_watch(object);
if (watch)
return -EPERM;
Expand Down Expand Up @@ -181,9 +176,6 @@ int obex_mime_type_driver_register(struct obex_mime_type_driver *driver)
return -EPERM;
}

if (driver->set_io_watch == NULL)
driver->set_io_watch = set_io_watch;

DBG("driver %p mimetype %s registered", driver, driver->mimetype);

drivers = g_slist_append(drivers, driver);
Expand Down
6 changes: 4 additions & 2 deletions obexd/src/mimetype.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ struct obex_mime_type_driver {
int (*copy) (const char *name, const char *destname);
int (*move) (const char *name, const char *destname);
int (*remove) (const char *name);
int (*set_io_watch) (void *object, obex_object_io_func func,
void *user_data);
};

int obex_mime_type_driver_register(struct obex_mime_type_driver *driver);
Expand All @@ -40,3 +38,7 @@ struct obex_mime_type_driver *obex_mime_type_driver_find(const uint8_t *target,
unsigned int who_size);

void obex_object_set_io_flags(void *object, int flags, int err);

void obex_object_reset_io_watch(void *object);
int obex_object_set_io_watch(void *object, obex_object_io_func func,
void *user_data);
12 changes: 6 additions & 6 deletions obexd/src/obex.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ static void os_reset_session(struct obex_session *os)
os_session_mark_aborted(os);

if (os->object) {
os->driver->set_io_watch(os->object, NULL, NULL);
obex_object_reset_io_watch(os->object);
os->driver->close(os->object);
if (os->aborted && os->cmd == G_OBEX_OP_PUT && os->path &&
os->driver->remove)
Expand Down Expand Up @@ -357,7 +357,7 @@ static gssize driver_read(struct obex_session *os, void *buf, gsize size)
if (len == -ENOSTR)
return 0;
if (len == -EAGAIN)
os->driver->set_io_watch(os->object, handle_async_io,
obex_object_set_io_watch(os->object, handle_async_io,
os);
}

Expand Down Expand Up @@ -395,7 +395,7 @@ static void transfer_complete(GObex *obex, GError *err, gpointer user_data)
if (os->object && os->driver && os->driver->flush) {
if (os->driver->flush(os->object) == -EAGAIN) {
g_obex_suspend(os->obex);
os->driver->set_io_watch(os->object, handle_async_io,
obex_object_set_io_watch(os->object, handle_async_io,
os);
return;
}
Expand Down Expand Up @@ -525,7 +525,7 @@ static gboolean recv_data(const void *buf, gsize size, gpointer user_data)

if (ret == -EAGAIN) {
g_obex_suspend(os->obex);
os->driver->set_io_watch(os->object, handle_async_io, os);
obex_object_set_io_watch(os->object, handle_async_io, os);
return TRUE;
}

Expand Down Expand Up @@ -699,7 +699,7 @@ int obex_get_stream_start(struct obex_session *os, const char *filename)
return err;

g_obex_suspend(os->obex);
os->driver->set_io_watch(os->object, handle_async_io, os);
obex_object_set_io_watch(os->object, handle_async_io, os);
return 0;
}

Expand Down Expand Up @@ -772,7 +772,7 @@ static gboolean check_put(GObex *obex, GObexPacket *req, void *user_data)
break;
case -EAGAIN:
g_obex_suspend(os->obex);
os->driver->set_io_watch(os->object, handle_async_io, os);
obex_object_set_io_watch(os->object, handle_async_io, os);
return TRUE;
default:
os_set_response(os, ret);
Expand Down

0 comments on commit 8e88f8c

Please sign in to comment.