feat: add dll interface.
Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com>
This commit is contained in:
parent
52546fcb85
commit
4653f35b8b
80
c_wrapper/c_init_login.go
Normal file
80
c_wrapper/c_init_login.go
Normal file
@ -0,0 +1,80 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
|
||||
typedef void (*base_func)();
|
||||
typedef void (*err_func)(int,void *);
|
||||
|
||||
extern base_func _onConnecting;
|
||||
extern base_func _onConnectSuccess;
|
||||
extern base_func _onKickedOffline;
|
||||
extern base_func _onUserTokenExpired;
|
||||
extern err_func _onConnectFailed;
|
||||
|
||||
extern void c_onConnecting();
|
||||
extern void c_onConnectSuccess();
|
||||
extern void c_onKickedOffline();
|
||||
extern void c_onUserTokenExpired();
|
||||
extern void c_onConnectFailed(int ,void*);
|
||||
|
||||
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"open_im_sdk/open_im_sdk"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//export InitSDK
|
||||
func InitSDK(onConnecting C.base_func,
|
||||
onConnectSuccess C.base_func,
|
||||
onKickedOffline C.base_func,
|
||||
onUserTokenExpired C.base_func,
|
||||
onConnectFailed C.err_func,
|
||||
operationID *C.char, config *C.char) bool {
|
||||
callback := NewConnCallback(onConnecting, onConnectSuccess, onKickedOffline, onUserTokenExpired, onConnectFailed)
|
||||
return open_im_sdk.InitSDK(callback, C.GoString(operationID), C.GoString(config))
|
||||
}
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
type ConnCallback struct {
|
||||
onConnecting C.base_func
|
||||
onConnectSuccess C.base_func
|
||||
onKickedOffline C.base_func
|
||||
onUserTokenExpired C.base_func
|
||||
onConnectFailed C.err_func
|
||||
}
|
||||
|
||||
func NewConnCallback(onConnecting C.base_func, onConnectSuccess C.base_func,
|
||||
onKickedOffline C.base_func, onUserTokenExpired C.base_func, onConnectFailed C.err_func) *ConnCallback {
|
||||
return &ConnCallback{onConnecting: onConnecting, onConnectSuccess: onConnectSuccess,
|
||||
onKickedOffline: onKickedOffline, onUserTokenExpired: onUserTokenExpired, onConnectFailed: onConnectFailed}
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnecting() {
|
||||
C._onConnecting = c.onConnecting
|
||||
C.c_onConnecting()
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnectSuccess() {
|
||||
C._onConnectSuccess = c.onConnectSuccess
|
||||
C.c_onConnectSuccess()
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnectFailed(errCode int32, errMsg string) {
|
||||
C._onConnectFailed = c.onConnectFailed
|
||||
C.c_onConnectFailed(C.int(errCode), unsafe.Pointer(C.CString(errMsg)))
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnKickedOffline() {
|
||||
C._onKickedOffline = c.onKickedOffline
|
||||
C.c_onKickedOffline()
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnUserTokenExpired() {
|
||||
C._onUserTokenExpired = c.onUserTokenExpired
|
||||
C.c_onUserTokenExpired()
|
||||
}
|
103
c_wrapper/c_wrapper.h
Normal file
103
c_wrapper/c_wrapper.h
Normal file
@ -0,0 +1,103 @@
|
||||
/* Code generated by cmd/cgo; DO NOT EDIT. */
|
||||
|
||||
/* package command-line-arguments */
|
||||
|
||||
|
||||
#line 1 "cgo-builtin-export-prolog"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef GO_CGO_EXPORT_PROLOGUE_H
|
||||
#define GO_CGO_EXPORT_PROLOGUE_H
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Start of preamble from import "C" comments. */
|
||||
|
||||
|
||||
#line 3 "c_init_login.go"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef void (*base_func)();
|
||||
typedef void (*err_func)(int,void *);
|
||||
|
||||
extern base_func _onConnecting;
|
||||
extern base_func _onConnectSuccess;
|
||||
extern base_func _onKickedOffline;
|
||||
extern base_func _onUserTokenExpired;
|
||||
extern err_func _onConnectFailed;
|
||||
|
||||
extern void c_onConnecting();
|
||||
extern void c_onConnectSuccess();
|
||||
extern void c_onKickedOffline();
|
||||
extern void c_onUserTokenExpired();
|
||||
extern void c_onConnectFailed(int ,void*);
|
||||
|
||||
|
||||
|
||||
#line 1 "cgo-generated-wrapper"
|
||||
|
||||
|
||||
/* End of preamble from import "C" comments. */
|
||||
|
||||
|
||||
/* Start of boilerplate cgo prologue. */
|
||||
#line 1 "cgo-gcc-export-header-prolog"
|
||||
|
||||
#ifndef GO_CGO_PROLOGUE_H
|
||||
#define GO_CGO_PROLOGUE_H
|
||||
|
||||
typedef signed char GoInt8;
|
||||
typedef unsigned char GoUint8;
|
||||
typedef short GoInt16;
|
||||
typedef unsigned short GoUint16;
|
||||
typedef int GoInt32;
|
||||
typedef unsigned int GoUint32;
|
||||
typedef long long GoInt64;
|
||||
typedef unsigned long long GoUint64;
|
||||
typedef GoInt64 GoInt;
|
||||
typedef GoUint64 GoUint;
|
||||
typedef size_t GoUintptr;
|
||||
typedef float GoFloat32;
|
||||
typedef double GoFloat64;
|
||||
#ifdef _MSC_VER
|
||||
#include <complex.h>
|
||||
typedef _Fcomplex GoComplex64;
|
||||
typedef _Dcomplex GoComplex128;
|
||||
#else
|
||||
typedef float _Complex GoComplex64;
|
||||
typedef double _Complex GoComplex128;
|
||||
#endif
|
||||
|
||||
/*
|
||||
static assertion to make sure the file is being used on architecture
|
||||
at least with matching size of GoInt.
|
||||
*/
|
||||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
|
||||
|
||||
#ifndef GO_CGO_GOSTRING_TYPEDEF
|
||||
typedef _GoString_ GoString;
|
||||
#endif
|
||||
typedef void *GoMap;
|
||||
typedef void *GoChan;
|
||||
typedef struct { void *t; void *v; } GoInterface;
|
||||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
|
||||
|
||||
#endif
|
||||
|
||||
/* End of boilerplate cgo prologue. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern __declspec(dllexport) GoUint8 InitSDK(base_func onConnecting, base_func onConnectSuccess, base_func onKickedOffline, base_func onUserTokenExpired, err_func onConnectFailed, char* operationID, char* config);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
1
c_wrapper/event_listener/listener.go
Normal file
1
c_wrapper/event_listener/listener.go
Normal file
@ -0,0 +1 @@
|
||||
package event_listener
|
35
c_wrapper/test.go
Normal file
35
c_wrapper/test.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
typedef void (*base_func)();
|
||||
typedef void (*err_func)(int,void *);
|
||||
|
||||
base_func _onConnecting;
|
||||
base_func _onConnectSuccess;
|
||||
base_func _onKickedOffline;
|
||||
base_func _onUserTokenExpired;
|
||||
err_func _onConnectFailed;
|
||||
|
||||
void c_onConnecting()
|
||||
{
|
||||
_onConnecting();
|
||||
}
|
||||
void c_onConnectSuccess()
|
||||
{
|
||||
_onConnectSuccess();
|
||||
}
|
||||
void c_onKickedOffline()
|
||||
{
|
||||
_onKickedOffline();
|
||||
}
|
||||
void c_onUserTokenExpired()
|
||||
{
|
||||
_onUserTokenExpired();
|
||||
}
|
||||
void c_onConnectFailed(int errCode,void* errMsg)
|
||||
{
|
||||
_onConnectFailed(errCode,errMsg);
|
||||
}
|
||||
*/
|
||||
import "C"
|
Loading…
x
Reference in New Issue
Block a user