- Added Session class

- Updated Disc::GetSession() to now return a new Session object.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5370 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2003-11-15 08:39:54 +00:00
parent ce80ee567b
commit ad4849879d
2 changed files with 85 additions and 30 deletions
@@ -21,6 +21,9 @@
#include "Disc.h" #include "Disc.h"
#include <DiskDeviceDefs.h>
#include <DiskDeviceTypes.h>
#include "Debug.h" #include "Debug.h"
static const char *kModuleDebugName = "session"; static const char *kModuleDebugName = "session";
@@ -355,7 +358,7 @@ Disc::Disc(int fd)
count = (header->length-2) / sizeof(cdrom_full_table_of_contents_entry); count = (header->length-2) / sizeof(cdrom_full_table_of_contents_entry);
error = _ParseTableOfContents(entries, count); error = _ParseTableOfContents(entries, count);
Dump(); // Dump();
if (!error) { if (!error) {
_SortAndRemoveDuplicates(); _SortAndRemoveDuplicates();
error = _CheckForErrorsAndWarnings(); error = _CheckForErrorsAndWarnings();
@@ -386,11 +389,10 @@ Disc::InitCheck()
Returns \c B_ENTRY_NOT_FOUND if no such session exists. Returns \c B_ENTRY_NOT_FOUND if no such session exists.
*/ */
status_t Session*
Disc::GetSessionInfo(int32 index) Disc::GetSession(int32 index)
{ {
// TRACE(("%s: Disc::GetSessionInfo(%ld, %ld, %p)\n", kModuleDebugName, DEBUG_INIT_ETC("Disc", ("index: %ld", index));
// index, blockSize, sessionInfo));
int32 counter = -1; int32 counter = -1;
for (session *session = (struct session*)fSessionList->First(); for (session *session = (struct session*)fSessionList->First();
session; session;
@@ -403,22 +405,24 @@ Disc::GetSessionInfo(int32 index)
// track with the end of session. // track with the end of session.
track *track = (struct track*)session->track_list.First(); track *track = (struct track*)session->track_list.First();
if (track) { if (track) {
TRACE(("%s: found session #%ld info (audio session)\n", kModuleDebugName, index)); PRINT(("found session #%ld info (audio session)\n", index));
off_t start_lba = track->start_lba; off_t start_lba = track->start_lba;
off_t end_lba = session->end_lba; off_t end_lba = session->end_lba;
/* sessionInfo->logical_block_size = blockSize; off_t offset = start_lba * kBlockSize;
sessionInfo->offset = start_lba * blockSize; off_t size = (end_lba - start_lba) * kBlockSize;
sessionInfo->size = (end_lba - start_lba) * blockSize;
sessionInfo->index = index; Session *result = new Session(offset, size, kBlockSize,
sessionInfo->flags = 0; index, B_PARTITION_READ_ONLY,
*/ kPartitionTypeAudioSession);
return B_OK; if (!result)
PRINT(("Error allocating new Session object; out of memory!\n"));
return result;
} else { } else {
TRACE(("%s: Disc::GetSessionInfo: session #%ld is an audio " PRINT(("Error: session #%ld is an audio "
"session with no tracks\n", kModuleDebugName, index)); "session with no tracks!\n", index));
return B_ENTRY_NOT_FOUND; return NULL;
} }
} }
} else { } else {
@@ -428,27 +432,29 @@ Disc::GetSessionInfo(int32 index)
{ {
counter++; counter++;
if (counter == index) { if (counter == index) {
TRACE(("%s: found session #%ld info (data session)\n", kModuleDebugName, index)); PRINT(("found session #%ld info (data session)\n", index));
off_t start_lba = track->start_lba; off_t start_lba = track->start_lba;
off_t end_lba = track->next off_t end_lba = track->next
? ((struct track*)track->next)->start_lba ? ((struct track*)track->next)->start_lba
: session->end_lba; : session->end_lba;
/* off_t offset = start_lba * kBlockSize;
sessionInfo->logical_block_size = blockSize; off_t size = (end_lba - start_lba) * kBlockSize;
sessionInfo->offset = start_lba * blockSize;
sessionInfo->size = (end_lba - start_lba) * blockSize; Session *result = new Session(offset, size, kBlockSize,
sessionInfo->index = index; index, B_PARTITION_READ_ONLY,
sessionInfo->flags = B_DATA_SESSION; kPartitionTypeDataSession);
*/ if (!result)
return B_OK; PRINT(("Error allocating new Session object; out of memory!\n"));
return result;
} }
} }
} }
} }
return B_ENTRY_NOT_FOUND; PRINT(("no session #%ld found!\n", index));
return NULL;
} }
/*! \brief Dumps a printout of the disc using TRACE. /*! \brief Dumps a printout of the disc using TRACE.
@@ -483,7 +489,7 @@ Disc::Dump()
status_t status_t
Disc::_ParseTableOfContents(cdrom_full_table_of_contents_entry entries[], uint32 count) Disc::_ParseTableOfContents(cdrom_full_table_of_contents_entry entries[], uint32 count)
{ {
TRACE(("%s: Disc::ParseTableOfContents(%p, %ld)\n", kModuleDebugName, entries, count)); DEBUG_INIT_ETC("Disc", ("entries: %p, count: %ld", entries, count));
for (uint32 i = 0; i < count; i++) { for (uint32 i = 0; i < count; i++) {
// Find or create the appropriate session // Find or create the appropriate session
uint8 session_index = entries[i].session; uint8 session_index = entries[i].session;
@@ -732,6 +738,25 @@ Disc::_CheckForErrorsAndWarnings() {
return B_OK; return B_OK;
} }
//------------------------------------------------------------------------------
// Session
//------------------------------------------------------------------------------
Session::Session(off_t offset, off_t size, uint32 blockSize, int32 index,
uint32 flags, const char *type)
: fOffset(offset)
, fSize(size)
, fBlockSize(blockSize)
, fIndex(index)
, fFlags(flags)
, fType(strdup(type))
{
}
Session::~Session() {
free(fType);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// C functions // C functions
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -793,6 +818,7 @@ static
void void
dump_full_table_of_contents(uchar *data, uint16 data_length) dump_full_table_of_contents(uchar *data, uint16 data_length)
{ {
return;
cdrom_table_of_contents_header *header; cdrom_table_of_contents_header *header;
cdrom_full_table_of_contents_entry *entries; cdrom_full_table_of_contents_entry *entries;
int i, count; int i, count;
@@ -853,8 +879,8 @@ read_table_of_contents(int deviceFD, uint32 first_session, uchar *buffer,
uchar sense_data[sense_data_length]; uchar sense_data[sense_data_length];
status_t error = buffer ? B_OK : B_BAD_VALUE; status_t error = buffer ? B_OK : B_BAD_VALUE;
TRACE(("%s: read_table_of_contents: (%d, %p, %d)\n", kModuleDebugName, DEBUG_INIT_ETC(NULL, ("fd: %d, buffer: %p, buffer_length: %d",
deviceFD, buffer, buffer_length)); deviceFD, buffer, buffer_length));
if (error) if (error)
return error; return error;
@@ -28,6 +28,7 @@
#include "scsi-mmc.h" #include "scsi-mmc.h"
class List; class List;
class Session;
/*! \brief A class that encapsulates a complete, parsed, and error /*! \brief A class that encapsulates a complete, parsed, and error
checked table of contents for a CD-ROM. checked table of contents for a CD-ROM.
@@ -38,7 +39,7 @@ public:
~Disc(); ~Disc();
status_t InitCheck(); status_t InitCheck();
status_t GetSessionInfo(int32 index); Session* GetSession(int32 index);
void Dump(); void Dump();
@@ -56,4 +57,32 @@ private:
List *fSessionList; List *fSessionList;
}; };
/*! \brief Encapsulates the pertinent information for a given session
on a Disc.
*/
class Session {
public:
~Session();
off_t Offset() { return fOffset; }
off_t Size() { return fSize; }
uint32 BlockSize() { return fBlockSize; }
int32 Index() { return fIndex; }
uint32 Flags() { return fFlags; }
const char* Type() { return fType; }
private:
friend class Disc;
Session(off_t offset, off_t size, uint32 blockSize, int32 index,
uint32 flags, const char *type);
Session(const Session &ref); // not implemented
Session& operator=(const Session &ref); // not implemented
off_t fOffset;
off_t fSize;
uint32 fBlockSize;
int32 fIndex;
uint32 fFlags;
char *fType;
};
#endif // _DISC_H #endif // _DISC_H