* 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:
@@ -37,9 +37,9 @@ status_t QueryPort(port_id requestPort, int32 msgCode, request_data* request,
|
|||||||
size_t requestSize, reply_data* reply, size_t replySize);
|
size_t requestSize, reply_data* reply, size_t replySize);
|
||||||
|
|
||||||
|
|
||||||
} // namespace dataexchange
|
} // namespace dataexchange
|
||||||
} // namespace media
|
} // namespace media
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate::media::dataexchange;
|
using namespace BPrivate::media::dataexchange;
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009, Axel Dörfler, [email protected].
|
|
||||||
* 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
|
|
||||||
@@ -154,6 +154,10 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
namespace media {
|
||||||
|
|
||||||
|
|
||||||
struct reply_data;
|
struct reply_data;
|
||||||
struct request_data;
|
struct request_data;
|
||||||
struct command_data;
|
struct command_data;
|
||||||
@@ -163,6 +167,9 @@ struct command_data;
|
|||||||
struct request_data {
|
struct request_data {
|
||||||
port_id reply_port;
|
port_id reply_port;
|
||||||
|
|
||||||
|
request_data();
|
||||||
|
~request_data();
|
||||||
|
|
||||||
status_t SendReply(status_t result, reply_data* reply,
|
status_t SendReply(status_t result, reply_data* reply,
|
||||||
size_t replySize) const;
|
size_t replySize) const;
|
||||||
};
|
};
|
||||||
@@ -236,6 +243,12 @@ private:
|
|||||||
char name[B_FILE_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace media
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
using namespace BPrivate::media;
|
||||||
|
|
||||||
// used by SERVER_GET_NODE and SERVER_SET_NODE
|
// used by SERVER_GET_NODE and SERVER_SET_NODE
|
||||||
enum node_type {
|
enum node_type {
|
||||||
VIDEO_INPUT,
|
VIDEO_INPUT,
|
||||||
|
|||||||
@@ -12,10 +12,8 @@
|
|||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
#include "debug.h"
|
#include <debug.h>
|
||||||
#include "PortPool.h"
|
#include <MediaMisc.h>
|
||||||
#include "MediaMisc.h"
|
|
||||||
#include "ServerInterface.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define TIMEOUT 15000000 // 15 seconds timeout!
|
#define TIMEOUT 15000000 // 15 seconds timeout!
|
||||||
@@ -79,15 +77,7 @@ find_media_addon_server_port()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
// #pragma mark -
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//! BMessage based data exchange with the media_server
|
//! BMessage based data exchange with the media_server
|
||||||
@@ -186,9 +176,6 @@ status_t
|
|||||||
QueryPort(port_id requestPort, int32 msgCode, request_data* request,
|
QueryPort(port_id requestPort, int32 msgCode, request_data* request,
|
||||||
size_t requestSize, reply_data* reply, size_t replySize)
|
size_t requestSize, reply_data* reply, size_t replySize)
|
||||||
{
|
{
|
||||||
|
|
||||||
request->reply_port = gPortPool->GetPort();
|
|
||||||
|
|
||||||
status_t status = write_port_etc(requestPort, msgCode, request, requestSize,
|
status_t status = write_port_etc(requestPort, msgCode, request, requestSize,
|
||||||
B_RELATIVE_TIMEOUT, TIMEOUT);
|
B_RELATIVE_TIMEOUT, TIMEOUT);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
@@ -202,17 +189,14 @@ QueryPort(port_id requestPort, int32 msgCode, request_data* request,
|
|||||||
&& requestPort == sMediaAddonServerPort) {
|
&& requestPort == sMediaAddonServerPort) {
|
||||||
find_media_addon_server_port();
|
find_media_addon_server_port();
|
||||||
requestPort = sMediaAddonServerPort;
|
requestPort = sMediaAddonServerPort;
|
||||||
} else {
|
} else
|
||||||
gPortPool->PutPort(request->reply_port);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
status = write_port_etc(requestPort, msgCode, request, requestSize,
|
status = write_port_etc(requestPort, msgCode, request, requestSize,
|
||||||
B_RELATIVE_TIMEOUT, TIMEOUT);
|
B_RELATIVE_TIMEOUT, TIMEOUT);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
ERROR("QueryPort: retrying write_port failed, msgcode 0x%lx, port "
|
ERROR("QueryPort: retrying write_port failed, msgcode 0x%lx, port "
|
||||||
"%ld: %s\n", msgCode, requestPort, strerror(status));
|
"%ld: %s\n", msgCode, requestPort, strerror(status));
|
||||||
gPortPool->PutPort(request->reply_port);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,9 +204,6 @@ QueryPort(port_id requestPort, int32 msgCode, request_data* request,
|
|||||||
int32 code;
|
int32 code;
|
||||||
status = read_port_etc(request->reply_port, &code, reply, replySize,
|
status = read_port_etc(request->reply_port, &code, reply, replySize,
|
||||||
B_RELATIVE_TIMEOUT, TIMEOUT);
|
B_RELATIVE_TIMEOUT, TIMEOUT);
|
||||||
|
|
||||||
gPortPool->PutPort(request->reply_port);
|
|
||||||
|
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
ERROR("QueryPort: read_port failed, msgcode 0x%lx, port %ld: %s\n",
|
ERROR("QueryPort: read_port failed, msgcode 0x%lx, port %ld: %s\n",
|
||||||
msgCode, request->reply_port, strerror(status));
|
msgCode, request->reply_port, strerror(status));
|
||||||
|
|||||||
@@ -57,7 +57,6 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <PortPool.h>
|
|
||||||
#include <MediaMisc.h>
|
#include <MediaMisc.h>
|
||||||
#include <ServerInterface.h>
|
#include <ServerInterface.h>
|
||||||
#include <DataExchange.h>
|
#include <DataExchange.h>
|
||||||
@@ -197,7 +196,6 @@ DormantNodeManager::RegisterAddOn(const char* path)
|
|||||||
{
|
{
|
||||||
TRACE("DormantNodeManager::RegisterAddon, path %s\n",path);
|
TRACE("DormantNodeManager::RegisterAddon, path %s\n",path);
|
||||||
|
|
||||||
server_register_add_on_request msg;
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
status_t status = get_ref_for_path(path, &ref);
|
status_t status = get_ref_for_path(path, &ref);
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
@@ -206,30 +204,18 @@ DormantNodeManager::RegisterAddOn(const char* path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
port_id port = find_port(MEDIA_SERVER_PORT_NAME);
|
server_register_add_on_request request;
|
||||||
if (port < 0) {
|
request.ref = ref;
|
||||||
ERROR("DormantNodeManager::RegisterAddon failed, couldn't find media "
|
|
||||||
"server\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.reply_port = gPortPool->GetPort();
|
server_register_add_on_reply reply;
|
||||||
msg.ref = ref;
|
status = QueryServer(SERVER_REGISTER_ADD_ON, &request, sizeof(request),
|
||||||
|
&reply, sizeof(reply));
|
||||||
status = write_port(port, SERVER_REGISTER_ADD_ON, &msg, sizeof(msg));
|
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
gPortPool->PutPort(msg.reply_port);
|
|
||||||
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
|
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
|
||||||
"media server\n");
|
"media server\n");
|
||||||
return 0;
|
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) {
|
if (status < B_OK) {
|
||||||
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
|
ERROR("DormantNodeManager::RegisterAddon failed, couldn't talk to "
|
||||||
"media server: %s\n", strerror(status));
|
"media server: %s\n", strerror(status));
|
||||||
@@ -263,27 +249,13 @@ DormantNodeManager::UnregisterAddOn(media_addon_id id)
|
|||||||
status_t
|
status_t
|
||||||
DormantNodeManager::FindAddOnPath(BPath* path, media_addon_id id)
|
DormantNodeManager::FindAddOnPath(BPath* path, media_addon_id id)
|
||||||
{
|
{
|
||||||
port_id port = find_port(MEDIA_SERVER_PORT_NAME);
|
server_get_add_on_ref_request request;
|
||||||
if (port < 0)
|
request.add_on_id = id;
|
||||||
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_reply reply;
|
server_get_add_on_ref_reply reply;
|
||||||
int32 code;
|
status_t status = QueryServer(SERVER_GET_ADD_ON_REF, &request,
|
||||||
status = read_port(msg.reply_port, &code, &reply, sizeof(reply));
|
sizeof(request), &reply, sizeof(reply));
|
||||||
|
if (status != B_OK)
|
||||||
gPortPool->PutPort(msg.reply_port);
|
|
||||||
|
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
entry_ref ref = reply.ref;
|
entry_ref ref = reply.ref;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ SharedLibrary libmedia.so :
|
|||||||
DefaultMediaTheme.cpp
|
DefaultMediaTheme.cpp
|
||||||
DormantNodeManager.cpp
|
DormantNodeManager.cpp
|
||||||
Notifications.cpp
|
Notifications.cpp
|
||||||
PortPool.cpp
|
request_data.cpp
|
||||||
SharedBufferList.cpp
|
SharedBufferList.cpp
|
||||||
TrackReader.cpp
|
TrackReader.cpp
|
||||||
TimedEventQueuePrivate.cpp
|
TimedEventQueuePrivate.cpp
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ char __dont_remove_copyright_from_binary[] = "Copyright (c) 2002-2006 Marcus "
|
|||||||
#include <MediaRosterEx.h>
|
#include <MediaRosterEx.h>
|
||||||
#include <MediaMisc.h>
|
#include <MediaMisc.h>
|
||||||
#include <Notifications.h>
|
#include <Notifications.h>
|
||||||
#include <PortPool.h>
|
|
||||||
#include <ServerInterface.h>
|
#include <ServerInterface.h>
|
||||||
#include <SharedBufferList.h>
|
#include <SharedBufferList.h>
|
||||||
|
|
||||||
@@ -1369,22 +1368,19 @@ BMediaRoster::SetProducerRate(const media_node& producer, int32 numer,
|
|||||||
if ((producer.kind & B_BUFFER_PRODUCER) == 0)
|
if ((producer.kind & B_BUFFER_PRODUCER) == 0)
|
||||||
return B_MEDIA_BAD_NODE;
|
return B_MEDIA_BAD_NODE;
|
||||||
|
|
||||||
producer_set_play_rate_request msg;
|
producer_set_play_rate_request request;
|
||||||
producer_set_play_rate_reply reply;
|
request.numer = numer;
|
||||||
status_t rv;
|
request.denom = denom;
|
||||||
int32 code;
|
status_t status = write_port(producer.node, PRODUCER_SET_PLAY_RATE,
|
||||||
|
&request, sizeof(request));
|
||||||
|
if (status != B_OK)
|
||||||
|
return status;
|
||||||
|
|
||||||
msg.numer = numer;
|
producer_set_play_rate_reply reply;
|
||||||
msg.denom = denom;
|
int32 code;
|
||||||
msg.reply_port = gPortPool->GetPort();
|
status = read_port(request.reply_port, &code, &reply, sizeof(reply));
|
||||||
rv = write_port(producer.node, PRODUCER_SET_PLAY_RATE, &msg, sizeof(msg));
|
|
||||||
if (rv != B_OK) {
|
return status < B_OK ? status : reply.result;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2268,15 +2264,12 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count,
|
|||||||
|
|
||||||
request.require_kinds = requireKinds;
|
request.require_kinds = requireKinds;
|
||||||
request.deny_kinds = denyKinds;
|
request.deny_kinds = denyKinds;
|
||||||
request.reply_port = gPortPool->GetPort();
|
|
||||||
|
|
||||||
server_get_dormant_nodes_reply reply;
|
server_get_dormant_nodes_reply reply;
|
||||||
status_t status = QueryServer(SERVER_GET_DORMANT_NODES, &request,
|
status_t status = QueryServer(SERVER_GET_DORMANT_NODES, &request,
|
||||||
sizeof(request), &reply, sizeof(reply));
|
sizeof(request), &reply, sizeof(reply));
|
||||||
if (status != B_OK) {
|
if (status != B_OK)
|
||||||
gPortPool->PutPort(request.reply_port);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
*_count = reply.count;
|
*_count = reply.count;
|
||||||
|
|
||||||
@@ -2287,7 +2280,6 @@ BMediaRoster::GetDormantNodes(dormant_node_info* _info, int32* _count,
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
reply.result = status;
|
reply.result = status;
|
||||||
}
|
}
|
||||||
gPortPool->PutPort(request.reply_port);
|
|
||||||
|
|
||||||
return reply.result;
|
return reply.result;
|
||||||
}
|
}
|
||||||
@@ -2587,13 +2579,9 @@ BMediaRosterEx::GetDormantFlavorInfo(media_addon_id addonID, int32 flavorID,
|
|||||||
server_get_dormant_flavor_info_request request;
|
server_get_dormant_flavor_info_request request;
|
||||||
request.add_on_id = addonID;
|
request.add_on_id = addonID;
|
||||||
request.flavor_id = flavorID;
|
request.flavor_id = flavorID;
|
||||||
request.reply_port = gPortPool->GetPort();
|
|
||||||
|
|
||||||
status_t status = QueryServer(SERVER_GET_DORMANT_FLAVOR_INFO, &request,
|
status_t status = QueryServer(SERVER_GET_DORMANT_FLAVOR_INFO, &request,
|
||||||
sizeof(request), reply, 16300);
|
sizeof(request), reply, 16300);
|
||||||
|
|
||||||
gPortPool->PutPort(request.reply_port);
|
|
||||||
|
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
free(reply);
|
free(reply);
|
||||||
return status;
|
return status;
|
||||||
|
|||||||
@@ -4,18 +4,37 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <PortPool.h>
|
#include <ServerInterface.h>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
|
#include <Locker.h>
|
||||||
|
|
||||||
|
#include <DataExchange.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
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;
|
static PortPool sPortPool;
|
||||||
PortPool* gPortPool = &sPortPool;
|
|
||||||
|
|
||||||
|
|
||||||
PortPool::PortPool()
|
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
|
} // namespace BPrivate
|
||||||
Reference in New Issue
Block a user