From ec44f528d8c1e0cebac12de75f0669c07451b0d2 Mon Sep 17 00:00:00 2001 From: "Bruno G. Albuquerque" Date: Mon, 25 Aug 2008 17:43:10 +0000 Subject: [PATCH] - Added handling for the table of contents (toc) attribute. Now it is ready to retrieve CDDB information. This is coming as soon as I have real time (as opposed to some minutes during lunch) to work on it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27200 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/cddb_daemon/Jamfile | 2 ++ src/servers/cddb_daemon/cddb_daemon.cpp | 37 ++++++++++++++++++++----- src/servers/cddb_daemon/cddb_daemon.h | 5 +++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/servers/cddb_daemon/Jamfile b/src/servers/cddb_daemon/Jamfile index e4feb508ef..8b769a4ed0 100644 --- a/src/servers/cddb_daemon/Jamfile +++ b/src/servers/cddb_daemon/Jamfile @@ -1,5 +1,7 @@ SubDir HAIKU_TOP src servers cddb_daemon ; +UsePrivateHeaders drivers ; + Server cddb_daemon : cddb_daemon.cpp : be diff --git a/src/servers/cddb_daemon/cddb_daemon.cpp b/src/servers/cddb_daemon/cddb_daemon.cpp index 309f9b5426..2b690f7953 100644 --- a/src/servers/cddb_daemon/cddb_daemon.cpp +++ b/src/servers/cddb_daemon/cddb_daemon.cpp @@ -13,9 +13,11 @@ #include #include +#include static const char* kCddaFsName = "cdda"; +static const int kMaxTocSize = 1024; CDDBDaemon::CDDBDaemon() @@ -26,11 +28,16 @@ CDDBDaemon::CDDBDaemon() BVolume volume; while (fVolumeRoster->GetNextVolume(&volume) == B_OK) { + scsi_toc_toc* toc = (scsi_toc_toc *)malloc(kMaxTocSize); + if (toc == NULL) + continue; + uint32 cddbId; - if (CanLookup(volume.Device(), &cddbId)) { + if (CanLookup(volume.Device(), &cddbId, toc)) { printf("CD can be looked up. CDDB id = %lu.\n", cddbId); // TODO(bga): Implement and enable CDDB database lookup. } + free(toc); } } @@ -52,12 +59,19 @@ CDDBDaemon::MessageReceived(BMessage* message) if (opcode == B_DEVICE_MOUNTED) { dev_t device; if (message->FindInt32("new device", &device) == B_OK) { + scsi_toc_toc* toc = + (scsi_toc_toc *)malloc(kMaxTocSize); + if (toc == NULL) + break; + uint32 cddbId; - if (CanLookup(device, &cddbId)) { + if (CanLookup(device, &cddbId, toc)) { printf("CD can be looked up. CDDB id = %lu.\n", cddbId); - // TODO(bga): Implement and enable CDDB database lookup. + // TODO(bga): Implement and enable CDDB + // database lookup. } + free(toc); } } } @@ -69,16 +83,20 @@ CDDBDaemon::MessageReceived(BMessage* message) bool -CDDBDaemon::CanLookup(const dev_t device, uint32* cddbId) const +CDDBDaemon::CanLookup(const dev_t _device, uint32* _cddbId, + scsi_toc_toc* _toc) const { + if (_cddbId == NULL || _toc == NULL) + return false; + // Is it an Audio disk? fs_info info; - fs_stat_dev(device, &info); + fs_stat_dev(_device, &info); if (strncmp(info.fsh_name, kCddaFsName, strlen(kCddaFsName)) != 0) return false; // Does it have the CD:do_lookup attribute and is it true? - BVolume volume(device); + BVolume volume(_device); BDirectory directory; volume.GetRootDirectory(&directory); @@ -88,10 +106,15 @@ CDDBDaemon::CanLookup(const dev_t device, uint32* cddbId) const return false; // Does it have the CD:cddbid attribute? - if (directory.ReadAttr("CD:cddbid", B_UINT32_TYPE, 0, (void *)cddbId, + if (directory.ReadAttr("CD:cddbid", B_UINT32_TYPE, 0, (void *)_cddbId, sizeof(uint32)) < B_OK) return false; + // Does it have the CD:toc attribute? + if (directory.ReadAttr("CD:toc", B_RAW_TYPE, 0, (void *)_toc, + kMaxTocSize) < B_OK) + return false; + return true; } diff --git a/src/servers/cddb_daemon/cddb_daemon.h b/src/servers/cddb_daemon/cddb_daemon.h index 8dcb36da31..30f771650d 100644 --- a/src/servers/cddb_daemon/cddb_daemon.h +++ b/src/servers/cddb_daemon/cddb_daemon.h @@ -9,6 +9,8 @@ #include #include +#include + class CDDBDaemon : public BApplication { public: @@ -18,7 +20,8 @@ public: virtual void MessageReceived(BMessage* message); private: - bool CanLookup(const dev_t device, uint32* cddbId) const; + bool CanLookup(const dev_t _device, uint32* _cddbId, + scsi_toc_toc* _toc) const; BVolumeRoster* fVolumeRoster; };