File: medialib-listall.c

package info (click to toggle)
ocp 1%3A3.0.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,972 kB
  • sloc: ansic: 332,849; cpp: 68,319; makefile: 6,685; sh: 4,344; tcl: 1,040; xml: 436; perl: 320; ruby: 126
file content (111 lines) | stat: -rw-r--r-- 3,157 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* OpenCP Module Player
 * copyright (c) 2005-'24 Stian Skjelstad <stian.skjelstad@gmail.com>
 *
 * MEDIALIBRARY listall dialog
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * revision history: (please note changes here)
 *  -ss050430   Stian Skjelstad <stian@nixia.no>
 *    -first release
 */

static void ocpdir_listall_ref (struct ocpdir_t *self)
{
	self->refcount++;
}

static void ocpdir_listall_unref (struct ocpdir_t *self)
{
	self->refcount--;
}

struct ocpdir_listall_handle_t
{
	void (*callback_file)(void *token, struct ocpfile_t *);
	//void (*callback_dir)(void *token, struct ocpdir_t *);
	void *token;
	int first;
	uint32_t dirdbnode;
};

static ocpdirhandle_pt ocpdir_listall_readdir_start (struct ocpdir_t *self, void(*callback_file)(void *token, struct ocpfile_t *), void(*callback_dir )(void *token, struct ocpdir_t *), void *token)
{
	struct ocpdir_listall_handle_t *retval = calloc (1, sizeof (*retval));
	if (!retval)
	{
		fprintf (stderr, "ocpdir_listall_readdir_start(): out of memory\n");
		return 0;
	}
	retval->callback_file = callback_file;
	retval->token = token;
	retval->first = 1;
	retval->dirdbnode = DIRDB_NOPARENT;

	return retval;
}

static void ocpdir_listall_readdir_cancel (ocpdirhandle_pt handle)
{
	free (handle);
}

static int ocpdir_listall_readdir_iterate (ocpdirhandle_pt _handle)
{
	uint32_t mdb_ref = UINT32_MAX;
	struct ocpdir_listall_handle_t *handle = (struct ocpdir_listall_handle_t *)_handle;
	if (!dirdbGetMdb(&handle->dirdbnode, &mdb_ref, &handle->first)) /* does not refcount.... */
	{
		struct dmDrive *drive = 0;
		struct ocpfile_t *file = 0;
		if (!filesystem_resolve_dirdb_file (handle->dirdbnode, &drive, &file))
		{
			handle->callback_file (handle->token, file);
			file->unref (file);
		}
		return 1;
	}
	return 0;
}

static struct ocpdir_t  *ocpdir_listall_readdir_dir  (struct ocpdir_t *self, uint32_t dirdb_ref)
{
	return 0;
}

static struct ocpfile_t *ocpdir_listall_readdir_file (struct ocpdir_t *self, uint32_t dirdb_ref)
{
	int first = 0;
	uint32_t dirdbnode = DIRDB_NOPARENT;
	uint32_t mdb_ref = UINT32_MAX;
	const char *temp1 = 0;
	dirdbGetName_internalstr (dirdb_ref, &temp1);
	while (!dirdbGetMdb(&dirdbnode, &mdb_ref, &first))
	{
		const char *temp2 = 0;
		dirdbGetName_internalstr (dirdbnode, &temp2);
		if (!strcmp (temp1, temp2))
		{
			struct dmDrive *drive = 0;
			struct ocpfile_t *file = 0;
			if (!filesystem_resolve_dirdb_file (dirdbnode, &drive, &file))
			{
				return file;
			}
			return 0;
		}
	}
	return 0;
}