delete c_init_login.go
move to export.go
This commit is contained in:
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
|
@ -2,21 +2,100 @@ package main
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
typedef void (*base_func)();
|
||||
typedef void (*err_func)(int,void *);
|
||||
typedef void (*success_func)(char *);
|
||||
|
||||
void c_base_caller(base_func func)
|
||||
typedef void (*CB)();
|
||||
typedef void (*CB_I_S)(int,char *);
|
||||
typedef void (*CB_S)(char *);
|
||||
__attribute__((weak))
|
||||
void Call_CB(CB func)
|
||||
{
|
||||
func();
|
||||
}
|
||||
void c_err_caller(err_func func,int errCode,void* errMsg)
|
||||
__attribute__((weak))
|
||||
void Call_CB_I_S(CB_I_S func,int errCode,char* errMsg)
|
||||
{
|
||||
func(errCode,errMsg);
|
||||
}
|
||||
void c_success_caller(success_func func,char* data)
|
||||
__attribute__((weak))
|
||||
void Call_CB_S(CB_S func,char* data)
|
||||
{
|
||||
func(data);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"open_im_sdk/open_im_sdk"
|
||||
)
|
||||
|
||||
type ConnCallback struct {
|
||||
onConnecting C.CB
|
||||
onConnectSuccess C.CB
|
||||
onConnectFailed C.CB_I_S
|
||||
onKickedOffline C.CB
|
||||
onUserTokenExpired C.CB
|
||||
}
|
||||
|
||||
func NewConnCallback(onConnecting C.CB, onConnectSuccess C.CB,
|
||||
onKickedOffline C.CB, onUserTokenExpired C.CB, onConnectFailed C.CB_I_S) *ConnCallback {
|
||||
return &ConnCallback{onConnecting: onConnecting, onConnectSuccess: onConnectSuccess,
|
||||
onKickedOffline: onKickedOffline, onUserTokenExpired: onUserTokenExpired, onConnectFailed: onConnectFailed}
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnecting() {
|
||||
C.Call_CB(c.onConnecting)
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnectSuccess() {
|
||||
C.Call_CB(c.onConnectSuccess)
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnConnectFailed(errCode int32, errMsg string) {
|
||||
C.Call_CB_I_S(c.onConnectFailed, C.int(errCode), C.CString(errMsg))
|
||||
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnKickedOffline() {
|
||||
C.Call_CB(c.onKickedOffline)
|
||||
}
|
||||
|
||||
func (c ConnCallback) OnUserTokenExpired() {
|
||||
C.Call_CB(c.onUserTokenExpired)
|
||||
}
|
||||
|
||||
type BaseCallback struct {
|
||||
successFunc C.CB_S
|
||||
failedFunc C.CB_I_S
|
||||
}
|
||||
|
||||
func NewBaseCallback(successFunc C.CB_S, failedFunc C.CB_I_S) *BaseCallback {
|
||||
return &BaseCallback{successFunc: successFunc, failedFunc: failedFunc}
|
||||
}
|
||||
|
||||
func (b BaseCallback) OnError(errCode int32, errMsg string) {
|
||||
C.Call_CB_I_S(b.failedFunc, C.int(errCode), C.CString(errMsg))
|
||||
}
|
||||
|
||||
func (b BaseCallback) OnSuccess(data string) {
|
||||
C.Call_CB_S(b.successFunc, C.CString(data))
|
||||
}
|
||||
|
||||
//export init_sdk
|
||||
func init_sdk(onConnecting C.CB,
|
||||
onConnectSuccess C.CB,
|
||||
onKickedOffline C.CB,
|
||||
onUserTokenExpired C.CB,
|
||||
onConnectFailed C.CB_I_S,
|
||||
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.CB_S, failedFunc C.CB_I_S, 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() {
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
// gcc -o test.exe -lc_wrapper.dll test.c
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "c_wrapper.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GoUint32 platformID;
|
||||
char apiAddr[256];
|
||||
char wsAddr[256];
|
||||
@ -19,30 +17,29 @@ typedef struct {
|
||||
GoUint8 isExternalExtensions;
|
||||
} IMConfigC;
|
||||
|
||||
|
||||
void on_connecting()
|
||||
{
|
||||
printf("on_connecting\n");
|
||||
printf("on_connecting\n");
|
||||
}
|
||||
void on_connect_success()
|
||||
{
|
||||
printf("on_connect_success\n");
|
||||
printf("on_connect_success\n");
|
||||
}
|
||||
void on_kick_offline()
|
||||
{
|
||||
printf("on_kick_offline\n");
|
||||
printf("on_kick_offline\n");
|
||||
}
|
||||
void on_user_token_expired()
|
||||
{
|
||||
printf("on_user_token_expired\n");
|
||||
printf("on_user_token_expired\n");
|
||||
}
|
||||
void on_connect_failed(int err_code,void * err_msg)
|
||||
void on_connect_failed(int err_code, void *err_msg)
|
||||
{
|
||||
char* message = (char*)err_msg;
|
||||
char *message = (char *)err_msg;
|
||||
printf("Error code: %d\n", err_code);
|
||||
printf("Error message: %s\n", message);
|
||||
}
|
||||
void success(char * data)
|
||||
void success(char *data)
|
||||
{
|
||||
printf("login success : %s\n", data);
|
||||
}
|
||||
@ -52,15 +49,13 @@ void main(int argc, char **argv)
|
||||
char uid[] = "6959062403";
|
||||
char token[] = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySUQiOiI2OTU5MDYyNDAzIiwiUGxhdGZvcm1JRCI6MywiZXhwIjoxNzAwNzIwOTg0LCJuYmYiOjE2OTI5NDQ2ODQsImlhdCI6MTY5Mjk0NDk4NH0.8otKTFrOCs8_ueV10rNOD-rzHrCT_EN0obKS9q79bIc";
|
||||
|
||||
char *jsonString = "{\"platformID\": 3, \"apiAddr\": \"http://125.124.195.201:10002\", \"wsAddr\":\"ws://125.124.195.201:10001\",\"dataDir\": \"./\", \"logLevel\": 1, \"isLogStandardOutput\": true, \"logFilePath\": \"./\", \"isExternalExtensions\": true}";
|
||||
|
||||
char* jsonString = "{\"platformID\": 3, \"apiAddr\": \"http://125.124.195.201:10002\", \"wsAddr\":\"ws://125.124.195.201:10001\",\"dataDir\": \"./\", \"logLevel\": 5, \"isLogStandardOutput\": true, \"logFilePath\": \"./\", \"isExternalExtensions\": true}";
|
||||
GoUint8 init_result;
|
||||
init_result = init_sdk(on_connecting, on_connect_success, on_kick_offline, on_user_token_expired, on_connect_failed, operationID, jsonString);
|
||||
printf("init_result: %u\n", init_result);
|
||||
|
||||
GoUint8 init_result;
|
||||
init_result=init_sdk(on_connecting, on_connect_success, on_kick_offline, on_user_token_expired,on_connect_failed, operationID, jsonString);
|
||||
printf("init_result: %u\n", init_result);
|
||||
|
||||
login(success,on_connect_failed,operationID,uid,token);
|
||||
login(success, on_connect_failed, operationID, uid, token);
|
||||
|
||||
sleep(1000000);
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user