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 32 * notifications up to the media_server which will broadcast 33 * them. 34 */ 35 /* XXX The BeBook, MediaDefs.h and the BeOS R5 do list 36 * XXX different strings for the message data fields of 37 * XXX the notification messages. 38 */ 39 #include <Messenger.h> 40 #include <MediaNode.h> 41 #include "debug.h" 42 #include "DataExchange.h" 43 #include "Notifications.h" 44 45 namespace BPrivate { 46 namespace media { 47 48 extern team_id team; 49 50 namespace notifications { 51 52 status_t 53 Register(const BMessenger ¬ifyHandler, const media_node &node, int32 notification) 54 { 55 CALLED(); 56 BMessage msg(MEDIA_SERVER_REQUEST_NOTIFICATIONS); 57 msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); 58 msg.AddInt32(NOTIFICATION_PARAM_TEAM, team); 59 msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); 60 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 61 return BPrivate::media::dataexchange::SendToServer(&msg); 62 } 63 64 65 status_t 66 Unregister(const BMessenger ¬ifyHandler, const media_node &node, int32 notification) 67 { 68 CALLED(); 69 BMessage msg(MEDIA_SERVER_CANCEL_NOTIFICATIONS); 70 msg.AddInt32(NOTIFICATION_PARAM_WHAT, notification); 71 msg.AddInt32(NOTIFICATION_PARAM_TEAM, team); 72 msg.AddMessenger(NOTIFICATION_PARAM_MESSENGER, notifyHandler); 73 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 74 return BPrivate::media::dataexchange::SendToServer(&msg); 75 } 76 77 78 status_t 79 ReportError(const media_node &node, BMediaNode::node_error what, const BMessage * info) 80 { 81 /* Transmits the error code specified by whichError to anyone that's receiving notifications from 82 * this node. If info isn't NULL, it's used as a model message for the error notification message. 83 * The message field "be:node_id" will contain the node ID. 84 */ 85 CALLED(); 86 BMessage msg; 87 if (info) 88 msg = *info; 89 msg.what = MEDIA_SERVER_SEND_NOTIFICATIONS; 90 msg.AddInt32(NOTIFICATION_PARAM_WHAT, what); 91 msg.AddInt32("be:node_id", node.node); 92 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 93 return BPrivate::media::dataexchange::SendToServer(&msg); 94 } 95 96 97 void 98 NodesCreated(const media_node_id *ids, int32 count) 99 { 100 CALLED(); 101 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 102 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_CREATED); 103 for (int32 i = 0; i < count; i++) { 104 msg.AddInt32("media_node_id", ids[i]); 105 } 106 BPrivate::media::dataexchange::SendToServer(&msg); 107 } 108 109 110 void 111 NodesDeleted(const media_node_id *ids, int32 count) 112 { 113 CALLED(); 114 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 115 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_DELETED); 116 for (int32 i = 0; i < count; i++) { 117 msg.AddInt32("media_node_id", ids[i]); 118 } 119 BPrivate::media::dataexchange::SendToServer(&msg); 120 } 121 122 123 void 124 ConnectionMade(const media_input &input, const media_output &output, const media_format &format) 125 { 126 CALLED(); 127 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 128 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_MADE); 129 msg.AddData("input", B_RAW_TYPE, &input, sizeof(input)); 130 msg.AddData("output", B_RAW_TYPE, &output, sizeof(output)); 131 msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); 132 BPrivate::media::dataexchange::SendToServer(&msg); 133 } 134 135 136 void 137 ConnectionBroken(const media_source &source, const media_destination &destination) 138 { 139 CALLED(); 140 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 141 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_CONNECTION_BROKEN); 142 msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); 143 msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); 144 BPrivate::media::dataexchange::SendToServer(&msg); 145 } 146 147 148 void 149 BuffersCreated(area_info *areas, int32 count) 150 { 151 CALLED(); 152 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 153 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_BUFFER_CREATED); 154 for (int32 i = 0; i < count; i++) { 155 msg.AddData("clone_info", B_RAW_TYPE, &areas[i], sizeof(area_info)); 156 } 157 BPrivate::media::dataexchange::SendToServer(&msg); 158 } 159 160 161 void 162 BuffersDeleted(const media_buffer_id *ids, int32 count) 163 { 164 CALLED(); 165 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 166 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_BUFFER_DELETED); 167 for (int32 i = 0; i < count; i++) { 168 msg.AddInt32("media_buffer_id", ids[i]); 169 } 170 BPrivate::media::dataexchange::SendToServer(&msg); 171 } 172 173 174 void 175 FormatChanged(const media_source &source, const media_destination &destination, const media_format &format) 176 { 177 CALLED(); 178 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 179 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FORMAT_CHANGED); 180 msg.AddData("source", B_RAW_TYPE, &source, sizeof(source)); 181 msg.AddData("destination", B_RAW_TYPE, &destination, sizeof(destination)); 182 msg.AddData("format", B_RAW_TYPE, &format, sizeof(format)); 183 BPrivate::media::dataexchange::SendToServer(&msg); 184 } 185 186 187 status_t 188 ParameterChanged(const media_node &node, int32 parameterid) 189 { 190 CALLED(); 191 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 192 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_PARAMETER_CHANGED); 193 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 194 msg.AddInt32("parameter", parameterid); 195 return BPrivate::media::dataexchange::SendToServer(&msg); 196 } 197 198 199 void 200 WebChanged(const media_node &node) 201 { 202 CALLED(); 203 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 204 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_WEB_CHANGED); 205 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 206 BPrivate::media::dataexchange::SendToServer(&msg); 207 } 208 209 210 status_t 211 NewParameterValue(const media_node &node, int32 parameterid, bigtime_t when, const void *param, size_t paramsize) 212 { 213 CALLED(); 214 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 215 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NEW_PARAMETER_VALUE); 216 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 217 msg.AddInt32("parameter", parameterid); 218 msg.AddInt64("when", when); 219 msg.AddData("value", B_RAW_TYPE, param, paramsize); 220 return BPrivate::media::dataexchange::SendToServer(&msg); 221 } 222 223 224 void 225 FlavorsChanged(media_addon_id addonid, int32 newcount, int32 gonecount) 226 { 227 CALLED(); 228 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 229 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_FLAVORS_CHANGED); 230 msg.AddInt32("be:addon_id", addonid); 231 msg.AddInt32("be:new_count", newcount); 232 msg.AddInt32("be:gone_count", gonecount); 233 BPrivate::media::dataexchange::SendToServer(&msg); 234 } 235 236 237 void 238 NodeStopped(const media_node &node, bigtime_t when) 239 { 240 CALLED(); 241 BMessage msg(MEDIA_SERVER_SEND_NOTIFICATIONS); 242 msg.AddInt32(NOTIFICATION_PARAM_WHAT, B_MEDIA_NODE_STOPPED); 243 msg.AddData("node", B_RAW_TYPE, &node, sizeof(node)); 244 msg.AddInt64("when", when); 245 BPrivate::media::dataexchange::SendToServer(&msg); 246 } 247 248 249 // XXX missing: B_MEDIA_TRANSPORT_STATE /* "state", "location", "realtime" */ 250 // XXX missing: B_MEDIA_DEFAULT_CHANGED /* "default", "node" */ 251 252 253 bool 254 IsValidNotificationRequest(bool node_specific, int32 notification) 255 { 256 switch (notification) { 257 // valid for normal and node specific watching 258 case B_MEDIA_WILDCARD: 259 case B_MEDIA_NODE_CREATED: 260 case B_MEDIA_NODE_DELETED: 261 case B_MEDIA_CONNECTION_MADE: 262 case B_MEDIA_CONNECTION_BROKEN: 263 case B_MEDIA_BUFFER_CREATED: 264 case B_MEDIA_BUFFER_DELETED: 265 case B_MEDIA_TRANSPORT_STATE: 266 case B_MEDIA_DEFAULT_CHANGED: 267 case B_MEDIA_FLAVORS_CHANGED: 268 return true; 269 270 // only valid for node specific watching 271 case B_MEDIA_PARAMETER_CHANGED: 272 case B_MEDIA_FORMAT_CHANGED: 273 case B_MEDIA_WEB_CHANGED: 274 case B_MEDIA_NEW_PARAMETER_VALUE: 275 case B_MEDIA_NODE_STOPPED: 276 return node_specific; 277 278 // everything else is invalid 279 default: 280 return false; 281 } 282 } 283 284 }; // namespace notifications 285 }; // namespace media 286 }; // namespace BPrivate 287