1 /* 2 * Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files or portions 6 * thereof (the "Software"), to deal in the Software without restriction, 7 * including without limitation the rights to use, copy, modify, merge, 8 * publish, distribute, sublicense, and/or sell copies of the Software, 9 * and to permit persons to whom the Software is furnished to do so, subject 10 * to the following conditions: 11 * 12 * * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * * Redistributions in binary form must reproduce the above copyright notice 16 * in the binary, as well as this list of conditions and the following 17 * disclaimer in the documentation and/or other materials provided with 18 * the distribution. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 * THE SOFTWARE. 27 */ 28 29 30 /*! This is a interface class for media kit notifications. 31 It is private to the media kit which uses it to pass notifications up to 32 the media_server which will broadcast them. 33 */ 34 35 // TODO: The BeBook, MediaDefs.h and the BeOS R5 do list 36 // different strings for the message data fields of 37 // the notification messages. 38 39 40 #include "Notifications.h" 41 42 #include <Messenger.h> 43 #include <MediaNode.h> 44 45 #include <AppMisc.h> 46 47 #include "debug.h" 48 #include "DataExchange.h" 49 50 51 namespace BPrivate { 52 namespace media { 53 namespace notifications { 54 55 56 status_t 57 Register(const BMessenger& notifyHandler, const media_node& node, 58 int32 notification) 59 { 60 CALLED(); 61 BMessage msg(MEDIA_SERVER_REQUEST_NOTIFICATIONS); 62 msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); 63 msg.AddInt32(NOTIFICATION_PARAM_TEAM, BPrivate::current_team()); 64 msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); 65 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 66 67 return BPrivate::media::dataexchange::SendToServer(&msg); 68 } 69 70 71 status_t 72 Unregister(const BMessenger& notifyHandler, const media_node& node, 73 int32 notification) 74 { 75 CALLED(); 76 BMessage msg(MEDIA_SERVER_CANCEL_NOTIFICATIONS); 77 msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); 78 msg.AddInt32(NOTIFICATION_PARAM_TEAM, BPrivate::current_team()); 79 msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); 80 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 81 82 return BPrivate::media::dataexchange::SendToServer(&msg); 83 } 84 85 86 /*! Transmits the error code specified by \a what to anyone who's receiving 87 notifications from this node. If \a info isn't \c NULL, it's used as a 88 model message for the error notification message. 89 The message field "be:node_id" will contain the node ID. 90 */ 91 status_t 92 ReportError(const media_node& node, BMediaNode::node_error what, 93 const BMessage* info) 94 { 95 CALLED(); 96 BMessage msg; 97 if (info != NULL) 98 msg = *info; 99 100 msg.what = MEDIA_SERVER_SEND_NOTIFICATIONS; 101 msg.AddInt32(NOTIFICATION_PARAM_WHAT, what); 102 msg.AddInt32("be:node_id", node.node); 103 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 104 105 return BPrivate::media::dataexchange::SendToServer(&msg); 106 } 107 108 109 void 110 NodesCreated(const media_node_id* ids, int32 count) 111 { 112 CALLED(); 113 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 114 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_CREATED); 115 for (int32 i = 0; i < count; i++) { 116 msg.AddInt32("media_node_id", ids[i]); 117 } 118 119 BPrivate::media::dataexchange::SendToServer(&msg); 120 } 121 122 123 void 124 NodesDeleted(const media_node_id* ids, int32 count) 125 { 126 CALLED(); 127 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 128 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_DELETED); 129 for (int32 i = 0; i < count; i++) { 130 msg.AddInt32("media_node_id", ids[i]); 131 } 132 133 BPrivate::media::dataexchange::SendToServer(&msg); 134 } 135 136 137 void 138 ConnectionMade(const media_input& input, const media_output& output, 139 const media_format& format) 140 { 141 CALLED(); 142 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 143 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_MADE); 144 msg.AddData("input", B_RAW_TYPE, &input, sizeof(input)); 145 msg.AddData("output", B_RAW_TYPE, &output, sizeof(output)); 146 msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); 147 148 BPrivate::media::dataexchange::SendToServer(&msg); 149 } 150 151 152 void 153 ConnectionBroken(const media_source& source, 154 const media_destination& destination) 155 { 156 CALLED(); 157 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 158 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_BROKEN); 159 msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); 160 msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); 161 162 BPrivate::media::dataexchange::SendToServer(&msg); 163 } 164 165 166 void 167 BuffersCreated(area_info* areas, int32 count) 168 { 169 CALLED(); 170 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 171 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_BUFFER_CREATED); 172 for (int32 i = 0; i < count; i++) { 173 msg.AddData("clone_info", B_RAW_TYPE, &areas[i], sizeof(area_info)); 174 } 175 176 BPrivate::media::dataexchange::SendToServer(&msg); 177 } 178 179 180 void 181 BuffersDeleted(const media_buffer_id* ids, int32 count) 182 { 183 CALLED(); 184 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 185 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_BUFFER_DELETED); 186 for (int32 i = 0; i < count; i++) { 187 msg.AddInt32("media_buffer_id", ids[i]); 188 } 189 190 BPrivate::media::dataexchange::SendToServer(&msg); 191 } 192 193 194 void 195 FormatChanged(const media_source& source, const media_destination& destination, 196 const media_format& format) 197 { 198 CALLED(); 199 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 200 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FORMAT_CHANGED); 201 msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); 202 msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); 203 msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); 204 205 BPrivate::media::dataexchange::SendToServer(&msg); 206 } 207 208 209 status_t 210 ParameterChanged(const media_node& node, int32 parameterID) 211 { 212 CALLED(); 213 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 214 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_PARAMETER_CHANGED); 215 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 216 msg.AddInt32("parameter", parameterID); 217 218 return BPrivate::media::dataexchange::SendToServer(&msg); 219 } 220 221 222 void 223 WebChanged(const media_node& node) 224 { 225 CALLED(); 226 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 227 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_WEB_CHANGED); 228 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 229 230 BPrivate::media::dataexchange::SendToServer(&msg); 231 } 232 233 234 status_t 235 NewParameterValue(const media_node& node, int32 parameterID, bigtime_t when, 236 const void* param, size_t paramsize) 237 { 238 CALLED(); 239 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 240 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NEW_PARAMETER_VALUE); 241 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 242 msg.AddInt32("parameter", parameterID); 243 msg.AddInt64("when", when); 244 msg.AddData("value", B_RAW_TYPE, param, paramsize); 245 246 return BPrivate::media::dataexchange::SendToServer(&msg); 247 } 248 249 250 void 251 FlavorsChanged(media_addon_id addOnID, int32 newCount, int32 goneCount) 252 { 253 CALLED(); 254 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 255 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FLAVORS_CHANGED); 256 msg.AddInt32("be:addon_id", addOnID); 257 msg.AddInt32("be:new_count", newCount); 258 msg.AddInt32("be:gone_count", goneCount); 259 260 BPrivate::media::dataexchange::SendToServer(&msg); 261 } 262 263 264 void 265 NodeStopped(const media_node& node, bigtime_t when) 266 { 267 CALLED(); 268 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 269 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_STOPPED); 270 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 271 msg.AddInt64("when", when); 272 273 BPrivate::media::dataexchange::SendToServer(&msg); 274 } 275 276 277 // TODO: missing: B_MEDIA_TRANSPORT_STATE: "state", "location", "realtime" 278 // TODO: missing: B_MEDIA_DEFAULT_CHANGED: "default", "node" 279 280 281 bool 282 IsValidNotificationRequest(bool node_specific, int32 notification) 283 { 284 switch (notification) { 285 // valid for normal and node specific watching 286 case B_MEDIA_WILDCARD: 287 case B_MEDIA_NODE_CREATED: 288 case B_MEDIA_NODE_DELETED: 289 case B_MEDIA_CONNECTION_MADE: 290 case B_MEDIA_CONNECTION_BROKEN: 291 case B_MEDIA_BUFFER_CREATED: 292 case B_MEDIA_BUFFER_DELETED: 293 case B_MEDIA_TRANSPORT_STATE: 294 case B_MEDIA_DEFAULT_CHANGED: 295 case B_MEDIA_FLAVORS_CHANGED: 296 return true; 297 298 // only valid for node specific watching 299 case B_MEDIA_PARAMETER_CHANGED: 300 case B_MEDIA_FORMAT_CHANGED: 301 case B_MEDIA_WEB_CHANGED: 302 case B_MEDIA_NEW_PARAMETER_VALUE: 303 case B_MEDIA_NODE_STOPPED: 304 return node_specific; 305 306 // everything else is invalid 307 default: 308 return false; 309 } 310 } 311 312 } // namespace notifications 313 } // namespace media 314 } // namespace BPrivate 315