Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv gs/ DataDesc/
[simgrid.git] / src / gras / DataDesc / type_driver.c
1 /* gs_type_driver.c */
2
3 #include "gs/gs_private.h"
4
5 static
6 gras_dict_t *p_type_driver_dict = NULL;
7
8 //GRAS_LOG_NEW_DEFAULT_CATEGORY(FIXME_type_driver);
9
10 void
11 gs_type_drivers_init(void) {
12   gras_error_t errcode;
13   
14   TRYFAIL(gras_dict_new(&p_type_driver_dict));
15   TRYFAIL(gras_dict_insert(p_type_driver_dict, "rl", gs_rl_type_driver(), NULL));
16 }
17
18
19 struct s_gs_type_driver *
20 gs_type_driver_init(const char *name) {
21
22         struct s_gs_type_driver_ops     *type_driver_ops = NULL;
23         struct s_gs_type_driver         *p_type_driver   = NULL;
24
25         gras_dict_retrieve(p_type_driver_dict, name, (void **)&type_driver_ops);
26         if (!type_driver_ops)
27                 GS_FAILURE("type driver not found");
28
29         p_type_driver           = calloc(1, sizeof (struct s_gs_type_driver));
30         p_type_driver->type_ops = type_driver_ops;
31         p_type_driver->specific = NULL;
32
33         if (type_driver_ops->_init) {
34                 type_driver_ops->_init(p_type_driver);
35         }
36
37         return p_type_driver;
38 }
39
40
41
42 void
43 gs_type_driver_exit(struct s_gs_type_driver     *p_type_driver){
44
45         struct s_gs_type_driver_ops     *type_driver_ops = NULL;
46
47         type_driver_ops = p_type_driver->type_ops;
48         if (type_driver_ops->_exit) {
49                 type_driver_ops->_exit(p_type_driver);
50         }
51
52         p_type_driver->type_ops = NULL;
53
54         if (p_type_driver->specific) {
55                 free(p_type_driver->specific);
56                 p_type_driver->specific = NULL;
57         }
58
59         free(p_type_driver);
60 }
61
62 struct s_gs_type_bag *
63 gs_type_bag_alloc(struct s_gs_type_driver       *p_driver) {
64
65         struct s_gs_type_bag            *p_bag   = NULL;
66         struct s_gs_type_bag_ops        *bag_ops = p_driver->bag_ops;
67
68         p_bag = calloc(1, sizeof(struct s_gs_type_bag));
69
70         p_bag->bag_ops          = bag_ops;
71         p_bag->p_type_driver    = p_driver;
72         p_bag->specific         = NULL;
73
74         if (bag_ops->_init) {
75                 bag_ops->_init(p_bag);
76         }
77
78         return p_bag;
79 }
80
81 void
82 gs_type_bag_free(struct s_gs_type_bag   *p_bag) {
83
84         struct s_gs_type_bag_ops        *bag_ops = p_bag->bag_ops;
85
86         if (bag_ops->_exit) {
87                 bag_ops->_exit(p_bag);
88         }
89
90         if (p_bag->specific) {
91                 free(p_bag->specific);
92                 p_bag->specific = NULL;
93         }
94
95         free(p_bag);
96 }
97