Skip to content

Commit

Permalink
Support signals that have enum/bitfield parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Dec 31, 2018
1 parent d961df8 commit b6021d1
Show file tree
Hide file tree
Showing 20 changed files with 4,156 additions and 70 deletions.
31 changes: 21 additions & 10 deletions internal/generate/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,31 @@ func (s *Signal) generateCgoPreamble() {

func (s *Signal) cTypeDeclaration(typ *Type) string {
cDeclaration := typ.CType
qname := QNameNew(s.Namespace, typ.Name)

if cDeclaration == "" {
qname := QNameNew(s.Namespace, typ.Name)
record, found := qname.namespace.recordOrClassRecordForName(qname.name)
if !found {
iface, found := qname.namespace.interfaceForName(qname.name)
if !found {
panic(fmt.Sprintf("Not found class, record, or interface %s, for signal %s, for class %s",
qname.name, s.Name, s.record.Name))
}
cDeclaration = iface.CType + " *"
} else {
cDeclaration = record.CType + " *"
if found {
return record.CType + " *"
}

iface, found := qname.namespace.interfaceForName(qname.name)
if found {
return iface.CType + " *"
}

bitfield, found := qname.namespace.bitfieldForName(qname.name)
if found {
return bitfield.CType
}

enum, found := qname.namespace.enumForName(qname.name)
if found {
return enum.CType
}

panic(fmt.Sprintf("Not found bitfield, class, enum interface, or record %s, for signal %s, for %s",
qname.name, s.Name, s.record.Name))
}

return cDeclaration
Expand Down
11 changes: 8 additions & 3 deletions internal/generate/type-generator-enumeration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package generate

import (
"fmt"

"github.com/dave/jennifer/jen"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ func (t *TypeGeneratorEnumeration) isSupportedAsArrayParamC(direction string) (s
}

func (t *TypeGeneratorEnumeration) isSupportedAsParamC() (supported bool, reason string) {
return false, ""
return true, ""
}

func (t *TypeGeneratorEnumeration) isSupportedAsField() (supported bool, reason string) {
Expand Down Expand Up @@ -71,7 +70,8 @@ func (t *TypeGeneratorEnumeration) generateArrayDeclaration(g *jen.Group, goVarN
func (t *TypeGeneratorEnumeration) generateArrayDeclarationC(g *jen.Group, cVarName string) {
}

func (t *TypeGeneratorEnumeration) generateDeclarationC(g *jen.Group, goVarName string) {
func (t *TypeGeneratorEnumeration) generateDeclarationC(g *jen.Group, cVarName string) {
g.Id(cVarName).Qual("C", t.enum.CType)
}

func (t *TypeGeneratorEnumeration) generateParamCallArgument(g *jen.Group, cVarName string) {
Expand All @@ -91,6 +91,11 @@ func (t *TypeGeneratorEnumeration) generateParamCVar(g *jen.Group, cVarName stri
}

func (t *TypeGeneratorEnumeration) generateParamGoVar(g *jen.Group, goVarName string, cVarName string, pkg string) {
g.
Id(goVarName).
Op(":=").
Do(t.typ.qname.generate).
Parens(jen.Id(cVarName))
}

func (t *TypeGeneratorEnumeration) generateParamOutCVar(g *jen.Group, cVarName string) {
Expand Down
142 changes: 140 additions & 2 deletions lib/gdk/class-3.20.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ import (
return g_signal_connect(instance, "seat-removed", G_CALLBACK(display_seatRemovedHandler), data);
}
*/
/*
void dragcontext_actionChangedHandler(GObject *, GdkDragAction, gpointer);
static gulong DragContext_signal_connect_action_changed(gpointer instance, gpointer data) {
return g_signal_connect(instance, "action-changed", G_CALLBACK(dragcontext_actionChangedHandler), data);
}
*/
/*
void dragcontext_cancelHandler(GObject *, GdkDragCancelReason, gpointer);
static gulong DragContext_signal_connect_cancel(gpointer instance, gpointer data) {
return g_signal_connect(instance, "cancel", G_CALLBACK(dragcontext_cancelHandler), data);
}
*/
/*
Expand Down Expand Up @@ -200,9 +218,129 @@ func (recv *Display) ListSeats() *glib.List {
return retGo
}

// Unsupported signal 'action-changed' for DragContext : unsupported parameter action : type DragAction :
type signalDragContextActionChangedDetail struct {
callback DragContextSignalActionChangedCallback
handlerID C.gulong
}

var signalDragContextActionChangedId int
var signalDragContextActionChangedMap = make(map[int]signalDragContextActionChangedDetail)
var signalDragContextActionChangedLock sync.RWMutex

// DragContextSignalActionChangedCallback is a callback function for a 'action-changed' signal emitted from a DragContext.
type DragContextSignalActionChangedCallback func(action DragAction)

/*
ConnectActionChanged connects the callback to the 'action-changed' signal for the DragContext.
The returned value represents the connection, and may be passed to DisconnectActionChanged to remove it.
*/
func (recv *DragContext) ConnectActionChanged(callback DragContextSignalActionChangedCallback) int {
signalDragContextActionChangedLock.Lock()
defer signalDragContextActionChangedLock.Unlock()

signalDragContextActionChangedId++
instance := C.gpointer(recv.native)
handlerID := C.DragContext_signal_connect_action_changed(instance, C.gpointer(uintptr(signalDragContextActionChangedId)))

detail := signalDragContextActionChangedDetail{callback, handlerID}
signalDragContextActionChangedMap[signalDragContextActionChangedId] = detail

return signalDragContextActionChangedId
}

/*
DisconnectActionChanged disconnects a callback from the 'action-changed' signal for the DragContext.
The connectionID should be a value returned from a call to ConnectActionChanged.
*/
func (recv *DragContext) DisconnectActionChanged(connectionID int) {
signalDragContextActionChangedLock.Lock()
defer signalDragContextActionChangedLock.Unlock()

detail, exists := signalDragContextActionChangedMap[connectionID]
if !exists {
return
}

instance := C.gpointer(recv.native)
C.g_signal_handler_disconnect(instance, detail.handlerID)
delete(signalDragContextActionChangedMap, connectionID)
}

//export dragcontext_actionChangedHandler
func dragcontext_actionChangedHandler(_ *C.GObject, c_action C.GdkDragAction, data C.gpointer) {
signalDragContextActionChangedLock.RLock()
defer signalDragContextActionChangedLock.RUnlock()

action := DragAction(c_action)

index := int(uintptr(data))
callback := signalDragContextActionChangedMap[index].callback
callback(action)
}

type signalDragContextCancelDetail struct {
callback DragContextSignalCancelCallback
handlerID C.gulong
}

var signalDragContextCancelId int
var signalDragContextCancelMap = make(map[int]signalDragContextCancelDetail)
var signalDragContextCancelLock sync.RWMutex

// DragContextSignalCancelCallback is a callback function for a 'cancel' signal emitted from a DragContext.
type DragContextSignalCancelCallback func(reason DragCancelReason)

/*
ConnectCancel connects the callback to the 'cancel' signal for the DragContext.
The returned value represents the connection, and may be passed to DisconnectCancel to remove it.
*/
func (recv *DragContext) ConnectCancel(callback DragContextSignalCancelCallback) int {
signalDragContextCancelLock.Lock()
defer signalDragContextCancelLock.Unlock()

signalDragContextCancelId++
instance := C.gpointer(recv.native)
handlerID := C.DragContext_signal_connect_cancel(instance, C.gpointer(uintptr(signalDragContextCancelId)))

detail := signalDragContextCancelDetail{callback, handlerID}
signalDragContextCancelMap[signalDragContextCancelId] = detail

return signalDragContextCancelId
}

/*
DisconnectCancel disconnects a callback from the 'cancel' signal for the DragContext.
The connectionID should be a value returned from a call to ConnectCancel.
*/
func (recv *DragContext) DisconnectCancel(connectionID int) {
signalDragContextCancelLock.Lock()
defer signalDragContextCancelLock.Unlock()

detail, exists := signalDragContextCancelMap[connectionID]
if !exists {
return
}

instance := C.gpointer(recv.native)
C.g_signal_handler_disconnect(instance, detail.handlerID)
delete(signalDragContextCancelMap, connectionID)
}

//export dragcontext_cancelHandler
func dragcontext_cancelHandler(_ *C.GObject, c_reason C.GdkDragCancelReason, data C.gpointer) {
signalDragContextCancelLock.RLock()
defer signalDragContextCancelLock.RUnlock()

reason := DragCancelReason(c_reason)

// Unsupported signal 'cancel' for DragContext : unsupported parameter reason : type DragCancelReason :
index := int(uintptr(data))
callback := signalDragContextCancelMap[index].callback
callback(reason)
}

type signalDragContextDndFinishedDetail struct {
callback DragContextSignalDndFinishedCallback
Expand Down
76 changes: 75 additions & 1 deletion lib/gio/class-2.28.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ import (
return g_signal_connect(instance, "activate", G_CALLBACK(simpleaction_activateHandler), data);
}
*/
/*
gboolean tlsconnection_acceptCertificateHandler(GObject *, GTlsCertificate *, GTlsCertificateFlags, gpointer);
static gulong TlsConnection_signal_connect_accept_certificate(gpointer instance, gpointer data) {
return g_signal_connect(instance, "accept-certificate", G_CALLBACK(tlsconnection_acceptCertificateHandler), data);
}
*/
import "C"

Expand Down Expand Up @@ -1300,7 +1309,72 @@ func CastToTlsConnection(object *gobject.Object) *TlsConnection {
return TlsConnectionNewFromC(object.ToC())
}

// Unsupported signal 'accept-certificate' for TlsConnection : unsupported parameter errors : type TlsCertificateFlags :
type signalTlsConnectionAcceptCertificateDetail struct {
callback TlsConnectionSignalAcceptCertificateCallback
handlerID C.gulong
}

var signalTlsConnectionAcceptCertificateId int
var signalTlsConnectionAcceptCertificateMap = make(map[int]signalTlsConnectionAcceptCertificateDetail)
var signalTlsConnectionAcceptCertificateLock sync.RWMutex

// TlsConnectionSignalAcceptCertificateCallback is a callback function for a 'accept-certificate' signal emitted from a TlsConnection.
type TlsConnectionSignalAcceptCertificateCallback func(peerCert *TlsCertificate, errors TlsCertificateFlags) bool

/*
ConnectAcceptCertificate connects the callback to the 'accept-certificate' signal for the TlsConnection.
The returned value represents the connection, and may be passed to DisconnectAcceptCertificate to remove it.
*/
func (recv *TlsConnection) ConnectAcceptCertificate(callback TlsConnectionSignalAcceptCertificateCallback) int {
signalTlsConnectionAcceptCertificateLock.Lock()
defer signalTlsConnectionAcceptCertificateLock.Unlock()

signalTlsConnectionAcceptCertificateId++
instance := C.gpointer(recv.native)
handlerID := C.TlsConnection_signal_connect_accept_certificate(instance, C.gpointer(uintptr(signalTlsConnectionAcceptCertificateId)))

detail := signalTlsConnectionAcceptCertificateDetail{callback, handlerID}
signalTlsConnectionAcceptCertificateMap[signalTlsConnectionAcceptCertificateId] = detail

return signalTlsConnectionAcceptCertificateId
}

/*
DisconnectAcceptCertificate disconnects a callback from the 'accept-certificate' signal for the TlsConnection.
The connectionID should be a value returned from a call to ConnectAcceptCertificate.
*/
func (recv *TlsConnection) DisconnectAcceptCertificate(connectionID int) {
signalTlsConnectionAcceptCertificateLock.Lock()
defer signalTlsConnectionAcceptCertificateLock.Unlock()

detail, exists := signalTlsConnectionAcceptCertificateMap[connectionID]
if !exists {
return
}

instance := C.gpointer(recv.native)
C.g_signal_handler_disconnect(instance, detail.handlerID)
delete(signalTlsConnectionAcceptCertificateMap, connectionID)
}

//export tlsconnection_acceptCertificateHandler
func tlsconnection_acceptCertificateHandler(_ *C.GObject, c_peer_cert *C.GTlsCertificate, c_errors C.GTlsCertificateFlags, data C.gpointer) C.gboolean {
signalTlsConnectionAcceptCertificateLock.RLock()
defer signalTlsConnectionAcceptCertificateLock.RUnlock()

peerCert := TlsCertificateNewFromC(unsafe.Pointer(c_peer_cert))

errors := TlsCertificateFlags(c_errors)

index := int(uintptr(data))
callback := signalTlsConnectionAcceptCertificateMap[index].callback
retGo := callback(peerCert, errors)
retC :=
boolToGboolean(retGo)
return retC
}

// EmitAcceptCertificate is a wrapper around the C function g_tls_connection_emit_accept_certificate.
func (recv *TlsConnection) EmitAcceptCertificate(peerCert *TlsCertificate, errors TlsCertificateFlags) bool {
Expand Down
Loading

0 comments on commit b6021d1

Please # to comment.