FreeWRL / FreeX3D 4.3.0
resources.h
1/*
2
3 FreeWRL support library.
4 Resources handling: URL, files, ...
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27#ifndef __LIBFREEWRL_RESOURCES_H__
28#define __LIBFREEWRL_RESOURCES_H__
29
30#include "list.h"
31
32// OLD_IPHONE_AQUA #ifdef AQUA
33// OLD_IPHONE_AQUA #include <system_threads.h>
34// OLD_IPHONE_AQUA #endif
35
36#ifdef _MSC_VER
37#include <system_threads.h>
38#endif
39
40#if defined(_ANDROID) || defined(ANDROIDNDK)
41#include <system_threads.h>
42#endif
43
44/* is this file name relative to another path, or is it really, really, a direct file name? */
45#if defined(_MSC_VER)
46#define IF_cleanedURL_IS_ABSOLUTE if(strchr(cleanedURL,':')) // if(cleanedURL[0] != '\0' && cleanedURL[1]== ':')
47
48#else
49
50#define IF_cleanedURL_IS_ABSOLUTE \
51 DEBUG_RES("resource_identify = we have base cleanedurl = %s\n", cleanedURL); \
52 if (cleanedURL[0] == '/')
53#endif
54
55typedef enum resource_type {
56 rest_invalid,
57 rest_url,
58 rest_file,
59 rest_multi,
60 rest_string /* inline VRML/X3D code */
61} resource_type_t;
62
63typedef enum resource_status {
64 ress_none, /* never processed */
65 ress_starts_good, /* path/url identification succeeded */
66 ress_invalid, /* path/url identification failed */
67 ress_downloaded, /* download succeeded (or local file available) */
68 ress_failed, /* download failed */
69 ress_loaded, /* loader succeeded */
70 ress_not_loaded, /* loader failed */
71 ress_parsed, /* parser succeeded */
72 ress_not_parsed /* parser failed */
73} resource_status_t;
74
75typedef enum resource_media_type {
76 resm_unknown,
77 resm_vrml,
78 resm_x3d,
79 resm_image,
80 resm_image_buffer,
81 resm_movie,
82 resm_script,
83 resm_pshader,
84 resm_fshader,
85 resm_audio,
86 resm_x3z,
87 resm_mocap,
88 resm_gltf,
89 resm_glb,
90 resm_bin,
91 resm_json,
92 resm_b3dm,
93 resm_i3dm,
94 resm_pnts,
95 resm_cmpt,
96 resm_midi, //midi
97 resm_external, //June 2016 html > frontend anchoring
98} resource_media_type_t;
99
100typedef enum resource_actions {
101 resa_default = 0, //all by default: download, load, parse/process: not using actions
102 resa_identify = 1,
103 resa_download = 2, //will & and | as bit flags so declare 1,2,4,8.. power of 2 or 1<<n
104 resa_load = 4,
105 resa_process = 8,
106 //resa_place,
107 //resa_ remove, delete ?? ... see parser_process_res()
108} resource_actions_t;
109
110typedef struct resource_item {
111
112 /* Parent */
113 struct resource_item *parent;
114 s_list_t *children;
115
116 bool network;
117 bool new_root;
118
119 /* Request */
120 resource_type_t type;
121 resource_status_t status;
122 resource_actions_t actions; //if 0, do default which is all actions: download, load, parse,
123 //else do specific requested actions (which are bitwise |= resource_actions_t's)
124 //resource_actions_t successful; //you could have more bitwise flags to track what steps succeeded, which were attempted etc.
125 //resource_actions_t attempted;
126
127 /* Resource has passed all the steps */
128 //July30,2014 dug9: clarification (and possible change) of the meaning of complete:
129 // work thread (and FE/ML download/load threads) has attempted all requested actions which are possible,
130 // and is finished with the resitem (some actions may have failed - test with last status ie ress_failed etc)
131 bool complete;
132 //for vrml/x3d media types:
133 void *ectx; //for parsing brotos - the X3D_Proto executionContext to put __ROUTES, __nodes, __subContext
134 void *whereToPlaceData; // usually X3D_Node*, except for Scripts and Shaders, it's Shader_Script* (which is a sub-struct)
135 int offsetFromWhereToPlaceData; //usually field offset (not used for Scripts/Shaders)
136 int textureNumber; //Dec 2014 textures don't use wheretoplacedata now, because the *tti might be zapped during inline unload before the image is downloaded ie Mars dataset
137 /* We can be feed with a Multi_String list of requests */
138 s_list_t *m_request;
139
140 /* Verbatim request : requested path/url */
141 char *URLrequest;
142
143 /* Base:
144 (base url or base path of the main world)
145 - if parent != NULL, use parent's base,
146 - else use own's base
147
148 MUST be complete: either have a trailing '/'
149 either be the end of a valid URI that can
150 be appended with a file:
151 'http://host/cgi?request_file='
152
153 This last example requires that we can
154 parse the main url and extract that 'base'.
155 Is there a 'base' declaration in X3D spec ?
156 */
157 char *URLbase;
158
159 /* Temporary directory:
160 (each main file/world has its own temp dir)
161 - if parent != NULL, use parent's dir,
162 - else use own's dir
163 */
164 char *temp_dir;
165
166 /* if we have a # character in it (eg, proto, Anchor) we'll have a mallocd bit of
167 memory here */
168 char *afterPoundCharacters;
169
170
171/*
172 * Note on temp dir: to improve user experience, each time a temporary
173 * file is created to mirror a network resource, we
174 * use the temporary directory created specificaly
175 * for this main file/world : this way the user (or
176 * a future menu in FreeWRL) can pack all that stuff
177 * more easily.
178 */
179
180 /* Parsed request:
181 - complete url to network file
182 - complete path to local file
183 */
184 char *parsed_request;
185
186 /* Cached files: first is actual file to read,
187 other are intermediate: zipped file,
188 file not in good format, ...
189 */
190 char *actual_file;
191 void *cached_files;
192
193 /* Openned files: to be able to close them. */
194 void *openned_files;
195
196 /* Convenient */
197 char four_first_bytes[4];
198
199 resource_media_type_t media_type;
200 int treat_as_root; //bandaid for .x3z doc.x3d to be seen as root res equivalent
201 pthread_t *_loadThread; //pthread_t * used for async_loading in middleLayer ML
202 void *tg; //gglobal context
203 int (*_loadFunc)(void *); //used for some experiments where the backend loads, but the frontend injects a load function
204 char *resm_specific; // use for anything a specific resm_ type needs
205 int resm_specific2;
206} resource_item_t;
207
208extern resource_item_t *root_res;
209
210bool resource_init_base(resource_item_t *root_res);
211
212resource_item_t* resource_create_single(const char *request);
213
214/* Quick hack to not be forced to include Structs.h */
215typedef struct Multi_String s_Multi_String_t;
216resource_item_t* resource_create_multi(const s_Multi_String_t *request);
217resource_item_t* resource_create_multi0(const s_Multi_String_t *request);
218
219resource_item_t* resource_create_from_string(const char *string);
220
221void push_resource_request(const char *request);
222void resource_identify(resource_item_t *base, resource_item_t *resresource_identify);
223bool resource_fetch(void *res);
224
225void resitem_enqueue(s_list_t *resitem);
226bool resource_load(resource_item_t *res);
227void resource_identify_type(resource_item_t *res);
228void resource_destroy(resource_item_t *res);
229void destroy_root_res();
230
231void resource_remove_child(resource_item_t *parent, resource_item_t *child);
232
233void send_resource_to_parser(resource_item_t *res);
234void send_resource_to_parser_async(resource_item_t *res);
235
236bool send_resource_to_parser_if_available(resource_item_t *res);
237
238void fwl_resitem_setStatus(void *resp, int status);
239
240void resource_push_multi_request(struct Multi_String *request);
241void resource_wait(resource_item_t *res);
242
243void resource_get_valid_url_from_multi(resource_item_t *parentPath, resource_item_t *res);
244
245void resource_dump(resource_item_t *res);
246void resource_tree_dump(int level, resource_item_t *root);
247void resource_tree_list_files(int level, resource_item_t *root);
248void resource_tree_destroy();
249
250char *resourceStatusToString(int status);
251char *resourceTypeToString(int type);
252char *resourceMediaTypeToString(int type);
253
254/* Initial URL loaded : replace IS_WORLD_LOADED */
255extern bool resource_is_root_loaded();
256void frontenditem_enqueue(s_list_t *item);
257
258void popInputResource();
259void pushInputResource(resource_item_t *url);
260resource_item_t *getInputResource();
261
262bool imagery_load(resource_item_t *res);
263bool movie_load(resource_item_t *res);
264
265#endif /* __LIBFREEWRL_RESOURCES_H__ */