vfs: check userland buffers before reading them.
[haiku.git] / src / servers / media / NodeManager.h
blobfab52e4f0814f7ed775bca675c0cf6e035da49fc
1 /*
2 * Copyright 2002, Marcus Overhagen. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef NODE_MANAGER_H
6 #define NODE_MANAGER_H
9 #include <map>
10 #include <vector>
12 #include <Locker.h>
14 #include "TStack.h"
15 #include "DataExchange.h"
18 class DefaultManager;
19 class BufferManager;
22 typedef std::map<team_id, int32> TeamCountMap;
23 typedef std::vector<media_input> InputList;
24 typedef std::vector<media_output> OutputList;
25 typedef std::vector<live_node_info> LiveNodeList;
28 struct registered_node {
29 media_node_id node_id;
30 media_node_id timesource_id;
31 media_addon_id add_on_id;
32 int32 flavor_id;
33 char name[B_MEDIA_NAME_LENGTH];
34 uint64 kinds;
35 port_id port;
36 team_id creator; // team that created the node
37 team_id containing_team;
38 int32 ref_count;
39 TeamCountMap team_ref_count;
40 InputList input_list;
41 OutputList output_list;
44 struct dormant_add_on_flavor_info {
45 media_addon_id add_on_id;
46 int32 flavor_id;
48 int32 max_instances_count;
49 int32 instances_count;
51 TeamCountMap team_instances_count;
53 bool info_valid;
54 dormant_flavor_info info;
58 class NodeManager : BLocker {
59 public:
60 NodeManager();
61 ~NodeManager();
63 // Management of system wide default nodes
64 status_t SetDefaultNode(node_type type,
65 const media_node* node,
66 const dormant_node_info* info,
67 const media_input* input);
68 status_t GetDefaultNode(node_type type,
69 media_node_id* _nodeID, char* inputName,
70 int32* _inputID);
71 status_t RescanDefaultNodes();
73 // Management of live nodes
74 status_t RegisterNode(media_addon_id addOnID,
75 int32 flavorID, const char* name,
76 uint64 kinds, port_id port, team_id team,
77 media_node_id timesource,
78 media_node_id* _nodeID);
79 status_t UnregisterNode(media_node_id nodeID,
80 team_id team, media_addon_id* addOnID,
81 int32* _flavorID);
82 status_t ReleaseNodeReference(media_node_id id,
83 team_id team);
84 status_t ReleaseNodeAll(media_node_id id);
85 status_t GetCloneForID(media_node_id id, team_id team,
86 media_node* node);
87 status_t GetClone(node_type type, team_id team,
88 media_node* node, char* inputName,
89 int32* _id);
90 status_t ReleaseNode(const media_node& node,
91 team_id team);
92 status_t PublishInputs(const media_node& node,
93 const media_input* inputs, int32 count);
94 status_t PublishOutputs(const media_node& node,
95 const media_output* outputs, int32 count);
96 status_t FindNodeID(port_id port, media_node_id* _id);
97 status_t GetLiveNodeInfo(const media_node& node,
98 live_node_info* liveInfo);
99 status_t GetInstances(media_addon_id addOnID,
100 int32 flavorID, media_node_id* ids,
101 int32* _count, int32 maxCount);
102 status_t GetLiveNodes(LiveNodeList& liveNodes,
103 int32 maxCount,
104 const media_format* inputFormat = NULL,
105 const media_format* outputFormat = NULL,
106 const char* name = NULL,
107 uint64 requireKinds = 0);
108 status_t GetDormantNodeInfo(const media_node& node,
109 dormant_node_info* nodeInfo);
110 status_t SetNodeCreator(media_node_id id,
111 team_id creator);
113 // Add media_node_id of all live nodes to the message
114 // int32 "media_node_id" (multiple items)
115 status_t GetLiveNodes(BMessage* message);
117 void RegisterAddOn(const entry_ref& ref,
118 media_addon_id* _newID);
119 void UnregisterAddOn(media_addon_id id);
121 status_t AddDormantFlavorInfo(
122 const dormant_flavor_info& flavorInfo);
123 void InvalidateDormantFlavorInfo(media_addon_id id);
124 void RemoveDormantFlavorInfo(media_addon_id id);
125 void CleanupDormantFlavorInfos();
127 status_t IncrementFlavorInstancesCount(
128 media_addon_id addOnID, int32 flavorID,
129 team_id team);
130 status_t DecrementFlavorInstancesCount(
131 media_addon_id addOnID, int32 flavorID,
132 team_id team);
134 status_t GetAddOnRef(media_addon_id addOnID,
135 entry_ref* ref);
136 status_t GetDormantNodes(dormant_node_info* infos,
137 int32* _count, const media_format* hasInput,
138 const media_format* hasOutput,
139 const char* name, uint64 requireKinds,
140 uint64 denyKinds);
142 status_t GetDormantFlavorInfoFor(media_addon_id addOnID,
143 int32 flavorID,
144 dormant_flavor_info* flavorInfo);
146 status_t SetNodeTimeSource(media_node_id node,
147 media_node_id timesource);
149 void CleanupTeam(team_id team);
151 status_t LoadState();
152 status_t SaveState();
154 void Dump();
156 private:
157 status_t _AcquireNodeReference(media_node_id id,
158 team_id team);
159 void _NotifyTimeSource(registered_node& node);
161 private:
162 typedef std::map<media_addon_id, registered_node> NodeMap;
163 typedef std::vector<dormant_add_on_flavor_info> DormantFlavorList;
164 typedef std::map<media_addon_id, entry_ref> PathMap;
166 media_addon_id fNextAddOnID;
167 media_node_id fNextNodeID;
169 DormantFlavorList fDormantFlavors;
170 PathMap fPathMap;
171 NodeMap fNodeMap;
172 DefaultManager* fDefaultManager;
175 #endif // NODE_MANAGER_H