File: rb-mtp-thread.h

package info (click to toggle)
rhythmbox 3.4.9-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 27,376 kB
  • sloc: ansic: 114,861; python: 4,941; xml: 730; javascript: 350; perl: 307; sh: 84; makefile: 43
file content (139 lines) | stat: -rw-r--r-- 5,280 bytes parent folder | download | duplicates (8)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 *  Copyright (C) 2009 Jonathan Matthew  <jonathan@d14n.org>
 *
 *  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.
 *
 *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 *  GStreamer plugins to be used and distributed together with GStreamer
 *  and Rhythmbox. This permission is above and beyond the permissions granted
 *  by the GPL license by which Rhythmbox is covered. If you modify this code
 *  you may extend this exception to your version of the code, but you are not
 *  obligated to do so. If you do not wish to do so, delete this exception
 *  statement from your 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 *
 */

#include <libmtp.h>

#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

/*
 * Worker thread for dealing with MTP devices.
 * libmtp isn't thread-aware, and some operations are pretty slow
 * (getting track listings, sending and retrieving tracks), so
 * we do everything except the initial setup in a dedicated thread.
 */

#ifndef __RB_MTP_THREAD_H
#define __RB_MTP_THREAD_H

typedef enum
{
	RB_MTP_THREAD_ERROR_NO_SPACE,
	RB_MTP_THREAD_ERROR_TEMPFILE,
	RB_MTP_THREAD_ERROR_GET_TRACK,
	RB_MTP_THREAD_ERROR_SEND_TRACK
} RBMtpThreadError;

GType rb_mtp_thread_error_get_type (void);
#define RB_TYPE_MTP_THREAD_ERROR (rb_mtp_thread_error_get_type ())
GQuark rb_mtp_thread_error_quark (void);
#define RB_MTP_THREAD_ERROR rb_mtp_thread_error_quark ()

#define RB_TYPE_MTP_THREAD         (rb_mtp_thread_get_type ())
#define RB_MTP_THREAD(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_MTP_THREAD, RBMtpThread))
#define RB_MTP_THREAD_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), RB_TYPE_MTP_THREAD, RBMtpThreadClass))
#define RB_IS_MTP_THREAD(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_MTP_THREAD))
#define RB_IS_MTP_THREAD_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), RB_TYPE_MTP_THREAD))
#define RB_MTP_THREAD_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), RB_TYPE_MTP_THREAD, RBMtpThreadClass))

typedef struct
{
	GObject parent;
	LIBMTP_mtpdevice_t *device;
	GHashTable *albums;

	GThread *thread;
	GAsyncQueue *queue;
} RBMtpThread;

typedef struct
{
	GObjectClass parent;
} RBMtpThreadClass;

/* callback types */
typedef void (*RBMtpOpenCallback) (LIBMTP_mtpdevice_t *device, gpointer user_data);
typedef void (*RBMtpTrackListCallback) (LIBMTP_track_t *tracklist, gpointer user_data);
typedef void (*RBMtpUploadCallback) (LIBMTP_track_t *track, GError *error, gpointer user_data);
typedef void (*RBMtpDownloadCallback) (uint32_t track_id, const char *filename, GError *error, gpointer user_data);
typedef void (*RBMtpThreadCallback) (LIBMTP_mtpdevice_t *device, gpointer user_data);
typedef void (*RBMtpCreateFolderCallback) (uint32_t folder_id, gpointer user_data);

GType		rb_mtp_thread_get_type (void);
RBMtpThread *	rb_mtp_thread_new (void);
void            _rb_mtp_thread_register_type (GTypeModule *module);

void		rb_mtp_thread_report_errors (RBMtpThread *thread);

void		rb_mtp_thread_open_device (RBMtpThread *thread,
					   LIBMTP_raw_device_t *raw_device,
					   RBMtpOpenCallback func,
					   gpointer data,
					   GDestroyNotify destroy_data);
void		rb_mtp_thread_get_track_list (RBMtpThread *thread,
					      RBMtpTrackListCallback func,
					      gpointer data,
					      GDestroyNotify destroy_data);

void		rb_mtp_thread_set_device_name (RBMtpThread *thread, const char *name);

void		rb_mtp_thread_queue_callback (RBMtpThread *thread,
					      RBMtpThreadCallback func,
					      gpointer data,
					      GDestroyNotify destroy_data);

/* folders */
void		rb_mtp_thread_create_folder (RBMtpThread *thread,
					     const char **path,
					     RBMtpCreateFolderCallback func,
					     gpointer data,
					     GDestroyNotify destroy_data);

/* albums */
void		rb_mtp_thread_add_to_album (RBMtpThread *thread, LIBMTP_track_t *track, const char *album);
void		rb_mtp_thread_remove_from_album (RBMtpThread *thread, LIBMTP_track_t *track, const char *album);
void		rb_mtp_thread_set_album_image (RBMtpThread *thread, const char *album, GdkPixbuf *image);

/* tracks */
void		rb_mtp_thread_delete_track (RBMtpThread *thread, LIBMTP_track_t *track);
void		rb_mtp_thread_upload_track (RBMtpThread *thread,
					    LIBMTP_track_t *track,
					    const char *filename,
					    RBMtpUploadCallback func,
					    gpointer data,
					    GDestroyNotify destroy_data);
void		rb_mtp_thread_download_track (RBMtpThread *thread,
					      uint32_t track_id,
					      const char *filename,
					      RBMtpDownloadCallback func,
					      gpointer data,
					      GDestroyNotify destroy_data);

#endif