Remove another layer of abstraction in linestack.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 13 Jun 2009 14:42:45 +0000 (16:42 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 13 Jun 2009 14:42:45 +0000 (16:42 +0200)
libirc/linestack.c
libirc/linestack.h
src/admin.c
src/repl_backends.c
testsuite/test-linestack.c

index 3bf13d07447f77664f0db9b94bb7a6982376f81a..392c6cb8362068e2abc3dc239a20fb09efe975ec 100644 (file)
@@ -248,24 +248,12 @@ void free_linestack_context(struct linestack_context *data)
        g_free(data);
 }
 
-static struct linestack_marker *wrap_linestack_marker(struct linestack_context *ctx, void *data)
-{
-       struct linestack_marker *mrk;
-       if (data == NULL)
-               return NULL;
-
-       mrk = g_new0(struct linestack_marker, 1);
-       mrk->data = data;
-       mrk->free_fn = g_free;
-       return mrk;
-}
-
 struct irc_network_state *linestack_get_state(
-               struct linestack_context *nd, struct linestack_marker *lm)
+               struct linestack_context *nd, linestack_marker to_index)
 {
        struct irc_network_state *ret;
-       gint64 *to_index, t, state_index;
-       struct linestack_marker m1, m2;
+       gint64 t;
+       guint64 state_index;
        GError *error = NULL;
        GIOStatus status;
        char *data_file;
@@ -273,7 +261,6 @@ struct irc_network_state *linestack_get_state(
 
        g_assert(nd != NULL);
 
-       to_index = lm?lm->data:NULL;
        if (nd == NULL) 
                return NULL;
 
@@ -328,11 +315,7 @@ struct irc_network_state *linestack_get_state(
        if (!marshall_network_state(MARSHALL_PULL, state_file, ret))
                return NULL;
 
-       m1.free_fn = NULL;
-       m1.data = &state_index;
-       m2.free_fn = NULL;
-       m2.data = to_index;
-       linestack_replay(nd, &m1, &m2, ret);
+       linestack_replay(nd, &state_index, to_index, ret);
 
        g_io_channel_unref(state_file);
        
@@ -342,7 +325,7 @@ struct irc_network_state *linestack_get_state(
 }
 
 gboolean linestack_traverse(struct linestack_context *nd,
-               struct linestack_marker *lm_from, struct linestack_marker *lm_to,
+               linestack_marker lm_from, linestack_marker lm_to,
                linestack_traverse_fn handler, void *userdata)
 {
        gint64 start_index, end_index;
@@ -352,10 +335,7 @@ gboolean linestack_traverse(struct linestack_context *nd,
        char *raw;
        struct irc_line *l;
        guint64 i;
-       void *mf, *mt;
 
-       mf = lm_from?lm_from->data:NULL;
-       mt = lm_to?lm_to->data:NULL;
        if (nd == NULL) 
                return FALSE;
 
@@ -364,16 +344,16 @@ gboolean linestack_traverse(struct linestack_context *nd,
 
        g_io_channel_flush(nd->index_file, &error);
        
-       if (mf == NULL) {
+       if (lm_from == NULL) {
                start_index = 0;
        } else {
-               start_index = *((guint64 *)mf);
+               start_index = *lm_from;
        }
        
-       if (mt == NULL) {
+       if (lm_to == NULL) {
                end_index = nd->count;
        } else {
-               end_index = *((guint64 *)mt);
+               end_index = *((guint64 *)lm_to);
        }
 
        raw = NULL;
@@ -488,8 +468,8 @@ static gboolean traverse_object_handler(struct irc_line *l, time_t t, void *stat
 gboolean linestack_traverse_object(
                        struct linestack_context *ctx,
                        const char *obj, 
-                       struct linestack_marker *lm_from, 
-                       struct linestack_marker *lm_to, linestack_traverse_fn hl,
+                       linestack_marker lm_from, 
+                       linestack_marker lm_to, linestack_traverse_fn hl,
                        void *userdata)
 {
        struct traverse_object_data d;
@@ -502,25 +482,20 @@ gboolean linestack_traverse_object(
        return linestack_traverse(ctx, lm_from, lm_to, traverse_object_handler, &d);
 }
 
-void linestack_free_marker(struct linestack_marker *lm)
+void linestack_free_marker(linestack_marker lm)
 {
-       if (lm == NULL)
-               return;
-
-       if (lm->free_fn != NULL) 
-               lm->free_fn(lm->data);
        g_free(lm);
 }
 
-struct linestack_marker *linestack_get_marker(struct linestack_context *nd)
+linestack_marker linestack_get_marker(struct linestack_context *nd)
 {
-       gint64 *pos;
+       guint64 *pos;
        if (nd == NULL)
                return NULL;
 
-       pos = g_new0(gint64, 1);
+       pos = g_new0(guint64, 1);
        (*pos) = nd->count;
-       return wrap_linestack_marker(nd, pos);
+       return pos;
 }
 
 static const char *linestack_messages[] = { 
@@ -678,7 +653,7 @@ static gboolean send_line_dataonly(struct irc_line *l, time_t t, void *_privdata
        return client_send_line(privdata->client, l, NULL);
 }
 
-gboolean linestack_send(struct linestack_context *ctx, struct linestack_marker *mf, struct linestack_marker *mt, struct irc_client *c, gboolean dataonly, gboolean timed, int time_offset)
+gboolean linestack_send(struct linestack_context *ctx, linestack_marker mf, linestack_marker mt, struct irc_client *c, gboolean dataonly, gboolean timed, int time_offset)
 {
        struct send_line_privdata privdata;
        linestack_traverse_fn trav_fn;
@@ -701,7 +676,7 @@ gboolean linestack_send(struct linestack_context *ctx, struct linestack_marker *
        return linestack_traverse(ctx, mf, mt, trav_fn, &privdata);
 }
 
-gboolean linestack_send_object(struct linestack_context *ctx, const char *obj, struct linestack_marker *mf, struct linestack_marker *mt, struct irc_client *c, gboolean dataonly, gboolean timed, int time_offset)
+gboolean linestack_send_object(struct linestack_context *ctx, const char *obj, linestack_marker mf, linestack_marker mt, struct irc_client *c, gboolean dataonly, gboolean timed, int time_offset)
 {
        struct send_line_privdata privdata;
        linestack_traverse_fn trav_fn;
@@ -732,8 +707,8 @@ static gboolean replay_line(struct irc_line *l, time_t t, void *state)
 }
 
 gboolean linestack_replay(struct linestack_context *ctx, 
-                                                 struct linestack_marker *mf, 
-                                                 struct linestack_marker *mt, 
+                                                 linestack_marker mf, 
+                                                 linestack_marker mt, 
                                                  struct irc_network_state *st)
 {
        return linestack_traverse(ctx, mf, mt, replay_line, st);
index 1fadbd062f1a11d3ac554d5390ba2aa5240c083f..4cf0a3cac3b776a6a3a528920a1a81e751123356 100644 (file)
@@ -34,47 +34,42 @@ struct irc_client;
 #include "hooks.h"
 
 struct irc_network_state;
-struct linestack_marker;
-struct ctrlproxy_config;
-
 /**
  * Mark set a specific point in time in a linestack.
  */
-struct linestack_marker {
-       void *data;
-       void (*free_fn) (void *);
-};
+typedef guint64 *linestack_marker;
+struct ctrlproxy_config;
 
 /* linestack.c */
 typedef gboolean (*linestack_traverse_fn) (struct irc_line *, time_t, void *);
 
-G_MODULE_EXPORT struct linestack_marker *linestack_get_marker_numlines (
+G_MODULE_EXPORT linestack_marker linestack_get_marker_numlines (
                struct linestack_context *,
                int lines);
 
 G_MODULE_EXPORT struct irc_network_state *linestack_get_state (
                struct linestack_context *,
-               struct linestack_marker *);
+               linestack_marker );
 
 G_MODULE_EXPORT gboolean linestack_traverse (
                struct linestack_context *,
-               struct linestack_marker *from,
-               struct linestack_marker *to, /* Can be NULL for 'now' */
+               linestack_marker from,
+               linestack_marker to, /* Can be NULL for 'now' */
                linestack_traverse_fn, 
                void *userdata);
 
 G_MODULE_EXPORT gboolean linestack_traverse_object (
                struct linestack_context *,
                const char *object,
-               struct linestack_marker *from,
-               struct linestack_marker *to, /* Can be NULL for 'now' */
+               linestack_marker from,
+               linestack_marker to, /* Can be NULL for 'now' */
                linestack_traverse_fn,
                void *userdata);
 
 G_MODULE_EXPORT gboolean linestack_send (
                struct linestack_context *,
-               struct linestack_marker *from,
-               struct linestack_marker *to, /* Can be NULL for 'now' */
+               linestack_marker from,
+               linestack_marker to, /* Can be NULL for 'now' */
                struct irc_client *, 
                gboolean dataonly, 
                gboolean timed,
@@ -83,8 +78,8 @@ G_MODULE_EXPORT gboolean linestack_send (
 G_MODULE_EXPORT gboolean linestack_send_object (
                struct linestack_context *,
                const char *object,
-               struct linestack_marker *from,
-               struct linestack_marker *to, /* Can be NULL for 'now' */
+               linestack_marker from,
+               linestack_marker to, /* Can be NULL for 'now' */
                struct irc_client *,
                gboolean dataonly,
                gboolean timed,
@@ -92,8 +87,8 @@ G_MODULE_EXPORT gboolean linestack_send_object (
 
 G_MODULE_EXPORT gboolean linestack_replay (
                struct linestack_context *,
-               struct linestack_marker *from,
-               struct linestack_marker *to,/* Can be NULL for 'now' */
+               linestack_marker from,
+               linestack_marker to,/* Can be NULL for 'now' */
                struct irc_network_state *st);
 
 G_MODULE_EXPORT gboolean linestack_insert_line(
@@ -102,8 +97,8 @@ G_MODULE_EXPORT gboolean linestack_insert_line(
                enum data_direction dir, 
                const struct irc_network_state *);
 
-G_MODULE_EXPORT void linestack_free_marker(struct linestack_marker *);
-G_MODULE_EXPORT struct linestack_marker *linestack_get_marker(struct linestack_context *);
+G_MODULE_EXPORT void linestack_free_marker(linestack_marker );
+G_MODULE_EXPORT linestack_marker linestack_get_marker(struct linestack_context *);
 
 /**
  * Create a new linestack context
index 46ce0b45aca3a4566a73e3296f901eb4063ef690..f43f04d5c3062413c8ca496a775e62ab7b7ceb8e 100644 (file)
@@ -574,7 +574,7 @@ static GHashTable *markers = NULL;
 
 static void cmd_backlog(admin_handle h, const char * const *args, void *userdata)
 {
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_network *n;
 
        if (admin_get_client(h) == NULL) {
index 7a4a009333ea8e84ed029ec5d7b817015d232f8d..71d09f7fe0c7e72e8565397529fc047767066ca4 100644 (file)
@@ -45,7 +45,7 @@ static gboolean check_highlight(struct irc_line *l, time_t t, void *userdata)
 
 static void highlight_replicate(struct irc_client *c)
 {
-       struct linestack_marker *lm = g_hash_table_lookup(markers, c->network);
+       linestack_marker lm = g_hash_table_lookup(markers, c->network);
 
        if (c->network->external_state) {
                client_send_state(c, c->network->external_state);
@@ -76,7 +76,7 @@ static void lastdisconnect_mark(struct irc_client *c, void *userdata)
 
 static void lastdisconnect_replicate(struct irc_client *c)
 {
-       struct linestack_marker *lm = g_hash_table_lookup(lastdisconnect_backlog, c->network);
+       linestack_marker lm = g_hash_table_lookup(lastdisconnect_backlog, c->network);
        struct irc_network_state *ns;
 
        if (c->network->linestack == NULL)
@@ -109,7 +109,7 @@ static gboolean log_data(struct irc_network *n, const struct irc_line *l, enum d
 
 static void simple_replicate(struct irc_client *c)
 {
-       struct linestack_marker *m;
+       linestack_marker m;
        struct irc_network_state *ns;
 
        if (c->network->linestack == NULL)
index 2129b4dddb404261075b45c55089ba76cbe5a792..6d0c1f067403c236ce331fb1b14fc86344f9d0a6 100644 (file)
@@ -205,7 +205,7 @@ END_TEST
 START_TEST(test_msg)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_client *cl;
 
        GIOChannel *ch1, *ch2;
@@ -238,7 +238,7 @@ END_TEST
 START_TEST(test_join_part)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_client *cl;
 
        GIOChannel *ch1, *ch2;
@@ -273,7 +273,7 @@ END_TEST
 START_TEST(test_skip_msg)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_client *cl;
 
        GIOChannel *ch1, *ch2;
@@ -308,7 +308,7 @@ END_TEST
 START_TEST(test_object_msg)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_client *cl;
 
        GIOChannel *ch1, *ch2;
@@ -346,7 +346,7 @@ END_TEST
 START_TEST(test_object_open)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *lm;
+       linestack_marker lm;
        struct irc_client *cl;
 
        GIOChannel *ch1, *ch2;
@@ -411,7 +411,7 @@ static gboolean line_track(struct irc_line *l, time_t t, void *data)
 START_TEST(bench_lots_of_lines)
        struct irc_network_state *ns1;
        struct linestack_context *ctx;
-       struct linestack_marker *marker;
+       linestack_marker marker;
        int i;
 
        ns1 = network_state_init("bla", "Gebruikersnaam", "Computernaam");