xref: /haiku/src/add-ons/media/plugins/ape_reader/LibMonkeysAudio/PositionBridgeIO.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*==============================================================================
2 	Bridge class for passing BPositionIO to functions who need CIO in MACLib
3 	Ver 1.01
4 	Copyright (C) 2005-2008 by SHINTA
5 ==============================================================================*/
6 
7 /*==============================================================================
8 BPositionIO* passed to SetPositionIO() must not be released before rleasing this class.
9 ==============================================================================*/
10 
11 //------------------------------------------------------------------------------
12 #include "PositionBridgeIO.h"
13 //------------------------------------------------------------------------------
14 // BeOS
15 // C++
16 // Proj
17 #include "All.h"
18 //------------------------------------------------------------------------------
19 //==============================================================================
20 TPositionBridgeIO::TPositionBridgeIO()
21 		: CIO()
22 {
23 	mPositionIO = NULL;
24 }
25 //------------------------------------------------------------------------------
26 TPositionBridgeIO::~TPositionBridgeIO()
27 {
28 }
29 //------------------------------------------------------------------------------
30 int	TPositionBridgeIO::Close()
31 {
32 	return B_OK;
33 }
34 //------------------------------------------------------------------------------
35 int	TPositionBridgeIO::Create(const wchar_t* oName)
36 {
37 	return B_OK;
38 }
39 //------------------------------------------------------------------------------
40 int	TPositionBridgeIO::Delete()
41 {
42 	return B_ERROR;
43 }
44 //------------------------------------------------------------------------------
45 int	TPositionBridgeIO::GetName(wchar_t* oBuffer)
46 {
47 	strcpy(oBuffer, "<TPositionBridgeIO>");
48 	return B_OK;
49 }
50 //------------------------------------------------------------------------------
51 int	TPositionBridgeIO::GetPosition()
52 {
53 	if ( mPositionIO == NULL )
54 		return 0;
55 	return mPositionIO->Position();
56 }
57 //------------------------------------------------------------------------------
58 int	TPositionBridgeIO::GetSize()
59 {
60 	if ( mPositionIO == NULL )
61 		return 0;
62 
63 	off_t aSize;
64 	status_t err = mPositionIO->GetSize(&aSize);
65 	if (err != B_OK)
66 		return -1;
67 
68 	return aSize;
69 }
70 //------------------------------------------------------------------------------
71 int	TPositionBridgeIO::Open(const wchar_t* oName)
72 {
73 	return B_OK;
74 }
75 //------------------------------------------------------------------------------
76 int	TPositionBridgeIO::Read(void* oBuf, unsigned int oBytesToRead, unsigned int* oBytesRead)
77 {
78 	if ( mPositionIO == NULL )
79 		return ERROR_IO_READ;
80 	*oBytesRead = mPositionIO->Read(oBuf, oBytesToRead);
81 	return *oBytesRead == 0 ? ERROR_IO_READ : B_OK;
82 }
83 //------------------------------------------------------------------------------
84 int	TPositionBridgeIO::Seek(int oDistance, unsigned int oMoveMode)
85 {
86 	if ( mPositionIO == NULL )
87 		return B_ERROR;
88 	return mPositionIO->Seek(oDistance, oMoveMode) < B_OK ? B_ERROR : B_OK;
89 }
90 //------------------------------------------------------------------------------
91 int	TPositionBridgeIO::SetEOF()
92 {
93 	if ( mPositionIO == NULL )
94 		return B_ERROR;
95 	mPositionIO->SetSize(mPositionIO->Position());
96 	return B_OK;
97 }
98 //------------------------------------------------------------------------------
99 status_t	TPositionBridgeIO::SetPositionIO(BPositionIO* oPositionIO)
100 {
101 	mPositionIO = oPositionIO;
102 	return B_OK;
103 }
104 //------------------------------------------------------------------------------
105 /* ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
106 untested function
107 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' */
108 int	TPositionBridgeIO::Write(const void* oBuf, unsigned int oBytesToWrite, unsigned int* oBytesWritten)
109 {
110 	if ( mPositionIO == NULL )
111 		return ERROR_IO_WRITE;
112 	*oBytesWritten = mPositionIO->Write(oBuf, oBytesToWrite);
113 	return *oBytesWritten != oBytesToWrite ? ERROR_IO_WRITE : B_OK;
114 }
115 //------------------------------------------------------------------------------
116 //==============================================================================
117