2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
10 #include "VolumeState.h"
12 #include <AutoDeleter.h>
13 #include <AutoLocker.h>
16 VolumeState::VolumeState()
18 fPackagesByFileName(),
24 VolumeState::~VolumeState()
26 fPackagesByFileName
.Clear();
28 Package
* package
= fPackagesByNodeRef
.Clear(true);
29 while (package
!= NULL
) {
30 Package
* next
= package
->NodeRefHashTableNext();
40 return fPackagesByFileName
.Init() == B_OK
41 && fPackagesByNodeRef
.Init() == B_OK
;
46 VolumeState::AddPackage(Package
* package
)
48 fPackagesByFileName
.Insert(package
);
49 fPackagesByNodeRef
.Insert(package
);
54 VolumeState::RemovePackage(Package
* package
)
56 fPackagesByFileName
.Remove(package
);
57 fPackagesByNodeRef
.Remove(package
);
62 VolumeState::SetPackageActive(Package
* package
, bool active
)
64 package
->SetActive(active
);
69 VolumeState::ActivationChanged(const PackageSet
& activatedPackage
,
70 const PackageSet
& deactivatePackages
)
72 for (PackageSet::iterator it
= activatedPackage
.begin();
73 it
!= activatedPackage
.end(); ++it
) {
74 (*it
)->SetActive(true);
77 for (PackageSet::iterator it
= deactivatePackages
.begin();
78 it
!= deactivatePackages
.end(); ++it
) {
79 Package
* package
= *it
;
80 RemovePackage(package
);
87 VolumeState::Clone() const
89 VolumeState
* clone
= new(std::nothrow
) VolumeState
;
92 ObjectDeleter
<VolumeState
> cloneDeleter(clone
);
94 for (PackageFileNameHashTable::Iterator it
95 = fPackagesByFileName
.GetIterator();
96 Package
* package
= it
.Next();) {
97 Package
* clonedPackage
= package
->Clone();
98 if (clonedPackage
== NULL
)
100 clone
->AddPackage(clonedPackage
);
103 return cloneDeleter
.Detach();