Honor the 80 chars per line limit.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25810 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-06-05 21:17:19 +00:00
parent a9fbc5482c
commit 171d365edf

View File

@ -28,7 +28,8 @@
*/
/* to comply with the license above, do not remove the following line */
char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de>";
char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002, 2003 "
"Marcus Overhagen <Marcus@Overhagen.de>";
#include <Application.h>
#include <Roster.h>
@ -136,7 +137,8 @@ ServerApp::ServerApp()
gAddOnManager = new AddOnManager;
control_port = create_port(64, MEDIA_SERVER_PORT_NAME);
control_thread = spawn_thread(controlthread, "media_server control", 105, this);
control_thread = spawn_thread(controlthread, "media_server control", 105,
this);
resume_thread(control_thread);
}
@ -235,8 +237,10 @@ void ServerApp::StartAddonServer()
if (err == B_OK)
return;
(new BAlert("media_server", "Launching media_addon_server failed.\n\nmedia_server will terminate", "OK"))->Go();
fprintf(stderr, "Launching media_addon_server (%s) failed: %s\n", B_MEDIA_ADDON_SERVER_SIGNATURE, strerror(err));
(new BAlert("media_server", "Launching media_addon_server failed.\n\n"
"media_server will terminate", "OK"))->Go();
fprintf(stderr, "Launching media_addon_server (%s) failed: %s\n",
B_MEDIA_ADDON_SERVER_SIGNATURE, strerror(err));
exit(1);
}
@ -253,9 +257,11 @@ void ServerApp::TerminateAddonServer()
ERROR("Trouble terminating media_addon_server. Messenger invalid\n");
} else {
BMessage msg(B_QUIT_REQUESTED);
status_t err = msger.SendMessage(&msg, (BHandler *)NULL, 2000000 /* 2 sec timeout */);
status_t err = msger.SendMessage(&msg, (BHandler *)NULL, 2000000);
// 2 sec timeout
if (err) {
ERROR("Trouble terminating media_addon_server (2). Error %d (%s)\n", err, strerror(err));
ERROR("Trouble terminating media_addon_server (2). Error %d "
"(%s)\n", err, strerror(err));
}
}
@ -289,13 +295,19 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
switch (code) {
case SERVER_CHANGE_ADDON_FLAVOR_INSTANCES_COUNT:
{
const server_change_addon_flavor_instances_count_request *request = reinterpret_cast<const server_change_addon_flavor_instances_count_request *>(data);
const server_change_addon_flavor_instances_count_request *request
= reinterpret_cast<
const server_change_addon_flavor_instances_count_request *>(
data);
server_change_addon_flavor_instances_count_reply reply;
ASSERT(request->delta == 1 || request->delta == -1);
if (request->delta == 1)
rv = gNodeManager->IncrementAddonFlavorInstancesCount(request->addonid, request->flavorid, request->team);
else
rv = gNodeManager->DecrementAddonFlavorInstancesCount(request->addonid, request->flavorid, request->team);
if (request->delta == 1) {
rv = gNodeManager->IncrementAddonFlavorInstancesCount(
request->addonid, request->flavorid, request->team);
} else {
rv = gNodeManager->DecrementAddonFlavorInstancesCount(
request->addonid, request->flavorid, request->team);
}
request->SendReply(rv, &reply, sizeof(reply));
break;
}
@ -308,7 +320,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_REGISTER_APP:
{
const server_register_app_request *request = reinterpret_cast<const server_register_app_request *>(data);
const server_register_app_request *request
= reinterpret_cast<const server_register_app_request *>(data);
server_register_app_reply reply;
rv = gAppManager->RegisterTeam(request->team, request->messenger);
request->SendReply(rv, &reply, sizeof(reply));
@ -317,7 +330,9 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_UNREGISTER_APP:
{
const server_unregister_app_request *request = reinterpret_cast<const server_unregister_app_request *>(data);
const server_unregister_app_request *request
= reinterpret_cast<const server_unregister_app_request *>(
data);
server_unregister_app_reply reply;
rv = gAppManager->UnregisterTeam(request->team);
request->SendReply(rv, &reply, sizeof(reply));
@ -326,7 +341,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_MEDIAADDON_REF:
{
server_get_mediaaddon_ref_request *msg = (server_get_mediaaddon_ref_request *)data;
server_get_mediaaddon_ref_request *msg
= (server_get_mediaaddon_ref_request *)data;
server_get_mediaaddon_ref_reply reply;
entry_ref tempref;
reply.result = gNodeManager->GetAddonRef(&tempref, msg->addonid);
@ -337,7 +353,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_NODE_ID_FOR:
{
const server_node_id_for_request *request = reinterpret_cast<const server_node_id_for_request *>(data);
const server_node_id_for_request *request
= reinterpret_cast<const server_node_id_for_request *>(data);
server_node_id_for_reply reply;
rv = gNodeManager->FindNodeId(&reply.nodeid, request->port);
request->SendReply(rv, &reply, sizeof(reply));
@ -346,16 +363,21 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_LIVE_NODE_INFO:
{
const server_get_live_node_info_request *request = reinterpret_cast<const server_get_live_node_info_request *>(data);
const server_get_live_node_info_request *request
= reinterpret_cast<const server_get_live_node_info_request *>(
data);
server_get_live_node_info_reply reply;
rv = gNodeManager->GetLiveNodeInfo(&reply.live_info, request->node);
rv = gNodeManager->GetLiveNodeInfo(&reply.live_info,
request->node);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_GET_LIVE_NODES:
{
const server_get_live_nodes_request *request = reinterpret_cast<const server_get_live_nodes_request *>(data);
const server_get_live_nodes_request *request
= reinterpret_cast<const server_get_live_nodes_request *>(
data);
server_get_live_nodes_reply reply;
Stack<live_node_info> livenodes;
rv = gNodeManager->GetLiveNodes(
@ -371,13 +393,18 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
livenodes.Pop(&reply.live_info[index]);
reply.area = -1;
} else {
// we create an area here, and pass it to the library, where it will be deleted.
// we create an area here, and pass it to the library,
// where it will be deleted.
live_node_info *start_addr;
size_t size;
size = ((reply.count * sizeof(live_node_info)) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("get live nodes", reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
size = ((reply.count * sizeof(live_node_info)) + B_PAGE_SIZE
- 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("get live nodes",
reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS,
size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (reply.area < B_OK) {
ERROR("SERVER_GET_LIVE_NODES: failed to create area, error %#lx\n", reply.area);
ERROR("SERVER_GET_LIVE_NODES: failed to create area, "
"error %#lx\n", reply.area);
reply.count = 0;
rv = B_ERROR;
} else {
@ -386,23 +413,28 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
}
}
rv = request->SendReply(rv, &reply, sizeof(reply));
if (rv != B_OK)
delete_area(reply.area); // if we couldn't send the message, delete the area
if (rv != B_OK) {
// if we couldn't send the message, delete the area
delete_area(reply.area);
}
break;
}
case SERVER_GET_NODE_FOR:
{
const server_get_node_for_request *request = reinterpret_cast<const server_get_node_for_request *>(data);
const server_get_node_for_request *request
= reinterpret_cast<const server_get_node_for_request *>(data);
server_get_node_for_reply reply;
rv = gNodeManager->GetCloneForId(&reply.clone, request->nodeid, request->team);
rv = gNodeManager->GetCloneForId(&reply.clone, request->nodeid,
request->team);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_RELEASE_NODE:
{
const server_release_node_request *request = reinterpret_cast<const server_release_node_request *>(data);
const server_release_node_request *request
= reinterpret_cast<const server_release_node_request *>(data);
server_release_node_reply reply;
rv = gNodeManager->ReleaseNode(request->node, request->team);
request->SendReply(rv, &reply, sizeof(reply));
@ -411,37 +443,50 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_REGISTER_NODE:
{
const server_register_node_request *request = reinterpret_cast<const server_register_node_request *>(data);
const server_register_node_request *request
= reinterpret_cast<const server_register_node_request *>(data);
server_register_node_reply reply;
rv = gNodeManager->RegisterNode(&reply.nodeid, request->addon_id, request->addon_flavor_id, request->name, request->kinds, request->port, request->team);
rv = gNodeManager->RegisterNode(&reply.nodeid, request->addon_id,
request->addon_flavor_id, request->name, request->kinds,
request->port, request->team);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_UNREGISTER_NODE:
{
const server_unregister_node_request *request = reinterpret_cast<const server_unregister_node_request *>(data);
const server_unregister_node_request *request
= reinterpret_cast<const server_unregister_node_request *>(
data);
server_unregister_node_reply reply;
rv = gNodeManager->UnregisterNode(&reply.addonid, &reply.flavorid, request->nodeid, request->team);
rv = gNodeManager->UnregisterNode(&reply.addonid, &reply.flavorid,
request->nodeid, request->team);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_PUBLISH_INPUTS:
{
const server_publish_inputs_request *request = reinterpret_cast<const server_publish_inputs_request *>(data);
const server_publish_inputs_request *request
= reinterpret_cast<const server_publish_inputs_request *>(
data);
server_publish_inputs_reply reply;
if (request->count <= MAX_INPUTS) {
rv = gNodeManager->PublishInputs(request->node, request->inputs, request->count);
rv = gNodeManager->PublishInputs(request->node,
request->inputs, request->count);
} else {
media_input *inputs;
area_id clone;
clone = clone_area("media_inputs clone", reinterpret_cast<void **>(&inputs), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area);
clone = clone_area("media_inputs clone",
reinterpret_cast<void **>(&inputs), B_ANY_ADDRESS,
B_READ_AREA | B_WRITE_AREA, request->area);
if (clone < B_OK) {
ERROR("SERVER_PUBLISH_INPUTS: failed to clone area, error %#lx\n", clone);
ERROR("SERVER_PUBLISH_INPUTS: failed to clone area, "
"error %#lx\n", clone);
rv = B_ERROR;
} else {
rv = gNodeManager->PublishInputs(request->node, inputs, request->count);
rv = gNodeManager->PublishInputs(request->node, inputs,
request->count);
delete_area(clone);
}
}
@ -451,19 +496,24 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_PUBLISH_OUTPUTS:
{
const server_publish_outputs_request *request = reinterpret_cast<const server_publish_outputs_request *>(data);
const server_publish_outputs_request *request
= reinterpret_cast<const server_publish_outputs_request *>(
data);
server_publish_outputs_reply reply;
if (request->count <= MAX_OUTPUTS) {
rv = gNodeManager->PublishOutputs(request->node, request->outputs, request->count);
rv = gNodeManager->PublishOutputs(request->node,
request->outputs, request->count);
} else {
media_output *outputs;
area_id clone;
clone = clone_area("media_outputs clone", reinterpret_cast<void **>(&outputs), B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area);
if (clone < B_OK) {
ERROR("SERVER_PUBLISH_OUTPUTS: failed to clone area, error %#lx\n", clone);
ERROR("SERVER_PUBLISH_OUTPUTS: failed to clone area, "
"error %#lx\n", clone);
rv = B_ERROR;
} else {
rv = gNodeManager->PublishOutputs(request->node, outputs, request->count);
rv = gNodeManager->PublishOutputs(request->node, outputs,
request->count);
delete_area(clone);
}
}
@ -473,38 +523,54 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_NODE:
{
const server_get_node_request *request = reinterpret_cast<const server_get_node_request *>(data);
const server_get_node_request *request
= reinterpret_cast<const server_get_node_request *>(data);
server_get_node_reply reply;
rv = gNodeManager->GetClone(&reply.node, reply.input_name, &reply.input_id, request->type, request->team);
rv = gNodeManager->GetClone(&reply.node, reply.input_name,
&reply.input_id, request->type, request->team);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_SET_NODE:
{
const server_set_node_request *request = reinterpret_cast<const server_set_node_request *>(data);
const server_set_node_request *request
= reinterpret_cast<const server_set_node_request *>(data);
server_set_node_reply reply;
rv = gNodeManager->SetDefaultNode(request->type, request->use_node ? &request->node : NULL, request->use_dni ? &request->dni : NULL, request->use_input ? &request->input : NULL);
rv = gNodeManager->SetDefaultNode(request->type,
request->use_node ? &request->node : NULL,
request->use_dni ? &request->dni : NULL,
request->use_input ? &request->input : NULL);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_GET_DORMANT_NODE_FOR:
{
const server_get_dormant_node_for_request *request = reinterpret_cast<const server_get_dormant_node_for_request *>(data);
const server_get_dormant_node_for_request *request
= reinterpret_cast<
const server_get_dormant_node_for_request *>(data);
server_get_dormant_node_for_reply reply;
rv = gNodeManager->GetDormantNodeInfo(&reply.node_info, request->node);
rv = gNodeManager->GetDormantNodeInfo(&reply.node_info,
request->node);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_GET_INSTANCES_FOR:
{
const server_get_instances_for_request *request = reinterpret_cast<const server_get_instances_for_request *>(data);
const server_get_instances_for_request *request
= reinterpret_cast<const server_get_instances_for_request *>(
data);
server_get_instances_for_reply reply;
rv = gNodeManager->GetInstances(reply.node_id, &reply.count, min_c(request->maxcount, MAX_NODE_ID), request->addon_id, request->addon_flavor_id);
if (reply.count == MAX_NODE_ID && request->maxcount > MAX_NODE_ID) { // XXX might be fixed by using an area
PRINT(1, "Warning: SERVER_GET_INSTANCES_FOR: returning possibly truncated list of node id's\n");
rv = gNodeManager->GetInstances(reply.node_id, &reply.count,
min_c(request->maxcount, MAX_NODE_ID), request->addon_id,
request->addon_flavor_id);
if (reply.count == MAX_NODE_ID
&& request->maxcount > MAX_NODE_ID) {
// XXX might be fixed by using an area
PRINT(1, "Warning: SERVER_GET_INSTANCES_FOR: returning "
"possibly truncated list of node id's\n");
}
request->SendReply(rv, &reply, sizeof(reply));
break;
@ -512,7 +578,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_REGISTER_MEDIAADDON:
{
server_register_mediaaddon_request *msg = (server_register_mediaaddon_request *)data;
server_register_mediaaddon_request *msg
= (server_register_mediaaddon_request *)data;
server_register_mediaaddon_reply reply;
gNodeManager->RegisterAddon(msg->ref, &reply.addonid);
write_port(msg->reply_port, 0, &reply, sizeof(reply));
@ -521,14 +588,16 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_UNREGISTER_MEDIAADDON:
{
server_unregister_mediaaddon_command *msg = (server_unregister_mediaaddon_command *)data;
server_unregister_mediaaddon_command *msg
= (server_unregister_mediaaddon_command *)data;
gNodeManager->UnregisterAddon(msg->addonid);
break;
}
case SERVER_REGISTER_DORMANT_NODE:
{
xfer_server_register_dormant_node *msg = (xfer_server_register_dormant_node *)data;
xfer_server_register_dormant_node *msg
= (xfer_server_register_dormant_node *)data;
dormant_flavor_info dfi;
if (msg->purge_id > 0)
gNodeManager->InvalidateDormantFlavorInfo(msg->purge_id);
@ -540,7 +609,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_DORMANT_NODES:
{
xfer_server_get_dormant_nodes *msg = (xfer_server_get_dormant_nodes *)data;
xfer_server_get_dormant_nodes *msg
= (xfer_server_get_dormant_nodes *)data;
xfer_server_get_dormant_nodes_reply reply;
dormant_node_info * infos = new dormant_node_info[msg->maxcount];
reply.count = msg->maxcount;
@ -556,18 +626,21 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
reply.count = 0;
write_port(msg->reply_port, 0, &reply, sizeof(reply));
if (reply.count > 0)
write_port(msg->reply_port, 0, infos, reply.count * sizeof(dormant_node_info));
write_port(msg->reply_port, 0, infos, reply.count
* sizeof(dormant_node_info));
delete [] infos;
break;
}
case SERVER_GET_DORMANT_FLAVOR_INFO:
{
xfer_server_get_dormant_flavor_info *msg = (xfer_server_get_dormant_flavor_info *)data;
xfer_server_get_dormant_flavor_info *msg
= (xfer_server_get_dormant_flavor_info *)data;
dormant_flavor_info dfi;
status_t rv;
rv = gNodeManager->GetDormantFlavorInfoFor(msg->addon, msg->flavor_id, &dfi);
rv = gNodeManager->GetDormantFlavorInfoFor(msg->addon,
msg->flavor_id, &dfi);
if (rv != B_OK) {
xfer_server_get_dormant_flavor_info_reply reply;
reply.result = rv;
@ -575,8 +648,10 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
} else {
xfer_server_get_dormant_flavor_info_reply *reply;
int replysize;
replysize = sizeof(xfer_server_get_dormant_flavor_info_reply) + dfi.FlattenedSize();
reply = (xfer_server_get_dormant_flavor_info_reply *)malloc(replysize);
replysize = sizeof(xfer_server_get_dormant_flavor_info_reply)
+ dfi.FlattenedSize();
reply = (xfer_server_get_dormant_flavor_info_reply *)malloc(
replysize);
reply->dfi_size = dfi.FlattenedSize();
reply->dfi_type = dfi.TypeCode();
@ -589,7 +664,9 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_SET_NODE_CREATOR:
{
const server_set_node_creator_request *request = reinterpret_cast<const server_set_node_creator_request *>(data);
const server_set_node_creator_request *request
= reinterpret_cast<const server_set_node_creator_request *>(
data);
server_set_node_creator_reply reply;
rv = gNodeManager->SetNodeCreator(request->node, request->creator);
request->SendReply(rv, &reply, sizeof(reply));
@ -598,7 +675,9 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_SHARED_BUFFER_AREA:
{
const server_get_shared_buffer_area_request *request = reinterpret_cast<const server_get_shared_buffer_area_request *>(data);
const server_get_shared_buffer_area_request *request
= reinterpret_cast<
const server_get_shared_buffer_area_request *>(data);
server_get_shared_buffer_area_reply reply;
reply.area = gBufferManager->SharedBufferListID();
@ -608,16 +687,24 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_REGISTER_BUFFER:
{
const server_register_buffer_request *request = reinterpret_cast<const server_register_buffer_request *>(data);
const server_register_buffer_request *request
= reinterpret_cast<const server_register_buffer_request *>(
data);
server_register_buffer_reply reply;
status_t status;
if (request->info.buffer == 0) {
reply.info = request->info; //size, offset, flags, area is kept
reply.info = request->info;
// size, offset, flags, area is kept
// get a new beuffer id into reply.info.buffer
status = gBufferManager->RegisterBuffer(request->team, request->info.size, request->info.flags, request->info.offset, request->info.area, &reply.info.buffer);
status = gBufferManager->RegisterBuffer(request->team,
request->info.size, request->info.flags,
request->info.offset, request->info.area,
&reply.info.buffer);
} else {
reply.info = request->info; //buffer id is kept
status = gBufferManager->RegisterBuffer(request->team, request->info.buffer, &reply.info.size, &reply.info.flags, &reply.info.offset, &reply.info.area);
status = gBufferManager->RegisterBuffer(request->team,
request->info.buffer, &reply.info.size, &reply.info.flags,
&reply.info.offset, &reply.info.area);
}
request->SendReply(status, &reply, sizeof(reply));
break;
@ -625,7 +712,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_UNREGISTER_BUFFER:
{
const server_unregister_buffer_command *cmd = reinterpret_cast<const server_unregister_buffer_command *>(data);
const server_unregister_buffer_command *cmd = reinterpret_cast<
const server_unregister_buffer_command *>(data);
gBufferManager->UnregisterBuffer(cmd->team, cmd->bufferid);
break;
@ -633,7 +721,8 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_REWINDTYPES:
{
const server_rewindtypes_request *request = reinterpret_cast<const server_rewindtypes_request *>(data);
const server_rewindtypes_request *request
= reinterpret_cast<const server_rewindtypes_request *>(data);
server_rewindtypes_reply reply;
BString **types = NULL;
@ -641,99 +730,125 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
rv = gMMediaFilesManager->RewindTypes(
&types, &reply.count);
if(reply.count>0) {
// we create an area here, and pass it to the library, where it will be deleted.
// we create an area here, and pass it to the library,
// where it will be deleted.
char *start_addr;
size_t size = ((reply.count * B_MEDIA_NAME_LENGTH) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("rewind types", reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
size_t size = ((reply.count * B_MEDIA_NAME_LENGTH)
+ B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("rewind types",
reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS,
size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (reply.area < B_OK) {
ERROR("SERVER_REWINDTYPES: failed to create area, error %s\n", strerror(reply.area));
ERROR("SERVER_REWINDTYPES: failed to create area, "
"error %s\n", strerror(reply.area));
reply.count = 0;
rv = B_ERROR;
} else {
for (int32 index = 0; index < reply.count; index++)
strncpy(start_addr + B_MEDIA_NAME_LENGTH * index, types[index]->String(), B_MEDIA_NAME_LENGTH);
for (int32 index = 0; index < reply.count; index++) {
strncpy(start_addr + B_MEDIA_NAME_LENGTH * index,
types[index]->String(), B_MEDIA_NAME_LENGTH);
}
}
}
delete types;
rv = request->SendReply(rv, &reply, sizeof(reply));
if (rv != B_OK)
delete_area(reply.area); // if we couldn't send the message, delete the area
if (rv != B_OK) {
// if we couldn't send the message, delete the area
delete_area(reply.area);
}
break;
}
case SERVER_REWINDREFS:
{
const server_rewindrefs_request *request = reinterpret_cast<const server_rewindrefs_request *>(data);
const server_rewindrefs_request *request
= reinterpret_cast<const server_rewindrefs_request *>(data);
server_rewindrefs_reply reply;
BString **items = NULL;
rv = gMMediaFilesManager->RewindRefs(request->type,
&items, &reply.count);
// we create an area here, and pass it to the library, where it will be deleted.
// we create an area here, and pass it to the library,
// where it will be deleted.
if(reply.count>0) {
char *start_addr;
size_t size = ((reply.count * B_MEDIA_NAME_LENGTH) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("rewind refs", reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS, size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
size_t size = ((reply.count * B_MEDIA_NAME_LENGTH)
+ B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
reply.area = create_area("rewind refs",
reinterpret_cast<void **>(&start_addr), B_ANY_ADDRESS,
size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
if (reply.area < B_OK) {
ERROR("SERVER_REWINDREFS: failed to create area, error %s\n", strerror(reply.area));
ERROR("SERVER_REWINDREFS: failed to create area, "
"error %s\n", strerror(reply.area));
reply.count = 0;
rv = B_ERROR;
} else {
for (int32 index = 0; index < reply.count; index++)
strncpy(start_addr + B_MEDIA_NAME_LENGTH * index, items[index]->String(), B_MEDIA_NAME_LENGTH);
for (int32 index = 0; index < reply.count; index++) {
strncpy(start_addr + B_MEDIA_NAME_LENGTH * index,
items[index]->String(), B_MEDIA_NAME_LENGTH);
}
}
}
delete items;
rv = request->SendReply(rv, &reply, sizeof(reply));
if (rv != B_OK)
delete_area(reply.area); // if we couldn't send the message, delete the area
if (rv != B_OK) {
// if we couldn't send the message, delete the area
delete_area(reply.area);
}
break;
}
case SERVER_GETREFFOR:
{
const server_getreffor_request *request = reinterpret_cast<const server_getreffor_request *>(data);
const server_getreffor_request *request
= reinterpret_cast<const server_getreffor_request *>(data);
server_getreffor_reply reply;
entry_ref *ref;
rv = gMMediaFilesManager->GetRefFor(request->type, request->item, &ref);
if(rv==B_OK) {
rv = gMMediaFilesManager->GetRefFor(request->type, request->item,
&ref);
if (rv == B_OK)
reply.ref = *ref;
}
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_SETREFFOR:
{
const server_setreffor_request *request = reinterpret_cast<const server_setreffor_request *>(data);
const server_setreffor_request *request
= reinterpret_cast<const server_setreffor_request *>(data);
server_setreffor_reply reply;
entry_ref ref = request->ref;
rv = gMMediaFilesManager->SetRefFor(request->type, request->item, ref);
rv = gMMediaFilesManager->SetRefFor(request->type, request->item,
ref);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_REMOVEREFFOR:
{
const server_removereffor_request *request = reinterpret_cast<const server_removereffor_request *>(data);
const server_removereffor_request *request
= reinterpret_cast<const server_removereffor_request *>(data);
server_removereffor_reply reply;
entry_ref ref = request->ref;
rv = gMMediaFilesManager->RemoveRefFor(request->type, request->item, ref);
rv = gMMediaFilesManager->RemoveRefFor(request->type,
request->item, ref);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_REMOVEITEM:
{
const server_removeitem_request *request = reinterpret_cast<const server_removeitem_request *>(data);
const server_removeitem_request *request
= reinterpret_cast<const server_removeitem_request *>(data);
server_removeitem_reply reply;
rv = gMMediaFilesManager->RemoveItem(request->type, request->item);
@ -743,24 +858,30 @@ ServerApp::HandleMessage(int32 code, void *data, size_t size)
case SERVER_GET_READERS:
{
const server_get_readers_request *request = reinterpret_cast<const server_get_readers_request *>(data);
const server_get_readers_request *request
= reinterpret_cast<const server_get_readers_request *>(data);
server_get_readers_reply reply;
rv = gAddOnManager->GetReaders(reply.ref, &reply.count, MAX_READERS);
rv = gAddOnManager->GetReaders(reply.ref, &reply.count,
MAX_READERS);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
case SERVER_GET_DECODER_FOR_FORMAT:
{
const server_get_decoder_for_format_request *request = reinterpret_cast<const server_get_decoder_for_format_request *>(data);
const server_get_decoder_for_format_request *request
= reinterpret_cast<
const server_get_decoder_for_format_request *>(data);
server_get_decoder_for_format_reply reply;
rv = gAddOnManager->GetDecoderForFormat(&reply.ref, request->format);
rv = gAddOnManager->GetDecoderForFormat(&reply.ref,
request->format);
request->SendReply(rv, &reply, sizeof(reply));
break;
}
default:
printf("media_server: received unknown message code %#08lx\n",code);
printf("media_server: received unknown message code %#08lx\n",
code);
}
TRACE("ServerApp::HandleMessage %#lx leave\n", code);
}
@ -774,8 +895,10 @@ ServerApp::controlthread(void *arg)
int32 code;
app = (ServerApp *)arg;
while ((size = read_port_etc(app->control_port, &code, data, sizeof(data), 0, 0)) > 0)
while ((size = read_port_etc(app->control_port, &code, data, sizeof(data),
0, 0)) > 0) {
app->HandleMessage(code, data, size);
}
return 0;
}