Skip to content

Commit

Permalink
add bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfarnum committed Sep 5, 2024
1 parent 82d9e28 commit 587c567
Show file tree
Hide file tree
Showing 6 changed files with 967 additions and 0 deletions.
297 changes: 297 additions & 0 deletions examples/app-library/linux/bridge/Bridge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,297 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (https://www.swig.org).
* Version 4.3.0
*
* Do not make changes to this file unless you know what you are doing - modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */

// source: Bridge.i

package bridge

/*
#define intgo swig_intgo
typedef void *swig_voidp;
#include <stddef.h>
#include <stdint.h>
typedef ptrdiff_t intgo;
typedef size_t uintgo;
typedef struct { char *p; intgo n; } _gostring_;
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
extern void _wrap_Swig_free_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern uintptr_t _wrap_Swig_malloc_Bridge_3fd1683bd95671e7(swig_intgo arg1);
extern void _wrap_ApplicationInit_Bridge_3fd1683bd95671e7(void);
extern void _wrap_ApplicationShutdown_Bridge_3fd1683bd95671e7(void);
extern uintptr_t _wrap__swig_NewDirectorBridgeBridge_Bridge_3fd1683bd95671e7(int);
extern void _wrap_DeleteDirectorBridge_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern void _wrap__swig_DirectorBridge_upcall_Cb_Bridge_3fd1683bd95671e7(uintptr_t);
extern void _wrap_delete_Bridge_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern void _wrap_Bridge_cb_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern uintptr_t _wrap_new_Bridge_Bridge_3fd1683bd95671e7(void);
extern uintptr_t _wrap_new_App_Bridge_3fd1683bd95671e7(void);
extern void _wrap_delete_App_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern void _wrap_App_delBridge_Bridge_3fd1683bd95671e7(uintptr_t arg1);
extern void _wrap_App_setBridge_Bridge_3fd1683bd95671e7(uintptr_t arg1, uintptr_t arg2);
extern swig_intgo _wrap_App_start_Bridge_3fd1683bd95671e7(uintptr_t arg1, swig_intgo arg2, swig_voidp arg3);
extern void _wrap_App_cb_Bridge_3fd1683bd95671e7(uintptr_t arg1);
#undef intgo
*/
import "C"

import "syscall"
import "unsafe"
import "sync"


type _ syscall.Sockaddr




type _ unsafe.Pointer



var Swig_escape_always_false bool
var Swig_escape_val interface{}


type _swig_fnptr *byte
type _swig_memberptr *byte


func getSwigcptr(v interface { Swigcptr() uintptr }) uintptr {
if v == nil {
return 0
}
return v.Swigcptr()
}


type _ sync.Mutex

func Swig_free(arg1 uintptr) {
_swig_i_0 := arg1
C._wrap_Swig_free_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

func Swig_malloc(arg1 int) (_swig_ret uintptr) {
var swig_r uintptr
_swig_i_0 := arg1
swig_r = (uintptr)(C._wrap_Swig_malloc_Bridge_3fd1683bd95671e7(C.swig_intgo(_swig_i_0)))
return swig_r
}

func ApplicationInit() {
C._wrap_ApplicationInit_Bridge_3fd1683bd95671e7()
}

func ApplicationShutdown() {
C._wrap_ApplicationShutdown_Bridge_3fd1683bd95671e7()
}

type _swig_DirectorBridge struct {
SwigcptrBridge
v interface{}
}

func (p *_swig_DirectorBridge) Swigcptr() uintptr {
return getSwigcptr(p.SwigcptrBridge)
}

func (p *_swig_DirectorBridge) SwigIsBridge() {
}

func (p *_swig_DirectorBridge) DirectorInterface() interface{} {
return p.v
}

func NewDirectorBridge(v interface{}) Bridge {
p := &_swig_DirectorBridge{0, v}
p.SwigcptrBridge = SwigcptrBridge(C._wrap__swig_NewDirectorBridgeBridge_Bridge_3fd1683bd95671e7(C.int(swigDirectorAdd(p))))
return p
}

func DeleteDirectorBridge(arg1 Bridge) {
_swig_i_0 := getSwigcptr(arg1)
C._wrap_DeleteDirectorBridge_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

//export Swiggo_DeleteDirector_Bridge_Bridge_3fd1683bd95671e7
func Swiggo_DeleteDirector_Bridge_Bridge_3fd1683bd95671e7(c int) {
swigDirectorLookup(c).(*_swig_DirectorBridge).SwigcptrBridge = 0
swigDirectorDelete(c)
}

type _swig_DirectorInterfaceBridgeCb interface {
Cb()
}

func (swig_p *_swig_DirectorBridge) Cb() {
if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceBridgeCb); swig_ok {
swig_g.Cb()
return
}
C._wrap__swig_DirectorBridge_upcall_Cb_Bridge_3fd1683bd95671e7(C.uintptr_t(swig_p.SwigcptrBridge))
}

func DirectorBridgeCb(swig_p Bridge) {
C._wrap__swig_DirectorBridge_upcall_Cb_Bridge_3fd1683bd95671e7(C.uintptr_t(swig_p.(*_swig_DirectorBridge).SwigcptrBridge))
}

//export Swig_DirectorBridge_callback_cb_Bridge_3fd1683bd95671e7
func Swig_DirectorBridge_callback_cb_Bridge_3fd1683bd95671e7(swig_c int) {
swig_p := swigDirectorLookup(swig_c).(*_swig_DirectorBridge)
swig_p.Cb()
}

type SwigcptrBridge uintptr

func (p SwigcptrBridge) Swigcptr() uintptr {
return (uintptr)(p)
}

func (p SwigcptrBridge) SwigIsBridge() {
}

func (p SwigcptrBridge) DirectorInterface() interface{} {
return nil
}

func DeleteBridge(arg1 Bridge) {
_swig_i_0 := getSwigcptr(arg1)
C._wrap_delete_Bridge_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

func (arg1 SwigcptrBridge) Cb() {
_swig_i_0 := arg1
C._wrap_Bridge_cb_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

func NewBridge() (_swig_ret Bridge) {
var swig_r Bridge
swig_r = (Bridge)(SwigcptrBridge(C._wrap_new_Bridge_Bridge_3fd1683bd95671e7()))
return swig_r
}

type Bridge interface {
Swigcptr() uintptr
SwigIsBridge()
DirectorInterface() interface{}
Cb()
}

type SwigcptrApp uintptr

func (p SwigcptrApp) Swigcptr() uintptr {
return (uintptr)(p)
}

func (p SwigcptrApp) SwigIsApp() {
}

func NewApp() (_swig_ret App) {
var swig_r App
swig_r = (App)(SwigcptrApp(C._wrap_new_App_Bridge_3fd1683bd95671e7()))
return swig_r
}

func DeleteApp(arg1 App) {
_swig_i_0 := getSwigcptr(arg1)
C._wrap_delete_App_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

func (arg1 SwigcptrApp) DelBridge() {
_swig_i_0 := arg1
C._wrap_App_delBridge_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

func (arg1 SwigcptrApp) SetBridge(arg2 Bridge) {
_swig_i_0 := arg1
_swig_i_1 := getSwigcptr(arg2)
C._wrap_App_setBridge_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0), C.uintptr_t(_swig_i_1))
}

func (arg1 SwigcptrApp) Start(arg2 int, arg3 *string) (_swig_ret int) {
var swig_r int
_swig_i_0 := arg1
_swig_i_1 := arg2
_swig_i_2 := arg3
swig_r = (int)(C._wrap_App_start_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0), C.swig_intgo(_swig_i_1), C.swig_voidp(_swig_i_2)))
return swig_r
}

func (arg1 SwigcptrApp) Cb() {
_swig_i_0 := arg1
C._wrap_App_cb_Bridge_3fd1683bd95671e7(C.uintptr_t(_swig_i_0))
}

type App interface {
Swigcptr() uintptr
SwigIsApp()
DelBridge()
SetBridge(arg2 Bridge)
Start(arg2 int, arg3 *string) (_swig_ret int)
Cb()
}


type SwigcptrSwigDirector_Bridge uintptr
type SwigDirector_Bridge interface {
Swigcptr() uintptr;
}
func (p SwigcptrSwigDirector_Bridge) Swigcptr() uintptr {
return uintptr(p)
}



var swigDirectorTrack struct {
sync.Mutex
m map[int]interface{}
c int
}

func swigDirectorAdd(v interface{}) int {
swigDirectorTrack.Lock()
defer swigDirectorTrack.Unlock()
if swigDirectorTrack.m == nil {
swigDirectorTrack.m = make(map[int]interface{})
}
swigDirectorTrack.c++
ret := swigDirectorTrack.c
swigDirectorTrack.m[ret] = v
return ret
}

func swigDirectorLookup(c int) interface{} {
swigDirectorTrack.Lock()
defer swigDirectorTrack.Unlock()
ret := swigDirectorTrack.m[c]
if ret == nil {
panic("C++ director pointer not found (possible use-after-free)")
}
return ret
}

func swigDirectorDelete(c int) {
swigDirectorTrack.Lock()
defer swigDirectorTrack.Unlock()
if swigDirectorTrack.m[c] == nil {
if c > swigDirectorTrack.c {
panic("C++ director pointer invalid (possible memory corruption")
} else {
panic("C++ director pointer not found (possible use-after-free)")
}
}
delete(swigDirectorTrack.m, c)
}
29 changes: 29 additions & 0 deletions examples/app-library/linux/bridge/Bridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <cstdio>
#include <iostream>

class App
{
private:
Bridge * _bridge;

public:
App() : _bridge(0) {}
~App() { delBridge(); }
void delBridge()
{
delete _bridge;
_bridge = 0;
}
void setBridge(Bridge * cb)
{
delBridge();
_bridge = cb;
}
void cb()
{
if (_bridge)
_bridge->cb();
}
};
9 changes: 9 additions & 0 deletions examples/app-library/linux/bridge/Bridge.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* File : Bridge.i */
%module(directors="1") Bridge
%{
#include "Bridge.h"
%}
/* turn on director wrapping Bridge */
%feature("director") Bridge;

%include "Bridge.h"
Loading

0 comments on commit 587c567

Please sign in to comment.