From: Emil Velikov <emil.l.velikov@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Emil Velikov <emil.velikov@collabora.com>
Subject: [PATCH BlueZ 15/20] obexd: remove obex_mime_type_driver::set_io_watch
Date: Tue, 16 Jan 2024 14:00:40 +0000 [thread overview]
Message-ID: <20240116-const-v1-15-17c87978f40b@gmail.com> (raw)
In-Reply-To: <20240116-const-v1-0-17c87978f40b@gmail.com>
From: Emil Velikov <emil.velikov@collabora.com>
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.
---
obexd/src/mimetype.c | 12 ++----------
obexd/src/mimetype.h | 6 ++++--
obexd/src/obex.c | 12 ++++++------
3 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/obexd/src/mimetype.c b/obexd/src/mimetype.c
index 212f24b18..cf6e15dc6 100644
--- a/obexd/src/mimetype.c
+++ b/obexd/src/mimetype.c
@@ -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;
@@ -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;
@@ -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);
diff --git a/obexd/src/mimetype.h b/obexd/src/mimetype.h
index e1c14f405..55ddded08 100644
--- a/obexd/src/mimetype.h
+++ b/obexd/src/mimetype.h
@@ -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);
@@ -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);
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 3a68fd66c..4bf5ad124 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -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)
@@ -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);
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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);
--
2.43.0
WARNING: multiple messages have this Message-ID (diff)
From: Emil Velikov via B4 Relay <devnull+emil.l.velikov.gmail.com@kernel.org>
To: linux-bluetooth@vger.kernel.org
Cc: Emil Velikov <emil.velikov@collabora.com>
Subject: [PATCH BlueZ 15/20] obexd: remove obex_mime_type_driver::set_io_watch
Date: Tue, 16 Jan 2024 14:00:40 +0000 [thread overview]
Message-ID: <20240116-const-v1-15-17c87978f40b@gmail.com> (raw)
In-Reply-To: <20240116-const-v1-0-17c87978f40b@gmail.com>
From: Emil Velikov <emil.velikov@collabora.com>
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.
---
obexd/src/mimetype.c | 12 ++----------
obexd/src/mimetype.h | 6 ++++--
obexd/src/obex.c | 12 ++++++------
3 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/obexd/src/mimetype.c b/obexd/src/mimetype.c
index 212f24b18..cf6e15dc6 100644
--- a/obexd/src/mimetype.c
+++ b/obexd/src/mimetype.c
@@ -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;
@@ -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;
@@ -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);
diff --git a/obexd/src/mimetype.h b/obexd/src/mimetype.h
index e1c14f405..55ddded08 100644
--- a/obexd/src/mimetype.h
+++ b/obexd/src/mimetype.h
@@ -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);
@@ -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);
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 3a68fd66c..4bf5ad124 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -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)
@@ -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);
}
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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);
--
2.43.0
next prev parent reply other threads:[~2024-01-16 14:00 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 14:00 [PATCH BlueZ 00/20] Constify all the things Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 01/20] src: const annotate the bluetooth plugin API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 18:37 ` Constify all the things bluez.test.bot
2024-01-16 14:00 ` [PATCH BlueZ 02/20] monitor: const annotate util_ltv_debugger instances and API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 03/20] monitor: const annotate cmd/handler tables Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 04/20] monitor: const annotate misc arrays Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 05/20] monitor: const annotate intel_version_tlv_desc::type_str and API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 06/20] monitor: const annotate type_table and related API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 07/20] profiles: annotate immutable data as const Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 08/20] attrib: " Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 09/20] client: annotate struct option instances " Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 10/20] emulator: const annotate rfcomm_crc_table[] Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 11/20] gobex: const annotate RO arrays, use G_N_ELEMENTS Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 12/20] lib: const annotate hci_map instances and related API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 13/20] lib: const annotate tupla instances and API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 14/20] mesh: const annotate misc data Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` Emil Velikov [this message]
2024-01-16 14:00 ` [PATCH BlueZ 15/20] obexd: remove obex_mime_type_driver::set_io_watch Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 16/20] obexd: const obex_mime_type_driver instances and API Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 17/20] obexd: const obex_service_driver " Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 18/20] obexd: const obex_transport_driver " Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 19/20] obexd: const annotate misc immutable data Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-16 14:00 ` [PATCH BlueZ 20/20] obexd: const annotate obex_plugin_desc entrypoint Emil Velikov
2024-01-16 14:00 ` Emil Velikov via B4 Relay
2024-01-22 23:53 ` [PATCH BlueZ 00/20] Constify all the things patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240116-const-v1-15-17c87978f40b@gmail.com \
--to=emil.l.velikov@gmail.com \
--cc=emil.velikov@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.