diff --git a/lib.go b/lib.go index 0a5452f..9eee4b0 100644 --- a/lib.go +++ b/lib.go @@ -69,7 +69,7 @@ func StartCwtch(dir_c *C.char, len C.int) { event.NewGetValMessageFromPeer, event.PeerStateChange, } - newApp.LoadProfiles("awesome") + newApp.LoadProfiles("be gay do crime") newApp.LaunchPeers() application = newApp log.Infof("Providing Handle %v", id) @@ -78,8 +78,8 @@ func StartCwtch(dir_c *C.char, len C.int) { //export ACNEvents func ACNEvents() *C.char { select { - case event := <- acnQueue.OutChan(): - return C.CString(fmt.Sprintf("%v", event)) + case myevent := <- acnQueue.OutChan(): + return C.CString(fmt.Sprintf("%v", myevent)) default: return C.CString("") } @@ -108,20 +108,20 @@ func GetContacts(onion_ptr *C.char, onion_len C.int) *C.char { onion := C.GoStringN(onion_ptr, onion_len) log.Infof("Get Contacts for %v", onion) - peer := application.GetPeer(onion) + mypeer := application.GetPeer(onion) contactEventsQueue = event.NewQueue() application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue) var contacts []Contact - for _,contact := range peer.GetContacts() { - contactInfo := peer.GetContact(contact) + for _,contact := range mypeer.GetContacts() { + contactInfo := mypeer.GetContact(contact) log.Infof("contactInfo %v", contactInfo) contacts = append(contacts, Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State}) } - byte,_ := json.Marshal(contacts) - return C.CString(string(byte)) + bytes,_ := json.Marshal(contacts) + return C.CString(string(bytes)) } @@ -138,13 +138,32 @@ func SelectProfile(onion_ptr *C.char, onion_len C.int) *C.char { //export ContactEvents func ContactEvents() *C.char { select { - case event := <- contactEventsQueue.OutChan(): - return C.CString(fmt.Sprintf("%v", event)) + case myevent := <- contactEventsQueue.OutChan(): + return C.CString(fmt.Sprintf("%v", myevent)) default: 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)) +} + func main() { -} \ No newline at end of file +}