]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce afs_max_size_handler_data and afs_max_size_handler().
authorAndre Noll <maan@systemlinux.org>
Mon, 16 Jan 2012 21:14:41 +0000 (22:14 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 5 May 2012 10:54:53 +0000 (12:54 +0200)
Whenever the maximal size of a para buffer is reached, para_printf()
calls the specified max size handler. This handler takes, in addition
to the actual buffer and its size, a void * context pointer.  Currently
all commands simply pass a pointer to the underlying file descriptor
here since this is the only context the handler needs to know about.

However, this is going to change since with sideband connections the
handler needs to know also the sideband designator.

To meet this future need, this patch introduces struct
afs_max_size_handler_data, which consists of the file descriptor only
at the moment, as well as a simple wrapper for pass_buffer_as_shm().

afs.c
afs.h
aft.c
attribute.c
blob.c
mood.c
playlist.c

diff --git a/afs.c b/afs.c
index 5939cbe69cc46c1095d7cb82ffc98a741d3f6505..04b6961168eedc979774019019e30f139456a965 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -546,8 +546,10 @@ static void com_select_callback(int fd, const struct osl_object *query)
 {
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler,
        };
        char *arg = query->data;
        int num_admissible, ret, ret2;
@@ -787,10 +789,6 @@ static void command_pre_select(struct sched *s, struct task *t)
  * \param size The size of \a buf.
  * \param fd_ptr A pointer to the file descriptor.
  *
- * This function is used as the \a max_size handler in a \ref para_buffer
- * structure. If used this way, it is called by \ref para_printf() whenever
- * the buffer passed to para_printf() is about to exceed its maximal size.
- *
  * This function creates a shared memory area large enough to hold
  * the content given by \a buf and \a size and sends the identifier
  * of this area to the file descriptor given by \a fd_ptr.
diff --git a/afs.h b/afs.h
index 7145c41b9ee71d10ad1fcaeb492532176dfcc25a..ba0d266ab7198896274f8dded4f215ee2131ca91 100644 (file)
--- a/afs.h
+++ b/afs.h
@@ -209,6 +209,34 @@ typedef int callback_result_handler(struct osl_object *result, void *private);
 int sc_send_result(struct osl_object *result, void *private);
 int pass_buffer_as_shm(char *buf, size_t size, void *fd_ptr);
 
+
+/** Structure passed to the AFS max_size handler. */
+struct afs_max_size_handler_data {
+       /** Local socket connecting the command handler and the AFS process. */
+       int fd;
+};
+
+/**
+ * Standard max_size handler for AFS commands.
+ *
+ * \param buf Contains (part of) the AFS command output.
+ * \param size The number of bytes in \a buf.
+ * \param private Pointer to a \ref afs_max_size_handler_data structure.
+ *
+ * Whenever the output of an AFS command exceeds the maximal size of a shared
+ * memory area, the max size handler of the para_buffer which holds the command
+ * output is called with \a private being a pointer to a structure of type
+ * afs_max_size_handler_data.
+ *
+ * \return The return value of the underlying call to \ref
+ *  pass_buffer_as_shm().
+ */
+_static_inline_ int afs_max_size_handler(char *buf, size_t size, void *private)
+{
+       struct afs_max_size_handler_data *amshd = private;
+       return pass_buffer_as_shm(buf, size, &amshd->fd);
+}
+
 __noreturn void afs_init(uint32_t cookie, int socket_fd);
 void afs_event(enum afs_events event, struct para_buffer *pb,
        void *data);
diff --git a/aft.c b/aft.c
index 7516e328e9bd63037476b99f37f4bbab5ffd0b37..dffe3a31526529b78099c3b1339710939b4309bc 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1349,9 +1349,14 @@ static void com_ls_callback(int fd, const struct osl_object *query)
 {
        struct ls_options *opts = query->data;
        char *p, *pattern_start = (char *)query->data + sizeof(*opts);
-       struct para_buffer b = {.max_size = shm_get_shmmax(),
+       struct para_buffer b = {
+               .max_size = shm_get_shmmax(),
                .flags = (opts->mode == LS_MODE_PARSER)? PBF_SIZE_PREFIX : 0,
-               .max_size_handler = pass_buffer_as_shm, .private_data = &fd};
+               .max_size_handler = afs_max_size_handler,
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               }
+       };
        int i = 0, ret;
        time_t current_time;
 
@@ -1674,8 +1679,13 @@ static void com_add_callback(int fd, const struct osl_object *query)
        char afsi_buf[AFSI_SIZE];
        uint32_t flags = read_u32(buf + CAB_FLAGS_OFFSET);
        struct afs_info default_afsi = {.last_played = 0};
-       struct para_buffer msg = {.max_size = shm_get_shmmax(),
-               .max_size_handler = pass_buffer_as_shm, .private_data = &fd};
+       struct para_buffer msg = {
+               .max_size = shm_get_shmmax(),
+               .max_size_handler = afs_max_size_handler,
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               }
+       };
        uint16_t afhi_offset, chunks_offset;
 
        hash = (unsigned char *)buf + CAB_HASH_OFFSET;
@@ -2082,7 +2092,7 @@ static void com_touch_callback(int fd, const struct osl_object *query)
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .max_size_handler = afs_max_size_handler
                }
        };
        int ret, ret2 = 0;
@@ -2223,7 +2233,7 @@ static void com_rm_callback(int fd, const struct osl_object *query)
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .max_size_handler = afs_max_size_handler
                }
        };
        int ret;
@@ -2365,7 +2375,7 @@ static void com_cpsi_callback(int fd, const struct osl_object *query)
                .pb = {
                        .max_size = shm_get_shmmax(),
                        .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .max_size_handler = afs_max_size_handler
                }
        };
        int ret;
@@ -2538,8 +2548,10 @@ void aft_check_callback(int fd, __a_unused const struct osl_object *query)
 {
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler
        };
        int ret = para_printf(&pb, "checking audio file table...\n");
 
index 19700944dff7c266db4c78a78e73eb79fda37713..9fddc1c3ddbdadf6226c65b664e33658dcbb35b5 100644 (file)
@@ -151,8 +151,10 @@ static void com_lsatt_callback(int fd, const struct osl_object *query)
                .flags = *(unsigned *) query->data,
                .pb = {
                        .max_size = shm_get_shmmax(),
-                       .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .private_data = &(struct afs_max_size_handler_data) {
+                               .fd = fd,
+                       },
+                       .max_size_handler = afs_max_size_handler
                }
 
        };
@@ -297,8 +299,10 @@ static void com_addatt_callback(int fd, const struct osl_object *query)
        int ret = 1, ret2 = 0;
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler
        };
        size_t len;
 
@@ -380,8 +384,10 @@ static void com_mvatt_callback(int fd, const struct osl_object *query)
        struct osl_row *row;
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler,
        };
        int ret;
 
@@ -450,8 +456,10 @@ static void com_rmatt_callback(int fd, const struct osl_object *query)
                .num_removed = 0,
                .pb = {
                        .max_size = shm_get_shmmax(),
-                       .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .private_data = &(struct afs_max_size_handler_data) {
+                               .fd = fd,
+                       },
+                       .max_size_handler = afs_max_size_handler,
                }
        };
        int ret, ret2 = 0;
diff --git a/blob.c b/blob.c
index 409e348709de83de48090c0535f3aced79dda2c8..fea230f190812ca7ed42cb3146989abdf9514896 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -133,8 +133,10 @@ static void com_lsblob_callback(struct osl_table *table,
                .flags = *(uint32_t *)query->data,
                .pb = {
                        .max_size = shm_get_shmmax(),
-                       .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .private_data = &(struct afs_max_size_handler_data) {
+                               .fd = fd,
+                       },
+                       .max_size_handler = afs_max_size_handler,
                }
        };
        struct pattern_match_data pmd = {
@@ -265,8 +267,10 @@ static void com_rmblob_callback(struct osl_table *table, int fd,
        struct rmblob_data rmbd = {
                .pb = {
                        .max_size = shm_get_shmmax(),
-                       .private_data = &fd,
-                       .max_size_handler = pass_buffer_as_shm
+                       .private_data = &(struct afs_max_size_handler_data) {
+                               .fd = fd,
+                       },
+                       .max_size_handler = afs_max_size_handler,
                }
        };
        struct pattern_match_data pmd = {
diff --git a/mood.c b/mood.c
index f580400dd52bfe4d129f7526034745929b0cdf7e..c892ff5c15fcfb8abfe8a11fe0a85911f073c740 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -425,8 +425,10 @@ void mood_check_callback(int fd, __a_unused const struct osl_object *query)
 {
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler
        };
 
        int ret = para_printf(&pb, "checking moods...\n");
index 13c2940428fb6720b32e4653207d5df0554c41f0..dd4371578179031403ed04274f0a0e7f872294c5 100644 (file)
@@ -132,8 +132,10 @@ void playlist_check_callback(int fd, __a_unused const struct osl_object *query)
 {
        struct para_buffer pb = {
                .max_size = shm_get_shmmax(),
-               .private_data = &fd,
-               .max_size_handler = pass_buffer_as_shm
+               .private_data = &(struct afs_max_size_handler_data) {
+                       .fd = fd,
+               },
+               .max_size_handler = afs_max_size_handler,
        };
        int ret = para_printf(&pb, "checking playlists...\n");