[Vala] Binding a C library w/ a message inheritance structure



Hi folks,

in one of our projects, we have the following .vapi (see attachement).
There's a callback that sends us messages via

void callback( int event, Message message )

We then have to cast to the actual type like that:

        switch ( event )
        {
            case Msmcomm.ResponseType.GET_IMEI:
                unowned Msmcomm.Reply.GetImei msg =
(Msmcomm.Reply.GetImei) message;
                details = @"IMEI = $(msg.getImei())";
                break;
            case Msmcomm.ResponseType.GET_FIRMWARE_INFO:
                // We want something like: var msg =
message.safeCast<Msmcomm.Reply.GetImei>( message );
                unowned Msmcomm.Reply.GetFirmwareInfo msg =
(Msmcomm.Reply.GetFirmwareInfo) message;
                details = @"FIRMWARE = $(msg.getInfo())";
                break;
            case Msmcomm.ResponseType.CM_CALL:
                unowned Msmcomm.Reply.Call msg = (Msmcomm.Reply.Call)
message;
                details = @"refId = $(msg.getRefId()) cmd =
$(msg.getCmd()) err = $(msg.getErrorCode())";
                break;
...

If I compile this code, it errors out with:

/local/pkg/fso/msmcomm/msmvterm/src/terminal.c:870: undefined reference
to `MSMCOMM_REPLY_GET_FIRMWARE_INFO'
/local/pkg/fso/msmcomm/msmvterm/src/terminal.c:860: undefined reference
to `MSMCOMM_REPLY_GET_IMEI'
/local/pkg/fso/msmcomm/msmvterm/src/terminal.c:882: undefined reference
to `MSMCOMM_REPLY_CALL'
/local/pkg/fso/msmcomm/msmvterm/src/terminal.c:895: undefined reference
to `MSMCOMM_REPLY_CHARGER_STATUS'
src/commands.o: In function `commands_end_call':
/local/pkg/fso/msmcomm/msmvterm/src/commands.c:772: undefined reference
to `msmcomm_message_unref'
src/commands.o: In function `commands_answer_call':
/local/pkg/fso/msmcomm/msmvterm/src/commands.c:762: undefined reference
to `msmcomm_message_unref'
src/commands.o: In function `commands_get_charger_status':
/local/pkg/fso/msmcomm/msmvterm/src/commands.c:675: undefined reference
to `msmcomm_message_unref'
src/commands.o: In function `commands_test_alive':
/local/pkg/fso/msmcomm/msmvterm/src/commands.c:638: undefined reference
to `msmcomm_message_unref'

all which I don't quite understand. The offending code is the message
cast, i.e. the line:

                        msg = MSMCOMM_REPLY_GET_FIRMWARE_INFO (message);

I have two questions now:

1.) Where does Vala take that MSMCOMM_REPLY_GET_FIRMWARE_INFO and how
can I fix the problem? Since all the concrete messages inherit from the
base class I would expect this to be a no-op in C, as we're just
ensuring Vala that we know which message type it is.

2.) Is there a better way to handle C-APIs like that?

Attachment: msmcomm-1.0.vapi
Description: Text Data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]