]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_core.c
Fixes Martin's previous commit
[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 FRSH_DISTRIBUTED_MODULE_SUPPORTED
8 #include <frsh_distributed.h>
9 #endif
10
11 #ifdef CONFIG_RESOURCE_DUMMY
12 #include <res_dummy.h>
13 #endif
14
15 struct frsh_forb frsh_forb_global;
16
17 static void *sch_executor_thread(void *arg)
18 {
19         return (void*)forb_executor_run(&frsh_forb_global.sch_executor);
20 }
21
22
23 int frsh_init()
24 {
25         int ret;
26         
27         frsh_forb_global.orb = forb_init(NULL, NULL, "frsh");
28         if (!frsh_forb_global.orb) {
29                 if (errno) return errno;
30                 else return -1;
31         }
32
33         frsh_forb_global.fcb = forb_resolve_reference(frsh_forb_global.orb,
34                                             fres_contract_broker_reg_name);
35         if (!frsh_forb_global.fcb) {
36                 ret = FRES_ERR_FCB_NOT_RUNNING;
37                 goto err;
38         }
39
40         /* Initialize resource schedulers */
41         ret = forb_executor_init(&frsh_forb_global.sch_executor);
42         if (ret) goto err;
43         
44 #ifdef CONFIG_RESOURCE_DUMMY
45         ret = frs_dummy_init(frsh_forb_global.orb, frsh_forb_global.fcb,
46                              &frsh_forb_global.sch_executor);
47         if (ret) goto err;
48 #endif
49
50 #ifdef FRSH_DISTRIBUTED_MODULE_SUPPORTED
51         ret = frsh_distributed_init();
52         if (ret) goto err;
53 #endif
54         /* Run resource schedulers */
55         fosa_thread_create(&frsh_forb_global.sch_executor_thread, NULL,
56                            sch_executor_thread, NULL);
57
58         return 0;
59 err:
60         return ret;
61 }
62