xref: /haiku/src/kits/media/TimeSourceObject.cpp (revision 4295907bd14047fb8c4156fe2cb0b9103c36bed6)
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 {
21*4295907bSbeveloper 	TRACE("TimeSourceObject::TimeSourceObject enter, id = %ld\n", node.node);
22d6379053Sbeveloper 	if (fControlPort > 0)
23287f7492Sbeveloper 		delete_port(fControlPort);
24d6379053Sbeveloper 	fControlPort = node.port;
25d6379053Sbeveloper 	ASSERT(fNodeID == node.node);
26d6379053Sbeveloper 	ASSERT(fKinds == node.kind);
27d6379053Sbeveloper 
285917dd5bSbeveloper 
295917dd5bSbeveloper 	if (node.node == NODE_SYSTEM_TIMESOURCE_ID) {
305917dd5bSbeveloper 		strcpy(fName, "System Clock");
315917dd5bSbeveloper 	} else {
32d6379053Sbeveloper 		live_node_info lni;
33d6379053Sbeveloper 		if (B_OK == BMediaRoster::Roster()->GetLiveNodeInfo(node, &lni)) {
34d6379053Sbeveloper 			strcpy(fName, lni.name);
35d6379053Sbeveloper 		} else {
36d6379053Sbeveloper 			sprintf(fName, "timesource %ld", node.node);
37d6379053Sbeveloper 		}
385917dd5bSbeveloper 	}
39d6379053Sbeveloper 
40d6379053Sbeveloper 	AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
4186bce45bSbeveloper 	AddNodeKind(NODE_KIND_NO_REFCOUNTING);
4286bce45bSbeveloper 	fControlPort = SHADOW_TIMESOURCE_CONTROL_PORT; // XXX if we don't do this, we get a infinite loop somewhere. This needs to be debugged
4386bce45bSbeveloper 
44*4295907bSbeveloper 	TRACE("TimeSourceObject::TimeSourceObject leave, node id %ld\n", fNodeID);
45287f7492Sbeveloper }
46287f7492Sbeveloper 
47287f7492Sbeveloper /* virtual */ status_t
48287f7492Sbeveloper TimeSourceObject::TimeSourceOp(
49287f7492Sbeveloper 				const time_source_op_info & op,
50287f7492Sbeveloper 				void * _reserved)
51287f7492Sbeveloper {
52287f7492Sbeveloper 	return B_OK;
53287f7492Sbeveloper }
54287f7492Sbeveloper 
55287f7492Sbeveloper /* virtual */ BMediaAddOn*
56287f7492Sbeveloper TimeSourceObject::AddOn(int32 *internal_id) const
57287f7492Sbeveloper {
58835140c8Sbeveloper 	if (internal_id)
59835140c8Sbeveloper 		*internal_id = 0;
60287f7492Sbeveloper 	return NULL;
61287f7492Sbeveloper }
62835140c8Sbeveloper 
63835140c8Sbeveloper /* virtual */ status_t
64835140c8Sbeveloper TimeSourceObject::DeleteHook(BMediaNode *node)
65835140c8Sbeveloper {
660e21b167Sbeveloper 	status_t status;
670e21b167Sbeveloper //	printf("TimeSourceObject::DeleteHook enter\n");
68835140c8Sbeveloper 	_TimeSourceObjectManager->ObjectDeleted(this);
690e21b167Sbeveloper 	status = BTimeSource::DeleteHook(node);
700e21b167Sbeveloper //	printf("TimeSourceObject::DeleteHook leave\n");
710e21b167Sbeveloper 	return status;
72835140c8Sbeveloper }
73835140c8Sbeveloper 
74d6379053Sbeveloper SystemTimeSourceObject::SystemTimeSourceObject(const media_node &node)
75d6379053Sbeveloper  : 	BMediaNode("System Clock",  node.node,  node.kind),
76d6379053Sbeveloper 	TimeSourceObject(node)
77835140c8Sbeveloper {
780e21b167Sbeveloper //	printf("SystemTimeSourceObject::SystemTimeSourceObject enter, id = %ld\n", id);
790e21b167Sbeveloper 	fIsRealtime = true;
80d6379053Sbeveloper 	AddNodeKind(NODE_KIND_SYSTEM_TIMESOURCE);
8186bce45bSbeveloper 	AddNodeKind(NODE_KIND_NO_REFCOUNTING);
820e21b167Sbeveloper //	printf("SystemTimeSourceObject::SystemTimeSourceObject leave, node id %ld\n", ID());
83835140c8Sbeveloper }
84835140c8Sbeveloper 
85835140c8Sbeveloper /* virtual */ status_t
86835140c8Sbeveloper SystemTimeSourceObject::DeleteHook(BMediaNode * node)
87835140c8Sbeveloper {
88835140c8Sbeveloper 	FATAL("SystemTimeSourceObject::DeleteHook called\n");
89835140c8Sbeveloper 	return B_ERROR;
90835140c8Sbeveloper }
91