Hi all! Could someone suggest, how to call C or C+...
# multiplatform
a
Hi all! Could someone suggest, how to call C or C++ callback (or interface) from Kotlin, or, to me more specific - how to implement Kotlin interface in C or C++ Ex:
Copy code
interface 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:
Copy code
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
Copy code
liblibsynctest_kref_com_alohamobile_profilesync_ProfileSyncWin psw = 
            lib->kotlin.root.com.alohamobile.profilesync.ProfileSyncWin.ProfileSyncWin();
and then
Copy code
liblibsynctest_kref_com_alohamobile_profilesync_util_http_HttpResponse resp = lib->kotlin.root.com.alohamobile.profilesync.ProfileSyncWin.performSync(psw, /* WHAT HERE???? */);
Thanks in advance