yay/vendor/github.com/jguer/go-alpm/callbacks.go

57 lines
1.2 KiB
Go
Raw Normal View History

2017-07-14 19:03:54 +02:00
// callbacks.go - Handles libalpm callbacks.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.
package alpm
/*
#include <stdint.h>
#include <alpm.h>
void logCallback(uint16_t level, char *cstring);
void go_alpm_log_cb(alpm_loglevel_t level, const char *fmt, va_list arg);
void go_alpm_set_logging(alpm_handle_t *handle);
2018-03-16 21:54:28 +01:00
void go_alpm_set_question(alpm_handle_t *handle);
2017-07-14 19:03:54 +02:00
*/
import "C"
2018-03-16 21:54:28 +01:00
import (
"unsafe"
)
type logCallbackSig func(uint16, string)
type questionCallbackSig func(QuestionAny)
2017-07-14 19:03:54 +02:00
var DefaultLogLevel = LogWarning
func DefaultLogCallback(lvl uint16, s string) {
if lvl <= DefaultLogLevel {
print("go-alpm: ", s)
}
}
2018-03-16 21:54:28 +01:00
var log_callback logCallbackSig
var question_callback questionCallbackSig
2017-07-14 19:03:54 +02:00
//export logCallback
func logCallback(level uint16, cstring *C.char) {
log_callback(level, C.GoString(cstring))
}
2018-03-16 21:54:28 +01:00
//export questionCallback
func questionCallback(question *C.alpm_question_t) {
q := (*C.alpm_question_any_t)(unsafe.Pointer(question))
question_callback(QuestionAny{q})
}
func (h *Handle) SetLogCallback(cb logCallbackSig) {
2017-07-14 19:03:54 +02:00
log_callback = cb
C.go_alpm_set_logging(h.ptr)
}
2018-03-16 21:54:28 +01:00
func (h *Handle) SetQuestionCallback(cb questionCallbackSig) {
question_callback = cb
C.go_alpm_set_question(h.ptr)
}