-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontext.go
31 lines (26 loc) · 891 Bytes
/
context.go
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
package gphoto
// #cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -lgphoto2 -lgphoto2_port
// #cgo CFLAGS: -I/usr/include
// #include <gphoto2/gphoto2.h>
// #include "callbacks.h"
import "C"
import "fmt"
//Free should be called afer you don't need the context anymore
func (c Context) Free() {
C.gp_context_unref(c.gpContext)
}
//GetNewGPhotoContext returns a new gphoto context
func GetNewGPhotoContext() (*Context, error) {
var gpContext *C.GPContext
fmt.Printf("Gpcontext before call %#v\n", gpContext)
gpContext = C.gp_context_new()
fmt.Printf("Gpcontext after call %#v\n", gpContext)
if gpContext == nil {
return nil, fmt.Errorf("Could not initialize libgphoto2 context")
}
C.gp_context_set_error_func(gpContext, (*[0]byte)(C.ctx_error_func), nil)
C.gp_context_set_status_func(gpContext, (*[0]byte)(C.ctx_status_func), nil)
return &Context{
gpContext: gpContext,
}, nil
}