Merge branch 'trunk' of git.openprivacy.ca:flutter/libcwtch-go into trunk
This commit is contained in:
commit
8e13a87a78
44
lib.go
44
lib.go
|
@ -1,5 +1,5 @@
|
||||||
package cwtchh
|
//package cwtch
|
||||||
//package main
|
package main
|
||||||
|
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
@ -71,7 +71,6 @@ func StartCwtch(dir_c *C.char, len C.int) {
|
||||||
event.PeerStateChange,
|
event.PeerStateChange,
|
||||||
}
|
}
|
||||||
newApp.LoadProfiles("be gay do crime")
|
newApp.LoadProfiles("be gay do crime")
|
||||||
//newApp.LoadProfiles("awesome")
|
|
||||||
newApp.LaunchPeers()
|
newApp.LaunchPeers()
|
||||||
application = newApp
|
application = newApp
|
||||||
log.Infof("Providing Handle %v", id)
|
log.Infof("Providing Handle %v", id)
|
||||||
|
@ -80,8 +79,8 @@ func StartCwtch(dir_c *C.char, len C.int) {
|
||||||
//export ACNEvents
|
//export ACNEvents
|
||||||
func ACNEvents() *C.char {
|
func ACNEvents() *C.char {
|
||||||
select {
|
select {
|
||||||
case event := <- acnQueue.OutChan():
|
case myevent := <- acnQueue.OutChan():
|
||||||
return C.CString(fmt.Sprintf("%v", event))
|
return C.CString(fmt.Sprintf("%v", myevent))
|
||||||
default:
|
default:
|
||||||
return C.CString("")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
|
@ -110,20 +109,20 @@ func GetContacts(onion_ptr *C.char, onion_len C.int) *C.char {
|
||||||
|
|
||||||
onion := C.GoStringN(onion_ptr, onion_len)
|
onion := C.GoStringN(onion_ptr, onion_len)
|
||||||
log.Infof("Get Contacts for %v", onion)
|
log.Infof("Get Contacts for %v", onion)
|
||||||
peer := application.GetPeer(onion)
|
mypeer := application.GetPeer(onion)
|
||||||
|
|
||||||
contactEventsQueue = event.NewQueue()
|
contactEventsQueue = event.NewQueue()
|
||||||
application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue)
|
application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue)
|
||||||
|
|
||||||
var contacts []Contact
|
var contacts []Contact
|
||||||
for _,contact := range peer.GetContacts() {
|
for _,contact := range mypeer.GetContacts() {
|
||||||
contactInfo := peer.GetContact(contact)
|
contactInfo := mypeer.GetContact(contact)
|
||||||
log.Infof("contactInfo %v", contactInfo)
|
log.Infof("contactInfo %v", contactInfo)
|
||||||
contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State})
|
contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State})
|
||||||
}
|
}
|
||||||
|
|
||||||
byte,_ := json.Marshal(contacts)
|
bytes,_ := json.Marshal(contacts)
|
||||||
return C.CString(string(byte))
|
return C.CString(string(bytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,12 +139,31 @@ func SelectProfile(onion_ptr *C.char, onion_len C.int) *C.char {
|
||||||
//export ContactEvents
|
//export ContactEvents
|
||||||
func ContactEvents() *C.char {
|
func ContactEvents() *C.char {
|
||||||
select {
|
select {
|
||||||
case event := <- contactEventsQueue.OutChan():
|
case myevent := <- contactEventsQueue.OutChan():
|
||||||
return C.CString(fmt.Sprintf("%v", event))
|
return C.CString(fmt.Sprintf("%v", myevent))
|
||||||
default:
|
default:
|
||||||
return C.CString("")
|
return C.CString("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export NumMessages
|
||||||
|
func NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n C.int) {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
handle := C.GoStringN(handle_ptr, handle_len)
|
||||||
|
n = C.int(len(application.GetPeer(profile).GetContact(handle).Timeline.Messages))
|
||||||
|
log.Infof("NumMessagse(%s, %s) = %d", profile, handle, n)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//export GetMessage
|
||||||
|
func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
|
||||||
|
profile := C.GoStringN(profile_ptr, profile_len)
|
||||||
|
handle := C.GoStringN(handle_ptr, handle_len)
|
||||||
|
message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index]
|
||||||
|
bytes,_ := json.Marshal(message)
|
||||||
|
log.Infof("GetMessage(%s, %s, %d) = %s", profile, handle, message_index, string(bytes))
|
||||||
|
return C.CString(string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
// Leave as is, needed by ffi
|
// Leave as is, needed by ffi
|
||||||
//func main() {}
|
func main() {}
|
Loading…
Reference in New Issue