xref: /haiku/src/kits/media/Controllable.cpp (revision 7120e97489acbf17d86d3f33e3b2e68974fd4b23)
1 /***********************************************************************
2  * AUTHOR: Marcus Overhagen
3  *   FILE: Controllable.cpp
4  *  DESCR:
5  ***********************************************************************/
6 #include <OS.h>
7 #include <Controllable.h>
8 #include "debug.h"
9 #include "Notifications.h"
10 
11 /*************************************************************
12  * protected BControllable
13  *************************************************************/
14 
15 BControllable::~BControllable()
16 {
17 	CALLED();
18 	if (fSem > 0)
19 		delete_sem(fSem);
20 }
21 
22 /*************************************************************
23  * public BControllable
24  *************************************************************/
25 
26 BParameterWeb *
27 BControllable::Web()
28 {
29 	CALLED();
30 	BParameterWeb *temp;
31 	LockParameterWeb();
32 	temp = fWeb;
33 	UnlockParameterWeb();
34 	return temp;
35 }
36 
37 
38 bool
39 BControllable::LockParameterWeb()
40 {
41 	CALLED();
42 	status_t rv;
43 	if (fSem <= 0)
44 		return false;
45 	if (atomic_add(&fBen, 1) > 0) {
46 		while (B_INTERRUPTED == (rv = acquire_sem(fSem)))
47 			;
48 		return rv == B_OK;
49 	}
50 	return true;
51 }
52 
53 /*************************************************************
54  * protected BControllable
55  *************************************************************/
56 
57 void
58 BControllable::UnlockParameterWeb()
59 {
60 	CALLED();
61 	if (fSem <= 0)
62 		return;
63 	if (atomic_add(&fBen, -1) > 1)
64 		release_sem(fSem);
65 }
66 
67 
68 BControllable::BControllable() :
69 	BMediaNode("XXX fixme"),
70 	fWeb(0),
71 	fSem(create_sem(0, "BControllable lock")),
72 	fBen(0)
73 {
74 	CALLED();
75 
76 	AddNodeKind(B_CONTROLLABLE);
77 }
78 
79 
80 status_t
81 BControllable::SetParameterWeb(BParameterWeb *web)
82 {
83 	CALLED();
84 	BParameterWeb *old;
85 	LockParameterWeb();
86 	old = fWeb;
87 	fWeb = web;
88 	UnlockParameterWeb();
89 	if (old != web && web != 0)
90 		BPrivate::media::notifications::WebChanged(Node());
91 
92 	return B_OK;
93 }
94 
95 
96 status_t
97 BControllable::HandleMessage(int32 message,
98 							 const void *data,
99 							 size_t size)
100 {
101 	INFO("BControllable::HandleMessage %#lx, node %ld\n", message, ID());
102 
103 	return B_ERROR;
104 }
105 
106 
107 status_t
108 BControllable::BroadcastChangedParameter(int32 id)
109 {
110 	CALLED();
111 	return BPrivate::media::notifications::ParameterChanged(Node(), id);
112 }
113 
114 
115 status_t
116 BControllable::BroadcastNewParameterValue(bigtime_t when,
117 										  int32 id,
118 										  void *newValue,
119 										  size_t valueSize)
120 {
121 	CALLED();
122 	return BPrivate::media::notifications::NewParameterValue(Node(), id, when, newValue, valueSize);
123 }
124 
125 
126 status_t
127 BControllable::StartControlPanel(BMessenger *out_messenger)
128 {
129 	UNIMPLEMENTED();
130 
131 	return B_ERROR;
132 }
133 
134 
135 status_t
136 BControllable::ApplyParameterData(const void *value,
137 								  size_t size)
138 {
139 	UNIMPLEMENTED();
140 
141 	return B_ERROR;
142 }
143 
144 
145 status_t
146 BControllable::MakeParameterData(const int32 *controls,
147 								 int32 count,
148 								 void *buf,
149 								 size_t *ioSize)
150 {
151 	UNIMPLEMENTED();
152 
153 	return B_ERROR;
154 }
155 
156 /*************************************************************
157  * private BControllable
158  *************************************************************/
159 
160 /*
161 private unimplemented
162 BControllable::BControllable(const BControllable &clone)
163 BControllable & BControllable::operator=(const BControllable &clone)
164 */
165 
166 status_t BControllable::_Reserved_Controllable_0(void *) { return B_ERROR; }
167 status_t BControllable::_Reserved_Controllable_1(void *) { return B_ERROR; }
168 status_t BControllable::_Reserved_Controllable_2(void *) { return B_ERROR; }
169 status_t BControllable::_Reserved_Controllable_3(void *) { return B_ERROR; }
170 status_t BControllable::_Reserved_Controllable_4(void *) { return B_ERROR; }
171 status_t BControllable::_Reserved_Controllable_5(void *) { return B_ERROR; }
172 status_t BControllable::_Reserved_Controllable_6(void *) { return B_ERROR; }
173 status_t BControllable::_Reserved_Controllable_7(void *) { return B_ERROR; }
174 status_t BControllable::_Reserved_Controllable_8(void *) { return B_ERROR; }
175 status_t BControllable::_Reserved_Controllable_9(void *) { return B_ERROR; }
176 status_t BControllable::_Reserved_Controllable_10(void *) { return B_ERROR; }
177 status_t BControllable::_Reserved_Controllable_11(void *) { return B_ERROR; }
178 status_t BControllable::_Reserved_Controllable_12(void *) { return B_ERROR; }
179 status_t BControllable::_Reserved_Controllable_13(void *) { return B_ERROR; }
180 status_t BControllable::_Reserved_Controllable_14(void *) { return B_ERROR; }
181 status_t BControllable::_Reserved_Controllable_15(void *) { return B_ERROR; }
182 
183 
184