Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add storage to workstation struct.
[simgrid.git] / src / surf / storage.c
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012. The SimGrid Team.
2  * All rights reserved.                                                                 */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package.             */
6
7 #include "xbt/ex.h"
8 #include "xbt/dict.h"
9 #include "portable.h"
10 #include "surf_private.h"
11 #include "surf/surf_resource.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf,
14                                 "Logging specific to the SURF storage module");
15
16 surf_model_t surf_storage_model = NULL;
17
18 typedef struct surf_storage {
19   s_surf_resource_t generic_resource;
20   const char* model;
21   const char* content; /*should be a dict */
22 } s_surf_storage_t, *surf_storage_t;
23
24 static surf_action_t storage_action_open(void *storage, const char* path, const char* mode)
25 {
26   return NULL;
27 }
28
29 static surf_action_t storage_action_close(void *storage, surf_file_t fp)
30 {
31   return NULL;
32 }
33
34 static surf_action_t storage_action_read(void *storage, void* ptr, size_t size, size_t nmemb, surf_file_t stream)
35 {
36   return NULL;
37 }
38
39 static surf_action_t storage_action_write(void *storage, const void* ptr, size_t size, size_t nmemb, surf_file_t stream)
40 {
41   return NULL;
42 }
43
44 static surf_action_t storage_action_stat(void *storage, int fd, void* buf)
45 {
46   return NULL;
47 }
48
49 static void* storage_create_resource(const char* id, const char* model,
50                                     const char* content, xbt_dict_t storage_properties)
51 {
52     XBT_INFO("SURF: storage_create_resource '%s'",id);
53     surf_storage_t storage = NULL;
54     xbt_assert(!surf_storage_resource_by_name(id),
55                 "Storage '%s' declared several times in the platform file",
56                 id);
57     storage = (surf_storage_t) surf_resource_new(sizeof(s_surf_storage_t),
58             surf_storage_model, id, storage_properties);
59     storage->model = model;
60     storage->content = content;
61     xbt_lib_set(storage_lib, id, SURF_STORAGE_LEVEL, storage);
62
63     return storage;
64 }
65
66 static void storage_finalize(void)
67 {
68   surf_model_exit(surf_storage_model);
69   surf_storage_model = NULL;
70 }
71
72 static void parse_storage_init(sg_platf_storage_cbarg_t storage)
73 {
74   storage_create_resource(storage->id,
75       storage->model,
76       storage->content,
77       storage->properties);
78 }
79
80 static void storage_define_callbacks()
81 {
82   sg_platf_storage_add_cb(parse_storage_init);
83 }
84
85 static void surf_storage_model_init_internal(void)
86 {
87   XBT_DEBUG("surf_storage_model_init_internal");
88   surf_storage_model = surf_model_init();
89
90   surf_storage_model->name = "Storage";
91
92   surf_storage_model->extension.storage.open = storage_action_open;
93   surf_storage_model->extension.storage.close = storage_action_close;
94   surf_storage_model->extension.storage.read = storage_action_read;
95   surf_storage_model->extension.storage.write = storage_action_write;
96   surf_storage_model->extension.storage.stat = storage_action_stat;
97   surf_storage_model->extension.storage.create_resource = storage_create_resource;
98
99   surf_storage_model->model_private->finalize = storage_finalize;
100
101   xbt_dynar_push(model_list, &surf_storage_model);
102 }
103
104 void surf_storage_model_init_default(void)
105 {
106   surf_storage_model_init_internal();
107   storage_define_callbacks();
108 }