diff --git a/headers/private/media/ServerInterface.h b/headers/private/media/ServerInterface.h index 2ccf76c668..d0185b6808 100644 --- a/headers/private/media/ServerInterface.h +++ b/headers/private/media/ServerInterface.h @@ -640,21 +640,19 @@ struct server_get_codec_info_reply : reply_data { // the codec info matching the cookie }; -struct xfer_server_get_dormant_flavor_info { +struct server_get_dormant_flavor_info_request : request_data { media_addon_id add_on_id; int32 flavor_id; - port_id reply_port; }; -struct xfer_server_get_dormant_flavor_info_reply { - status_t result; +struct server_get_dormant_flavor_info_reply : reply_data { type_code type; // the flatten type_code size_t flattened_size; char flattened_data[1]; // a flattened dormant_flavor_info, flattened_size large }; -struct xfer_server_get_dormant_nodes { +struct server_get_dormant_nodes_request : request_data { int32 max_count; bool has_input; media_format input_format; @@ -664,17 +662,15 @@ struct xfer_server_get_dormant_nodes { char name[B_MEDIA_NAME_LENGTH + 1]; // 1 for a trailing "*" uint64 require_kinds; uint64 deny_kinds; - port_id reply_port; }; -struct xfer_server_get_dormant_nodes_reply { - status_t result; +struct server_get_dormant_nodes_reply : reply_data { int32 count; // if count > 0, a second reply containing count dormant_node_infos // is send }; -struct xfer_server_register_dormant_node { +struct server_register_dormant_node_command : command_data { media_addon_id purge_id; // if > 0, server must first remove all dormant_flavor_infos // belonging to that id diff --git a/src/kits/media/MediaRoster.cpp b/src/kits/media/MediaRoster.cpp index d5e2f1b53a..29ed33ef8f 100644 --- a/src/kits/media/MediaRoster.cpp +++ b/src/kits/media/MediaRoster.cpp @@ -2249,65 +2249,50 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count, if (_info == NULL || _count == NULL || *_count <= 0) return B_BAD_VALUE; - xfer_server_get_dormant_nodes msg; - port_id port; - status_t rv; - - port = find_port(MEDIA_SERVER_PORT_NAME); - if (port <= B_OK) - return B_ERROR; - - msg.max_count = *_count; - msg.has_input = hasInput != NULL; + server_get_dormant_nodes_request request; + request.max_count = *_count; + request.has_input = hasInput != NULL; if (hasInput != NULL) { // TODO: we should not make a flat copy of media_format - msg.input_format = *hasInput; + request.input_format = *hasInput; } - msg.has_output = hasOutput != NULL; + request.has_output = hasOutput != NULL; if (hasOutput != NULL) { // TODO: we should not make a flat copy of media_format - msg.output_format = *hasOutput; + request.output_format = *hasOutput; } - msg.has_name = name != NULL; - if (name != NULL) { - int len = strlen(name); - len = min_c(len, (int)sizeof(msg.name) - 1); - memcpy(msg.name, name, len); - msg.name[len] = 0; - } - msg.require_kinds = requireKinds; - msg.deny_kinds = denyKinds; - msg.reply_port = gPortPool->GetPort(); + request.has_name = name != NULL; + if (name != NULL) + strlcpy(request.name, name, sizeof(request.name)); - rv = write_port(port, SERVER_GET_DORMANT_NODES, &msg, sizeof(msg)); - if (rv != B_OK) { - gPortPool->PutPort(msg.reply_port); - return rv; - } + request.require_kinds = requireKinds; + request.deny_kinds = denyKinds; + request.reply_port = gPortPool->GetPort(); - xfer_server_get_dormant_nodes_reply reply; - int32 code; - - rv = read_port(msg.reply_port, &code, &reply, sizeof(reply)); - if (rv < B_OK) { - gPortPool->PutPort(msg.reply_port); - return rv; + server_get_dormant_nodes_reply reply; + status_t status = QueryServer(SERVER_GET_DORMANT_NODES, &request, + sizeof(request), &reply, sizeof(reply)); + if (status != B_OK) { + gPortPool->PutPort(request.reply_port); + return status; } *_count = reply.count; - if (*_count > 0) { - rv = read_port(msg.reply_port, &code, _info, - *_count * sizeof(dormant_node_info)); - if (rv < B_OK) - reply.result = rv; + if (reply.count > 0) { + int32 code; + status = read_port(request.reply_port, &code, _info, + reply.count * sizeof(dormant_node_info)); + if (status < B_OK) + reply.result = status; } - gPortPool->PutPort(msg.reply_port); + gPortPool->PutPort(request.reply_port); return reply.result; } + /*! This function is used to do the real work of instantiating a dormant node. It is either called by the media_addon_server to instantiate a global node, or it gets called from BMediaRoster::InstantiateDormantNode() to create a @@ -2592,32 +2577,24 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonID, int32 flavorID, if (_flavor == NULL) return B_BAD_VALUE; - port_id port = find_port(MEDIA_SERVER_PORT_NAME); - if (port < 0) - return B_ERROR; + // TODO: better use an area here as well! - xfer_server_get_dormant_flavor_info_reply* reply - = (xfer_server_get_dormant_flavor_info_reply*)malloc(16300); + server_get_dormant_flavor_info_reply* reply + = (server_get_dormant_flavor_info_reply*)malloc(16300); if (reply == NULL) return B_NO_MEMORY; - xfer_server_get_dormant_flavor_info msg; - msg.add_on_id = addonID; - msg.flavor_id = flavorID; - msg.reply_port = gPortPool->GetPort(); - status_t status = write_port(port, SERVER_GET_DORMANT_FLAVOR_INFO, &msg, - sizeof(msg)); + server_get_dormant_flavor_info_request request; + request.add_on_id = addonID; + request.flavor_id = flavorID; + request.reply_port = gPortPool->GetPort(); + + status_t status = QueryServer(SERVER_GET_DORMANT_FLAVOR_INFO, &request, + sizeof(request), reply, 16300); + + gPortPool->PutPort(request.reply_port); + if (status != B_OK) { - free(reply); - gPortPool->PutPort(msg.reply_port); - return status; - } - - int32 code; - status = read_port(msg.reply_port, &code, reply, 16000); - gPortPool->PutPort(msg.reply_port); - - if (status < B_OK) { free(reply); return status; } diff --git a/src/servers/media/media_server.cpp b/src/servers/media/media_server.cpp index dabf96e5ef..7e16cd7003 100644 --- a/src/servers/media/media_server.cpp +++ b/src/servers/media/media_server.cpp @@ -600,14 +600,14 @@ ServerApp::_HandleMessage(int32 code, const void* data, size_t size) case SERVER_REGISTER_DORMANT_NODE: { - xfer_server_register_dormant_node& request - = *static_cast(data); - if (request.purge_id > 0) - gNodeManager->InvalidateDormantFlavorInfo(request.purge_id); + server_register_dormant_node_command& command + = *static_cast(data); + if (command.purge_id > 0) + gNodeManager->InvalidateDormantFlavorInfo(command.purge_id); dormant_flavor_info dormantFlavorInfo; - status_t status = dormantFlavorInfo.Unflatten(request.type, - request.flattened_data, request.flattened_size); + status_t status = dormantFlavorInfo.Unflatten(command.type, + command.flattened_data, command.flattened_size); if (status == B_OK) gNodeManager->AddDormantFlavorInfo(dormantFlavorInfo); break; @@ -615,10 +615,10 @@ ServerApp::_HandleMessage(int32 code, const void* data, size_t size) case SERVER_GET_DORMANT_NODES: { - xfer_server_get_dormant_nodes& request - = *static_cast(data); + server_get_dormant_nodes_request& request + = *static_cast(data); - xfer_server_get_dormant_nodes_reply reply; + server_get_dormant_nodes_reply reply; reply.count = request.max_count; dormant_node_info* infos @@ -635,7 +635,8 @@ ServerApp::_HandleMessage(int32 code, const void* data, size_t size) if (reply.result != B_OK) reply.count = 0; - write_port(request.reply_port, 0, &reply, sizeof(reply)); + + request.SendReply(reply.result, &reply, sizeof(reply)); if (reply.count > 0) { write_port(request.reply_port, 0, infos, reply.count * sizeof(dormant_node_info)); @@ -646,22 +647,22 @@ ServerApp::_HandleMessage(int32 code, const void* data, size_t size) case SERVER_GET_DORMANT_FLAVOR_INFO: { - xfer_server_get_dormant_flavor_info& request - = *static_cast(data); + server_get_dormant_flavor_info_request& request + = *static_cast(data); dormant_flavor_info dormantFlavorInfo; status_t status = gNodeManager->GetDormantFlavorInfoFor( request.add_on_id, request.flavor_id, &dormantFlavorInfo); if (status != B_OK) { - xfer_server_get_dormant_flavor_info_reply reply; + server_get_dormant_flavor_info_reply reply; reply.result = status; - write_port(request.reply_port, 0, &reply, sizeof(reply)); + request.SendReply(reply.result, &reply, sizeof(reply)); } else { size_t replySize - = sizeof(xfer_server_get_dormant_flavor_info_reply) + = sizeof(server_get_dormant_flavor_info_reply) + dormantFlavorInfo.FlattenedSize(); - xfer_server_get_dormant_flavor_info_reply* reply - = (xfer_server_get_dormant_flavor_info_reply*)malloc( + server_get_dormant_flavor_info_reply* reply + = (server_get_dormant_flavor_info_reply*)malloc( replySize); if (reply != NULL) { reply->type = dormantFlavorInfo.TypeCode(); @@ -669,12 +670,12 @@ ServerApp::_HandleMessage(int32 code, const void* data, size_t size) reply->result = dormantFlavorInfo.Flatten( reply->flattened_data, reply->flattened_size); - write_port(request.reply_port, 0, reply, replySize); + request.SendReply(reply->result, reply, replySize); free(reply); } else { - xfer_server_get_dormant_flavor_info_reply reply; + server_get_dormant_flavor_info_reply reply; reply.result = B_NO_MEMORY; - write_port(request.reply_port, 0, &reply, sizeof(reply)); + request.SendReply(reply.result, &reply, sizeof(reply)); } } break; diff --git a/src/servers/media_addon/MediaAddonServer.cpp b/src/servers/media_addon/MediaAddonServer.cpp index f6e6fa315c..f0969eeec5 100644 --- a/src/servers/media_addon/MediaAddonServer.cpp +++ b/src/servers/media_addon/MediaAddonServer.cpp @@ -451,12 +451,6 @@ MediaAddonServer::_ScanAddOnFlavors(BMediaAddOn* addon) TRACE("MediaAddonServer::_ScanAddOnFlavors: id %ld\n", addon->AddonID()); - port_id port = find_port(MEDIA_SERVER_PORT_NAME); - if (port <= B_OK) { - ERROR("couldn't find media_server port\n"); - return; - } - // cache the media_addon_id in a local variable to avoid // calling BMediaAddOn::AddonID() too often media_addon_id addonID = addon->AddonID(); @@ -496,9 +490,9 @@ MediaAddonServer::_ScanAddOnFlavors(BMediaAddOn* addon) size_t flattenedSize = dormantFlavorInfo.FlattenedSize(); size_t messageSize = flattenedSize - + sizeof(xfer_server_register_dormant_node); - xfer_server_register_dormant_node* message - = (xfer_server_register_dormant_node*)malloc(messageSize); + + sizeof(server_register_dormant_node_command); + server_register_dormant_node_command* message + = (server_register_dormant_node_command*)malloc(messageSize); if (message == NULL) break; @@ -511,7 +505,7 @@ MediaAddonServer::_ScanAddOnFlavors(BMediaAddOn* addon) message->flattened_size = flattenedSize; dormantFlavorInfo.Flatten(message->flattened_data, flattenedSize); - status_t status = write_port(port, SERVER_REGISTER_DORMANT_NODE, + status_t status = SendToServer(SERVER_REGISTER_DORMANT_NODE, message, messageSize); if (status != B_OK) { ERROR("MediaAddonServer::_ScanAddOnFlavors: couldn't register "