* Moved the port pool into the new request_data.cpp file; it's no longer

accessible from the outside.
* Instead, request_data now retrieves/releases a reply port on its own.
* There were some more places that still used write_port()/read_port() instead
  of QueryServer().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34597 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-12-09 17:40:45 +00:00
parent e4c87231a3
commit 6cafce94b5
8 changed files with 92 additions and 133 deletions
+3 -3
View File
@@ -37,9 +37,9 @@ status_t QueryPort(port_id requestPort, int32 msgCode, request_data* request,
size_t requestSize, reply_data* reply, size_t replySize);
} // namespace dataexchange
} // namespace media
} // namespace BPrivate
} // namespace dataexchange
} // namespace media
} // namespace BPrivate
using namespace BPrivate::media::dataexchange;
-41
View File
@@ -1,41 +0,0 @@
/*
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
* Distributed under the terms of the MIT License.
*/
#ifndef PORT_POOL_H
#define PORT_POOL_H
#include <set>
#include <Locker.h>
namespace BPrivate {
class PortPool : BLocker {
public:
PortPool();
~PortPool();
port_id GetPort();
void PutPort(port_id port);
private:
typedef std::set<port_id> PortSet;
PortSet fPool;
};
extern PortPool* gPortPool;
} // namespace BPrivate
using BPrivate::gPortPool;
#endif // PORT_POOL_H
+13
View File
@@ -154,6 +154,10 @@ enum {
};
namespace BPrivate {
namespace media {
struct reply_data;
struct request_data;
struct command_data;
@@ -163,6 +167,9 @@ struct command_data;
struct request_data {
port_id reply_port;
request_data();
~request_data();
status_t SendReply(status_t result, reply_data* reply,
size_t replySize) const;
};
@@ -236,6 +243,12 @@ private:
char name[B_FILE_NAME_LENGTH];
};
} // namespace media
} // namespace BPrivate
using namespace BPrivate::media;
// used by SERVER_GET_NODE and SERVER_SET_NODE
enum node_type {
VIDEO_INPUT,
+4 -23
View File
@@ -12,10 +12,8 @@
#include <Messenger.h>
#include <OS.h>
#include "debug.h"
#include "PortPool.h"
#include "MediaMisc.h"
#include "ServerInterface.h"
#include <debug.h>
#include <MediaMisc.h>
#define TIMEOUT 15000000 // 15 seconds timeout!
@@ -79,15 +77,7 @@ find_media_addon_server_port()
}
status_t
request_data::SendReply(status_t result, reply_data *reply,
size_t replySize) const
{
reply->result = result;
// we cheat and use the (command_data *) version of SendToPort
return SendToPort(reply_port, 0, reinterpret_cast<command_data *>(reply),
replySize);
}
// #pragma mark -
//! BMessage based data exchange with the media_server
@@ -186,9 +176,6 @@ status_t
QueryPort(port_id requestPort, int32 msgCode, request_data* request,
size_t requestSize, reply_data* reply, size_t replySize)
{
request->reply_port = gPortPool->GetPort();
status_t status = write_port_etc(requestPort, msgCode, request, requestSize,
B_RELATIVE_TIMEOUT, TIMEOUT);
if (status != B_OK) {
@@ -202,17 +189,14 @@ QueryPort(port_id requestPort, int32 msgCode, request_data* request,
&& requestPort == sMediaAddonServerPort) {
find_media_addon_server_port();
requestPort = sMediaAddonServerPort;
} else {
gPortPool->PutPort(request->reply_port);
} else
return status;
}
status = write_port_etc(requestPort, msgCode, request, requestSize,
B_RELATIVE_TIMEOUT, TIMEOUT);
if (status != B_OK) {
ERROR("QueryPort: retrying write_port failed, msgcode 0x%lx, port "
"%ld: %s\n", msgCode, requestPort, strerror(status));
gPortPool->PutPort(request->reply_port);
return status;
}
}
@@ -220,9 +204,6 @@ QueryPort(port_id requestPort, int32 msgCode, request_data* request,
int32 code;
status = read_port_etc(request->reply_port, &code, reply, replySize,
B_RELATIVE_TIMEOUT, TIMEOUT);
gPortPool->PutPort(request->reply_port);
if (status < B_OK) {
ERROR("QueryPort: read_port failed, msgcode 0x%lx, port %ld: %s\n",
msgCode, request->reply_port, strerror(status));
+10 -38
View File
@@ -57,7 +57,6 @@
#include <Path.h>
#include <debug.h>
#include <PortPool.h>
#include <MediaMisc.h>
#include <ServerInterface.h>
#include <DataExchange.h>
@@ -197,7 +196,6 @@ DormantNodeManager::RegisterAddOn(const char* path)
{
TRACE("DormantNodeManager::RegisterAddon, path %s\n",path);
server_register_add_on_request msg;
entry_ref ref;
status_t status = get_ref_for_path(path, &ref);
if (status != B_OK) {
@@ -206,30 +204,18 @@ DormantNodeManager::RegisterAddOn(const char* path)
return 0;
}
port_id port = find_port(MEDIA_SERVER_PORT_NAME);
if (port < 0) {
ERROR("DormantNodeManager::RegisterAddon failed, couldn't find media "
"server\n");
return 0;
}
server_register_add_on_request request;
request.ref = ref;
msg.reply_port = gPortPool->GetPort();
msg.ref = ref;
status = write_port(port, SERVER_REGISTER_ADD_ON, &msg, sizeof(msg));
server_register_add_on_reply reply;
status = QueryServer(SERVER_REGISTER_ADD_ON, &request, sizeof(request),
&reply, sizeof(reply));
if (status != B_OK) {
gPortPool->PutPort(msg.reply_port);
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
"media server\n");
return 0;
}
server_register_add_on_reply reply;
int32 code;
status = read_port(msg.reply_port, &code, &reply, sizeof(reply));
gPortPool->PutPort(msg.reply_port);
if (status < B_OK) {
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
"media server: %s\n", strerror(status));
@@ -263,27 +249,13 @@ DormantNodeManager::UnregisterAddOn(media_addon_id id)
status_t
DormantNodeManager::FindAddOnPath(BPath* path, media_addon_id id)
{
port_id port = find_port(MEDIA_SERVER_PORT_NAME);
if (port < 0)
return B_ERROR;
server_get_add_on_ref_request msg;
msg.add_on_id = id;
msg.reply_port = gPortPool->GetPort();
status_t status = write_port(port, SERVER_GET_ADD_ON_REF, &msg,
sizeof(msg));
if (status != B_OK) {
gPortPool->PutPort(msg.reply_port);
return status;
}
server_get_add_on_ref_request request;
request.add_on_id = id;
server_get_add_on_ref_reply reply;
int32 code;
status = read_port(msg.reply_port, &code, &reply, sizeof(reply));
gPortPool->PutPort(msg.reply_port);
if (status < B_OK)
status_t status = QueryServer(SERVER_GET_ADD_ON_REF, &request,
sizeof(request), &reply, sizeof(reply));
if (status != B_OK)
return status;
entry_ref ref = reply.ref;
+1 -1
View File
@@ -52,7 +52,7 @@ SharedLibrary libmedia.so :
DefaultMediaTheme.cpp
DormantNodeManager.cpp
Notifications.cpp
PortPool.cpp
request_data.cpp
SharedBufferList.cpp
TrackReader.cpp
TimedEventQueuePrivate.cpp
+13 -25
View File
@@ -63,7 +63,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
#include <MediaRosterEx.h>
#include <MediaMisc.h>
#include <Notifications.h>
#include <PortPool.h>
#include <ServerInterface.h>
#include <SharedBufferList.h>
@@ -1369,22 +1368,19 @@ BMediaRoster::SetProducerRate(const media_node& producer, int32 numer,
if ((producer.kind & B_BUFFER_PRODUCER) == 0)
return B_MEDIA_BAD_NODE;
producer_set_play_rate_request msg;
producer_set_play_rate_reply reply;
status_t rv;
int32 code;
producer_set_play_rate_request request;
request.numer = numer;
request.denom = denom;
status_t status = write_port(producer.node, PRODUCER_SET_PLAY_RATE,
&request, sizeof(request));
if (status != B_OK)
return status;
msg.numer = numer;
msg.denom = denom;
msg.reply_port = gPortPool->GetPort();
rv = write_port(producer.node, PRODUCER_SET_PLAY_RATE, &msg, sizeof(msg));
if (rv != B_OK) {
gPortPool->PutPort(msg.reply_port);
return rv;
}
rv = read_port(msg.reply_port, &code, &reply, sizeof(reply));
gPortPool->PutPort(msg.reply_port);
return (rv < B_OK) ? rv : reply.result;
producer_set_play_rate_reply reply;
int32 code;
status = read_port(request.reply_port, &code, &reply, sizeof(reply));
return status < B_OK ? status : reply.result;
}
@@ -2268,15 +2264,12 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count,
request.require_kinds = requireKinds;
request.deny_kinds = denyKinds;
request.reply_port = gPortPool->GetPort();
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);
if (status != B_OK)
return status;
}
*_count = reply.count;
@@ -2287,7 +2280,6 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count,
if (status < B_OK)
reply.result = status;
}
gPortPool->PutPort(request.reply_port);
return reply.result;
}
@@ -2587,13 +2579,9 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonID, int32 flavorID,
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);
return status;
@@ -4,18 +4,37 @@
*/
#include <PortPool.h>
#include <ServerInterface.h>
#include <set>
#include <Autolock.h>
#include <Locker.h>
#include <DataExchange.h>
#include <debug.h>
namespace BPrivate {
namespace media {
class PortPool : BLocker {
public:
PortPool();
~PortPool();
port_id GetPort();
void PutPort(port_id port);
private:
typedef std::set<port_id> PortSet;
PortSet fPool;
};
static PortPool sPortPool;
PortPool* gPortPool = &sPortPool;
PortPool::PortPool()
@@ -65,4 +84,31 @@ PortPool::PutPort(port_id port)
}
// #pragma mark -
request_data::request_data()
{
reply_port = sPortPool.GetPort();
}
request_data::~request_data()
{
sPortPool.PutPort(reply_port);
}
status_t
request_data::SendReply(status_t result, reply_data *reply,
size_t replySize) const
{
reply->result = result;
// we cheat and use the (command_data *) version of SendToPort
return SendToPort(reply_port, 0, reinterpret_cast<command_data *>(reply),
replySize);
}
} // namespace media
} // namespace BPrivate