xref: /haiku/src/kits/media/TimeSourceObject.cpp (revision 92e575c103c50b3795b6a68aa9c4aeb7420e5a22)
1287f7492Sbeveloper /***********************************************************************
2287f7492Sbeveloper  * Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
3287f7492Sbeveloper  * This file may be used under the terms of the OpenBeOS License.
4287f7492Sbeveloper  *
5287f7492Sbeveloper  * The object returned by BMediaRoster's
6287f7492Sbeveloper  * BTimeSource * MakeTimeSourceFor(const media_node & for_node);
7287f7492Sbeveloper  *
8287f7492Sbeveloper  ***********************************************************************/
9287f7492Sbeveloper 
10287f7492Sbeveloper #include <OS.h>
11287f7492Sbeveloper #include <stdio.h>
12287f7492Sbeveloper #include <MediaRoster.h>
1386bce45bSbeveloper #include "MediaMisc.h"
14287f7492Sbeveloper #include "TimeSourceObject.h"
15835140c8Sbeveloper #include "TimeSourceObjectManager.h"
16287f7492Sbeveloper 
17d6379053Sbeveloper TimeSourceObject::TimeSourceObject(const media_node &node)
18d6379053Sbeveloper  :	BMediaNode("some timesource object", node.node, node.kind),
19d6379053Sbeveloper 	BTimeSource(node.node)
20287f7492Sbeveloper {
214295907bSbeveloper 	TRACE("TimeSourceObject::TimeSourceObject enter, id = %ld\n", node.node);
22d6379053Sbeveloper 	if (fControlPort > 0)
23287f7492Sbeveloper 		delete_port(fControlPort);
24*92e575c1Sbeveloper 
25*92e575c1Sbeveloper 	// we use the control port of the real time source object.
26*92e575c1Sbeveloper 	// this way, all messages are send to the real time source,
27*92e575c1Sbeveloper 	// and this shadow object won't receive any.
28d6379053Sbeveloper 	fControlPort = node.port;
29d6379053Sbeveloper 	ASSERT(fNodeID == node.node);
30d6379053Sbeveloper 	ASSERT(fKinds == node.kind);
31d6379053Sbeveloper 
325917dd5bSbeveloper 	if (node.node == NODE_SYSTEM_TIMESOURCE_ID) {
335917dd5bSbeveloper 		strcpy(fName, "System Clock");
34*92e575c1Sbeveloper 		fIsRealtime = true;
355917dd5bSbeveloper 	} else {
36d6379053Sbeveloper 		live_node_info lni;
37d6379053Sbeveloper 		if (B_OK == BMediaRoster::Roster()->GetLiveNodeInfo(node, &lni)) {
38d6379053Sbeveloper 			strcpy(fName, lni.name);
39d6379053Sbeveloper 		} else {
40d6379053Sbeveloper 			sprintf(fName, "timesource %ld", node.node);
41d6379053Sbeveloper 		}
425917dd5bSbeveloper 	}
43d6379053Sbeveloper 
44d6379053Sbeveloper 	AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
4586bce45bSbeveloper 	AddNodeKind(NODE_KIND_NO_REFCOUNTING);
4686bce45bSbeveloper 
474295907bSbeveloper 	TRACE("TimeSourceObject::TimeSourceObject leave, node id %ld\n", fNodeID);
48287f7492Sbeveloper }
49287f7492Sbeveloper 
50287f7492Sbeveloper /* virtual */ status_t
51287f7492Sbeveloper TimeSourceObject::TimeSourceOp(
52287f7492Sbeveloper 				const time_source_op_info & op,
53287f7492Sbeveloper 				void * _reserved)
54287f7492Sbeveloper {
55*92e575c1Sbeveloper 	// we don't get anything here
56287f7492Sbeveloper 	return B_OK;
57287f7492Sbeveloper }
58287f7492Sbeveloper 
59287f7492Sbeveloper /* virtual */ BMediaAddOn*
60287f7492Sbeveloper TimeSourceObject::AddOn(int32 *internal_id) const
61287f7492Sbeveloper {
62835140c8Sbeveloper 	if (internal_id)
63835140c8Sbeveloper 		*internal_id = 0;
64287f7492Sbeveloper 	return NULL;
65287f7492Sbeveloper }
66835140c8Sbeveloper 
67835140c8Sbeveloper /* virtual */ status_t
68835140c8Sbeveloper TimeSourceObject::DeleteHook(BMediaNode *node)
69835140c8Sbeveloper {
700e21b167Sbeveloper 	status_t status;
71*92e575c1Sbeveloper //	if (fIsRealtime) {
72*92e575c1Sbeveloper //		ERROR("TimeSourceObject::DeleteHook: system time source clone delete hook called\n");
73*92e575c1Sbeveloper //		return B_ERROR;
74*92e575c1Sbeveloper //	}
75*92e575c1Sbeveloper 	printf("TimeSourceObject::DeleteHook enter\n");
76835140c8Sbeveloper 	_TimeSourceObjectManager->ObjectDeleted(this);
770e21b167Sbeveloper 	status = BTimeSource::DeleteHook(node);
78*92e575c1Sbeveloper 	printf("TimeSourceObject::DeleteHook leave\n");
790e21b167Sbeveloper 	return status;
80835140c8Sbeveloper }
81835140c8Sbeveloper 
82