xref: /haiku/src/kits/media/TimeSourceObject.cpp (revision f2ced752a08ff5d2618826bcd3ae3976c9f3e92e)
1 /***********************************************************************
2  * Copyright (c) 2002 Marcus Overhagen. All Rights Reserved.
3  * This file may be used under the terms of the OpenBeOS License.
4  *
5  * The object returned by BMediaRoster's
6  * BTimeSource * MakeTimeSourceFor(const media_node & for_node);
7  *
8  ***********************************************************************/
9 
10 #include <OS.h>
11 #include <stdio.h>
12 #include <MediaRoster.h>
13 #include "MediaMisc.h"
14 #include "TimeSourceObject.h"
15 #include "TimeSourceObjectManager.h"
16 
17 TimeSourceObject::TimeSourceObject(const media_node &node)
18  :	BMediaNode("some timesource object", node.node, node.kind),
19 	BTimeSource(node.node)
20 {
21 	TRACE("TimeSourceObject::TimeSourceObject enter, id = %ld\n", node.node);
22 	if (fControlPort > 0)
23 		delete_port(fControlPort);
24 
25 	// we use the control port of the real time source object.
26 	// this way, all messages are send to the real time source,
27 	// and this shadow object won't receive any.
28 	fControlPort = node.port;
29 	ASSERT(fNodeID == node.node);
30 	ASSERT(fKinds == node.kind);
31 
32 	if (node.node == NODE_SYSTEM_TIMESOURCE_ID) {
33 		strcpy(fName, "System Clock");
34 		fIsRealtime = true;
35 	} else {
36 		live_node_info lni;
37 		if (B_OK == BMediaRoster::Roster()->GetLiveNodeInfo(node, &lni)) {
38 			strcpy(fName, lni.name);
39 		} else {
40 			sprintf(fName, "timesource %ld", node.node);
41 		}
42 	}
43 
44 	AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
45 	AddNodeKind(NODE_KIND_NO_REFCOUNTING);
46 
47 	TRACE("TimeSourceObject::TimeSourceObject leave, node id %ld\n", fNodeID);
48 }
49 
50 /* virtual */ status_t
51 TimeSourceObject::TimeSourceOp(
52 				const time_source_op_info & op,
53 				void * _reserved)
54 {
55 	// we don't get anything here
56 	return B_OK;
57 }
58 
59 /* virtual */ BMediaAddOn*
60 TimeSourceObject::AddOn(int32 *internal_id) const
61 {
62 	if (internal_id)
63 		*internal_id = 0;
64 	return NULL;
65 }
66 
67 /* virtual */ status_t
68 TimeSourceObject::DeleteHook(BMediaNode *node)
69 {
70 	status_t status;
71 //	if (fIsRealtime) {
72 //		ERROR("TimeSourceObject::DeleteHook: system time source clone delete hook called\n");
73 //		return B_ERROR;
74 //	}
75 	printf("TimeSourceObject::DeleteHook enter\n");
76 	_TimeSourceObjectManager->ObjectDeleted(this);
77 	status = BTimeSource::DeleteHook(node);
78 	printf("TimeSourceObject::DeleteHook leave\n");
79 	return status;
80 }
81 
82