1/*
2 * Copyright 2008-2016, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *              Bruno Albuquerque, bga@bug-br.org.br
7 */
8#ifndef _CDDB_SERVER_H
9#define _CDDB_SERVER_H
10
11
12#include <NetAddress.h>
13#include <NetEndpoint.h>
14#include <ObjectList.h>
15#include <String.h>
16
17#include <scsi_cmds.h>
18
19
20// CD track specific data.
21struct TrackData {
22	uint32 trackNumber;
23	BString title;
24	BString artist;
25};
26
27
28// Query command response.
29struct QueryResponseData {
30	BString category;
31	BString cddbID;
32	BString artist;
33	BString title;
34};
35
36
37// Read command response.
38struct ReadResponseData {
39	BString title;
40	BString artist;
41	BString genre;
42	uint32 year;
43	BObjectList<TrackData> tracks;
44
45	ReadResponseData()
46		:
47		tracks(20, true)
48	{
49	}
50};
51
52
53typedef BObjectList<QueryResponseData> QueryResponseList;
54
55
56class CDDBServer {
57public:
58								CDDBServer(const BString& cddbServer);
59
60	// CDDB commands interface.
61			status_t			Query(uint32 cddbID, const scsi_toc_toc* toc,
62									QueryResponseList& queryResponses);
63			status_t			Read(const QueryResponseData& diskData,
64									ReadResponseData& readResponse,
65									bool verbose = false);
66			status_t			Read(const BString& category,
67									const BString& cddbID,
68									const BString& artist,
69									ReadResponseData& readResponse,
70									bool verbose = false);
71
72private:
73			status_t 			_ParseAddress(const BString& cddbServer);
74
75			status_t			_OpenConnection();
76			void				_CloseConnection();
77
78			status_t			_SendCommand(const BString& command,
79									BString& output);
80			TrackData*			_Track(ReadResponseData& response,
81									uint32 track) const;
82
83private:
84			BString				fLocalHostName;
85			BString				fLocalUserName;
86			BNetAddress			fServerAddress;
87			BNetEndpoint		fConnection;
88			bool				fInitialized;
89			bool				fConnected;
90};
91
92
93#endif  // _CDDB_SERVER_H
94