* BParameterWeb::StartWatching() now just calls BMediaRoster::StartWatching()
as on Dano - since the functionality is already there, those two functions aren't really needed, though, so we could remove them again. * Cleaned up DataExchange.h, and added basic reply/request structs for anything that needs an area. * BControllable now uses a helper class ReceiveTransfer to deal with requests with areas. * Major style cleanup of MediaRoster.cpp, though one could still bury some hours there... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30045 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5bb7f41847
commit
34c7214442
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de>
|
||||
*
|
||||
@ -35,32 +40,82 @@
|
||||
#include "DataExchange.h"
|
||||
#include "Notifications.h"
|
||||
|
||||
/*************************************************************
|
||||
* protected BControllable
|
||||
*************************************************************/
|
||||
|
||||
namespace BPrivate { namespace media {
|
||||
|
||||
/*! A helper class for the communication with the media server that
|
||||
takes care of large buffers that need an area.
|
||||
*/
|
||||
class ReceiveTransfer {
|
||||
public:
|
||||
ReceiveTransfer(const area_request_data& request, const void* smallBuffer)
|
||||
{
|
||||
if (request.area == -1 && smallBuffer != NULL) {
|
||||
// small data transfer uses buffer in reply
|
||||
fArea = -1;
|
||||
fData = const_cast<void*>(smallBuffer);
|
||||
// The caller is actually responsible to enforce the const;
|
||||
// we don't touch the data.
|
||||
} else {
|
||||
// large data transfer, clone area
|
||||
fArea = clone_area("get parameter data clone", &fData,
|
||||
B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request.area);
|
||||
if (fArea < B_OK) {
|
||||
ERROR("BControllabe: cloning area failed: %s\n",
|
||||
strerror(fArea));
|
||||
fData = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~ReceiveTransfer()
|
||||
{
|
||||
if (fArea >= B_OK)
|
||||
delete_area(fArea);
|
||||
}
|
||||
|
||||
status_t InitCheck() const
|
||||
{
|
||||
return fData != NULL ? B_OK : fArea;
|
||||
}
|
||||
|
||||
void* Data() const
|
||||
{
|
||||
return fData;
|
||||
}
|
||||
|
||||
private:
|
||||
area_id fArea;
|
||||
void* fData;
|
||||
};
|
||||
|
||||
} // namespace media
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::media::ReceiveTransfer;
|
||||
|
||||
|
||||
// #pragma mark - protected
|
||||
|
||||
|
||||
BControllable::~BControllable()
|
||||
{
|
||||
CALLED();
|
||||
if (fSem > 0)
|
||||
delete_sem(fSem);
|
||||
if (fWeb)
|
||||
delete fWeb;
|
||||
|
||||
delete fWeb;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* public BControllable
|
||||
*************************************************************/
|
||||
|
||||
BParameterWeb *
|
||||
// #pragma mark - public
|
||||
|
||||
|
||||
BParameterWeb*
|
||||
BControllable::Web()
|
||||
{
|
||||
CALLED();
|
||||
BParameterWeb *temp;
|
||||
LockParameterWeb();
|
||||
temp = fWeb;
|
||||
UnlockParameterWeb();
|
||||
return temp;
|
||||
return fWeb;
|
||||
}
|
||||
|
||||
|
||||
@ -68,20 +123,21 @@ bool
|
||||
BControllable::LockParameterWeb()
|
||||
{
|
||||
CALLED();
|
||||
status_t rv;
|
||||
if (fSem <= 0)
|
||||
return false;
|
||||
|
||||
if (atomic_add(&fBen, 1) > 0) {
|
||||
while (B_INTERRUPTED == (rv = acquire_sem(fSem)))
|
||||
;
|
||||
return rv == B_OK;
|
||||
status_t status;
|
||||
do {
|
||||
status = acquire_sem(fSem);
|
||||
} while (status == B_INTERRUPTED);
|
||||
|
||||
return status == B_OK;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* protected BControllable
|
||||
*************************************************************/
|
||||
|
||||
void
|
||||
BControllable::UnlockParameterWeb()
|
||||
@ -89,14 +145,18 @@ BControllable::UnlockParameterWeb()
|
||||
CALLED();
|
||||
if (fSem <= 0)
|
||||
return;
|
||||
|
||||
if (atomic_add(&fBen, -1) > 1)
|
||||
release_sem(fSem);
|
||||
}
|
||||
|
||||
|
||||
BControllable::BControllable() :
|
||||
BMediaNode("this one is never called"),
|
||||
fWeb(0),
|
||||
// #pragma mark - protected
|
||||
|
||||
|
||||
BControllable::BControllable()
|
||||
: BMediaNode("this one is never called"),
|
||||
fWeb(NULL),
|
||||
fSem(create_sem(0, "BControllable lock")),
|
||||
fBen(0)
|
||||
{
|
||||
@ -107,19 +167,22 @@ BControllable::BControllable() :
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::SetParameterWeb(BParameterWeb *web)
|
||||
BControllable::SetParameterWeb(BParameterWeb* web)
|
||||
{
|
||||
CALLED();
|
||||
BParameterWeb *old;
|
||||
|
||||
LockParameterWeb();
|
||||
old = fWeb;
|
||||
BParameterWeb* old = fWeb;
|
||||
fWeb = web;
|
||||
|
||||
if (fWeb)
|
||||
fWeb->fNode = Node(); // initialize BParameterWeb member variable
|
||||
|
||||
if (fWeb != NULL) {
|
||||
// initialize BParameterWeb member variable
|
||||
fWeb->fNode = Node();
|
||||
}
|
||||
|
||||
UnlockParameterWeb();
|
||||
if (old != web && web != 0)
|
||||
|
||||
if (old != web && web != NULL)
|
||||
BPrivate::media::notifications::WebChanged(Node());
|
||||
delete old;
|
||||
return B_OK;
|
||||
@ -127,122 +190,124 @@ BControllable::SetParameterWeb(BParameterWeb *web)
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::HandleMessage(int32 message, const void *data, size_t size)
|
||||
BControllable::HandleMessage(int32 message, const void* data, size_t size)
|
||||
{
|
||||
PRINT(4, "BControllable::HandleMessage %#lx, node %ld\n", message, ID());
|
||||
|
||||
status_t rv;
|
||||
switch (message) {
|
||||
case CONTROLLABLE_GET_PARAMETER_DATA:
|
||||
{
|
||||
const controllable_get_parameter_data_request *request = static_cast<const controllable_get_parameter_data_request *>(data);
|
||||
const controllable_get_parameter_data_request& request
|
||||
= *static_cast<const controllable_get_parameter_data_request*>(
|
||||
data);
|
||||
controllable_get_parameter_data_reply reply;
|
||||
area_id area;
|
||||
void *data;
|
||||
|
||||
if (request->area == -1) {
|
||||
// small data transfer uses buffer in reply
|
||||
area = -1;
|
||||
data = reply.rawdata;
|
||||
} else {
|
||||
// large data transfer, clone area
|
||||
area = clone_area("get parameter data clone", &data, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area);
|
||||
if (area < B_OK) {
|
||||
ERROR("CONTROLLABLE_GET_PARAMETER_DATA cloning area failed\n");
|
||||
request->SendReply(B_NO_MEMORY, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
ReceiveTransfer transfer(request, reply.raw_data);
|
||||
if (transfer.InitCheck() != B_OK) {
|
||||
request.SendReply(transfer.InitCheck(), &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
reply.size = request->requestsize;
|
||||
rv = GetParameterValue(request->parameter_id, &reply.last_change, data, &reply.size);
|
||||
if (area != -1)
|
||||
delete_area(area);
|
||||
request->SendReply(rv, &reply, sizeof(reply));
|
||||
|
||||
reply.size = request.request_size;
|
||||
status_t status = GetParameterValue(request.parameter_id,
|
||||
&reply.last_change, transfer.Data(), &reply.size);
|
||||
|
||||
request.SendReply(status, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
case CONTROLLABLE_SET_PARAMETER_DATA:
|
||||
{
|
||||
const controllable_set_parameter_data_request *request = static_cast<const controllable_set_parameter_data_request *>(data);
|
||||
const controllable_set_parameter_data_request& request
|
||||
= *static_cast<const controllable_set_parameter_data_request*>(
|
||||
data);
|
||||
controllable_set_parameter_data_reply reply;
|
||||
area_id area;
|
||||
const void *data;
|
||||
|
||||
if (request->area == -1) {
|
||||
// small data transfer uses buffer in request
|
||||
area = -1;
|
||||
data = request->rawdata;
|
||||
} else {
|
||||
// large data transfer, clone area
|
||||
area = clone_area("set parameter data clone", (void **)&data, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area);
|
||||
if (area < B_OK) {
|
||||
ERROR("CONTROLLABLE_SET_PARAMETER_DATA cloning area failed\n");
|
||||
request->SendReply(B_NO_MEMORY, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
ReceiveTransfer transfer(request, request.raw_data);
|
||||
if (transfer.InitCheck() != B_OK) {
|
||||
request.SendReply(transfer.InitCheck(), &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
SetParameterValue(request->parameter_id, request->when, data, request->size);
|
||||
if (area != -1)
|
||||
delete_area(area);
|
||||
request->SendReply(B_OK, &reply, sizeof(reply));
|
||||
|
||||
SetParameterValue(request.parameter_id, request.when,
|
||||
transfer.Data(), request.size);
|
||||
request.SendReply(B_OK, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
case CONTROLLABLE_GET_PARAMETER_WEB:
|
||||
{
|
||||
const controllable_get_parameter_web_request *request = static_cast<const controllable_get_parameter_web_request *>(data);
|
||||
const controllable_get_parameter_web_request& request
|
||||
= *static_cast<const controllable_get_parameter_web_request*>(
|
||||
data);
|
||||
controllable_get_parameter_web_reply reply;
|
||||
bool waslocked = LockParameterWeb();
|
||||
if (fWeb != NULL && fWeb->FlattenedSize() > request->maxsize) {
|
||||
reply.code = 0;
|
||||
reply.size = -1; // parameter web too large
|
||||
rv = B_OK;
|
||||
} else if (fWeb != NULL && fWeb->FlattenedSize() <= request->maxsize) {
|
||||
void *buffer;
|
||||
area_id area;
|
||||
area = clone_area("cloned parameter web", &buffer, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, request->area);
|
||||
if (area < B_OK) {
|
||||
ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB clone_area failed\n");
|
||||
rv = B_ERROR;
|
||||
|
||||
status_t status = B_OK;
|
||||
bool wasLocked = true;
|
||||
if (!LockParameterWeb()) {
|
||||
status = B_ERROR;
|
||||
wasLocked = false;
|
||||
}
|
||||
|
||||
if (status == B_OK && fWeb != NULL) {
|
||||
if (fWeb->FlattenedSize() > request.max_size) {
|
||||
// parameter web too large
|
||||
reply.code = 0;
|
||||
reply.size = -1;
|
||||
status = B_OK;
|
||||
} else {
|
||||
reply.code = fWeb->TypeCode();
|
||||
reply.size = fWeb->FlattenedSize();
|
||||
rv = fWeb->Flatten(buffer, reply.size);
|
||||
if (rv != B_OK) {
|
||||
ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB Flatten failed\n");
|
||||
} else {
|
||||
printf("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n",
|
||||
reply.size, ((uint32*)buffer)[0], ((uint32*)buffer)[1], ((uint32*)buffer)[2], ((uint32*)buffer)[3]);
|
||||
ReceiveTransfer transfer(request, NULL);
|
||||
status = transfer.InitCheck();
|
||||
if (status == B_OK) {
|
||||
reply.code = fWeb->TypeCode();
|
||||
reply.size = fWeb->FlattenedSize();
|
||||
status = fWeb->Flatten(transfer.Data(), reply.size);
|
||||
if (status != B_OK) {
|
||||
ERROR("BControllable::HandleMessage "
|
||||
"CONTROLLABLE_GET_PARAMETER_WEB Flatten failed\n");
|
||||
#if 0
|
||||
} else {
|
||||
printf("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n",
|
||||
reply.size, ((uint32*)buffer)[0], ((uint32*)buffer)[1], ((uint32*)buffer)[2], ((uint32*)buffer)[3]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
delete_area(area);
|
||||
}
|
||||
} else {
|
||||
// no parameter web
|
||||
reply.code = 0;
|
||||
reply.size = 0; // no parameter web
|
||||
rv = B_OK;
|
||||
reply.size = 0;
|
||||
}
|
||||
if (waslocked)
|
||||
if (wasLocked)
|
||||
UnlockParameterWeb();
|
||||
request->SendReply(rv, &reply, sizeof(reply));
|
||||
|
||||
request.SendReply(status, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
case CONTROLLABLE_START_CONTROL_PANEL:
|
||||
{
|
||||
const controllable_start_control_panel_request *request = static_cast<const controllable_start_control_panel_request*>(data);
|
||||
const controllable_start_control_panel_request* request
|
||||
= static_cast<const controllable_start_control_panel_request*>(
|
||||
data);
|
||||
controllable_start_control_panel_reply reply;
|
||||
BMessenger targetMessenger;
|
||||
rv = StartControlPanel(&targetMessenger);
|
||||
if (rv != B_OK) {
|
||||
ERROR("BControllable::HandleMessage CONTROLLABLE_START_CONTROL_PANEL failed\n");
|
||||
status_t status = StartControlPanel(&targetMessenger);
|
||||
if (status != B_OK) {
|
||||
ERROR("BControllable::HandleMessage "
|
||||
"CONTROLLABLE_START_CONTROL_PANEL failed\n");
|
||||
}
|
||||
reply.result = rv;
|
||||
reply.result = status;
|
||||
reply.team = targetMessenger.Team();
|
||||
request->SendReply(rv, &reply, sizeof(reply));
|
||||
request->SendReply(status, &reply, sizeof(reply));
|
||||
return B_OK;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return B_ERROR;
|
||||
}
|
||||
return B_ERROR;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -255,18 +320,17 @@ BControllable::BroadcastChangedParameter(int32 id)
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::BroadcastNewParameterValue(bigtime_t when,
|
||||
int32 id,
|
||||
void *newValue,
|
||||
size_t valueSize)
|
||||
BControllable::BroadcastNewParameterValue(bigtime_t when, int32 id,
|
||||
void* newValue, size_t valueSize)
|
||||
{
|
||||
CALLED();
|
||||
return BPrivate::media::notifications::NewParameterValue(Node(), id, when, newValue, valueSize);
|
||||
return BPrivate::media::notifications::NewParameterValue(Node(), id, when,
|
||||
newValue, valueSize);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::StartControlPanel(BMessenger *out_messenger)
|
||||
BControllable::StartControlPanel(BMessenger* _messenger)
|
||||
{
|
||||
CALLED();
|
||||
|
||||
@ -277,43 +341,39 @@ BControllable::StartControlPanel(BMessenger *out_messenger)
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
image_id imageId = addon->ImageID();
|
||||
image_id imageID = addon->ImageID();
|
||||
image_info info;
|
||||
if ((imageId <= 0) || (get_image_info(imageId, &info) != B_OK)) {
|
||||
if (imageID <= 0 || get_image_info(imageID, &info) != B_OK) {
|
||||
ERROR("BControllable::StartControlPanel Error accessing image\n");
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
team_id id;
|
||||
entry_ref ref;
|
||||
|
||||
if (BEntry(info.name).GetRef(&ref) != B_OK) {
|
||||
if (get_ref_for_path(info.name, &ref) != B_OK) {
|
||||
ERROR("BControllable::StartControlPanel Error getting ref\n");
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
// The first argument is "node=id" with id meaning the media_node_id
|
||||
char *arg = (char*) malloc(10);
|
||||
sprintf(arg, "node=%d" , (int) ID());
|
||||
char arg[32];
|
||||
snprintf(arg, sizeof(arg), "node=%d", (int)ID());
|
||||
|
||||
if (be_roster->Launch(&ref, 1, &arg, &id) != B_OK) {
|
||||
free(arg);
|
||||
team_id team;
|
||||
if (be_roster->Launch(&ref, 1, (const char* const*)&arg, &team) != B_OK) {
|
||||
ERROR("BControllable::StartControlPanel Error launching application\n");
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
printf("BControllable::StartControlPanel done with id: %ld\n", id);
|
||||
free(arg);
|
||||
printf("BControllable::StartControlPanel done with id: %ld\n", team);
|
||||
|
||||
if (out_messenger)
|
||||
*out_messenger = BMessenger(0, id);
|
||||
if (_messenger)
|
||||
*_messenger = BMessenger(NULL, team);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::ApplyParameterData(const void *value,
|
||||
size_t size)
|
||||
BControllable::ApplyParameterData(const void* value, size_t size)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
|
||||
@ -322,25 +382,17 @@ BControllable::ApplyParameterData(const void *value,
|
||||
|
||||
|
||||
status_t
|
||||
BControllable::MakeParameterData(const int32 *controls,
|
||||
int32 count,
|
||||
void *buf,
|
||||
size_t *ioSize)
|
||||
BControllable::MakeParameterData(const int32* controls, int32 count,
|
||||
void* buffer, size_t* ioSize)
|
||||
{
|
||||
UNIMPLEMENTED();
|
||||
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* private BControllable
|
||||
*************************************************************/
|
||||
|
||||
/*
|
||||
private unimplemented
|
||||
BControllable::BControllable(const BControllable &clone)
|
||||
BControllable & BControllable::operator=(const BControllable &clone)
|
||||
*/
|
||||
// #pragma mark - private
|
||||
|
||||
|
||||
status_t BControllable::_Reserved_Controllable_0(void *) { return B_ERROR; }
|
||||
status_t BControllable::_Reserved_Controllable_1(void *) { return B_ERROR; }
|
||||
@ -358,5 +410,3 @@ status_t BControllable::_Reserved_Controllable_12(void *) { return B_ERROR; }
|
||||
status_t BControllable::_Reserved_Controllable_13(void *) { return B_ERROR; }
|
||||
status_t BControllable::_Reserved_Controllable_14(void *) { return B_ERROR; }
|
||||
status_t BControllable::_Reserved_Controllable_15(void *) { return B_ERROR; }
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,13 +15,14 @@
|
||||
#include <ParameterWeb.h>
|
||||
|
||||
#include <new>
|
||||
#include <string.h>
|
||||
|
||||
#include <MediaNode.h>
|
||||
#include <string.h>
|
||||
#include "DataExchange.h"
|
||||
#include "MediaMisc.h"
|
||||
#include <MediaRoster.h>
|
||||
|
||||
#include "DataExchange.h"
|
||||
#include "debug.h"
|
||||
#include "MediaMisc.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -422,14 +423,22 @@ BParameterWeb::ParameterAt(int32 index)
|
||||
status_t
|
||||
BParameterWeb::StartWatching(const BMessenger& target, int32 notificationType)
|
||||
{
|
||||
return B_ERROR;
|
||||
if (BMediaRoster::CurrentRoster() == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
return BMediaRoster::CurrentRoster()->StartWatching(target, fNode,
|
||||
notificationType);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BParameterWeb::StopWatching(const BMessenger& target, int32 notificationType)
|
||||
{
|
||||
return B_ERROR;
|
||||
if (BMediaRoster::CurrentRoster() == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
return BMediaRoster::CurrentRoster()->StopWatching(target, fNode,
|
||||
notificationType);
|
||||
}
|
||||
|
||||
|
||||
@ -1285,11 +1294,11 @@ BParameter::GetValue(void* buffer, size_t* _size, bigtime_t* _when)
|
||||
}
|
||||
} else {
|
||||
area = -1;
|
||||
data = reply.rawdata;
|
||||
data = reply.raw_data;
|
||||
}
|
||||
|
||||
request.parameter_id = fID;
|
||||
request.requestsize = size;
|
||||
request.request_size = size;
|
||||
request.area = area;
|
||||
|
||||
status_t status = QueryPort(node.port, CONTROLLABLE_GET_PARAMETER_DATA,
|
||||
@ -1356,7 +1365,7 @@ BParameter::SetValue(const void* buffer, size_t size, bigtime_t when)
|
||||
}
|
||||
} else {
|
||||
area = -1;
|
||||
data = request.rawdata;
|
||||
data = request.raw_data;
|
||||
}
|
||||
|
||||
memcpy(data, buffer, size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user