first working plugin demo
This commit is contained in:
@@ -19,7 +19,7 @@ arguments: arguments.c Makefile
|
||||
no-op: no-op.c Makefile
|
||||
gcc -Wall $< -o $@
|
||||
|
||||
#------------- IPC
|
||||
#------------- IPC -----------------------
|
||||
|
||||
get-signal: get-signal.c Makefile
|
||||
gcc -Wall $< -o $@
|
||||
@@ -35,3 +35,11 @@ fifo-tx: fifo-tx.c my-fifo.h dtime.o Makefile
|
||||
fifo-rx: fifo-rx.c my-fifo.h dtime.o Makefile
|
||||
gcc -Wall $< dtime.o -o $@
|
||||
|
||||
#------------- PLUGIN --------------------
|
||||
|
||||
plugiciel.so: plugiciel.c plugiciel.h Makefile
|
||||
gcc -Wall -shared -fPIC $< -o $@
|
||||
|
||||
appelant: appelant.c plugiciel.h Makefile
|
||||
gcc -Wall $< -ldl -o $@
|
||||
|
||||
|
||||
33
code/appelant.c
Normal file
33
code/appelant.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/* appelant.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
void affichage(char *titre, float vals[4]);
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
void *handle;
|
||||
float values[4];
|
||||
|
||||
void (*funcname)(const char*, const float *);
|
||||
|
||||
handle = dlopen("./plugiciel.so", RTLD_LAZY);
|
||||
if (!handle) {
|
||||
/* fail to load the library */
|
||||
fprintf(stderr, "Error: %s\n", dlerror());
|
||||
return 1;
|
||||
}
|
||||
|
||||
*(void**)(&funcname) = dlsym(handle, "affichage");
|
||||
|
||||
values[0] = 13.37; values[1] = 16.64;
|
||||
values[2] = 3.14159; values[3] = 0.5;
|
||||
|
||||
funcname("rgb * a =", values);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
12
code/plugiciel.c
Normal file
12
code/plugiciel.c
Normal file
@@ -0,0 +1,12 @@
|
||||
/* plugiciel.c */
|
||||
|
||||
#include <stdio.h>
|
||||
#include "plugiciel.h"
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
void affichage(char *titre, float vals[4])
|
||||
{
|
||||
printf("%s : %f %f %f\n", titre,
|
||||
vals[0]*vals[3], vals[1]*vals[3], vals[2]*vals[3]);
|
||||
}
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
1
code/plugiciel.h
Normal file
1
code/plugiciel.h
Normal file
@@ -0,0 +1 @@
|
||||
void affichage(char *titre, float vals[4]);
|
||||
Reference in New Issue
Block a user