parent
c2d7b57853
commit
8968c1f2a3
@ -1 +1 @@ |
||||
go build -buildmode=c-shared -o c_wrapper.dll c_init_login.go export.go |
||||
go build -buildmode=c-shared -ldflags="-s -w" -o c_wrapper.dll export.go |
@ -1,94 +0,0 @@ |
||||
package main |
||||
|
||||
/* |
||||
#include <stdio.h> |
||||
|
||||
typedef void (*base_func)(); |
||||
typedef void (*err_func)(int,void *); |
||||
typedef void (*success_func)(char *); |
||||
|
||||
|
||||
extern void c_base_caller(base_func func); |
||||
extern void c_err_caller(err_func func,int ,void*); |
||||
extern void c_success_caller(success_func func,char* data); |
||||
|
||||
|
||||
*/ |
||||
import "C" |
||||
import ( |
||||
"open_im_sdk/open_im_sdk" |
||||
"unsafe" |
||||
) |
||||
|
||||
//export init_sdk
|
||||
func init_sdk(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)) |
||||
} |
||||
|
||||
//export login
|
||||
func login(successFunc C.success_func, failedFunc C.err_func, operationID, uid, token *C.char) { |
||||
baseCallback := NewBaseCallback(successFunc, failedFunc) |
||||
open_im_sdk.Login(baseCallback, C.GoString(operationID), C.GoString(uid), C.GoString(token)) |
||||
} |
||||
|
||||
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.c_base_caller(c.onConnecting) |
||||
} |
||||
|
||||
func (c ConnCallback) OnConnectSuccess() { |
||||
C.c_base_caller(c.onConnectSuccess) |
||||
} |
||||
|
||||
func (c ConnCallback) OnConnectFailed(errCode int32, errMsg string) { |
||||
C.c_err_caller(c.onConnectFailed, C.int(errCode), unsafe.Pointer(C.CString(errMsg))) |
||||
|
||||
} |
||||
|
||||
func (c ConnCallback) OnKickedOffline() { |
||||
C.c_base_caller(c.onKickedOffline) |
||||
} |
||||
|
||||
func (c ConnCallback) OnUserTokenExpired() { |
||||
C.c_base_caller(c.onUserTokenExpired) |
||||
} |
||||
|
||||
type BaseCallback struct { |
||||
successFunc C.success_func |
||||
failedFunc C.err_func |
||||
} |
||||
|
||||
func NewBaseCallback(successFunc C.success_func, failedFunc C.err_func) *BaseCallback { |
||||
return &BaseCallback{successFunc: successFunc, failedFunc: failedFunc} |
||||
} |
||||
|
||||
func (b BaseCallback) OnError(errCode int32, errMsg string) { |
||||
C.c_err_caller(b.failedFunc, C.int(errCode), unsafe.Pointer(C.CString(errMsg))) |
||||
} |
||||
|
||||
func (b BaseCallback) OnSuccess(data string) { |
||||
C.c_success_caller(b.successFunc, C.CString(data)) |
||||
} |
Binary file not shown.
@ -1,81 +0,0 @@ |
||||
/* 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. */ |
||||
|
||||
|
||||
|
||||
|
||||
/* 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) void Init_SDK(); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
Loading…
Reference in new issue