2 * Copyright 2002 Marcus Overhagen. All Rights Reserved.
3 * This file may be used under the terms of the MIT License.
7 /*! This works like a cache for time source objects, to make sure
8 each team only has one object representation for each time source.
12 #include "TimeSourceObjectManager.h"
17 #include <MediaRoster.h>
20 #include <MediaMisc.h>
22 #include "TimeSourceObject.h"
29 TimeSourceObjectManager
* gTimeSourceObjectManager
;
30 // initialized by BMediaRoster.
33 TimeSourceObjectManager::TimeSourceObjectManager()
35 BLocker("time source object manager")
40 TimeSourceObjectManager::~TimeSourceObjectManager()
44 // force unloading all currently loaded time sources
45 NodeMap::iterator iterator
= fMap
.begin();
46 for (; iterator
!= fMap
.end(); iterator
++) {
47 BTimeSource
* timeSource
= iterator
->second
;
49 PRINT(1, "Forcing release of TimeSource id %ld...\n", timeSource
->ID());
51 while (timeSource
->Release() != NULL
)
54 PRINT(1, "Forcing release of TimeSource done, released %d times\n",
60 /*! BMediaRoster::MakeTimeSourceFor does use this function to request
61 a time source object. If it is already in memory, it will be
62 Acquired(), if not, a new TimeSourceObject will be created.
65 TimeSourceObjectManager::GetTimeSource(const media_node
& node
)
70 PRINT(1, "TimeSourceObjectManager::GetTimeSource, node id %ld\n",
73 NodeMap::iterator found
= fMap
.find(node
.node
);
74 if (found
!= fMap
.end())
75 return dynamic_cast<BTimeSource
*>(found
->second
->Acquire());
77 // time sources are not accounted in node reference counting
78 BTimeSource
* timeSource
= new(std::nothrow
) TimeSourceObject(node
);
79 if (timeSource
== NULL
)
82 fMap
.insert(std::make_pair(node
.node
, timeSource
));
87 /*! This function is called during deletion of the time source object.
90 TimeSourceObjectManager::ObjectDeleted(BTimeSource
* timeSource
)
95 PRINT(1, "TimeSourceObjectManager::ObjectDeleted, node id %ld\n",
98 fMap
.erase(timeSource
->ID());
100 status_t status
= BMediaRoster::Roster()->ReleaseNode(timeSource
->Node());
101 if (status
!= B_OK
) {
102 ERROR("TimeSourceObjectManager::ObjectDeleted, ReleaseNode failed\n");
108 } // namespace BPrivate