1f4ec236cSAxel Dörfler /*
2f4ec236cSAxel Dörfler * Copyright 2002 Marcus Overhagen. All Rights Reserved.
3f4ec236cSAxel Dörfler * This file may be used under the terms of the MIT License.
4f4ec236cSAxel Dörfler */
5287f7492Sbeveloper
6f4ec236cSAxel Dörfler
7f4ec236cSAxel Dörfler /*! The object returned by BMediaRoster's
8f4ec236cSAxel Dörfler MakeTimeSourceFor(const media_node& forNode);
9f4ec236cSAxel Dörfler */
10f4ec236cSAxel Dörfler
11f4ec236cSAxel Dörfler
12f4ec236cSAxel Dörfler #include "TimeSourceObject.h"
13f4ec236cSAxel Dörfler
14287f7492Sbeveloper #include <stdio.h>
15758b1d0eSIngo Weinhold #include <string.h>
16f4ec236cSAxel Dörfler
17287f7492Sbeveloper #include <MediaRoster.h>
18f4ec236cSAxel Dörfler #include <OS.h>
19f4ec236cSAxel Dörfler
20f4ec236cSAxel Dörfler #include <MediaMisc.h>
21*b84955d4SBarrett17 #include <MediaDebug.h>
22f4ec236cSAxel Dörfler
23835140c8Sbeveloper #include "TimeSourceObjectManager.h"
24287f7492Sbeveloper
25f4ec236cSAxel Dörfler
TimeSourceObject(const media_node & node)26d6379053Sbeveloper TimeSourceObject::TimeSourceObject(const media_node& node)
27f4ec236cSAxel Dörfler :
28f4ec236cSAxel Dörfler BMediaNode("some timesource object", node.node, node.kind),
29d6379053Sbeveloper BTimeSource(node.node)
30287f7492Sbeveloper {
312ceb090fSDario Casalinuovo TRACE("TimeSourceObject::TimeSourceObject enter, id = %"
322ceb090fSDario Casalinuovo B_PRId32 "\n", node.node);
332ceb090fSDario Casalinuovo
34d6379053Sbeveloper if (fControlPort > 0)
35287f7492Sbeveloper delete_port(fControlPort);
3692e575c1Sbeveloper
37f4ec236cSAxel Dörfler // We use the control port of the real time source object.
3892e575c1Sbeveloper // this way, all messages are send to the real time source,
3992e575c1Sbeveloper // and this shadow object won't receive any.
40d6379053Sbeveloper fControlPort = node.port;
41f4ec236cSAxel Dörfler
42d6379053Sbeveloper ASSERT(fNodeID == node.node);
43d6379053Sbeveloper ASSERT(fKinds == node.kind);
44d6379053Sbeveloper
455917dd5bSbeveloper if (node.node == NODE_SYSTEM_TIMESOURCE_ID) {
463e6fa229SStephan Aßmus strcpy(fName, "System clock");
4792e575c1Sbeveloper fIsRealtime = true;
485917dd5bSbeveloper } else {
49f4ec236cSAxel Dörfler live_node_info liveNodeInfo;
50f4ec236cSAxel Dörfler if (BMediaRoster::Roster()->GetLiveNodeInfo(node, &liveNodeInfo)
51f4ec236cSAxel Dörfler == B_OK)
52f4ec236cSAxel Dörfler strlcpy(fName, liveNodeInfo.name, B_MEDIA_NAME_LENGTH);
53332cc6bcSAxel Dörfler else {
54332cc6bcSAxel Dörfler snprintf(fName, B_MEDIA_NAME_LENGTH, "timesource %" B_PRId32,
55332cc6bcSAxel Dörfler node.node);
56332cc6bcSAxel Dörfler }
575917dd5bSbeveloper }
58d6379053Sbeveloper
59d6379053Sbeveloper AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
6086bce45bSbeveloper AddNodeKind(NODE_KIND_NO_REFCOUNTING);
6186bce45bSbeveloper
62332cc6bcSAxel Dörfler TRACE("TimeSourceObject::TimeSourceObject leave, node id %" B_PRId32 "\n",
63332cc6bcSAxel Dörfler fNodeID);
64287f7492Sbeveloper }
65287f7492Sbeveloper
66f4ec236cSAxel Dörfler
67f4ec236cSAxel Dörfler status_t
TimeSourceOp(const time_source_op_info & op,void * _reserved)68f4ec236cSAxel Dörfler TimeSourceObject::TimeSourceOp(const time_source_op_info& op, void* _reserved)
69287f7492Sbeveloper {
7092e575c1Sbeveloper // we don't get anything here
71287f7492Sbeveloper return B_OK;
72287f7492Sbeveloper }
73287f7492Sbeveloper
74f4ec236cSAxel Dörfler
75f4ec236cSAxel Dörfler BMediaAddOn*
AddOn(int32 * _id) const76f4ec236cSAxel Dörfler TimeSourceObject::AddOn(int32* _id) const
77287f7492Sbeveloper {
78f4ec236cSAxel Dörfler if (_id != NULL)
79f4ec236cSAxel Dörfler *_id = 0;
80f4ec236cSAxel Dörfler
81287f7492Sbeveloper return NULL;
82287f7492Sbeveloper }
83835140c8Sbeveloper
84f4ec236cSAxel Dörfler
85f4ec236cSAxel Dörfler status_t
DeleteHook(BMediaNode * node)86835140c8Sbeveloper TimeSourceObject::DeleteHook(BMediaNode* node)
87835140c8Sbeveloper {
8892e575c1Sbeveloper // if (fIsRealtime) {
8992e575c1Sbeveloper // ERROR("TimeSourceObject::DeleteHook: system time source clone delete hook called\n");
9092e575c1Sbeveloper // return B_ERROR;
9192e575c1Sbeveloper // }
926813f2c7SIngo Weinhold PRINT(1, "TimeSourceObject::DeleteHook enter\n");
93f4ec236cSAxel Dörfler gTimeSourceObjectManager->ObjectDeleted(this);
94f4ec236cSAxel Dörfler status_t status = BTimeSource::DeleteHook(node);
956813f2c7SIngo Weinhold PRINT(1, "TimeSourceObject::DeleteHook leave\n");
960e21b167Sbeveloper return status;
97835140c8Sbeveloper }
98835140c8Sbeveloper
99