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>
|
2018-07-26 14:58:51 +02:00
|
|
|
void logCallback(alpm_loglevel_t level, char *cstring);
|
2017-07-14 19:03:54 +02:00
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
2018-07-26 14:58:51 +02:00
|
|
|
type logCallbackSig func(LogLevel, string)
|
2018-03-16 21:54:28 +01:00
|
|
|
type questionCallbackSig func(QuestionAny)
|
|
|
|
|
2017-07-14 19:03:54 +02:00
|
|
|
var DefaultLogLevel = LogWarning
|
|
|
|
|
2018-07-26 14:58:51 +02:00
|
|
|
func DefaultLogCallback(lvl LogLevel, s string) {
|
2017-07-14 19:03:54 +02:00
|
|
|
if lvl <= DefaultLogLevel {
|
|
|
|
print("go-alpm: ", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:29:33 +02:00
|
|
|
var globalLogCallback logCallbackSig
|
|
|
|
var globalQuestionCallback questionCallbackSig
|
2017-07-14 19:03:54 +02:00
|
|
|
|
|
|
|
//export logCallback
|
2018-07-26 14:58:51 +02:00
|
|
|
func logCallback(level C.alpm_loglevel_t, cstring *C.char) {
|
2018-09-14 02:29:33 +02:00
|
|
|
globalLogCallback(LogLevel(level), C.GoString(cstring))
|
2017-07-14 19:03:54 +02:00
|
|
|
}
|
|
|
|
|
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))
|
2018-09-14 02:29:33 +02:00
|
|
|
globalQuestionCallback(QuestionAny{q})
|
2018-03-16 21:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handle) SetLogCallback(cb logCallbackSig) {
|
2018-09-14 02:29:33 +02:00
|
|
|
globalLogCallback = cb
|
2017-07-14 19:03:54 +02:00
|
|
|
C.go_alpm_set_logging(h.ptr)
|
|
|
|
}
|
2018-03-16 21:54:28 +01:00
|
|
|
|
|
|
|
func (h *Handle) SetQuestionCallback(cb questionCallbackSig) {
|
2018-09-14 02:29:33 +02:00
|
|
|
globalQuestionCallback = cb
|
2018-03-16 21:54:28 +01:00
|
|
|
C.go_alpm_set_question(h.ptr)
|
|
|
|
}
|