Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds finished callback support #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"./wkhtmltopdf"
"fmt"
"github.com/hailocab/wkhtmltopdf-go/wkhtmltopdf"
)

func main() {
Expand Down Expand Up @@ -40,6 +40,9 @@ func main() {
c.Phase = func(c *wkhtmltopdf.Converter) {
fmt.Printf("Phase\n")
}
c.Finished = func(c *wkhtmltopdf.Converter, s int) {
fmt.Printf("Finished: %d\n", s)
}
c.Convert()

fmt.Printf("Got error code: %d\n", c.ErrorCode())
Expand Down
11 changes: 11 additions & 0 deletions wkhtmltopdf/pdf_c_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ package wkhtmltopdf
//#include <string.h>
//#include <stdlib.h>
//#include <wkhtmltox/pdf.h>
//extern void finished_cb(void*, const int);
//extern void progress_changed_cb(void*, const int);
//extern void error_cb(void*, char *msg);
//extern void warning_cb(void*, char *msg);
//extern void phase_changed_cb(void*);
//static void setup_callbacks(wkhtmltopdf_converter * c) {
// wkhtmltopdf_set_finished_callback(c, (wkhtmltopdf_int_callback)finished_cb);
// wkhtmltopdf_set_progress_changed_callback(c, (wkhtmltopdf_int_callback)progress_changed_cb);
// wkhtmltopdf_set_error_callback(c, (wkhtmltopdf_str_callback)error_cb);
// wkhtmltopdf_set_warning_callback(c, (wkhtmltopdf_str_callback)warning_cb);
Expand All @@ -34,6 +36,7 @@ type ObjectSettings struct {

type Converter struct {
c *C.wkhtmltopdf_converter
Finished func(*Converter, int)
ProgressChanged func(*Converter, int)
Error func(*Converter, string)
Warning func(*Converter, string)
Expand Down Expand Up @@ -78,6 +81,14 @@ func (self *GlobalSettings) NewConverter() *Converter {
return c
}

//export finished_cb
func finished_cb(c unsafe.Pointer, s C.int) {
conv := converter_map[c]
if conv.Finished != nil {
conv.Finished(conv, int(s))
}
}

//export progress_changed_cb
func progress_changed_cb(c unsafe.Pointer, p C.int) {
conv := converter_map[c]
Expand Down