added a Dumm template enumerator

This commit is contained in:
Martin Willi 2009-05-11 17:18:59 +02:00
parent 05ac17f0e1
commit 608046c09c
2 changed files with 61 additions and 0 deletions

View File

@ -193,6 +193,59 @@ static bool load_template(private_dumm_t *this, char *dir)
return TRUE;
}
/**
* Template directory enumerator
*/
typedef struct {
/** implements enumerator_t */
enumerator_t public;
/** directory enumerator */
enumerator_t *inner;
} template_enumerator_t;
/**
* Implementation of template_enumerator_t.enumerate
*/
static bool template_enumerate(template_enumerator_t *this, char **template)
{
struct stat st;
char *rel;
while (this->inner->enumerate(this->inner, &rel, NULL, &st))
{
if (S_ISDIR(st.st_mode) && *rel != '.')
{
*template = rel;
return TRUE;
}
}
return FALSE;
}
/**
* Implementation of template_enumerator_t.destroy
*/
static void template_enumerator_destroy(template_enumerator_t *this)
{
this->inner->destroy(this->inner);
free(this);
}
/**
* Implementation of dumm_t.create_template_enumerator
*/
static enumerator_t* create_template_enumerator(private_dumm_t *this)
{
template_enumerator_t *enumerator;
enumerator = malloc_thing(template_enumerator_t);
enumerator->public.enumerate = (void*)template_enumerate;
enumerator->public.destroy = (void*)template_enumerator_destroy;
enumerator->inner = enumerator_create_directory(TEMPLATE_DIR);
return &enumerator->public;
}
/**
* Implementation of dumm_t.destroy
*/
@ -270,6 +323,7 @@ dumm_t *dumm_create(char *dir)
this->public.create_bridge_enumerator = (enumerator_t*(*)(dumm_t*))create_bridge_enumerator;
this->public.delete_bridge = (void(*)(dumm_t*,bridge_t*))delete_bridge;
this->public.load_template = (bool(*)(dumm_t*, char *name))load_template;
this->public.create_template_enumerator = (enumerator_t*(*)(dumm_t*))create_template_enumerator;
this->public.destroy = (void(*)(dumm_t*))destroy;
if (dir && *dir == '/')

View File

@ -90,6 +90,13 @@ struct dumm_t {
*/
bool (*load_template)(dumm_t *this, char *dir);
/**
* @brief Create an enumerator over all available templates.
*
* @return enumerator over char*
*/
enumerator_t* (*create_template_enumerator)(dumm_t *this);
/**
* @brief stop all guests and destroy the modeler
*/