I've been working on calling a c lib from julia. I can open the library and
basic functions are working fine. However, I am stumped on the ccalls
making use of callbacks. I've read through the documentation and am just
not able to spot what I am doing wrong. (Admittedly, my C is very rusty.)
Below are the relevant C header lines from the library:
typedef void * Handle;
typedef enum
{
Disconnected = 0,
Connecting = 1,
Connected = 2,
Reconnecting = 3,
Disconnecting = 4,
SessionLost = 5,
} SessionStatus;
typedef void (*SESSION_STATUS_CALLBACK)(SessionStatus eSessionStatus);
typedef void (*LOGIN_FAILED_CALLBACK)(const char *error);
extern libXC void SessionStatusListener_setSessionStatus(Handle
listener,SESSION_STATUS_CALLBACK sessionStatus
);
In julia I do the following:
Using Match
typealias Handle Ptr{Void}
typealias SessionStatus Cint
lib = string(lib_path,"/../lib/libXC")
dlopen(lib)
function getstatusdescription(v)
@match v begin
0 => "Disconnected"
1 => "Connecting"
2 => "Connected"
3 => "Reconnecting"
4 => "Disconnecting"
5 => "SessionLost"
_ => "Unknown Status Returned!"
end
end
function onsessionstatuschanged(eSessionStatus::SessionStatus)
status = getstatusdescription(eSessionStatus)
println("SessionStatus: $status")
return a::Void
end
function onloginfailed(error_str::Ptr{Uint8})
login_error = bytestring(error_str)
println("Error: $login_error")
return a::Void
end
const onsessionstatuschanged_c = cfunction(onsessionstatuschanged, Void, (
SessionStatus,))
const onloginfailed_c = cfunction(onloginfailed, Void, (Ptr{Uint8},))
h_session_listener = ccall((:SessionStatusListener_create, "libXC"), Handle,
(Ptr{Void}, Ptr{Void}),(onsessionstatuschanged_c, onloginfailed_c))
Everything seems to be fine until the ccall fails with the following error:
ERROR: error compiling anonymous: ccall: wrong number of arguments to C
function
Any guidance would be greatly appreciated!
Thanks!