]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blobdiff - resources/dummy/fra_dummy.c
dummy: Enable use of multiple dummy resources
[frescor/frsh-forb.git] / resources / dummy / fra_dummy.c
index bd052c59b2517de1b1ff911219a5e1c6b23d1028..3536410e4aa3415d7bf04dc76d2334dab34e2011 100644 (file)
@@ -167,3 +167,34 @@ int fra_dummy_init(void)
        fres_block_register_dummy();
        return fra_register(&dummy_allocator);
 }
+
+/** 
+ * Initializes addition dummy resource allocator.
+ *
+ * This is intended for the use in automatic tests which need to work
+ * with multiple resources. The test can initialize several dummy
+ * resources, not just the default one with id 255.
+ * 
+ * @param id 
+ * 
+ * @return Zero on success, non-zero error code on error.
+ */
+int fra_dummy_init_and_activate_id(frsh_resource_id_t res_id)
+{
+       struct fres_allocator *fra;
+       int ret;
+       fres_block_register_dummy();
+       fra = malloc(sizeof(*fra));
+       if (!fra)
+               goto err;
+       *fra = dummy_allocator;
+       fra->res_id = res_id;
+       fra->priv = malloc(sizeof(int));
+       ret = fra_register(fra);
+       if (ret)
+               goto err;
+       ret = fra_activate(fra->res_type, fra->res_id);
+       return ret;
+err:
+       return -1;
+}