From 67b2796087542d72beb21aa80f3fc5b0d23b36b5 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 19 Feb 2018 20:25:49 +0000 Subject: [PATCH] Adopt new conference peer nick/list_changed callbacks. --- .travis.yml | 24 ++++++++++++---------- const.go | 7 ------- group.go | 51 ++++++++++++++++++++++++++++++++++------------ group_legacy.go | 10 --------- tools/generrmsg.go | 7 +++---- tox.go | 14 +++++++------ tox_test.go | 2 +- toxav.go | 2 +- 8 files changed, 64 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7400af8..e7160e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,4 @@ language: go -compiler: clang sudo: required addons: @@ -12,21 +11,22 @@ addons: - libsodium-dev - libvpx-dev -go: -#- 1.4.x -#- 1.5.x -#- 1.6.x -#- 1.7.x -#- 1.8.x -#- 1.9.x -- master +matrix: + include: + - go: 1.7.x + if: type IN (push, api, cron) + - go: 1.8.x + if: type IN (push, api, cron) + - go: 1.9.x + if: type IN (push, api, cron) + - go: master before_install: - go get github.com/mattn/goveralls install: # Add libclang's lib directory to search path for Go. -- export CGO_LDFLAGS="-L`llvm-config --libdir`" +- export CGO_LDFLAGS="-L`llvm-config-3.4 --libdir`" # Install toxcore. - git clone https://github.com/TokTok/c-toxcore - cd c-toxcore @@ -37,14 +37,16 @@ install: - sudo ldconfig > /dev/null # Install Go packages. - go get github.com/bitly/go-simplejson -- go get github.com/go-clang/v3.8/clang +- go get github.com/go-clang/v3.4/clang - go get github.com/kitech/godsts/maps/hashbidimap - go get github.com/kitech/godsts/maps/hashmap - go get github.com/kitech/godsts/sets/hashset - go get github.com/masatana/go-textdistance - go get github.com/sasha-s/go-deadlock +- go get github.com/streamrail/concurrent-map - go get github.com/sysr-q/gopp/gopp - go get github.com/xrash/smetrics script: +- go run tools/generrmsg.go > const_auto.go && git diff --exit-code - $GOPATH/bin/goveralls -service=travis-ci diff --git a/const.go b/const.go index 28c3ac8..0dc81c2 100644 --- a/const.go +++ b/const.go @@ -58,13 +58,6 @@ const ( CONFERENCE_TYPE_AV = uint8(C.TOX_CONFERENCE_TYPE_AV) ) -type ChatChangeType int - -const ( - CONFERENCE_STATE_CHANGE_LIST_CHANGED = int(C.TOX_CONFERENCE_STATE_CHANGE_LIST_CHANGED) - CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE = int(C.TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE) -) - type CallControlType int const ( diff --git a/group.go b/group.go index bf0c2a5..1796799 100644 --- a/group.go +++ b/group.go @@ -11,7 +11,8 @@ void callbackConferenceMessageWrapperForC(Tox *, uint32_t, uint32_t, TOX_MESSAGE // void callbackConferenceActionWrapperForC(Tox*, uint32_t, uint32_t, uint8_t*, size_t, void*); void callbackConferenceTitleWrapperForC(Tox*, uint32_t, uint32_t, uint8_t*, size_t, void*); -void callbackConferenceNameListChangeWrapperForC(Tox*, uint32_t, uint32_t, TOX_CONFERENCE_STATE_CHANGE, void*); +void callbackConferencePeerNameWrapperForC(Tox*, uint32_t, uint32_t, uint8_t*, size_t, void*); +void callbackConferencePeerListChangedWrapperForC(Tox*, uint32_t, void*); // fix nouse compile warning static inline __attribute__((__unused__)) void fixnousetoxgroup() { @@ -33,7 +34,8 @@ type cb_conference_message_ftype func(this *Tox, groupNumber uint32, peerNumber type cb_conference_action_ftype func(this *Tox, groupNumber uint32, peerNumber uint32, action string, userData interface{}) type cb_conference_title_ftype func(this *Tox, groupNumber uint32, peerNumber uint32, title string, userData interface{}) -type cb_conference_namelist_change_ftype func(this *Tox, groupNumber uint32, peerNumber uint32, change uint8, userData interface{}) +type cb_conference_peer_name_ftype func(this *Tox, groupNumber uint32, peerNumber uint32, name string, userData interface{}) +type cb_conference_peer_list_changed_ftype func(this *Tox, groupNumber uint32, userData interface{}) // tox_callback_conference_*** @@ -135,26 +137,49 @@ func (this *Tox) CallbackConferenceTitleAdd(cbfn cb_conference_title_ftype, user C.tox_callback_conference_title(this.toxcore, (*C.tox_conference_title_cb)(C.callbackConferenceTitleWrapperForC)) } -//export callbackConferenceNameListChangeWrapperForC -func callbackConferenceNameListChangeWrapperForC(m *C.Tox, a0 C.uint32_t, a1 C.uint32_t, a2 C.TOX_CONFERENCE_STATE_CHANGE, a3 unsafe.Pointer) { +//export callbackConferencePeerNameWrapperForC +func callbackConferencePeerNameWrapperForC(m *C.Tox, a0 C.uint32_t, a1 C.uint32_t, a2 *C.uint8_t, a3 C.size_t, a4 unsafe.Pointer) { var this = cbUserDatas.get(m) - for cbfni, ud := range this.cb_conference_namelist_changes { - cbfn := *(*cb_conference_namelist_change_ftype)(cbfni) - this.putcbevts(func() { cbfn(this, uint32(a0), uint32(a1), uint8(a2), ud) }) + for cbfni, ud := range this.cb_conference_peer_names { + cbfn := *(*cb_conference_peer_name_ftype)(cbfni) + peer_name := C.GoStringN((*C.char)((unsafe.Pointer)(a2)), C.int(a3)) + this.putcbevts(func() { cbfn(this, uint32(a0), uint32(a1), peer_name, ud) }) } } -func (this *Tox) CallbackConferenceNameListChange(cbfn cb_conference_namelist_change_ftype, userData interface{}) { - this.CallbackConferenceNameListChangeAdd(cbfn, userData) +func (this *Tox) CallbackConferencePeerName(cbfn cb_conference_peer_name_ftype, userData interface{}) { + this.CallbackConferencePeerNameAdd(cbfn, userData) } -func (this *Tox) CallbackConferenceNameListChangeAdd(cbfn cb_conference_namelist_change_ftype, userData interface{}) { +func (this *Tox) CallbackConferencePeerNameAdd(cbfn cb_conference_peer_name_ftype, userData interface{}) { cbfnp := (unsafe.Pointer)(&cbfn) - if _, ok := this.cb_conference_namelist_changes[cbfnp]; ok { + if _, ok := this.cb_conference_peer_names[cbfnp]; ok { return } - this.cb_conference_namelist_changes[cbfnp] = userData + this.cb_conference_peer_names[cbfnp] = userData - C.tox_callback_conference_namelist_change(this.toxcore, (*C.tox_conference_namelist_change_cb)(C.callbackConferenceNameListChangeWrapperForC)) + C.tox_callback_conference_peer_name(this.toxcore, (*C.tox_conference_peer_name_cb)(C.callbackConferencePeerNameWrapperForC)) +} + +//export callbackConferencePeerListChangedWrapperForC +func callbackConferencePeerListChangedWrapperForC(m *C.Tox, a0 C.uint32_t, a1 unsafe.Pointer) { + var this = cbUserDatas.get(m) + for cbfni, ud := range this.cb_conference_peer_list_changeds { + cbfn := *(*cb_conference_peer_list_changed_ftype)(cbfni) + this.putcbevts(func() { cbfn(this, uint32(a0), ud) }) + } +} + +func (this *Tox) CallbackConferencePeerListChanged(cbfn cb_conference_peer_list_changed_ftype, userData interface{}) { + this.CallbackConferencePeerListChangedAdd(cbfn, userData) +} +func (this *Tox) CallbackConferencePeerListChangedAdd(cbfn cb_conference_peer_list_changed_ftype, userData interface{}) { + cbfnp := (unsafe.Pointer)(&cbfn) + if _, ok := this.cb_conference_peer_list_changeds[cbfnp]; ok { + return + } + this.cb_conference_peer_list_changeds[cbfnp] = userData + + C.tox_callback_conference_peer_list_changed(this.toxcore, (*C.tox_conference_peer_list_changed_cb)(C.callbackConferencePeerListChangedWrapperForC)) } // methods tox_conference_* diff --git a/group_legacy.go b/group_legacy.go index 66a86f7..849fd7e 100644 --- a/group_legacy.go +++ b/group_legacy.go @@ -60,16 +60,6 @@ func (this *Tox) CallbackGroupTitleAdd(cbfn cb_group_title_ftype, userData inter this.CallbackConferenceTitleAdd(cbfn_, userData) } -func (this *Tox) CallbackGroupNameListChange(cbfn cb_group_namelist_change_ftype, userData interface{}) { - this.CallbackGroupNameListChangeAdd(cbfn, userData) -} -func (this *Tox) CallbackGroupNameListChangeAdd(cbfn cb_group_namelist_change_ftype, userData interface{}) { - cbfn_ := func(this *Tox, groupNumber uint32, peerNumber uint32, change uint8, userData interface{}) { - cbfn(this, int(groupNumber), int(peerNumber), change, userData) - } - this.CallbackConferenceNameListChangeAdd(cbfn_, userData) -} - // methods func (this *Tox) AddGroupChat() (int, error) { gn, err := this.ConferenceNew() diff --git a/tools/generrmsg.go b/tools/generrmsg.go index 7410e32..6560cad 100644 --- a/tools/generrmsg.go +++ b/tools/generrmsg.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/go-clang/v3.8/clang" + "github.com/go-clang/v3.4/clang" ) func main() { @@ -22,9 +22,8 @@ func main() { _ = tuArgs cmdArgs := []string{ "-std=c99", - "-I/usr/include/", - "-I/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include"} - tu := idx.ParseTranslationUnit("/usr/include/tox/tox.h", cmdArgs, nil, 0) + "-I/usr/lib/clang/3.4/include"} + tu := idx.ParseTranslationUnit("/usr/local/include/tox/tox.h", cmdArgs, nil, 0) defer tu.Dispose() for _, d := range tu.Diagnostics() { diff --git a/tox.go b/tox.go index 08ab6cc..954e0ec 100644 --- a/tox.go +++ b/tox.go @@ -93,11 +93,12 @@ type Tox struct { cb_friend_lossless_packets map[unsafe.Pointer]interface{} cb_self_connection_statuss map[unsafe.Pointer]interface{} - cb_conference_invites map[unsafe.Pointer]interface{} - cb_conference_messages map[unsafe.Pointer]interface{} - cb_conference_actions map[unsafe.Pointer]interface{} - cb_conference_titles map[unsafe.Pointer]interface{} - cb_conference_namelist_changes map[unsafe.Pointer]interface{} + cb_conference_invites map[unsafe.Pointer]interface{} + cb_conference_messages map[unsafe.Pointer]interface{} + cb_conference_actions map[unsafe.Pointer]interface{} + cb_conference_titles map[unsafe.Pointer]interface{} + cb_conference_peer_names map[unsafe.Pointer]interface{} + cb_conference_peer_list_changeds map[unsafe.Pointer]interface{} cb_file_recv_controls map[unsafe.Pointer]interface{} cb_file_recvs map[unsafe.Pointer]interface{} @@ -500,7 +501,8 @@ func NewTox(opt *ToxOptions) *Tox { tox.cb_conference_messages = make(map[unsafe.Pointer]interface{}) tox.cb_conference_actions = make(map[unsafe.Pointer]interface{}) tox.cb_conference_titles = make(map[unsafe.Pointer]interface{}) - tox.cb_conference_namelist_changes = make(map[unsafe.Pointer]interface{}) + tox.cb_conference_peer_names = make(map[unsafe.Pointer]interface{}) + tox.cb_conference_peer_list_changeds = make(map[unsafe.Pointer]interface{}) tox.cb_file_recv_controls = make(map[unsafe.Pointer]interface{}) tox.cb_file_recvs = make(map[unsafe.Pointer]interface{}) diff --git a/tox_test.go b/tox_test.go index e68558e..31d72aa 100644 --- a/tox_test.go +++ b/tox_test.go @@ -709,7 +709,7 @@ func TestGroup(t *testing.T) { }, nil) groupNameChangeTimes := 0 - t2.t.CallbackGroupNameListChange(func(_ *Tox, groupNumber int, peerNumber int, change uint8, ud interface{}) { + t2.t.CallbackConferencePeerListChanged(func(_ *Tox, groupNumber uint32, ud interface{}) { groupNameChangeTimes += 1 }, nil) diff --git a/toxav.go b/toxav.go index de601a2..cceaf36 100644 --- a/toxav.go +++ b/toxav.go @@ -367,7 +367,7 @@ func (this *Tox) JoinAVGroupChat(friendNumber uint32, cookie string) (int, error if err != nil { return 0, errors.New("Invalid cookie:" + cookie) } - var _fn = C.int32_t(friendNumber) + var _fn = C.uint32_t(friendNumber) var _data = (*C.uint8_t)((unsafe.Pointer)(&data[0])) var length = len(data) var _length = C.uint16_t(length)