alexacy
08/24/2020, 6:21 AMinterface SyncCallback {
fun onResponse(httpResponse: HttpResponse /* out class, just for example */)
}
class ProfileSyncWin {
fun performSync(callback: SyncCallback) {
GlobalScope.launch(Dispatchers.Unconfined) {
val response = HttpResponse() // Just stub
println("Hello from Kotlin")
callback.onResponse(response)
}
}
}
Kotlin/multiplatform generates the following .h file:
struct {
liblibsynctest_KType* (*_type)(void);
liblibsynctest_kref_com_alohamobile_profilesync_ProfileSyncWin (*ProfileSyncWin)();
void (*createCallback)(liblibsynctest_kref_com_alohamobile_profilesync_ProfileSyncWin thiz, liblibsynctest_kref_kotlin_Function invokable);
void (*performSync)(liblibsynctest_kref_com_alohamobile_profilesync_ProfileSyncWin thiz, liblibsynctest_kref_com_alohamobile_profilesync_SyncCallback callback);
} ProfileSyncWin;
struct {
liblibsynctest_KType* (*_type)(void);
void (*onResponse)(liblibsynctest_kref_com_alohamobile_profilesync_SyncCallback thiz, liblibsynctest_kref_com_alohamobile_profilesync_util_http_HttpResponse httpResponse);
} SyncCallback;
So, we do have SyncCallback
struct and liblibsynctest_kref_com_alohamobile_profilesync_SyncCallback
And here's the main question come:
How to implement SyncCallback
in C in order to Kolkin code calls C callback?
We start with
liblibsynctest_kref_com_alohamobile_profilesync_ProfileSyncWin psw =
lib->kotlin.root.com.alohamobile.profilesync.ProfileSyncWin.ProfileSyncWin();
and then
liblibsynctest_kref_com_alohamobile_profilesync_util_http_HttpResponse resp = lib->kotlin.root.com.alohamobile.profilesync.ProfileSyncWin.performSync(psw, /* WHAT HERE???? */);
Thanks in advance