]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/frsh_core.c
Resource scheduler renamed to resource allocator
[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 #ifdef CONFIG_RESOURCE_ITEM
16 #include <item.h>
17 #endif
18
19 struct frsh_forb frsh_forb_global;
20
21 static void *alloc_executor_thread(void *arg)
22 {
23         return (void*)forb_executor_run(&frsh_forb_global.alloc_executor);
24 }
25
26
27 int frsh_init()
28 {
29         int ret;
30         
31         frsh_forb_global.orb = forb_init(NULL, NULL, "frsh");
32         if (!frsh_forb_global.orb) {
33                 if (errno) return errno;
34                 else return -1;
35         }
36
37         frsh_forb_global.fcb = forb_resolve_reference(frsh_forb_global.orb,
38                                             fres_contract_broker_reg_name);
39         if (!frsh_forb_global.fcb) {
40                 ret = FRES_ERR_FCB_NOT_RUNNING;
41                 goto err;
42         }
43
44         /* Initialize resource allocators */
45         ret = forb_executor_init(&frsh_forb_global.alloc_executor);
46         if (ret) goto err;
47         
48 #ifdef CONFIG_RESOURCE_DUMMY
49         ret = fra_dummy_init(frsh_forb_global.orb, frsh_forb_global.fcb,
50                              &frsh_forb_global.alloc_executor);
51         if (ret) goto err;
52 #endif
53
54 #ifdef FRSH_DISTRIBUTED_MODULE_SUPPORTED
55         ret = frsh_distributed_init();
56         if (ret) goto err;
57 #endif
58
59 #ifdef CONFIG_RESOURCE_ITEM
60         ret = fra_item_init(frsh_forb_global.orb, frsh_forb_global.fcb,
61                             &frsh_forb_global.alloc_executor);
62         if (ret) goto err;
63 #endif
64         /* Run resource allocators */
65         fosa_thread_create(&frsh_forb_global.alloc_executor_thread, NULL,
66                            alloc_executor_thread, NULL);
67         
68         return 0;
69 err:
70         return ret;
71 }
72