eccodes/src/action_class_close.cc

118 lines
3.4 KiB
C++
Raw Normal View History

2014-06-20 16:25:20 +00:00
/*
2020-01-28 14:32:34 +00:00
* (C) Copyright 2005- ECMWF.
2014-06-20 16:25:20 +00:00
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
2014-06-20 16:25:20 +00:00
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = action
IMPLEMENTS = destroy;execute
MEMBERS = char *filename
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "action.class" and rerun ./make_class.pl
*/
static void init_class (grib_action_class*);
static void destroy (grib_context*,grib_action*);
static int execute(grib_action* a,grib_handle* h);
2014-06-20 16:25:20 +00:00
typedef struct grib_action_close {
2022-12-07 19:25:57 +00:00
grib_action act;
2020-01-22 13:10:59 +00:00
/* Members defined in close */
char *filename;
2014-06-20 16:25:20 +00:00
} grib_action_close;
static grib_action_class _grib_action_class_close = {
2024-08-30 14:27:35 +00:00
0, /* super */
"action_class_close", /* name */
sizeof(grib_action_close), /* size */
0, /* inited */
&init_class, /* init_class */
2024-08-30 14:27:35 +00:00
0, /* init */
&destroy, /* destroy */
2024-08-30 14:27:35 +00:00
0, /* dump */
0, /* xref */
0, /* create_accessor */
0, /* notify_change */
0, /* reparse */
&execute, /* execute */
2014-06-20 16:25:20 +00:00
};
grib_action_class* grib_action_class_close = &_grib_action_class_close;
static void init_class(grib_action_class* c)
{
}
/* END_CLASS_IMP */
2024-09-05 10:37:47 +00:00
grib_action* grib_action_create_close(grib_context* context, const char* filename)
2014-06-20 16:25:20 +00:00
{
2019-09-25 13:35:43 +00:00
char buf[1024];
2020-01-22 13:10:59 +00:00
grib_action_close* a;
grib_action_class* c = grib_action_class_close;
grib_action* act = (grib_action*)grib_context_malloc_clear_persistent(context, c->size);
act->op = grib_context_strdup_persistent(context, "section");
2014-06-20 16:25:20 +00:00
2020-01-22 13:10:59 +00:00
act->cclass = c;
a = (grib_action_close*)act;
act->context = context;
2014-06-20 16:25:20 +00:00
2020-01-22 13:10:59 +00:00
a->filename = grib_context_strdup_persistent(context, filename);
2014-06-20 16:25:20 +00:00
snprintf(buf, 1024, "close_%p", (void*)a->filename);
2014-06-20 16:25:20 +00:00
2020-01-22 13:10:59 +00:00
act->name = grib_context_strdup_persistent(context, buf);
2014-06-20 16:25:20 +00:00
2019-09-25 13:35:43 +00:00
return act;
2014-06-20 16:25:20 +00:00
}
2020-01-22 13:10:59 +00:00
static int execute(grib_action* act, grib_handle* h)
2014-06-20 16:25:20 +00:00
{
2020-01-22 13:10:59 +00:00
grib_action_close* self = (grib_action_close*)act;
2019-09-25 13:35:43 +00:00
2024-08-10 19:25:07 +00:00
char filename[2048] = {0,};
size_t len = sizeof(filename);
int err = grib_get_string(h, self->filename, filename, &len);
2019-09-25 13:35:43 +00:00
/* fprintf(stderr,"++++ name %s\n",filename); */
2020-01-22 13:10:59 +00:00
if (err)
return err;
2019-09-25 13:35:43 +00:00
/* grib_file_close(filename,1,&err); */
2024-08-10 19:25:07 +00:00
grib_file* file = grib_get_file(filename, &err);
2020-01-22 13:10:59 +00:00
if (err)
return err;
if (file)
grib_file_pool_delete_file(file);
2019-09-25 13:35:43 +00:00
return GRIB_SUCCESS;
2014-06-20 16:25:20 +00:00
}
2020-01-22 13:10:59 +00:00
static void destroy(grib_context* context, grib_action* act)
2014-06-20 16:25:20 +00:00
{
2020-01-22 13:10:59 +00:00
grib_action_close* a = (grib_action_close*)act;
2014-06-20 16:25:20 +00:00
2019-09-25 13:35:43 +00:00
grib_context_free_persistent(context, a->filename);
grib_context_free_persistent(context, act->name);
grib_context_free_persistent(context, act->op);
2014-06-20 16:25:20 +00:00
}