struct rdllib * rdllib_open (void) { struct rdllib *rl = malloc (sizeof (*rl)); if (rl == NULL) return NULL; rl->L = luaL_newstate (); if (rl->L == NULL) { rdllib_close (rl); return NULL; } luaL_openlibs (rl->L); rl->errf = default_err_f ? default_err_f : &verr; rl->errctx = default_err_ctx; rl->rdl_list = list_create ((ListDelF) rdl_free); if (rl->rdl_list == NULL) { rdllib_close (rl); return (NULL); } if (rdllib_init (rl) < 0) return NULL; return (rl); }
static void freectx (void *arg) { ctx_t *ctx = arg; free_simstate (ctx->sim_state); while (zlist_size (ctx->queued_events) > 0) free (zlist_pop (ctx->queued_events)); zlist_destroy (&ctx->queued_events); while (zlist_size (ctx->running_jobs) > 0) free_job (zlist_pop (ctx->running_jobs)); zlist_destroy (&ctx->running_jobs); rdllib_close (ctx->rdllib); free (ctx->rdl); free (ctx); }
resrc_flow_t *resrc_flow_generate_rdl (const char *path, char *uri) { resrc_flow_t *flow = NULL; struct rdl *rdl = NULL; struct rdllib *l = NULL; struct resource *r = NULL; if (!(l = rdllib_open ()) || !(rdl = rdl_loadfile (l, path))) goto ret; if ((r = rdl_resource_get (rdl, uri))) flow = resrc_flow_add_rdl (NULL, r); rdl_destroy (rdl); rdllib_close (l); ret: return flow; }
int main (int argc, char *argv[]) { struct rdllib *l; struct rdl *rdl1, *rdl2; struct rdl_accumulator *a; struct resource *r, *c; int64_t val; const char *h = NULL; const char *filename = argv[1]; log_init (basename (argv[0])); rdllib_set_default_errf (NULL, &perr); if (!(l = rdllib_open ())) log_err_exit ("rdllib_open"); if (filename == NULL || *filename == '\0') filename = getenv ("TESTRDL_INPUT_FILE"); if (!(rdl1 = rdl_loadfile (l, filename))) log_err_exit ("loadfile: %s", filename); while ((h = rdl_next_hierarchy (rdl1, h))) fprintf (stderr, "%s\n", h); if (!(rdl2 = rdl_copy (rdl1))) log_err_exit ("copy"); r = rdl_resource_get (rdl1, "default"); if (rdl_resource_set_int (r, "test-tag", 5959) < 0) exit (1); rdl_resource_get_int (r, "test-tag", &val); if (val != 5959) exit (1); rdl_resource_delete_tag (r, "test-tag"); c = rdl_resource_next_child (r); a = rdl_accumulator_create (rdl1); if (rdl_accumulator_add (a, c) < 0) exit (1); rdl2 = rdl_accumulator_copy (a); rdl_accumulator_destroy (a); print_resource (rdl_resource_get (rdl2, "default"), 0); /* * Test find */ json_t *args = Jnew (); Jadd_str (args, "type", "node"); Jadd_int (args, "id", 300); rdl2 = rdl_find (rdl1, args); if (rdl2 == NULL) log_err_exit ("rdl_find"); json_decref (args); r = rdl_resource_get (rdl2, "default"); if (r == NULL) exit (1); c = rdl_resource_next_child (r); printf ("found %s\n", rdl_resource_name (c)); rdl_resource_destroy (r); rdl_destroy (rdl2); r = rdl_resource_get (rdl1, "default:/hype/hype300/socket0/memory"); if (r == NULL) exit (1); print_resource (r, 0); rdl_resource_alloc (r, 1024); printf ("After alloc:\n"); print_resource (r, 0); rdl_resource_free (r, 1024); printf ("After free:\n"); print_resource (r, 0); rdllib_close (l); log_fini (); return 0; }