void l_eval(const char *source, const char *source_file, LClosure *closure) { LAst ast = l_parse(source, source_file); list_iter_p iter = list_iterator(ast, FRONT); while(list_next(iter) != NULL) { l_eval_node((LNode*)list_current(iter), closure); } }
int plugin_load(char *name) { char filename[256]; struct sa_plugin_t * (*plugin_register)(void); int (*plugin_load)(); struct sa_plugin_t *plugin; char *error; debug_printf("Loading plugin %s\n", name); // Fill in name in list element strcpy(plugin_item.name, name); // Check that plugin is not already loaded list_iter_p iter = list_iterator(plugin_list, FRONT); while (list_next(iter) != NULL) { plugin_item_p = (struct plugin_item_t *)list_current(iter); if (strcmp(plugin_item_p->name, name) == 0) { printf("Error: Plugin already loaded!\n"); return -1; } } // Add plugin location sprintf(filename, "sensact-%s.so", name); // Open plugin plugin_item.handle = dlopen(filename, RTLD_LAZY); if (!plugin_item.handle) { fprintf(stderr, "%s\n", dlerror()); return -1; } else { // Add plugin to list of loaded plugins list_add(plugin_list, &plugin_item, sizeof(plugin_item)); // Call plugin_register() plugin_register = dlsym(plugin_item.handle, "plugin_register"); if ((error = dlerror()) != NULL) fprintf(stderr, "%s\n", error); plugin = (*plugin_register)(); // Print plugin information plugin_print_info(plugin, name); // Call plugin load callback (if defined) if (plugin->load != NULL) { plugin_load = plugin->load; (*plugin_load)(); } } return 0; }
int plugin_unload(char *name) { struct sa_plugin_t * (*plugin_register)(void); int (*plugin_unload)(void); struct sa_plugin_t *plugin; char *error; bool found = false; debug_printf("Unloading plugin %s\n", name); // Check that the plugin is loaded list_iter_p iter = list_iterator(plugin_list, FRONT); while (list_next(iter) != NULL) { plugin_item_p = (struct plugin_item_t *)list_current(iter); if (strcmp(plugin_item_p->name, name) == 0) { found = true; break; } } if (!found) { printf("Error: Plugin not found!\n"); return -1; } // Call plugin_register() plugin_register = dlsym(plugin_item_p->handle, "plugin_register"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); return -1; } plugin = (*plugin_register)(); // Call plugin unload callback (if defined) if (plugin->unload != NULL) { plugin_unload = plugin->unload; (*plugin_unload)(); } // Unload plugin if (dlclose(plugin_item_p->handle)) { fprintf(stderr, "%s\n", error); return -1; } // Remove plugin from list of loaded plugins list_pluck(plugin_list, iter->current); return 0; }
/** * Advances the iterator to the previous item in the list and returns the data * stored there. * * \param list pointer to a iterator * \return container of the previous element */ static container_p list_prev(list_iter_p iter) { if(!iter->started&&iter->current!=NULL) { iter->started = 1; return iter->current->cont; } if(iter->current!=NULL) { iter->current = iter->current->prev; return list_current(iter); } return NULL; }
void* list_prev(list_iter_p iter){ if(!iter->started&&iter->current!=NULL){ iter->started=1; return iter->current->data; } if(iter->current!=NULL){ iter->current = iter->current->prev; return list_current(iter); } return NULL; }
/** * Advances the iterator to the next item in the list and returns the data * stored there. If the end of the list is reached it continues with the first * element of the list. * * \param list pointer to a iterator * \return container of the next element */ static container_p list_cycl_next(list_iter_p iter) { if(!iter->started && iter->current != NULL) { iter->started = 1; return iter->current->cont; } if(iter->current != NULL) { iter->current = iter->current->next; if(iter->current == NULL) { iter->current = iter->list->first; } return list_current(iter); } return NULL; }