static int  create_accessor(grib_section* p, grib_action* act, grib_loader *h )
{
	int ret = GRIB_SUCCESS;
	grib_action_trigger* a = ( grib_action_trigger*)act;
	grib_action* next = NULL;
	grib_accessor* as = NULL;
	grib_section*         gs = NULL;


	as = grib_accessor_factory(p, act,0,NULL);  

	if(!as) return GRIB_INTERNAL_ERROR;

	gs = as->sub_section;
	gs->branch = 0; /* Force a reparse each time */

	grib_push_accessor(as,p->block);
	grib_dependency_observe_arguments(as,a->trigger_on);

	next = a->block;

	while(next){
		ret = grib_create_accessor(gs, next,h);
		if(ret != GRIB_SUCCESS) return ret;
		next= next->next;
	}

	return GRIB_SUCCESS;

}
static int  create_accessor(grib_section* p, grib_action* act, grib_loader *h ){
  int ret = GRIB_SUCCESS;
  grib_action_template* a = ( grib_action_template*)act;
  grib_action* la = NULL;
  grib_action* next = NULL;
  grib_accessor* as = NULL;
  grib_section*         gs = NULL;

  char fname[1024]={0,};
  char *fpath=0;

  as = grib_accessor_factory(p, act,0,NULL);

  if(!as) return GRIB_INTERNAL_ERROR;
  if(a->arg){
    ret = grib_recompose_name(p->h,as,a->arg,fname,1);

	if ((fpath=grib_context_full_defs_path(p->h->context,fname))==NULL) {
      if (!a->nofail) {
        grib_context_log(p->h->context,GRIB_LOG_ERROR,
                         "Unable to find template %s from %s ",act->name,fname);
        return GRIB_FILE_NOT_FOUND;
      }
	  la = get_empty_template(p->h->context,&ret);
	  if (ret) return ret;
    } else 
      la = grib_parse_file(p->h->context, fpath);
  }
  as->flags |= GRIB_ACCESSOR_FLAG_HIDDEN;
  gs = as->sub_section;
  gs->branch = la; /* Will be used to prevent unecessary reparse */

  grib_push_accessor(as,p->block);

  if(la){
    next = la;

    while(next){
      ret = grib_create_accessor(gs, next,h);
      if(ret != GRIB_SUCCESS) {
      if(p->h->context->debug)
    {
      grib_context_log(p->h->context,GRIB_LOG_ERROR,
      "Error processing template %s: %s [%s] %04lx",
      fname,grib_get_error_message(ret),next->name,next->flags);
    }
      return ret;
    }
      next= next->next;
    }
  }
  return GRIB_SUCCESS;
}
示例#3
0
static int create_accessor( grib_section* p, grib_action* act, grib_loader *h)
{
    grib_action_if* a = (grib_action_if*)act;
    grib_action* next = NULL;
    int ret = 0;
    long lres=0;

    grib_accessor* as = NULL;
    grib_section*  gs = NULL;

    as = grib_accessor_factory(p, act,0,NULL);
    if(!as)return GRIB_INTERNAL_ERROR;
    gs = as->sub_section;
    grib_push_accessor(as,p->block);

    if ((ret=grib_expression_evaluate_long(p->h,a->expression,&lres)) != GRIB_SUCCESS)
        return ret;

    if(lres)
        next = a->block_true;
    else
        next = a->block_false;

    if(p->h->context->debug > 1)
    {
        printf("EVALUATE create_accessor_handle ");
        grib_expression_print(p->h->context,a->expression,p->h);
        printf(" [%s][_if%p]\n", (next == a->block_true ? "true":"false"), (void*)a);

        /*grib_dump_action_branch(stdout,next,5);*/
    }

    gs->branch = next;
    grib_dependency_observe_expression(as,a->expression);

    while(next){

        ret = grib_create_accessor(gs, next, h);
        if(ret != GRIB_SUCCESS) return ret;
        next= next->next;
    }

    return GRIB_SUCCESS;
}
static int execute(grib_action* a, grib_handle *h)
{
	return grib_create_accessor(h->root, a, NULL );
}
示例#5
0
static int notify_change(grib_action* act, grib_accessor * notified,
                         grib_accessor* changed)
{

  grib_loader loader = { 0,};

  grib_section *old_section = NULL;
  grib_handle *h = notified->parent->h;
  size_t len = 0;
  size_t size = 0;
  int err=0;
  grib_handle* tmp_handle;
  int doit = 0;

  grib_action* la        = NULL;

  grib_context_log(h->context,
      GRIB_LOG_DEBUG,"------------- SECTION action %s (%s) is triggerred by [%s]",
      act->name, notified->name, changed->name);

  la = grib_action_reparse(act,notified,&doit);
  old_section = notified->sub_section;
  Assert(old_section);

  Assert(old_section->h == h);

  /* printf("old = %p\n",(void*)old_section->branch); */
  /* printf("new = %p\n",(void*)la); */

  grib_context_log(h->context,
      GRIB_LOG_DEBUG,"------------- DOIT %ld OLD %p NEW %p",
      doit,old_section->branch,la);


  if(!doit) {
    if(la != NULL || old_section->branch != NULL)
      if(la == old_section->branch)
      {
        grib_context_log(h->context,GRIB_LOG_DEBUG,"IGNORING TRIGGER action %s (%s) is triggerred %p", act->name, notified->name
            ,(void*)la);
        return GRIB_SUCCESS;
      }
  }

  loader.list_is_resized = (la == old_section->branch);

  if (!strcmp(changed->name,"GRIBEditionNumber")) loader.changing_edition=1;
  else loader.changing_edition=0;

  old_section->branch = la;

  tmp_handle = grib_new_handle(h->context);
  if(!tmp_handle)
    return GRIB_OUT_OF_MEMORY;

  tmp_handle->buffer = grib_create_growable_buffer(h->context);
  Assert(tmp_handle->buffer); /* FIXME */

  loader.data          = h;
  loader.lookup_long   = grib_lookup_long_from_handle;
  loader.init_accessor = grib_init_accessor_from_handle;


  Assert(h->kid == NULL);
  tmp_handle->loader = &loader;
  tmp_handle->main  = h;
  h->kid = tmp_handle;
  /* printf("tmp_handle- main %p %p\n",(void*)tmp_handle,(void*)h); */

  grib_context_log(h->context,GRIB_LOG_DEBUG,"------------- CREATE TMP BLOCK ", act->name, notified->name);
  tmp_handle->root  = grib_section_create(tmp_handle,NULL);

  tmp_handle->use_trie=1;

  err=grib_create_accessor(tmp_handle->root, act, &loader);

  grib_section_adjust_sizes(tmp_handle->root,1,0);

  grib_section_post_init(tmp_handle->root);

  /* grib_recompute_sections_lengths(tmp_handle->root); */
  grib_get_block_length(tmp_handle->root,&len);
  grib_context_log(h->context,GRIB_LOG_DEBUG,"-------------  TMP BLOCK IS sectlen=%d buffer=%d", len,  tmp_handle->buffer->ulength);

#if 0
  if(h->context->debug > 10)
    grib_dump_content(tmp_handle,stdout,NULL,0,NULL);
#endif

  /* Assert(tmp_handle->buffer->ulength == len); */
  /* grib_empty_section(h->context,old_section); */

  grib_buffer_replace(notified, tmp_handle->buffer->data, tmp_handle->buffer->ulength,0,1);

  grib_swap_sections(old_section,
      tmp_handle->root->block->first->sub_section);

  Assert(tmp_handle->dependencies == NULL);
  /* printf("grib_handle_delete %p\n",(void*)tmp_handle); */


  grib_handle_delete(tmp_handle);

  h->use_trie = 1;
  h->trie_invalid=1;
  h->kid = NULL;

  grib_section_adjust_sizes(h->root,1,0);

  grib_section_post_init(h->root);

  grib_get_block_length(old_section,&size);

  grib_context_log(h->context,GRIB_LOG_DEBUG,"-------------   BLOCK SIZE %ld, buffer len=%ld", size,len);
  if(h->context->debug > 10)
    grib_dump_content(h,stdout,"debug",~0,NULL);

  Assert(size == len);

  grib_update_paddings(old_section);


  return err;
}