예제 #1
0
int main(int argc, char* argv[]) {

	// Test byte_sort
	printf("Testing byte_sort()...\n");
	assert(byte_sort(0x0706050403020100), 0x0706050403020100, 1);
	assert(byte_sort(0x0403deadbeef0201), 0xefdebead04030201, 2);
	assert(byte_sort(0x0001020304050607), 0x0706050403020100, 3);
	assert(byte_sort(0x0000000000000000), 0x0000000000000000, 4);
	assert(byte_sort(0xFFFFFFFFFFFFFFFF), 0xFFFFFFFFFFFFFFFF, 5);
	assert(byte_sort(0x0100000000000000), 0x0100000000000000, 6);
	assert(byte_sort(0x0000000000000001), 0x0100000000000000, 7);
	assert(byte_sort(0x1), 0x0100000000000000, 8);

	// Test nibble_sort
	printf("Testing nibble_sort()...\n");
	assert(nibble_sort(0xfedcba9876543210), 0xfedcba9876543210, 9);
	assert(nibble_sort(0x0403deadbeef0201), 0xfeeeddba43210000, 10);
	assert(nibble_sort(0x0000000000000000), 0x0000000000000000, 11);
	assert(nibble_sort(0xffffffffffffffff), 0xffffffffffffffff, 12);
	assert(nibble_sort(0x1000000000000000), 0x1000000000000000, 13);
	assert(nibble_sort(0x0101010101010101), 0x1111111100000000, 14);
	assert(nibble_sort(0x0000000000000010), 0x1000000000000000, 15);
	assert(nibble_sort(0x1), 0x1000000000000000, 16);

	// Test name_list
	printf("Testing name_list()...\n");
	struct elt * name = name_list();
	printf("%c%c%c%c%c%c\n", name->val, name->link->val, name->link->link->val,
		   name->link->link->link->val, name->link->link->link->link->val,
		   name->link->link->link->link->link->val);

	// Test Convert
	printf("Testing convert()...\n");
	convert(HEX, 0xdeadbeef);
	convert(BIN, 0x0123456789abcdef);	
	convert(BIN, 0xabcdef);
	convert(BIN, 0xfedcba987);
	convert(OCT, 0xdeadbeef);
	convert(OCT, 0xFFFFFFFFFFFFFFFF);
	convert(OCT, 0xFFFFFFFFFFFFFFF);	
	convert(1, 0xFFFFFFFFFFFFFFFF);
	convert(2, 0xFFFFFFFFFFFFFFFF);
	convert(3, 0xFFFFFFFFFFFFFFFF);

	// Test draw_me
	printf("Testing draw_me()...\n");
	draw_me();

	return 0;
}
예제 #2
0
void N3DView::send_server_info_to_client( SignalArgs& node ){
  SignalFrame& options = node.map( Protocol::Tags::key_options() );

  std::vector<std::string> data = options.get_array<std::string>("pathinfo");

  std::string path = data[0];
  std::string name = data[1];

  std::vector<QString> path_list(1);
  path_list[0] = QString(path.c_str());

  std::vector<QString> name_list(1);
  name_list[0] = QString(name.c_str());

  TabBuilder::instance()->getWidget<Widget3D>(as_ptr<CNode>())
      ->loadPaths(path_list, name_list);

}
예제 #3
0
    void refreshNameTable()
    {
        cachedNameTable.clear();
        std::map< std::string, NameTableEntry > vNamesO;

        UniValue names;
        try {
            JSONRPCRequest jreq = JSONRPCRequest();
            names = name_list(jreq).get_array();
        } catch (const UniValue& e) {
            LogPrintf ("name_list lookup error: %s\n", e.getValStr().c_str());
        }

        // pull all our names from wallet
        for (unsigned int idx = 0; idx < names.size(); idx++) {
            const UniValue& v = names[idx];
            std::string name = find_value ( v, "name").get_str();
            std::string data = find_value ( v, "value").get_str();
            int height = find_value ( v, "height").get_int();
            vNamesO[name] = NameTableEntry(name, data, height);
        }

        // Add existing names
        BOOST_FOREACH(const PAIRTYPE(std::string, NameTableEntry)& item, vNamesO)
            cachedNameTable.append(item.second);

        // Add pending names (name_new)
        BOOST_FOREACH(const PAIRTYPE(std::string, NameNewReturn)& item, pendingNameFirstUpdate)
            cachedNameTable.append(
                NameTableEntry(item.first,
                               item.second.data,
                               NameTableEntry::NAME_NEW));

        // qLowerBound() and qUpperBound() require our cachedNameTable list to be sorted in asc order
        qSort(cachedNameTable.begin(), cachedNameTable.end(), NameTableEntryLessThan());
    }
예제 #4
0
int main(int argc, char *argv[])
{
	struct {
		struct kdbus_cmd_make head;

		/* bloom size item */
		struct {
			uint64_t size;
			uint64_t type;
			struct kdbus_bloom_parameter bloom;
		} bs;

		/* name item */
		uint64_t n_size;
		uint64_t n_type;
		char name[64];
	} bus_make;
	int fdc, ret;
	char *bus;
	struct conn *activator, *conn_a;
	struct pollfd fds[2];
	bool activator_done = false;
	struct kdbus_policy_access access[2];

	printf("-- opening /dev/" KBUILD_MODNAME "/control\n");
	fdc = open("/dev/" KBUILD_MODNAME "/control", O_RDWR|O_CLOEXEC);
	if (fdc < 0) {
		fprintf(stderr, "--- error %d (%m)\n", fdc);
		return EXIT_FAILURE;
	}

	memset(&bus_make, 0, sizeof(bus_make));
	bus_make.bs.size = sizeof(bus_make.bs);
	bus_make.bs.type = KDBUS_ITEM_BLOOM_PARAMETER;
	bus_make.bs.bloom.size = 64;
	bus_make.bs.bloom.n_hash = 1;

	snprintf(bus_make.name, sizeof(bus_make.name), "%u-testbus", getuid());
	bus_make.n_type = KDBUS_ITEM_MAKE_NAME;
	bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;

	bus_make.head.size = sizeof(struct kdbus_cmd_make) +
			     sizeof(bus_make.bs) +
			     bus_make.n_size;

	printf("-- creating bus '%s'\n", bus_make.name);
	ret = ioctl(fdc, KDBUS_CMD_BUS_MAKE, &bus_make);
	if (ret) {
		fprintf(stderr, "--- error %d (%m)\n", ret);
		return EXIT_FAILURE;
	}

	if (asprintf(&bus, "/dev/" KBUILD_MODNAME "/%s/bus", bus_make.name) < 0)
		return EXIT_FAILURE;

	access[0].type = KDBUS_POLICY_ACCESS_USER;
	access[0].id = 1001;
	access[0].access = KDBUS_POLICY_OWN;

	access[1].type = KDBUS_POLICY_ACCESS_WORLD;
	access[1].access = KDBUS_POLICY_TALK;

	activator = kdbus_hello_activator(bus, "foo.test.activator", access, 2);
	if (!activator)
		return EXIT_FAILURE;

	conn_a = kdbus_hello(bus, 0, NULL, 0);
	if (!conn_a)
		return EXIT_FAILURE;

	add_match_empty(conn_a->fd);

	name_list(conn_a, KDBUS_NAME_LIST_NAMES |
			  KDBUS_NAME_LIST_UNIQUE |
			  KDBUS_NAME_LIST_ACTIVATORS |
			  KDBUS_NAME_LIST_QUEUED);

	msg_send(conn_a, "foo.test.activator", 0xdeafbeef, 0, 0, 0, KDBUS_DST_ID_NAME);

	fds[0].fd = activator->fd;
	fds[1].fd = conn_a->fd;

	printf("-- entering poll loop ...\n");
	for (;;) {
		int i, nfds = sizeof(fds) / sizeof(fds[0]);

		for (i = 0; i < nfds; i++) {
			fds[i].events = POLLIN | POLLPRI;
			fds[i].revents = 0;
		}

		ret = poll(fds, nfds, 3000);
		if (ret <= 0)
			break;

		name_list(conn_a, KDBUS_NAME_LIST_NAMES);

		if ((fds[0].revents & POLLIN) && !activator_done) {
			printf("Starter was called back!\n");
			ret = name_acquire(conn_a, "foo.test.activator", KDBUS_NAME_REPLACE_EXISTING);
			if (ret != 0)
				break;

			activator_done = true;
		}

		if (fds[1].revents & POLLIN) {
			msg_recv(conn_a);
			break;
		}
	}

	printf("-- closing bus connections\n");
	close(activator->fd);
	close(conn_a->fd);
	free(activator);
	free(conn_a);

	printf("-- closing bus master\n");
	close(fdc);
	free(bus);

	return EXIT_SUCCESS;
}
예제 #5
0
int main(int argc, char *argv[])
{
    struct {
        struct kdbus_cmd_bus_make head;

        /* name item */
        uint64_t n_size;
        uint64_t n_type;
        char name[64];
    } __attribute__ ((__aligned__(8))) bus_make;
    int fdc, ret, cookie;
    char *bus;
    struct conn *conn_a, *conn_b;
    struct pollfd fds[2];
    int count;
    int r;

    printf("-- opening /dev/kdbus/control\n");
    fdc = open("/dev/kdbus/control", O_RDWR|O_CLOEXEC);
    if (fdc < 0) {
        fprintf(stderr, "--- error %d (%m)\n", fdc);
        return EXIT_FAILURE;
    }

    memset(&bus_make, 0, sizeof(bus_make));
    bus_make.head.bloom_size = 64;

    snprintf(bus_make.name, sizeof(bus_make.name), "%u-testbus", getuid());
    bus_make.n_type = KDBUS_ITEM_MAKE_NAME;
    bus_make.n_size = KDBUS_ITEM_HEADER_SIZE + strlen(bus_make.name) + 1;

    bus_make.head.size = sizeof(struct kdbus_cmd_bus_make) +
                         bus_make.n_size;

    printf("-- creating bus '%s'\n", bus_make.name);
    ret = ioctl(fdc, KDBUS_CMD_BUS_MAKE, &bus_make);
    if (ret) {
        fprintf(stderr, "--- error %d (%m)\n", ret);
        return EXIT_FAILURE;
    }

    if (asprintf(&bus, "/dev/kdbus/%s/bus", bus_make.name) < 0)
        return EXIT_FAILURE;

    conn_a = connect_to_bus(bus);
    conn_b = connect_to_bus(bus);
    if (!conn_a || !conn_b)
        return EXIT_FAILURE;

    r = upload_policy(conn_a->fd, "foo.bar.test");
    if (r < 0)
        return EXIT_FAILURE;
    r = upload_policy(conn_a->fd, "foo.bar.baz");
    if (r < 0)
        return EXIT_FAILURE;
    r = upload_policy(conn_a->fd, "foo.bar.double");
    if (r < 0)
        return EXIT_FAILURE;

    r = name_acquire(conn_a, "foo.bar.test", KDBUS_NAME_ALLOW_REPLACEMENT);
    if (r < 0)
        return EXIT_FAILURE;
    r = name_acquire(conn_a, "foo.bar.baz", 0);
    if (r < 0)
        return EXIT_FAILURE;
    r = name_acquire(conn_b, "foo.bar.baz", KDBUS_NAME_QUEUE);
    if (r < 0)
        return EXIT_FAILURE;

    r = name_acquire(conn_a, "foo.bar.double", 0);
    if (r < 0)
        return EXIT_FAILURE;
    r = name_acquire(conn_a, "foo.bar.double", 0);
    if (r != -EALREADY)
        return EXIT_FAILURE;

    r = name_release(conn_a, "foo.bar.double");
    if (r < 0)
        return EXIT_FAILURE;
    r = name_release(conn_a, "foo.bar.double");
    if (r != -ESRCH)
        return EXIT_FAILURE;

    name_list(conn_b, KDBUS_NAME_LIST_UNIQUE | KDBUS_NAME_LIST_NAMES);

    add_match_empty(conn_a->fd);
    add_match_empty(conn_b->fd);

    cookie = 0;
    msg_send(conn_b, NULL, 0xc0000000 | cookie, KDBUS_DST_ID_BROADCAST);

    fds[0].fd = conn_a->fd;
    fds[1].fd = conn_b->fd;

    printf("-- entering poll loop ...\n");

    for (count = 0;; count++) {
        int i, nfds = sizeof(fds) / sizeof(fds[0]);

        for (i = 0; i < nfds; i++) {
            fds[i].events = POLLIN | POLLPRI | POLLHUP;
            fds[i].revents = 0;
        }

        ret = poll(fds, nfds, 3000);
        if (ret <= 0)
            break;

        if (fds[0].revents & POLLIN) {
            if (count > 2)
                name_release(conn_a, "foo.bar.baz");

            msg_recv(conn_a);
            msg_send(conn_a, NULL, 0xc0000000 | cookie++, conn_b->id);
        }

        if (fds[1].revents & POLLIN) {
            msg_recv(conn_b);
            msg_send(conn_b, NULL, 0xc0000000 | cookie++, conn_a->id);
        }

        name_list(conn_b, KDBUS_NAME_LIST_UNIQUE | KDBUS_NAME_LIST_NAMES);

        if (count > 10)
            break;
    }

    printf("-- closing bus connections\n");
    close(conn_a->fd);
    close(conn_b->fd);
    free(conn_a);
    free(conn_b);

    printf("-- closing bus master\n");
    close(fdc);
    free(bus);

    return EXIT_SUCCESS;
}