summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_model_load.c
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-09 17:25:01 +0200
committerBogdan Devichev <b.devichev@samsung.com>2014-12-09 17:25:01 +0200
commitdbf100eb8ef6995cbdf5797f5c74957947f7277f (patch)
tree16affbb172d4be09c1c00f402289c557c3865ce2 /src/lib/evas/common/evas_model_load.c
parent063c83a01dde06f3d2b4e7f86d2b5262c3b2c53e (diff)
Model_save_load. Step 7. Entry points to modules is new struct with Eina_file, not const char *file.
Diffstat (limited to 'src/lib/evas/common/evas_model_load.c')
-rw-r--r--src/lib/evas/common/evas_model_load.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/src/lib/evas/common/evas_model_load.c b/src/lib/evas/common/evas_model_load.c
index 73503776d4..4ccb30cfad 100644
--- a/src/lib/evas/common/evas_model_load.c
+++ b/src/lib/evas/common/evas_model_load.c
@@ -7,12 +7,67 @@
7#include "evas_common_private.h" 7#include "evas_common_private.h"
8#include "evas_private.h" 8#include "evas_private.h"
9 9
10static inline void
11_model_common_loader_fini(Model_Common_Loader *loader)
12{
13 if (loader->map)
14 {
15 eina_file_map_free(loader->file, loader->map);
16 loader->map = NULL;
17 }
18
19 if (loader->file)
20 {
21 eina_file_close(loader->file);
22 loader->file = NULL;
23 }
24}
25
26static inline Eina_Bool
27_model_common_loader_init(Model_Common_Loader *loader, const char *file)
28{
29 Eina_File *tmp_file = eina_file_open(file, 0);
30 memset(loader, 0x00, sizeof(Model_Common_Loader));
31
32 /* Open given file. */
33 loader->file = eina_file_dup(tmp_file);
34
35 if (loader->file == NULL)
36 {
37 ERR("Failed to open file %s\n", file);
38 goto error;
39 }
40
41 /* Map the file. */
42 loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
43
44 if (loader->map == NULL)
45 {
46 ERR("Failed to create map from file %s\n", file);
47 goto error;
48 }
49
50 eina_file_close(tmp_file);
51 return EINA_TRUE;
52
53error:
54 eina_file_close(tmp_file);
55 _model_common_loader_fini(loader);
56 return EINA_FALSE;
57}
10 58
11void 59void
12evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file) 60evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
13{ 61{
14 char *p; 62 char *p;
15 char *loader = NULL; 63 char *loader_type = NULL;
64 Model_Common_Loader *loader = malloc(sizeof(Model_Common_Loader));
65
66 if (!_model_common_loader_init(loader, file))
67 {
68 ERR("Failed to initialize loader.");
69 return;
70 }
16 71
17 p = strrchr(file, '.'); 72 p = strrchr(file, '.');
18 if (p) 73 if (p)
@@ -21,8 +76,8 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
21#define CHECK_EXTENTION_BY_FILE_NAME(extention) \ 76#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
22 if (!strcasecmp(p, #extention)) \ 77 if (!strcasecmp(p, #extention)) \
23 { \ 78 { \
24 evas_model_load_file_##extention(model, file); \ 79 evas_model_load_file_##extention(model, loader); \
25 loader = #extention; \ 80 loader_type = #extention; \
26 } 81 }
27 CHECK_EXTENTION_BY_FILE_NAME(eet) 82 CHECK_EXTENTION_BY_FILE_NAME(eet)
28 CHECK_EXTENTION_BY_FILE_NAME(md2) 83 CHECK_EXTENTION_BY_FILE_NAME(md2)
@@ -30,5 +85,9 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
30 CHECK_EXTENTION_BY_FILE_NAME(ply) 85 CHECK_EXTENTION_BY_FILE_NAME(ply)
31#undef CHECK_EXTENTION_BY_FILE_NAME 86#undef CHECK_EXTENTION_BY_FILE_NAME
32 } 87 }
33 if (!loader) ERR("Invalid mesh file type."); 88 if (!loader_type) ERR("Invalid mesh file type.");
89
90 _model_common_loader_fini(loader);
91 free(loader);
34} 92}
93