Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code format on push #66

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Language: Cpp # single option
BasedOnStyle: Chromium
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlwaysBreakAfterReturnType: TopLevelDefinitions
BinPackParameters: true
ColumnLimit: 100
LineEnding: LF
TabWidth: 4
IndentWidth: 4
UseTab: Always
BraceWrapping:
AfterCaseLabel: true
AfterEnum: true
AfterFunction: true
BreakBeforeBraces: Custom
SeparateDefinitionBlocks: Leave
MaxEmptyLinesToKeep: 2

34 changes: 34 additions & 0 deletions .github/workflows/codeformat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format (clang-format)

on:
push:
branches:
- 'master'
pull_request:
paths:
- '**.h'
- '**.cpp'
- '**.c'

jobs:
prettier:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up clang-format
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main"
sudo apt install clang-format-17

- name: Run clang-format
run: |
which clang-format-17
clang-format-17 -i source/*.cpp source/*.h

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply clang-format changes
137 changes: 62 additions & 75 deletions source/AdapterIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@

class RelativePositionIO : public BPositionIO {
public:
RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer,
bigtime_t timeout)
:
BPositionIO(),
fOwner(owner),
fBackPosition(0),
fStartOffset(0),
fBuffer(buffer),
fTimeout(timeout)
RelativePositionIO(BAdapterIO* owner, BPositionIO* buffer, bigtime_t timeout)
: BPositionIO(),
fOwner(owner),
fBackPosition(0),
fStartOffset(0),
fBuffer(buffer),
fTimeout(timeout)
{
}

virtual ~RelativePositionIO()
{
delete fBuffer;
}
virtual ~RelativePositionIO() { delete fBuffer; }

status_t ResetStartOffset(off_t offset)
{
Expand Down Expand Up @@ -105,26 +100,21 @@ class RelativePositionIO : public BPositionIO {
return B_OK;
}

virtual ssize_t ReadAt(off_t position, void* buffer,
size_t size)
virtual ssize_t ReadAt(off_t position, void* buffer, size_t size)
{
AutoReadLocker _(fLock);

return fBuffer->ReadAt(
_PositionToRelative(position), buffer, size);

return fBuffer->ReadAt(_PositionToRelative(position), buffer, size);
}

virtual ssize_t WriteAt(off_t position,
const void* buffer, size_t size)
virtual ssize_t WriteAt(off_t position, const void* buffer, size_t size)
{
AutoWriteLocker _(fLock);

return fBuffer->WriteAt(
_PositionToRelative(position), buffer, size);
return fBuffer->WriteAt(_PositionToRelative(position), buffer, size);
}

virtual off_t Seek(off_t position, uint32 seekMode)
virtual off_t Seek(off_t position, uint32 seekMode)
{
AutoWriteLocker _(fLock);

Expand All @@ -140,14 +130,14 @@ class RelativePositionIO : public BPositionIO {
return _RelativeToPosition(fBuffer->Position());
}

virtual status_t SetSize(off_t size)
virtual status_t SetSize(off_t size)
{
AutoWriteLocker _(fLock);

return fBuffer->SetSize(_PositionToRelative(size));
}

virtual status_t GetSize(off_t* size) const
virtual status_t GetSize(off_t* size) const
{
AutoReadLocker _(fLock);

Expand Down Expand Up @@ -194,51 +184,35 @@ class RelativePositionIO : public BPositionIO {
return ((flags & B_MEDIA_SEEKABLE) == B_MEDIA_SEEKABLE);
}

const BPositionIO* Buffer() const
{
return fBuffer;
}
const BPositionIO* Buffer() const { return fBuffer; }

private:
off_t _PositionToRelative(off_t position) const { return position - fStartOffset; }

off_t _PositionToRelative(off_t position) const
{
return position - fStartOffset;
}
off_t _RelativeToPosition(off_t position) const { return position + fStartOffset; }

off_t _RelativeToPosition(off_t position) const
{
return position + fStartOffset;
}
BAdapterIO* fOwner;
off_t fBackPosition;
off_t fStartOffset;

BAdapterIO* fOwner;
off_t fBackPosition;
off_t fStartOffset;
BPositionIO* fBuffer;

BPositionIO* fBuffer;
mutable RWLocker fLock;

mutable RWLocker fLock;

bigtime_t fTimeout;
bigtime_t fTimeout;
};


BAdapterIO::BAdapterIO(int32 flags, bigtime_t timeout)
:
fFlags(flags),
fBuffer(NULL),
fTotalSize(0),
fOpened(false),
fSeekSem(-1),
fInputAdapter(NULL)
: fFlags(flags), fBuffer(NULL), fTotalSize(0), fOpened(false), fSeekSem(-1), fInputAdapter(NULL)
{
CALLED();

fBuffer = new RelativePositionIO(this, new BMallocIO(), timeout);
}


BAdapterIO::BAdapterIO(const BAdapterIO &)
BAdapterIO::BAdapterIO(const BAdapterIO&)
{
// copying not allowed...
}
Expand Down Expand Up @@ -293,19 +267,17 @@ BAdapterIO::Seek(off_t position, uint32 seekMode)
off_t size = 0;

if (seekMode == SEEK_CUR)
absolutePosition = Position()+position;
absolutePosition = Position() + position;
else if (seekMode == SEEK_END) {
if (GetSize(&size) != B_OK)
return B_NOT_SUPPORTED;

absolutePosition = size-position;
absolutePosition = size - position;
}

status_t ret = _EvaluateWait(absolutePosition, 0);

if (ret == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming()
&& fBuffer->IsSeekable()) {

if (ret == B_RESOURCE_UNAVAILABLE && fBuffer->IsStreaming() && fBuffer->IsSeekable()) {
fSeekSem = create_sem(0, "BAdapterIO seek sem");

if (SeekRequested(absolutePosition) != B_OK)
Expand Down Expand Up @@ -445,8 +417,8 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size)
if (GetSize(&totalSize) != B_OK)
TRACE("BAdapterIO::ReadAt: Can't get our size!\n");

TRACE("BAdapterIO::_EvaluateWait TS %" B_PRId64 " P %" B_PRId64
" S %" B_PRId64 "\n", totalSize, pos, size);
TRACE("BAdapterIO::_EvaluateWait TS %" B_PRId64 " P %" B_PRId64 " S %" B_PRId64 "\n", totalSize,
pos, size);

status_t err = fBuffer->EvaluatePosition(pos, totalSize);

Expand All @@ -461,16 +433,10 @@ BAdapterIO::_EvaluateWait(off_t pos, off_t size)
}


BInputAdapter::BInputAdapter(BAdapterIO* io)
:
fIO(io)
{
}
BInputAdapter::BInputAdapter(BAdapterIO* io) : fIO(io) {}


BInputAdapter::~BInputAdapter()
{
}
BInputAdapter::~BInputAdapter() {}


ssize_t
Expand All @@ -481,11 +447,32 @@ BInputAdapter::Write(const void* buffer, size_t size)


// FBC
void BAdapterIO::_ReservedAdapterIO1() {}
void BAdapterIO::_ReservedAdapterIO2() {}
void BAdapterIO::_ReservedAdapterIO3() {}
void BAdapterIO::_ReservedAdapterIO4() {}
void BAdapterIO::_ReservedAdapterIO5() {}

void BInputAdapter::_ReservedInputAdapter1() {}
void BInputAdapter::_ReservedInputAdapter2() {}
void
BAdapterIO::_ReservedAdapterIO1()
{
}
void
BAdapterIO::_ReservedAdapterIO2()
{
}
void
BAdapterIO::_ReservedAdapterIO3()
{
}
void
BAdapterIO::_ReservedAdapterIO4()
{
}
void
BAdapterIO::_ReservedAdapterIO5()
{
}

void
BInputAdapter::_ReservedInputAdapter1()
{
}
void
BInputAdapter::_ReservedInputAdapter2()
{
}
Loading