Hi, David
   I just modified the  src/libsystemd/sd-bus/test-bus-match.c. 
And you could add the following two lines in the bloom_add_data() in bus-bloom.c
         for (i = 0; i < size/sizeof(uint64_t); i++)
            log_info("bloom: filter[%d] = 0x%llx",i, filter[i]);


 > Hi, All,
>      I use libsystemd.so for the kdbus protocol layer, and  I met a
> question that I added a signal matching rule by sd_bus_add_match() , then I
> sent signal by sd_bus_send().
> But I couldn't receive this signal  because its bloom_filter  caculated by
> siphash24()  NOT match the bloom_mask which was also caculated by
> siphash24().
>
>  For example ,  when adding matching rule for "
> type='signal',interface='service.a.interface',path='/service/a',member='com_0yunos_0spms_0uninstall',arg0path='/p1/p2/p3'
> " by sd_bus_add_match(),
> Can you provide a real C-code example so we can reproduce this?



Thank you very much!
Li Cheng

/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/

/***
  This file is part of systemd.

  Copyright 2013 Lennart Poettering

  systemd is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as published by
  the Free Software Foundation; either version 2.1 of the License, or
  (at your option) any later version.

  systemd is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/

#include "log.h"
#include "macro.h"

#include "bus-match.h"
#include "bus-message.h"
#include "bus-util.h"
#include "bus-slot.h"

static bool mask[32];

static int filter(sd_bus *b, sd_bus_message *m, void *userdata, sd_bus_error 
*ret_error) {
        log_info("Ran %u", PTR_TO_UINT(userdata));
        assert_se(PTR_TO_UINT(userdata) < ELEMENTSOF(mask));
        mask[PTR_TO_UINT(userdata)] = true;
        return 0;
}

static bool mask_contains(unsigned a[], unsigned n) {
        unsigned i, j;

        for (i = 0; i < ELEMENTSOF(mask); i++) {
                bool found = false;

                for (j = 0; j < n; j++)
                        if (a[j] == i) {
                                found = true;
                                break;
                        }

                if (found != mask[i])
                        return false;
        }

        return true;
}

static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const 
char *match, int value) {
        struct bus_match_component *components = NULL;
        unsigned n_components = 0;
        sd_bus_slot *s;
        int r;

        s = slots + value;
        zero(*s);

        r = bus_match_parse(match, &components, &n_components);
        if (r < 0)
                return r;

        s->userdata = INT_TO_PTR(value);
        s->match_callback.callback = filter;

        r = bus_match_add(root, components, n_components, &s->match_callback);
        bus_match_parse_free(components, n_components);

        return r;
}

int main(int argc, char *argv[]) {
        struct bus_match_node root = {
                .type = BUS_MATCH_ROOT,
        };

        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
        enum bus_match_node_type i;
        sd_bus_slot *slots[19];
        int r;

        r = sd_bus_open_system(&bus);
        if (r < 0)
                return EXIT_TEST_SKIP;

        //assert_se(match_add(slots, &root, 
"type='signal',interface='service.a.interface',path='/service/a',member='com_0yunos_0spms_0uninstall',arg0path='/p1/p2/p3',",
 1) >= 0);
        assert_se(sd_bus_add_match(bus, &slots[1], 
"type='signal',interface='service.a.interface',path='/service/a',member='com_0yunos_0spms_0uninstall',arg0path='/p1/p2/p3',",
 filter, NULL) >= 0);

        bus_match_dump(&bus->match_callbacks, 0);

        assert_se(sd_bus_message_new_signal(bus, &m, "/service/a", 
"service.a.interface", "com_0yunos_0spms_0uninstall") >= 0);
      //  assert_se(sd_bus_message_append(m, "s", "/p1/p2/p3") >= 0);
        assert_se(sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, 
"/p1/p2/p3") >= 0);
//        assert_se(bus_message_seal(m, 1, 0) >= 0);
        assert_se(sd_bus_send(bus, m, NULL) >= 0);


        bus_match_free(&root);

        return 0;
}
_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to