1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
|
/*
(c) Copyright 2012-2013 DirectFB integrated media GmbH
(c) Copyright 2001-2013 The world wide DirectFB Open Source Community (directfb.org)
(c) Copyright 2000-2004 Convergence (integrated media) GmbH
All rights reserved.
Written by Denis Oliver Kropp <dok@directfb.org>,
Andreas Shimokawa <andi@directfb.org>,
Marek Pikarski <mass@directfb.org>,
Sven Neumann <neo@directfb.org>,
Ville Syrjälä <syrjala@sci.fi> and
Claudio Ciccani <klan@users.sf.net>.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
//#define DIRECT_ENABLE_DEBUG
#include <config.h>
#include <list>
extern "C" {
#include <direct/debug.h>
#include <direct/messages.h>
#include <direct/util.h>
#include <voodoo/conf.h>
#include <voodoo/server.h>
}
#include <voodoo/connection_packet.h>
#include <voodoo/connection_raw.h>
#include <voodoo/link.h>
#include <voodoo/manager.h>
D_DEBUG_DOMAIN( Voodoo_Manager, "Voodoo/Manager", "Voodoo Manager" );
/**********************************************************************************************************************/
#define VOODOO_MANAGER_MESSAGE_BLOCKS_MAX 20
static __inline__ int
calc_blocks( va_list args,
VoodooMessageBlock *ret_blocks, size_t *ret_num )
{
int size = 4; /* for the terminating VMBT_NONE */
size_t num = 0;
VoodooMessageBlockType type;
/* Fetch first block type. */
type = (VoodooMessageBlockType) va_arg( args, int );
while (type != VMBT_NONE) {
if (num == VOODOO_MANAGER_MESSAGE_BLOCKS_MAX) {
// FIXME: support more blocks?
D_UNIMPLEMENTED();
break;
}
/* Set message block type. */
ret_blocks[num].type = type;
switch (type) {
case VMBT_ID:
ret_blocks[num].len = 4;
ret_blocks[num].ptr = NULL;
ret_blocks[num].val = va_arg( args, u32 );
D_DEBUG( "Voodoo/Message: + ID %u\n", ret_blocks[num].val );
break;
case VMBT_INT:
ret_blocks[num].len = 4;
ret_blocks[num].ptr = NULL;
ret_blocks[num].val = va_arg( args, s32 );
D_DEBUG( "Voodoo/Message: + INT %d\n", ret_blocks[num].val );
break;
case VMBT_UINT:
ret_blocks[num].len = 4;
ret_blocks[num].ptr = NULL;
ret_blocks[num].val = va_arg( args, u32 );
D_DEBUG( "Voodoo/Message: + UINT %u\n", ret_blocks[num].val );
break;
case VMBT_DATA:
ret_blocks[num].len = va_arg( args, int );
ret_blocks[num].ptr = va_arg( args, void * );
// D_ASSERT( ret_blocks[num].len > 0 );
D_ASSERT( ret_blocks[num].ptr != NULL );
D_DEBUG( "Voodoo/Message: + DATA at %p with length %d\n", ret_blocks[num].ptr, ret_blocks[num].len );
break;
case VMBT_ODATA:
ret_blocks[num].len = va_arg( args, int );
ret_blocks[num].ptr = va_arg( args, void * );
D_ASSERT( ret_blocks[num].len > 0 );
D_DEBUG( "Voodoo/Message: + ODATA at %p with length %d\n", ret_blocks[num].ptr, ret_blocks[num].len );
if (!ret_blocks[num].ptr)
ret_blocks[num].len = 0;
break;
case VMBT_STRING:
ret_blocks[num].ptr = va_arg( args, char * );
ret_blocks[num].len = strlen( (const char*) ret_blocks[num].ptr ) + 1;
D_ASSERT( ret_blocks[num].ptr != NULL );
D_DEBUG( "Voodoo/Message: + STRING '%s' at %p with length %d\n", (char*) ret_blocks[num].ptr, ret_blocks[num].ptr, ret_blocks[num].len );
break;
default:
D_BREAK( "unknown message block type" );
}
/* Fetch next block type. */
type = (VoodooMessageBlockType) va_arg( args, int );
size += 8 + VOODOO_MSG_ALIGN(ret_blocks[num].len);
num++;
}
*ret_num = num;
return size;
}
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/* Old C API
*/
/*
register add refs proxy
unregister releases proxy
proxy destruct releases real
*/
class VoodooInstanceInterface : public VoodooInstance {
public:
VoodooManager *manager;
VoodooInstance *super;
IAny *proxy;
IAny *real;
VoodooDispatch dispatch;
static std::list<VoodooInstanceInterface*> interfaces;
public:
VoodooInstanceInterface( VoodooManager *manager,
VoodooInstance *super,
IAny *proxy,
IAny *real,
VoodooDispatch dispatch )
:
manager( manager ),
super( super ),
proxy( proxy ),
real( real ),
dispatch( dispatch )
{
D_DEBUG_AT( Voodoo_Manager, "VoodooInstanceInterface::%s( %p, manager %p, super %p, proxy %p, real %p, dispatch %p )\n",
__func__, this, manager, super, proxy, real, dispatch );
if (super)
super->AddRef();
interfaces.push_back( this );
}
protected:
virtual ~VoodooInstanceInterface()
{
D_DEBUG_AT( Voodoo_Manager, "VoodooInstanceInterface::%s( %p )\n", __func__, this );
D_MAGIC_ASSERT( this, VoodooInstance );
if (proxy) {
D_DEBUG_AT( Voodoo_Manager, " -> releasing proxy interface\n" );
proxy->Release( proxy );
}
if (super) {
D_DEBUG_AT( Voodoo_Manager, " -> releasing super instance\n" );
super->Release();
}
interfaces.remove( this );
}
public:
virtual DirectResult
Dispatch( VoodooManager *manager,
VoodooRequestMessage *msg )
{
D_DEBUG_AT( Voodoo_Manager, "VoodooInstanceInterface::%s( %p, manager %p, msg %p )\n", __func__, this, manager, msg );
D_MAGIC_ASSERT( this, VoodooInstance );
D_ASSERT( dispatch != NULL );
return dispatch( proxy, real, manager, msg );
}
};
std::list<VoodooInstanceInterface*> VoodooInstanceInterface::interfaces;
/**********************************************************************************************************************/
class VoodooContextClassic : public VoodooContext {
private:
VoodooServer *server;
public:
VoodooContextClassic( VoodooServer *server )
:
server( server )
{
}
virtual DirectResult
HandleSuper( VoodooManager *manager, const char *name, VoodooInstanceID *ret_instance )
{
return voodoo_server_construct( server, manager, name, ret_instance );
}
};
DirectResult
voodoo_manager_create( VoodooLink *link,
VoodooClient *client,
VoodooServer *server,
VoodooManager **ret_manager )
{
VoodooConnection *connection;
D_ASSERT( ret_manager != NULL );
/* Add connection */
if ((link->code & 0x8000ffff) == 0x80008676) {
D_INFO( "Voodoo/Manager: Connection mode is PACKET\n" );
connection = new VoodooConnectionPacket( link );
}
else {
D_INFO( "Voodoo/Manager: Connection mode is RAW\n" );
connection = new VoodooConnectionRaw( link );
// FIXME: query manager dynamically for compression instead
voodoo_config->compression_min = 0;
}
*ret_manager = new VoodooManager( connection, new VoodooContextClassic( server ) ); // FIXME: leak
return DR_OK;
}
DirectResult
voodoo_manager_quit( VoodooManager *manager )
{
D_MAGIC_ASSERT( manager, VoodooManager );
manager->quit();
return DR_OK;
}
DirectResult
voodoo_manager_destroy( VoodooManager *manager )
{
D_MAGIC_ASSERT( manager, VoodooManager );
delete manager;
for (std::list<VoodooInstanceInterface*>::const_iterator iter = VoodooInstanceInterface::interfaces.begin();
iter != VoodooInstanceInterface::interfaces.end(); iter++)
{
VoodooInstanceInterface *instance = *iter;
if (instance->manager == manager)
D_INFO( "Zombie: Instance %p, proxy %p, real %p, super %p\n", instance, instance->proxy, instance->real, instance->super );
}
return DR_OK;
}
bool
voodoo_manager_is_closed( const VoodooManager *manager )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->is_quit;
}
/**************************************************************************************************/
DirectResult
voodoo_manager_super( VoodooManager *manager,
const char *name,
VoodooInstanceID *ret_instance )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->do_super( name, ret_instance );
}
DirectResult
voodoo_manager_request( VoodooManager *manager,
VoodooInstanceID instance,
VoodooMethodID method,
VoodooRequestFlags flags,
VoodooResponseMessage **ret_response, ... )
{
DirectResult ret;
D_MAGIC_ASSERT( manager, VoodooManager );
va_list ap;
va_start( ap, ret_response );
VoodooMessageBlock blocks[VOODOO_MANAGER_MESSAGE_BLOCKS_MAX];
size_t num_blocks;
size_t data_size;
data_size = calc_blocks( ap, blocks, &num_blocks );
ret = manager->do_request( instance, method, flags, ret_response, blocks, num_blocks, data_size );
va_end( ap );
return ret;
}
DirectResult
voodoo_manager_next_response( VoodooManager *manager,
VoodooResponseMessage *response,
VoodooResponseMessage **ret_response )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->next_response( response, ret_response );
}
DirectResult
voodoo_manager_finish_request( VoodooManager *manager,
VoodooResponseMessage *response )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->finish_request( response );
}
DirectResult
voodoo_manager_respond( VoodooManager *manager,
bool flush,
VoodooMessageSerial request,
DirectResult result,
VoodooInstanceID instance, ... )
{
DirectResult ret;
D_MAGIC_ASSERT( manager, VoodooManager );
va_list ap;
va_start( ap, instance );
VoodooMessageBlock blocks[VOODOO_MANAGER_MESSAGE_BLOCKS_MAX];
size_t num_blocks;
size_t data_size;
data_size = calc_blocks( ap, blocks, &num_blocks );
ret = manager->do_respond( flush, request, result, instance, blocks, num_blocks, data_size );
va_end( ap );
return ret;
}
DirectResult
voodoo_manager_register_local( VoodooManager *manager,
VoodooInstanceID super,
void *dispatcher,
void *real,
VoodooDispatch dispatch,
VoodooInstanceID *ret_instance )
{
DirectResult ret;
VoodooInstance *super_instance = NULL;
D_MAGIC_ASSERT( manager, VoodooManager );
if (super != VOODOO_INSTANCE_NONE) {
ret = manager->lookup_local( super, &super_instance );
if (ret) {
D_DERROR( ret, "Voodoo/Manager: Could not lookup super instance %u!\n", super );
return ret;
}
}
VoodooInstanceInterface *instance = new VoodooInstanceInterface( manager, super_instance, (IAny*) dispatcher, (IAny*) real, dispatch );
ret = manager->register_local( instance, ret_instance );
instance->Release();
return ret;
}
DirectResult
voodoo_manager_unregister_local( VoodooManager *manager,
VoodooInstanceID instance_id )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->unregister_local( instance_id );
}
DirectResult
voodoo_manager_lookup_local( VoodooManager *manager,
VoodooInstanceID instance_id,
void **ret_dispatcher,
void **ret_real )
{
DirectResult ret;
VoodooInstance *instance;
D_MAGIC_ASSERT( manager, VoodooManager );
ret = manager->lookup_local( instance_id, &instance );
if (ret)
return ret;
if (ret_dispatcher)
*ret_dispatcher = ((VoodooInstanceInterface*) instance)->proxy;
if (ret_real)
*ret_real = ((VoodooInstanceInterface*) instance)->real;
return DR_OK;
}
DirectResult
voodoo_manager_register_remote( VoodooManager *manager,
bool super,
void *requestor,
VoodooInstanceID instance_id )
{
DirectResult ret;
D_MAGIC_ASSERT( manager, VoodooManager );
VoodooInstanceInterface *instance = new VoodooInstanceInterface( manager, NULL, (IAny*) requestor, NULL, NULL);
ret = manager->register_remote( instance, instance_id );
instance->Release();
return ret;
}
DirectResult
voodoo_manager_lookup_remote( VoodooManager *manager,
VoodooInstanceID instance_id,
void **ret_requestor )
{
DirectResult ret;
VoodooInstance *instance;
D_MAGIC_ASSERT( manager, VoodooManager );
ret = manager->lookup_remote( instance_id, &instance );
if (ret)
return ret;
if (ret_requestor)
*ret_requestor = ((VoodooInstanceInterface*) instance)->proxy;
return DR_OK;
}
DirectResult
voodoo_manager_check_allocation( VoodooManager *manager,
unsigned int amount )
{
#ifndef WIN32
FILE *f;
char buf[2000];
int size;
char *p;
size_t bytes;
D_MAGIC_ASSERT( manager, VoodooManager );
if (!voodoo_config->memory_max)
return DR_OK;
direct_snprintf( buf, sizeof(buf), "/proc/%d/status", direct_getpid() );
f = fopen( buf, "r" );
if (!f) {
D_ERROR( "Could not open '%s'!\n", buf );
return DR_FAILURE;
}
bytes = fread( buf, 1, sizeof(buf)-1, f );
fclose( f );
if (bytes) {
buf[bytes] = 0;
p = strstr( buf, "VmRSS:" );
if (!p) {
D_ERROR( "Could not find memory information!\n" );
return DR_FAILURE;
}
sscanf( p + 6, " %u", &size );
D_INFO( "SIZE: %u kB (+%u kB)\n", size, amount / 1024 );
if (size * 1024 + amount > voodoo_config->memory_max)
return DR_LIMITEXCEEDED;
}
#endif
return DR_OK;
}
long long
voodoo_manager_connection_delay( VoodooManager *manager )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->connection_delay();
}
long long
voodoo_manager_clock_to_local( VoodooManager *manager,
long long remote )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->clock_to_local( remote );
}
long long
voodoo_manager_clock_to_remote( VoodooManager *manager,
long long local )
{
D_MAGIC_ASSERT( manager, VoodooManager );
return manager->clock_to_remote( local );
}
|