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/*==============================================================================
8BPositionIO* 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//==============================================================================
20TPositionBridgeIO::TPositionBridgeIO()
21		: CIO()
22{
23	mPositionIO = NULL;
24}
25//------------------------------------------------------------------------------
26TPositionBridgeIO::~TPositionBridgeIO()
27{
28}
29//------------------------------------------------------------------------------
30int	TPositionBridgeIO::Close()
31{
32	return B_OK;
33}
34//------------------------------------------------------------------------------
35int	TPositionBridgeIO::Create(const wchar_t* oName)
36{
37	return B_OK;
38}
39//------------------------------------------------------------------------------
40int	TPositionBridgeIO::Delete()
41{
42	return B_ERROR;
43}
44//------------------------------------------------------------------------------
45int	TPositionBridgeIO::GetName(wchar_t* oBuffer)
46{
47	strcpy(oBuffer, "<TPositionBridgeIO>");
48	return B_OK;
49}
50//------------------------------------------------------------------------------
51int	TPositionBridgeIO::GetPosition()
52{
53	if ( mPositionIO == NULL )
54		return 0;
55	return mPositionIO->Position();
56}
57//------------------------------------------------------------------------------
58int	TPositionBridgeIO::GetSize()
59{
60	off_t	aCurPos;
61	off_t	aSize;
62
63	if ( mPositionIO == NULL )
64		return 0;
65	aCurPos = mPositionIO->Position();
66	mPositionIO->Seek(0, SEEK_END);
67	aSize = mPositionIO->Position();
68	mPositionIO->Seek(aCurPos, SEEK_SET);
69	return aSize;
70}
71//------------------------------------------------------------------------------
72int	TPositionBridgeIO::Open(const wchar_t* oName)
73{
74	return B_OK;
75}
76//------------------------------------------------------------------------------
77int	TPositionBridgeIO::Read(void* oBuf, unsigned int oBytesToRead, unsigned int* oBytesRead)
78{
79	if ( mPositionIO == NULL )
80		return ERROR_IO_READ;
81	*oBytesRead = mPositionIO->Read(oBuf, oBytesToRead);
82	return *oBytesRead == 0 ? ERROR_IO_READ : B_OK;
83}
84//------------------------------------------------------------------------------
85int	TPositionBridgeIO::Seek(int oDistance, unsigned int oMoveMode)
86{
87	if ( mPositionIO == NULL )
88		return B_ERROR;
89	return mPositionIO->Seek(oDistance, oMoveMode) < B_OK ? B_ERROR : B_OK;
90}
91//------------------------------------------------------------------------------
92int	TPositionBridgeIO::SetEOF()
93{
94	if ( mPositionIO == NULL )
95		return B_ERROR;
96	mPositionIO->SetSize(mPositionIO->Position());
97	return B_OK;
98}
99//------------------------------------------------------------------------------
100status_t	TPositionBridgeIO::SetPositionIO(BPositionIO* oPositionIO)
101{
102	mPositionIO = oPositionIO;
103	return B_OK;
104}
105//------------------------------------------------------------------------------
106/* ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
107untested function
108'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' */
109int	TPositionBridgeIO::Write(const void* oBuf, unsigned int oBytesToWrite, unsigned int* oBytesWritten)
110{
111	if ( mPositionIO == NULL )
112		return ERROR_IO_WRITE;
113	*oBytesWritten = mPositionIO->Write(oBuf, oBytesToWrite);
114	return *oBytesWritten != oBytesToWrite ? ERROR_IO_WRITE : B_OK;
115}
116//------------------------------------------------------------------------------
117//==============================================================================
118