vfs: check userland buffers before reading them.
[haiku.git] / src / kits / media / TimeSourceObject.cpp
blobf300c472d40cc91aade9fca9b3e8d90ce8de0b1a
1 /*
2 * Copyright 2002 Marcus Overhagen. All Rights Reserved.
3 * This file may be used under the terms of the MIT License.
4 */
7 /*! The object returned by BMediaRoster's
8 MakeTimeSourceFor(const media_node& forNode);
9 */
12 #include "TimeSourceObject.h"
14 #include <stdio.h>
15 #include <string.h>
17 #include <MediaRoster.h>
18 #include <OS.h>
20 #include <MediaMisc.h>
21 #include <debug.h>
23 #include "TimeSourceObjectManager.h"
26 TimeSourceObject::TimeSourceObject(const media_node& node)
28 BMediaNode("some timesource object", node.node, node.kind),
29 BTimeSource(node.node)
31 TRACE("TimeSourceObject::TimeSourceObject enter, id = %"
32 B_PRId32 "\n", node.node);
34 if (fControlPort > 0)
35 delete_port(fControlPort);
37 // We use the control port of the real time source object.
38 // this way, all messages are send to the real time source,
39 // and this shadow object won't receive any.
40 fControlPort = node.port;
42 ASSERT(fNodeID == node.node);
43 ASSERT(fKinds == node.kind);
45 if (node.node == NODE_SYSTEM_TIMESOURCE_ID) {
46 strcpy(fName, "System clock");
47 fIsRealtime = true;
48 } else {
49 live_node_info liveNodeInfo;
50 if (BMediaRoster::Roster()->GetLiveNodeInfo(node, &liveNodeInfo)
51 == B_OK)
52 strlcpy(fName, liveNodeInfo.name, B_MEDIA_NAME_LENGTH);
53 else {
54 snprintf(fName, B_MEDIA_NAME_LENGTH, "timesource %" B_PRId32,
55 node.node);
59 AddNodeKind(NODE_KIND_SHADOW_TIMESOURCE);
60 AddNodeKind(NODE_KIND_NO_REFCOUNTING);
62 TRACE("TimeSourceObject::TimeSourceObject leave, node id %" B_PRId32 "\n",
63 fNodeID);
67 status_t
68 TimeSourceObject::TimeSourceOp(const time_source_op_info& op, void* _reserved)
70 // we don't get anything here
71 return B_OK;
75 BMediaAddOn*
76 TimeSourceObject::AddOn(int32* _id) const
78 if (_id != NULL)
79 *_id = 0;
81 return NULL;
85 status_t
86 TimeSourceObject::DeleteHook(BMediaNode* node)
88 // if (fIsRealtime) {
89 // ERROR("TimeSourceObject::DeleteHook: system time source clone delete hook called\n");
90 // return B_ERROR;
91 // }
92 PRINT(1, "TimeSourceObject::DeleteHook enter\n");
93 gTimeSourceObjectManager->ObjectDeleted(this);
94 status_t status = BTimeSource::DeleteHook(node);
95 PRINT(1, "TimeSourceObject::DeleteHook leave\n");
96 return status;