2002-10-02 05:04:48 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2002, Marcus Overhagen. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <OS.h>
|
2002-10-02 20:54:53 +04:00
|
|
|
#include <Messenger.h>
|
2002-10-08 04:26:45 +04:00
|
|
|
#include <string.h>
|
2002-10-02 20:54:53 +04:00
|
|
|
#include "debug.h"
|
|
|
|
#include "PortPool.h"
|
2002-10-02 05:04:48 +04:00
|
|
|
#include "DataExchange.h"
|
2002-10-02 20:54:53 +04:00
|
|
|
#include "ServerInterface.h" // NEW_MEDIA_SERVER_SIGNATURE
|
|
|
|
|
|
|
|
#define TIMEOUT 100000
|
2002-10-02 05:04:48 +04:00
|
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
team_id team;
|
|
|
|
|
|
|
|
namespace dataexchange {
|
|
|
|
|
2002-10-02 20:54:53 +04:00
|
|
|
BMessenger *MediaServerMessenger;
|
|
|
|
static port_id MediaServerPort;
|
|
|
|
static port_id MediaAddonServerPort;
|
|
|
|
|
|
|
|
class initit
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
initit()
|
|
|
|
{
|
|
|
|
MediaServerMessenger = new BMessenger(NEW_MEDIA_SERVER_SIGNATURE);
|
|
|
|
MediaServerPort = find_port("media_server port");
|
|
|
|
MediaAddonServerPort = find_port("media_addon_server port");
|
|
|
|
}
|
|
|
|
~initit()
|
|
|
|
{
|
|
|
|
delete MediaServerMessenger;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
initit _initit;
|
|
|
|
|
|
|
|
|
2002-10-08 04:26:45 +04:00
|
|
|
status_t
|
2002-10-03 02:12:10 +04:00
|
|
|
request_data::SendReply(status_t result, reply_data *reply, int replysize) const
|
2002-10-02 05:04:48 +04:00
|
|
|
{
|
2002-10-03 02:12:10 +04:00
|
|
|
reply->result = result;
|
2002-10-08 04:26:45 +04:00
|
|
|
return SendToPort(reply_port, 0, reply, replysize);
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// BMessage based data exchange with the media_server
|
|
|
|
status_t SendToServer(BMessage *msg)
|
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t rv;
|
|
|
|
rv = MediaServerMessenger->SendMessage(msg, static_cast<BHandler *>(NULL), TIMEOUT);
|
|
|
|
if (rv != B_OK)
|
|
|
|
TRACE("SendToServer: SendMessage failed\n");
|
|
|
|
return rv;
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t QueryServer(BMessage *request, BMessage *reply)
|
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t rv;
|
|
|
|
rv = MediaServerMessenger->SendMessage(request, reply, TIMEOUT, TIMEOUT);
|
|
|
|
if (rv != B_OK)
|
|
|
|
TRACE("QueryServer: SendMessage failed\n");
|
|
|
|
return rv;
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Raw data based data exchange with the media_server
|
|
|
|
status_t SendToServer(int32 msgcode, void *msg, int size)
|
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
return SendToPort(MediaServerPort, msgcode, msg, size);
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t QueryServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
|
2002-10-02 05:04:48 +04:00
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
return QueryPort(MediaServerPort, msgcode, request, requestsize, reply, replysize);
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Raw data based data exchange with the media_addon_server
|
|
|
|
status_t SendToAddonServer(int32 msgcode, void *msg, int size)
|
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
return SendToPort(MediaAddonServerPort, msgcode, msg, size);
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t QueryAddonServer(int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
|
2002-10-02 05:04:48 +04:00
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
return QueryPort(MediaAddonServerPort, msgcode, request, requestsize, reply, replysize);
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Raw data based data exchange with the media_server
|
|
|
|
status_t SendToPort(port_id sendport, int32 msgcode, void *msg, int size)
|
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t rv;
|
|
|
|
rv = write_port(sendport, msgcode, msg, size);
|
|
|
|
if (rv != B_OK)
|
2002-10-08 04:26:45 +04:00
|
|
|
TRACE("SendToPort: write_port failed, port %#lx, error %#lx (%s)\n", sendport, rv, strerror(rv));
|
2002-10-02 05:04:48 +04:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t QueryPort(port_id requestport, int32 msgcode, request_data *request, int requestsize, reply_data *reply, int replysize)
|
2002-10-02 05:04:48 +04:00
|
|
|
{
|
2002-10-02 20:54:53 +04:00
|
|
|
status_t rv;
|
|
|
|
int32 code;
|
|
|
|
|
|
|
|
request->reply_port = _PortPool->GetPort();
|
|
|
|
|
|
|
|
rv = write_port(requestport, msgcode, request, requestsize);
|
|
|
|
if (rv != B_OK) {
|
2002-10-08 04:26:45 +04:00
|
|
|
TRACE("QueryPort: write_port failed, port %#lx, error %#lx (%s)\n", requestport, rv, strerror(rv));
|
2002-10-02 20:54:53 +04:00
|
|
|
_PortPool->PutPort(request->reply_port);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = read_port(request->reply_port, &code, reply, replysize);
|
|
|
|
_PortPool->PutPort(request->reply_port);
|
|
|
|
|
|
|
|
if (rv < B_OK)
|
2002-10-08 04:26:45 +04:00
|
|
|
TRACE("QueryPort: read_port failed, port %#lx, error %#lx (%s)\n", request->reply_port, rv, strerror(rv));
|
2002-10-02 20:54:53 +04:00
|
|
|
|
|
|
|
return (rv < B_OK) ? rv : reply->result;
|
2002-10-02 05:04:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // dataexchange
|
|
|
|
}; // media
|
|
|
|
}; // BPrivate
|
|
|
|
|