tcp: Fix 64 bit build with debugging features enabled.
[haiku.git] / src / kits / media / TimeSourceObjectManager.cpp
blobce0f61004dfda86bcba1f35df0d72c1487ff2f91
1 /*
2 * Copyright 2002 Marcus Overhagen. All Rights Reserved.
3 * This file may be used under the terms of the MIT License.
4 */
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.
9 */
12 #include "TimeSourceObjectManager.h"
14 #include <stdio.h>
16 #include <Autolock.h>
17 #include <MediaRoster.h>
19 #include <debug.h>
20 #include <MediaMisc.h>
22 #include "TimeSourceObject.h"
25 namespace BPrivate {
26 namespace media {
29 TimeSourceObjectManager* gTimeSourceObjectManager;
30 // initialized by BMediaRoster.
33 TimeSourceObjectManager::TimeSourceObjectManager()
35 BLocker("time source object manager")
40 TimeSourceObjectManager::~TimeSourceObjectManager()
42 CALLED();
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());
50 int32 debugCount = 0;
51 while (timeSource->Release() != NULL)
52 debugCount++;
54 PRINT(1, "Forcing release of TimeSource done, released %d times\n",
55 debugCount);
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.
64 BTimeSource*
65 TimeSourceObjectManager::GetTimeSource(const media_node& node)
67 CALLED();
68 BAutolock _(this);
70 PRINT(1, "TimeSourceObjectManager::GetTimeSource, node id %ld\n",
71 node.node);
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)
80 return NULL;
82 fMap.insert(std::make_pair(node.node, timeSource));
83 return timeSource;
87 /*! This function is called during deletion of the time source object.
89 void
90 TimeSourceObjectManager::ObjectDeleted(BTimeSource* timeSource)
92 CALLED();
93 BAutolock _(this);
95 PRINT(1, "TimeSourceObjectManager::ObjectDeleted, node id %ld\n",
96 timeSource->ID());
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");
107 } // namespace media
108 } // namespace BPrivate