node-dbus icon indicating copy to clipboard operation
node-dbus copied to clipboard

Missing support for UNIX_FD type + My fix.

Open g00dnatur3 opened this issue 8 years ago • 0 comments

Inside encoder.cc just add the single line case DBUS_TYPE_UNIX_FD: as shown below:

        **case DBUS_TYPE_UNIX_FD:**
        case DBUS_TYPE_UINT32:
        {
            dbus_uint32_t data = value->Uint32Value();
            // printf("DBUS_TYPE_UINT32: ");
            // printf("value: %u\n",data);

            if (!dbus_message_iter_append_basic(iter, type, &data)) {
                printf("Failed to encode numeric value\n");
                return false;
            }

            break;
        }

Inside decoder.cc just add t he singe line DBUS_BASIC_TYPE(DBUS_TYPE_UNIX_FD, dbus_uint32_t, 0, Number) as shown below

        DBUS_BASIC_TYPE(DBUS_TYPE_BOOLEAN, dbus_bool_t, false, Boolean)
        DBUS_BASIC_TYPE(DBUS_TYPE_BYTE, unsigned char, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_INT16, dbus_int16_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_UINT16, dbus_uint16_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_INT32, dbus_int32_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_UINT32, dbus_uint32_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_INT64, dbus_int64_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_UINT64, dbus_uint64_t, 0, Number)
        DBUS_BASIC_TYPE(DBUS_TYPE_DOUBLE, double, 0, Number)
        **DBUS_BASIC_TYPE(DBUS_TYPE_UNIX_FD, dbus_uint32_t, 0, Number)**

finally inside utils.js update the Signature function ti support a 'File' type as shown below:

var Signature = function(type) {
    **if (type == 'File') {
        return 'h';
    }** else if (type == 'Auto') {
        return 'v';
    } else if (type === String) {
        return 's';
    } else if (type === Number) {
        return 'd';
    } else if (type === Boolean) {
        return 'b';
    } else if (type === Array) {
        return 'av';
    } else if (type === Object) {
        return 'a{sv}';
    } 

    return 'v';
};

Example usage:

        iface.addMethod('NewConnection', {in: [ DBus.Define(Object), DBus.Define('File'), DBus.Define(Object) ]}, function(device, fd, props, callback) {
            console.log('>> Profile.NewConnection called');
            console.log('device: ' + device);
            console.log('fd: ' + fd);
            console.log('props: ' + JSON.stringify(props));

            var writeStream = fs.createWriteStream(null, { fd: fd });
            // Write to &3 / oob1 (out-of-band 1)
            writeStream.write('hello world');

            var readStream = fs.createReadStream(null, { fd: fd });
            readStream.on('data', function(data) {
                console.log(data.toString());
            });

            callback();
        });

Please add this fix, that would be awesome.

Thank you.

g00dnatur3 avatar Aug 28 '16 11:08 g00dnatur3