mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 01:27:21 +01:00
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// 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);
|
|
void go_alpm_set_question(alpm_handle_t *handle);
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
type logCallbackSig func(uint16, string)
|
|
type questionCallbackSig func(QuestionAny)
|
|
|
|
var DefaultLogLevel = LogWarning
|
|
|
|
func DefaultLogCallback(lvl uint16, s string) {
|
|
if lvl <= DefaultLogLevel {
|
|
print("go-alpm: ", s)
|
|
}
|
|
}
|
|
|
|
var log_callback logCallbackSig
|
|
var question_callback questionCallbackSig
|
|
|
|
//export logCallback
|
|
func logCallback(level uint16, cstring *C.char) {
|
|
log_callback(level, C.GoString(cstring))
|
|
}
|
|
|
|
//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) {
|
|
log_callback = cb
|
|
C.go_alpm_set_logging(h.ptr)
|
|
}
|
|
|
|
func (h *Handle) SetQuestionCallback(cb questionCallbackSig) {
|
|
question_callback = cb
|
|
C.go_alpm_set_question(h.ptr)
|
|
}
|