File: threads.go

package info (click to toggle)
golang-github-zenhack-go.notmuch 0.0~git20190821.5a19619-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 240 kB
  • sloc: makefile: 22
file content (53 lines) | stat: -rw-r--r-- 1,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package notmuch

// Copyright © 2015 The go.notmuch Authors. Authors can be found in the AUTHORS file.
// Licensed under the GPLv3 or later.
// See COPYING at the root of the repository for details.

// #cgo LDFLAGS: -lnotmuch
// #include <stdlib.h>
// #include <notmuch.h>
import "C"

import "unsafe"

// Threads represents notmuch threads.
type Threads cStruct

func (ts *Threads) toC() *C.notmuch_threads_t {
	return (*C.notmuch_threads_t)(ts.cptr)
}

func (ts *Threads) Close() error {
	return (*cStruct)(ts).doClose(func() error {
		C.notmuch_threads_destroy(ts.toC())
		return nil
	})
}

// Next retrieves the next thread from the result set. Next returns true if a thread
// was successfully retrieved.
func (ts *Threads) Next(t **Thread) bool {
	if !ts.valid() {
		return false
	}
	*t = ts.get()
	C.notmuch_threads_move_to_next(ts.toC())
	return true
}

func (ts *Threads) get() *Thread {
	cthread := C.notmuch_threads_get(ts.toC())
	checkOOM(unsafe.Pointer(cthread))
	thread := &Thread{
		cptr:   unsafe.Pointer(cthread),
		parent: (*cStruct)(ts),
	}
	setGcClose(thread)
	return thread
}

func (ts *Threads) valid() bool {
	cbool := C.notmuch_threads_valid(ts.toC())
	return int(cbool) != 0
}