diff options
author | Anonymized <anonymous@example.com> | 2018-01-07 21:06:26 +0100 |
---|---|---|
committer | Anonymized <anonymous@example.com> | 2018-01-07 21:06:26 +0100 |
commit | b7813c7458e5560b5f6b5e3d5d2360b47fcbece4 (patch) | |
tree | 12016079ebd311fbc88f44e9e8957a6b5b34061a | |
parent | 16268cb7d9921da5e8f5135d806ccd8b2ae9df0f (diff) | |
download | gnunet-guile2-b7813c7458e5560b5f6b5e3d5d2360b47fcbece4.tar.gz gnunet-guile2-b7813c7458e5560b5f6b5e3d5d2360b47fcbece4.zip |
add example.{c,scm} to show the issue with progress info
-rw-r--r-- | example.c | 13 | ||||
-rw-r--r-- | example.scm | 27 |
2 files changed, 40 insertions, 0 deletions
diff --git a/example.c b/example.c new file mode 100644 index 0000000..ddff0e3 --- /dev/null +++ b/example.c | |||
@@ -0,0 +1,13 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_fs_service.h" | ||
3 | |||
4 | |||
5 | struct GNUNET_FS_ProgressInfo * test() { | ||
6 | struct GNUNET_FS_ProgressInfo * info = malloc(sizeof(struct GNUNET_FS_ProgressInfo)); | ||
7 | info->status = 42; | ||
8 | return info; | ||
9 | } | ||
10 | |||
11 | |||
12 | // compile with | ||
13 | // c99 -I/gnu/store/nfaljkxhj0hgxkzxbd4pgmm70h9niq7q-gnunet-git-0.10.1-2.477e0de/include/gnunet/ -c example.c -o libexample.o && gcc -shared libexample.o -o libexample.so | ||
diff --git a/example.scm b/example.scm new file mode 100644 index 0000000..06da020 --- /dev/null +++ b/example.scm | |||
@@ -0,0 +1,27 @@ | |||
1 | (use-modules ((bytestructures guile))) | ||
2 | (use-modules ((gnunet config))) | ||
3 | (use-modules ((gnunet))) | ||
4 | (use-modules ((system foreign) #:prefix ffi:)) | ||
5 | |||
6 | (define* (dynamic-link* #:optional library-name) | ||
7 | (let ((shared-object (if library-name (dynamic-link library-name) (dynamic-link)))) | ||
8 | (lambda (return-value function-name . arguments) | ||
9 | (let ((function (dynamic-func function-name shared-object))) | ||
10 | (ffi:pointer->procedure return-value function arguments))))) | ||
11 | |||
12 | ;; bytestructures helper | ||
13 | |||
14 | (define (pointer->bytestructure desc pointer) | ||
15 | (let ((size (bytestructure-descriptor-size desc))) | ||
16 | (let ((bv (ffi:pointer->bytevector pointer size))) | ||
17 | (make-bytestructure bv 0 desc)))) | ||
18 | |||
19 | ;;; gnunet-util bindings, gnunet_util_lib.h | ||
20 | |||
21 | (define fs (dynamic-link* %libgnunet-fs)) | ||
22 | (define libexample (dynamic-link* "./libexample.so")) | ||
23 | |||
24 | (define test (libexample '* "test")) | ||
25 | |||
26 | (define info (pointer->bytestructure %fs-progress-info (test))) | ||
27 | (pk (fs-progress-info-status info)) | ||