1616#include < pthread.h>
1717#include " robin-hood-hashing/src/include/robin_hood.h"
1818
19- struct IOClass ;
19+ struct IOTask ;
2020
2121JNIEnv *env;
2222JavaVM *jvm;
23- IOClass *ioioClass ;
23+ IOTask *ioioTask ;
2424int nextId = 1 ;
2525
2626#define CLASS_ANALOGINPUT " net/sourceforge/smallbasic/ioio/AnalogInputImpl"
@@ -30,12 +30,12 @@ int nextId = 1;
3030#define CLASS_PWMOUTPUT " net/sourceforge/smallbasic/ioio/PwmOutputImpl"
3131#define CLASS_CAPSENSE " net/sourceforge/smallbasic/ioio/CapsenseImpl"
3232#define CLASS_IOIO " net/sourceforge/smallbasic/ioio/IOIOImpl"
33- #define CLASS_IOCLASS_ID 1
33+ #define CLASS_IOTASK_ID 1
3434
35- struct IOClass {
36- IOClass (): _clazz(nullptr ), _instance(nullptr ) {}
35+ struct IOTask {
36+ IOTask (): _clazz(nullptr ), _instance(nullptr ) {}
3737
38- virtual ~IOClass () {
38+ virtual ~IOTask () {
3939 _clazz = nullptr ;
4040 _instance = nullptr ;
4141 }
@@ -200,18 +200,18 @@ struct IOClass {
200200 jobject _instance;
201201};
202202
203- robin_hood::unordered_map<int , IOClass> _classMap ;
203+ robin_hood::unordered_map<int , IOTask> _ioTaskMap ;
204204
205205static int get_io_class_id (var_s *map, var_s *retval) {
206206 int result = -1 ;
207207 if (is_map (map)) {
208208 int id = map->v .m .id ;
209- if (id != -1 && _classMap .find (id) != _classMap .end ()) {
209+ if (id != -1 && _ioTaskMap .find (id) != _ioTaskMap .end ()) {
210210 result = id;
211211 }
212212 }
213213 if (result == -1 ) {
214- error (retval, " IOClass not found" );
214+ error (retval, " IOTask not found" );
215215 }
216216 return result;
217217}
@@ -225,6 +225,9 @@ FUNC_SIG lib_func[] = {
225225 {1 , 2 , " OPENDIGITALOUTPUT" , cmd_opendigitaloutput},
226226 {1 , 2 , " OPENPULSEINPUT" , cmd_openpulseinput},
227227 {1 , 2 , " OPENPWMOUTPUT" , cmd_openpwmoutput},
228+ };
229+
230+ FUNC_SIG lib_proc[] = {
228231 {0 , 0 , " BEGINBATCH" , cmd_beginbatch},
229232 {0 , 0 , " DISCONNECT" , cmd_disconnect},
230233 {0 , 0 , " ENDBATCH" , cmd_endbatch},
@@ -235,8 +238,6 @@ FUNC_SIG lib_func[] = {
235238 {0 , 0 , " WAITFORDISCONNECT" , cmd_waitfordisconnect},
236239};
237240
238- FUNC_SIG lib_proc[] = {};
239-
240241SBLIB_API int sblib_proc_count () {
241242 return (sizeof (lib_proc) / sizeof (lib_proc[0 ]));
242243}
@@ -263,9 +264,9 @@ int sblib_init(const char *sourceFile) {
263264 fprintf (stderr, " Failed to create JVM\n " );
264265 }
265266
266- ioioClass = new IOClass ();
267- if (!ioioClass || !ioioClass ->create (CLASS_IOIO)) {
268- fprintf (stderr, " Failed to IOIOClass \n " );
267+ ioioTask = new IOTask ();
268+ if (!ioioTask || !ioioTask ->create (CLASS_IOIO)) {
269+ fprintf (stderr, " Failed to IOIOTask \n " );
269270 result = 0 ;
270271 }
271272 return result;
@@ -274,23 +275,23 @@ int sblib_init(const char *sourceFile) {
274275SBLIB_API void sblib_free (int cls_id, int id) {
275276 if (id != -1 ) {
276277 switch (cls_id) {
277- case CLASS_IOCLASS_ID :
278- if (id != -1 && _classMap .find (id) != _classMap .end ()) {
279- _classMap .at (id).invokeVoidVoid (" close" , nullptr );
280- _classMap .erase (id);
278+ case CLASS_IOTASK_ID :
279+ if (id != -1 && _ioTaskMap .find (id) != _ioTaskMap .end ()) {
280+ _ioTaskMap .at (id).invokeVoidVoid (" close" , nullptr );
281+ _ioTaskMap .erase (id);
281282 }
282283 break ;
283284 }
284285 }
285286}
286287
287288void sblib_close (void ) {
288- if (ioioClass ) {
289- delete ioioClass ;
289+ if (ioioTask ) {
290+ delete ioioTask ;
290291 }
291- if (!_classMap .empty ()) {
292- fprintf (stderr, " IOClass leak detected\n " );
293- _classMap .clear ();
292+ if (!_ioTaskMap .empty ()) {
293+ fprintf (stderr, " IOTask leak detected\n " );
294+ _ioTaskMap .clear ();
294295 }
295296 jvm->DetachCurrentThread ();
296297 // calling this hangs
0 commit comments