Skip to content

Commit 0cc3281

Browse files
author
Chris Warren-Smith
committed
COMMON: implement plugin_refresh_id for variable lifecycle handling
1 parent 6bb8324 commit 0cc3281

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/common/plugins.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef int (*sblib_count_fn) (void);
4242
typedef int (*sblib_init_fn) (const char *);
4343
typedef int (*sblib_has_window_ui_fn) (void);
4444
typedef int (*sblib_free_fn) (int, int);
45+
typedef int (*sblib_refresh_id_fn) (int, int);
4546
typedef void (*sblib_close_fn) (void);
4647

4748
typedef struct {
@@ -51,6 +52,7 @@ typedef struct {
5152
sblib_exec_fn _sblib_proc_exec;
5253
sblib_exec_fn _sblib_func_exec;
5354
sblib_free_fn _sblib_free;
55+
sblib_refresh_id_fn _sblib_refresh_id;
5456
ext_func_node_t *_func_list;
5557
ext_proc_node_t *_proc_list;
5658
uint32_t _id;
@@ -327,6 +329,7 @@ static void slib_import_routines(slib_t *lib, int comp) {
327329
lib->_sblib_func_exec = slib_getoptptr(lib, "sblib_func_exec");
328330
lib->_sblib_proc_exec = slib_getoptptr(lib, "sblib_proc_exec");
329331
lib->_sblib_free = slib_getoptptr(lib, "sblib_free");
332+
lib->_sblib_refresh_id = slib_getoptptr(lib, "sblib_refresh_id");
330333
sblib_count_fn fcount = slib_getoptptr(lib, "sblib_proc_count");
331334
sblib_getname_fn fgetname = slib_getoptptr(lib, "sblib_proc_getname");
332335

@@ -565,6 +568,17 @@ void plugin_free(int lib_id, int cls_id, int id) {
565568
}
566569
}
567570

571+
int plugin_refresh_id(int lib_id, int cls_id, int id) {
572+
int result = id;
573+
if (lib_id != -1 && cls_id != -1 && id != -1) {
574+
slib_t *lib = get_lib(lib_id);
575+
if (lib && lib->_sblib_refresh_id) {
576+
result = lib->_sblib_refresh_id(cls_id, id);
577+
}
578+
}
579+
return result;
580+
}
581+
568582
void plugin_close() {
569583
for (int i = 0; i < MAX_SLIBS; i++) {
570584
if (plugins[i]) {
@@ -594,6 +608,7 @@ void *plugin_get_func(const char *name) { return 0; }
594608
int plugin_procexec(int lib_id, int index) { return -1; }
595609
int plugin_funcexec(int lib_id, int index, var_t *ret) { return -1; }
596610
void plugin_free(int lib_id, int cls_id, int id) {}
611+
int plugin_refresh_id(int lib_id, int cls_id, int id) {return id;}
597612
void plugin_close() {}
598613
#endif
599614

src/common/plugins.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ int plugin_funcexec(int lib_id, int index, var_t *ret);
7171
//
7272
void plugin_free(int lib_id, int cls_id, int id);
7373

74+
//
75+
// in v_move and plugin_free later called on source, dest remains registered
76+
//
77+
int plugin_refresh_id(int lib_id, int cls_id, int id);
78+
7479
//
7580
// closes the plugin system
7681
//

src/common/var.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "common/sys.h"
1111
#include "common/sberr.h"
12+
#include "common/plugins.h"
1213

1314
#define INT_STR_LEN 64
1415

@@ -571,9 +572,9 @@ void v_move(var_t *dest, const var_t *src) {
571572
dest->v.m.map = src->v.m.map;
572573
dest->v.m.count = src->v.m.count;
573574
dest->v.m.size = src->v.m.size;
574-
dest->v.m.id = src->v.m.id;
575575
dest->v.m.lib_id = src->v.m.lib_id;
576576
dest->v.m.cls_id = src->v.m.cls_id;
577+
dest->v.m.id = plugin_refresh_id(src->v.m.lib_id, src->v.m.cls_id, src->v.m.id);
577578
break;
578579
case V_REF:
579580
dest->v.ref = src->v.ref;

src/common/var_map.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ void map_set(var_p_t dest, const var_p_t src) {
317317
hashmap_create(dest, src->v.m.count);
318318
hashmap_foreach(src, map_set_cb, &cb);
319319
dest->v.m.count = src->v.m.count;
320-
dest->v.m.id = src->v.m.id;
321-
dest->v.m.lib_id = -1;
322-
dest->v.m.cls_id = -1;
320+
dest->v.m.lib_id = src->v.m.lib_id;
321+
dest->v.m.cls_id = src->v.m.cls_id;
322+
dest->v.m.id = plugin_refresh_id(src->v.m.lib_id, src->v.m.cls_id, src->v.m.id);
323323
}
324324
}
325325

src/include/module.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,23 @@ int sblib_func_exec(int index, int param_count, slib_par_t *params, var_t *retva
120120
/**
121121
* @ingroup modlib
122122
*
123-
* executes a function
123+
* free resources associated with the variable
124124
*
125125
* @param cls_id the variable class identifier
126126
* @param id the variable instance identifier
127127
*/
128128
int sblib_free(int cls_id, int id);
129129

130+
/**
131+
* @ingroup modlib
132+
*
133+
* registers a fresh id to replace the given id
134+
*
135+
* @param cls_id the variable class identifier
136+
* @param id the variable instance identifier
137+
*/
138+
int sblib_refresh_id(int cls_id, int id);
139+
130140
/**
131141
* @ingroup modlib
132142
*

0 commit comments

Comments
 (0)