summaryrefslogtreecommitdiff
path: root/src/libpts/pts/pts_file_meta.c
blob: 6ed1c01b4f4da0c733239f3f2e1af5c94fce0777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2011 Sansar Choinyambuu
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

#include "pts_file_meta.h"

#include <utils/linked_list.h>
#include <debug.h>

typedef struct private_pts_file_meta_t private_pts_file_meta_t;

/**
 * Private data of a pts_file_meta_t object.
 *
 */
struct private_pts_file_meta_t {

	/**
	 * Public pts_file_meta_t interface.
	 */
	pts_file_meta_t public;

	/**
	 * List of File Metadata
	 */
	linked_list_t *list;
};

/**
 * Free an pts_file_metadata_t object
 */
static void free_entry(pts_file_metadata_t *entry)
{
	if (entry)
	{
		free(entry->filename);
		free(entry);
	}
}

METHOD(pts_file_meta_t, get_file_count, int,
	private_pts_file_meta_t *this)
{
	return this->list->get_count(this->list);
}

METHOD(pts_file_meta_t, add, void,
	private_pts_file_meta_t *this, pts_file_metadata_t *metadata)
{
	this->list->insert_last(this->list, metadata);
}

METHOD(pts_file_meta_t, create_enumerator, enumerator_t*,
	private_pts_file_meta_t *this)
{
	return this->list->create_enumerator(this->list);
}

METHOD(pts_file_meta_t, destroy, void,
	private_pts_file_meta_t *this)
{
	this->list->destroy_function(this->list, (void *)free_entry);
	free(this);
}

/**
 * See header
 */
pts_file_meta_t *pts_file_meta_create()
{
	private_pts_file_meta_t *this;

	INIT(this,
		.public = {
			.get_file_count = _get_file_count,
			.add = _add,
			.create_enumerator = _create_enumerator,
			.destroy = _destroy,
		},
		.list = linked_list_create(),
	);

	return &this->public;
}