xref: /haiku/src/kits/media/TimeSourceObject.cpp (revision 31f5d420edd1625a5c211fceee69e943677593d2)
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 "TimeSourceObject.h"
14 #include "TimeSourceObjectManager.h"
15 
16 TimeSourceObject::TimeSourceObject(const media_node &node)
17  :	BMediaNode("some timesource object", node.node, node.kind),
18 	BTimeSource(node.node)
19 {
20 //	printf("TimeSourceObject::TimeSourceObject enter, id = %ld\n", id);
21 	if (fControlPort > 0)
22 		delete_port(fControlPort);
23 	fControlPort = node.port;
24 	ASSERT(fNodeID == node.node);
25 	ASSERT(fKinds == node.kind);
26 
27 	live_node_info lni;
28 	if (B_OK == BMediaRoster::Roster()->GetLiveNodeInfo(node, &lni)) {
29 		strcpy(fName, lni.name);
30 	} else {
31 		sprintf(fName, "timesource %ld", node.node);
32 	}
33 
34 	AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
35 	fControlPort = -1234;
36 //	printf("TimeSourceObject::TimeSourceObject leave, node id %ld\n", fNodeID);
37 }
38 
39 /* virtual */ status_t
40 TimeSourceObject::TimeSourceOp(
41 				const time_source_op_info & op,
42 				void * _reserved)
43 {
44 	return B_OK;
45 }
46 
47 /* virtual */ BMediaAddOn*
48 TimeSourceObject::AddOn(int32 *internal_id) const
49 {
50 	if (internal_id)
51 		*internal_id = 0;
52 	return NULL;
53 }
54 
55 /* virtual */ status_t
56 TimeSourceObject::DeleteHook(BMediaNode *node)
57 {
58 	status_t status;
59 //	printf("TimeSourceObject::DeleteHook enter\n");
60 	_TimeSourceObjectManager->ObjectDeleted(this);
61 	status = BTimeSource::DeleteHook(node);
62 //	printf("TimeSourceObject::DeleteHook leave\n");
63 	return status;
64 }
65 
66 
67 SystemTimeSourceObject::SystemTimeSourceObject(const media_node &node)
68  : 	BMediaNode("System Clock", node.node, node.kind),
69 	TimeSourceObject(node)
70 {
71 //	printf("SystemTimeSourceObject::SystemTimeSourceObject enter, id = %ld\n", id);
72 	fIsRealtime = true;
73 	AddNodeKind(NODE_KIND_SYSTEM_TIMESOURCE);
74 //	printf("SystemTimeSourceObject::SystemTimeSourceObject leave, node id %ld\n", ID());
75 }
76 
77 /* virtual */ status_t
78 SystemTimeSourceObject::DeleteHook(BMediaNode * node)
79 {
80 	FATAL("SystemTimeSourceObject::DeleteHook called\n");
81 	return B_ERROR;
82 }
83