Better SWIG integration: autogen func & attributes

This commit is contained in:
slurdge authored and Philippe Teuwen committed 2020-06-14 21:35:23 +02:00
1 parent 756b624668
commit 538ee4dabb
12 files changed
+887 -1037

No files matched your search

+5 -50
View File
@@ -1,56 +1,11 @@
#ifndef LIBPM3_H
#define LIBPM3_H
#ifdef SWIG
%module pm3
%{
/* Include the header in the wrapper code */
#include "pm3.h"
%}
/* Strip "pm3_" from API functions for SWIG */
%rename("%(strip:[pm3_])s") "";
%feature("immutable","1") pm3_current_dev;
struct pm3_device { };
%extend pm3_device {
pm3_device() {
printf("SWIG pm3_device constructor, get current pm3\n");
_embedded = 1;
return pm3_get_current_dev();
}
pm3_device(char *port) {
printf("SWIG pm3_device constructor with port, open pm3\n");
_embedded = 0;
return pm3_open(port);
}
~pm3_device() {
if (_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_close($self);
}
}
int console(char *cmd) {
return pm3_console($self, cmd);
}
char *get_name() {
return pm3_get_name($self);
}
}
//%nodefaultctor pm3_device;
//%nodefaultdtor pm3_device;
/* Parse the header file to generate wrappers */
#endif // SWIG
// TODO better than this global?
int _embedded;
typedef struct pm3_device pm3_device;
pm3_device* pm3_open(char *port);
int pm3_console(pm3_device* dev, char *cmd);
char *pm3_get_name(pm3_device* dev);
void pm3_close(pm3_device* dev);
pm3_device* pm3_get_current_dev(void);
int pm3_device_console(pm3_device* dev, char *cmd);
char *pm3_device_name_get(pm3_device* dev);
void pm3_device_close(pm3_device* dev);
pm3_device* pm3_device_get_current_dev(void);
#endif // LIBPM3_H
+39
View File
@@ -0,0 +1,39 @@
%module pm3
%{
/* Include the header in the wrapper code */
#include "pm3.h"
#include "comms.h"
%}
/* Strip "pm3_" from API functions for SWIG */
%rename("%(strip:[pm3_])s") "";
%feature("immutable","1") pm3_current_dev;
typedef struct {
%extend {
pm3_device() {
printf("SWIG pm3_device constructor, get current pm3\n");
pm3_device * p = pm3_device_get_current_dev();
p->script_embedded = 1;
return p;
}
pm3_device(char *port) {
printf("SWIG pm3_device constructor with port, open pm3\n");
pm3_device * p = pm3_open(port);
p->script_embedded = 1;
return p;
}
~pm3_device() {
if ($self->script_embedded) {
printf("SWIG pm3_device destructor, nothing to do\n");
} else {
printf("SWIG pm3_device destructor, close pm3\n");
pm3_device_close($self);
}
}
int console(char *cmd);
char const * const name;
}
} pm3_device;
//%nodefaultctor device;
//%nodefaultdtor device;
/* Parse the header file to generate wrappers */