]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_core.c
Added initialization of resource schedulers in frsh_init()
[frescor/frsh.git] / frsh_api / frsh_core.c
1 #include <frsh_core.h>
2 #include <fcb.h>
3 #include <forb.h>
4 #include "frsh_forb.h"
5 #include <frsh_resources.h>
6
7 #ifdef CONFIG_RESOURCE_DUMMY
8 #include <res_dummy.h>
9 #endif
10
11 struct frsh_forb frsh_forb_global;
12
13 static void *sch_executor_thread(void *arg)
14 {
15         return (void*)forb_executor_run(&frsh_forb_global.sch_executor);
16 }
17
18
19 int frsh_init()
20 {
21         int ret;
22         
23         frsh_forb_global.orb = forb_init(NULL, NULL, "frsh");
24         if (!frsh_forb_global.orb) {
25                 if (errno) return errno;
26                 else return -1;
27         }
28
29         frsh_forb_global.fcb = forb_resolve_reference(frsh_forb_global.orb,
30                                             fres_contract_broker_reg_name);
31         if (!frsh_forb_global.fcb) {
32                 ret = FRES_ERR_FCB_NOT_RUNNING;
33                 goto err;
34         }
35
36         /* Initialize resource schedulers */
37         ret = forb_executor_init(&frsh_forb_global.sch_executor);
38         if (ret) goto err;
39         
40 #ifdef CONFIG_RESOURCE_DUMMY
41         ret = frs_dummy_init(frsh_forb_global.orb, frsh_forb_global.fcb,
42                              &frsh_forb_global.sch_executor);
43         if (ret) goto err;
44 #endif
45
46         /* Run resource schedulers */
47         fosa_thread_create(&frsh_forb_global.sch_executor_thread, NULL,
48                            sch_executor_thread, NULL);
49
50         return 0;
51 err:
52         return ret;
53 }
54