static void loadInline(struct X3D_Inline *me)  
{
	resource_item_t *res = NULL;
	struct Multi_String *url = NULL;
	resource_item_t *parentPath = NULL;

	url = &(me->url);
	parentPath = me->_parentResource;

/*
	printf ("loadInline, we have status of ");
	switch (me->__loadstatus) {
		case INLINE_INITIAL_STATE: printf ("INLINE_INITIAL_STATE\n"); break;
		case INLINE_FETCHING_RESOURCE: printf ("INLINE_FETCHING_RESOURCE\n"); break;
		case INLINE_PARSING: printf ("INLINE_PARSING\n"); break;
		case INLINE_STABLE: printf ("INLINE_STABLE\n"); break;
	};
    printf ("url.n %d\n",url->n);
    printf ("url.p[0] %s\n",url->p[0]->strptr);
*/

	// get the resource pointer from the Inline node.
	res = me->__loadResource;

	switch (me->__loadstatus) {

		case INLINE_INITIAL_STATE: {
			// starting up here. Is the URL empty?
			if (me->url.n == 0) {
				me->__loadstatus = INLINE_STABLE; 
			} else {
				// create the resource;
				res = resource_create_multi(url);

				// save it...;
				me->__loadResource = res;

				// Setup parent
				resource_identify(parentPath, res);
				res->media_type = resm_image; /* quick hack */

				// go to next one
				me->__loadstatus = INLINE_FETCHING_RESOURCE;
			}
			break;
		}

		case INLINE_FETCHING_RESOURCE: {
			bool rv;

			 /* 
              printf ("load_Inline, before resource_fetch, we have type  %s  status %s\n",
				resourceTypeToString(res->type), resourceStatusToString(res->status)); 
			*/
			
			rv = resource_fetch(res);

			/* printf ("load_Inline, after resource_fetch, we have type  %s  status %s\n",
				resourceTypeToString(res->type), resourceStatusToString(res->status)); 
            */

			/* do we try the next url in the multi-url? */
			if ((res->status == ress_failed) && (res->m_request != NULL)) {
				/* printf ("load_Inline, not found, lets try this again\n");*/
				res->status = ress_invalid;
				res->type = rest_multi;

			/* did we get this one? */
			} else if (res->status == ress_downloaded) {
				res->media_type = resm_unknown;
				res->whereToPlaceData = X3D_NODE(me);
				res->offsetFromWhereToPlaceData = (float) offsetof (struct X3D_Inline, __children);
                //printf ("going to send resource to parser async for res %p\n",res);
				if (send_resource_to_parser_if_available(res)) {
				me->__loadstatus = INLINE_PARSING; /* a "do-nothing" approach */
			} else {
                    //printf ("have to wait here for parser to finish\n");
                }
                //printf ("done the send resource to parser async for res %p\n",res);
                
				
			} else {
				if ((res->status == ress_failed) || (res->status == ress_invalid)) {
					printf ("resource failed to load\n");
					me->__loadstatus = INLINE_STABLE; /* a "do-nothing" approach */
				} else {
					printf ("resource Inline in invalid state\n");
					me->__loadstatus = INLINE_STABLE; /* a "do-nothing" approach */
				}
			}

			break;
		}
Exemple #2
0
static BOOL script_initCodeFromUri(struct Shader_Script* me, const char* uri)
{
 size_t i;
 int rv;
 resource_item_t *res;
	ppCScripts p = (ppCScripts)gglobal()->CScripts.prv;

  rv = FALSE; /* initialize it */

 /* strip off whitespace at the beginning JAS */
 while ((*uri<= ' ') && (*uri>0)) uri++;

 /* Try javascript protocol */
 for(i=0; i!=ARR_SIZE(JS_PROTOCOLS); ++i)
 {
  const char* u=uri;
  const char* v=JS_PROTOCOLS[i];

  while(*u && *v && *u==*v)
  {
   ++u;
   ++v;
  }

  /* Is this a "data:text/plain," uri? JAS*/
  if((!*v && *u==',') || (!*v && *u==':')) {
   	if (me != NULL) {
		return script_initCode(me, u+1); /* a script */
	} else {
		p->buffer = STRDUP(u+1);
		return TRUE; /* a shader, program text will be in the "buffer" */
	}
   }
 }

 /* Not a valid script in this SFString. Lets see if this
    is this a possible file that we have to get? */

 DEBUG_CPARSER("script_initCodeFromUri, uri is %s\n", uri); 
 printf ("script_initCodeFromUri, uri is %s\n", uri); 

 res = resource_create_single(uri);
 resource_identify(gglobal()->resources.root_res, res);
 if (res->type != rest_invalid) {
	 if (resource_fetch(res)) {
		 if (resource_load(res)) {
			 s_list_t *l;
			 openned_file_t *of;

			 l = res->openned_files;
			 of = ml_elem(l);

			/* ok - Scripts get initialized; shaders get the buffer returned */
			if (me==NULL) { /* a Shader */
			 	p->buffer = STRDUP(of->fileData);
			 	/* JAS printf("**** Shader:\n%s\n", buffer); 
				printf ("*** Shader: doing the quick return here\n"); */
				return TRUE;
			} else {
				/* a Script */
			 	/* printf("**** Script:\n%s\n", buffer); */
			 	rv = script_initCode(me, of->fileData);
			}
		 }
	 }
 }
 
 
 if (res->status == ress_loaded && rv) {
	 /* ok - we are replacing EXTERNPROTO with PROTO */
	 res->status = ress_parsed;
	 res->complete = TRUE;
	 return TRUE;
 } else {
	 /* failure, FIXME: remove res from root_res... */
/* 		resource_destroy(res); */
 }

 return FALSE;
}