2003-04-15 03:31:32 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002, 2003 Marcus Overhagen <Marcus@Overhagen.de>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files or portions
|
|
|
|
* thereof (the "Software"), to deal in the Software without restriction,
|
|
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject
|
|
|
|
* to the following conditions:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice
|
|
|
|
* in the binary, as well as this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials provided with
|
|
|
|
* the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-10-10 22:55:47 +04:00
|
|
|
#include <OS.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <Controllable.h>
|
2003-03-24 02:58:17 +03:00
|
|
|
#include <ParameterWeb.h>
|
2008-03-29 23:53:01 +03:00
|
|
|
#include <Roster.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include "debug.h"
|
2003-03-24 02:58:17 +03:00
|
|
|
#include "DataExchange.h"
|
2002-10-02 05:04:48 +04:00
|
|
|
#include "Notifications.h"
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* protected BControllable
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
BControllable::~BControllable()
|
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
CALLED();
|
|
|
|
if (fSem > 0)
|
|
|
|
delete_sem(fSem);
|
2003-03-24 02:58:17 +03:00
|
|
|
if (fWeb)
|
|
|
|
delete fWeb;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* public BControllable
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
BParameterWeb *
|
|
|
|
BControllable::Web()
|
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
CALLED();
|
|
|
|
BParameterWeb *temp;
|
|
|
|
LockParameterWeb();
|
|
|
|
temp = fWeb;
|
|
|
|
UnlockParameterWeb();
|
|
|
|
return temp;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
BControllable::LockParameterWeb()
|
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* protected BControllable
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
BControllable::UnlockParameterWeb()
|
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
CALLED();
|
|
|
|
if (fSem <= 0)
|
|
|
|
return;
|
|
|
|
if (atomic_add(&fBen, -1) > 1)
|
|
|
|
release_sem(fSem);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-10 22:55:47 +04:00
|
|
|
BControllable::BControllable() :
|
2003-03-24 02:58:17 +03:00
|
|
|
BMediaNode("this one is never called"),
|
2002-10-10 22:55:47 +04:00
|
|
|
fWeb(0),
|
|
|
|
fSem(create_sem(0, "BControllable lock")),
|
|
|
|
fBen(0)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
CALLED();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
AddNodeKind(B_CONTROLLABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::SetParameterWeb(BParameterWeb *web)
|
|
|
|
{
|
2002-10-10 22:55:47 +04:00
|
|
|
CALLED();
|
|
|
|
BParameterWeb *old;
|
|
|
|
LockParameterWeb();
|
|
|
|
old = fWeb;
|
|
|
|
fWeb = web;
|
2003-06-13 16:07:58 +04:00
|
|
|
|
|
|
|
if (fWeb)
|
|
|
|
fWeb->mNode = Node(); // initialize BParameterWeb member variable
|
|
|
|
|
2002-10-10 22:55:47 +04:00
|
|
|
UnlockParameterWeb();
|
|
|
|
if (old != web && web != 0)
|
|
|
|
BPrivate::media::notifications::WebChanged(Node());
|
2003-03-24 02:58:17 +03:00
|
|
|
if (old)
|
|
|
|
delete old;
|
2002-10-10 22:55:47 +04:00
|
|
|
return B_OK;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
2003-03-24 02:58:17 +03:00
|
|
|
BControllable::HandleMessage(int32 message, const void *data, size_t size)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-19 18:53:41 +04:00
|
|
|
PRINT(4, "BControllable::HandleMessage %#lx, node %ld\n", message, ID());
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-03-24 02:58:17 +03:00
|
|
|
status_t rv;
|
|
|
|
switch (message) {
|
2003-06-13 04:42:55 +04:00
|
|
|
case CONTROLLABLE_GET_PARAMETER_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) {
|
2003-06-19 18:53:41 +04:00
|
|
|
ERROR("CONTROLLABLE_GET_PARAMETER_DATA cloning area failed\n");
|
2003-06-13 04:42:55 +04:00
|
|
|
request->SendReply(B_NO_MEMORY, &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));
|
|
|
|
return B_OK;
|
|
|
|
}
|
2003-06-13 16:43:52 +04:00
|
|
|
|
|
|
|
case CONTROLLABLE_SET_PARAMETER_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) {
|
2003-06-19 18:53:41 +04:00
|
|
|
// small data transfer uses buffer in request
|
2003-06-13 16:43:52 +04:00
|
|
|
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) {
|
2003-06-19 18:53:41 +04:00
|
|
|
ERROR("CONTROLLABLE_SET_PARAMETER_DATA cloning area failed\n");
|
2003-06-13 16:43:52 +04:00
|
|
|
request->SendReply(B_NO_MEMORY, &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));
|
|
|
|
return B_OK;
|
|
|
|
}
|
2003-06-13 04:42:55 +04:00
|
|
|
|
2003-03-24 02:58:17 +03:00
|
|
|
case CONTROLLABLE_GET_PARAMETER_WEB:
|
|
|
|
{
|
|
|
|
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) {
|
2003-06-19 18:53:41 +04:00
|
|
|
ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB clone_area failed\n");
|
2003-03-24 02:58:17 +03:00
|
|
|
rv = B_ERROR;
|
|
|
|
} else {
|
|
|
|
reply.code = fWeb->TypeCode();
|
|
|
|
reply.size = fWeb->FlattenedSize();
|
|
|
|
rv = fWeb->Flatten(buffer, reply.size);
|
|
|
|
if (rv != B_OK) {
|
2003-06-19 18:53:41 +04:00
|
|
|
ERROR("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB Flatten failed\n");
|
2003-03-24 02:58:17 +03:00
|
|
|
} else {
|
2003-08-31 06:18:11 +04:00
|
|
|
printf("BControllable::HandleMessage CONTROLLABLE_GET_PARAMETER_WEB %ld bytes, 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n",
|
2003-03-24 02:58:17 +03:00
|
|
|
reply.size, ((uint32*)buffer)[0], ((uint32*)buffer)[1], ((uint32*)buffer)[2], ((uint32*)buffer)[3]);
|
|
|
|
}
|
|
|
|
delete_area(area);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reply.code = 0;
|
|
|
|
reply.size = 0; // no parameter web
|
|
|
|
rv = B_OK;
|
|
|
|
}
|
|
|
|
if (waslocked)
|
|
|
|
UnlockParameterWeb();
|
|
|
|
request->SendReply(rv, &reply, sizeof(reply));
|
|
|
|
return B_OK;
|
|
|
|
}
|
2008-03-29 23:53:01 +03:00
|
|
|
|
|
|
|
case CONTROLLABLE_START_CONTROL_PANEL:
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
reply.result = rv;
|
|
|
|
reply.team = targetMessenger.Team();
|
|
|
|
request->SendReply(rv, &reply, sizeof(reply));
|
|
|
|
return B_OK;
|
|
|
|
}
|
2003-03-24 02:58:17 +03:00
|
|
|
}
|
2002-07-12 18:01:44 +04:00
|
|
|
return B_ERROR;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::BroadcastChangedParameter(int32 id)
|
|
|
|
{
|
2002-08-23 03:34:33 +04:00
|
|
|
CALLED();
|
2002-10-02 05:04:48 +04:00
|
|
|
return BPrivate::media::notifications::ParameterChanged(Node(), id);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::BroadcastNewParameterValue(bigtime_t when,
|
|
|
|
int32 id,
|
|
|
|
void *newValue,
|
|
|
|
size_t valueSize)
|
|
|
|
{
|
2002-08-23 03:34:33 +04:00
|
|
|
CALLED();
|
2002-10-02 05:04:48 +04:00
|
|
|
return BPrivate::media::notifications::NewParameterValue(Node(), id, when, newValue, valueSize);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::StartControlPanel(BMessenger *out_messenger)
|
|
|
|
{
|
2008-03-29 23:53:01 +03:00
|
|
|
CALLED();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2008-03-29 23:53:01 +03:00
|
|
|
int32 internalId;
|
|
|
|
BMediaAddOn* addon = AddOn(&internalId);
|
|
|
|
if (!addon) {
|
|
|
|
ERROR("BControllable::StartControlPanel not instantiated per AddOn\n");
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_id imageId = addon->ImageID();
|
|
|
|
image_info info;
|
|
|
|
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) {
|
|
|
|
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());
|
|
|
|
|
|
|
|
if (be_roster->Launch(&ref, 1, &arg, &id) != B_OK) {
|
|
|
|
free(arg);
|
|
|
|
ERROR("BControllable::StartControlPanel Error launching application\n");
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
}
|
|
|
|
printf("BControllable::StartContolPanel done wiht id: %d\n" , id);
|
|
|
|
free(arg);
|
|
|
|
|
|
|
|
if (out_messenger)
|
|
|
|
*out_messenger = BMessenger(0, id);
|
|
|
|
|
|
|
|
return B_OK;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::ApplyParameterData(const void *value,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
2002-07-12 18:01:44 +04:00
|
|
|
return B_ERROR;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t
|
|
|
|
BControllable::MakeParameterData(const int32 *controls,
|
|
|
|
int32 count,
|
|
|
|
void *buf,
|
|
|
|
size_t *ioSize)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED();
|
|
|
|
|
2002-07-12 18:01:44 +04:00
|
|
|
return B_ERROR;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
* private BControllable
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
private unimplemented
|
|
|
|
BControllable::BControllable(const BControllable &clone)
|
|
|
|
BControllable & BControllable::operator=(const BControllable &clone)
|
|
|
|
*/
|
|
|
|
|
|
|
|
status_t BControllable::_Reserved_Controllable_0(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_1(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_2(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_3(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_4(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_5(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_6(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_7(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_8(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_9(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_10(void *) { return B_ERROR; }
|
|
|
|
status_t BControllable::_Reserved_Controllable_11(void *) { return B_ERROR; }
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|