Beispiel #1
0
// Direct initialize `d` by a paren-enclosed list of expressions
// `es`.
Expr&
Parser::on_paren_initialization(Decl& d, Expr_list& es)
{
  Expr& i = direct_initialize(cxt, declared_type(d), es);
  initialize_declaration(d, i);
  return i;
}
Beispiel #2
0
int
main( int argc, char *argv[] )
{
     DirectResult           ret;
     SH7722_JPEG_context    info;
     DFBSurfacePixelFormat  format;
     int                    pitch;
     DirectStream          *stream = NULL;

     if (argc != 2) {
          fprintf( stderr, "Usage: %s <filename>\n", argv[0] );
          return -1;
     }

#ifndef STANDALONE
     direct_initialize();

     direct_config->debug = true;
#endif

     ret = SH7722_JPEG_Initialize();
     if (ret)
          return ret;

     ret = direct_stream_create( argv[1], &stream );
     if (ret)
          goto out;

     ret = SH7722_JPEG_Open( stream, &info );
     if (ret)
          goto out;

     D_INFO( "SH7722/JPEGTool: Opened %dx%d image (4:%s)\n", info.width, info.height,
             info.mode420 ? "2:0" : info.mode444 ? "4:4" : "2:2?" );

     format = DSPF_RGB24;// info.mode444 ? DSPF_NV16 : DSPF_NV12;
     pitch  = (DFB_BYTES_PER_LINE( format, info.width ) + 31) & ~31;

     ret = SH7722_JPEG_Decode( &info, NULL, NULL, format, 0x0f800000, NULL, pitch, info.width, info.height );
     if (ret)
          goto out;


//  Use RGB24 format for this
//     write_ppm( "test.ppm", 0x0f800000, pitch, info.width, info.height );

     ret = SH7722_JPEG_Encode( "test.jpg", NULL, format, 0x0f800000, pitch, info.width, info.height, 0 );
     if (ret)
          goto out;


out:
     if (stream)
          direct_stream_destroy( stream );

     SH7722_JPEG_Shutdown();

     return ret;
}
Beispiel #3
0
int
fusion_init( int world, int abi_version, int *ret_world )
{
     direct_initialize();

     if (ret_world)
          *ret_world = 0;

     return 1;
}
Beispiel #4
0
// Determine if e can be contextually converted to bool, and if so,
// returns the expression that produces a boolean value from `e`.
Expr&
contextual_conversion_to_bool(Context& cxt, Expr& e)
{
  Builder b(cxt);

  // Contextual conversion to bool tries to do this:
  //
  //    bool b(e);
  //
  // so we preform direct initialization.
  Expr& init = direct_initialize(cxt, b.get_bool_type(), e);

  // Based on the initializer selected, we can either
  // 1. return the converted value directly
  // 2. synthesize an object using a constructor
  // 3. invoke a user-defined conversion
  if (Copy_init* i = as<Copy_init>(&init))
    return i->expression();

  banjo_unhandled_case(init);
}
int
main( int argc, char *argv[] )
{
     DirectClock clock;
     int         counter = 0;
     int         res;
     (void)res;
     /* Initialize libdirect. */
     direct_initialize();

//     direct_config->log_level = DIRECT_LOG_ALL;

     direct_log_domain_config_level( "Voodoo/Input", DIRECT_LOG_DEBUG_9 );
     direct_log_domain_config_level( "Voodoo/Output", DIRECT_LOG_DEBUG_9 );
     direct_log_domain_config_level( "Voodoo/Dispatch", DIRECT_LOG_DEBUG_9 );
     direct_log_domain_config_level( "Voodoo/Manager", DIRECT_LOG_DEBUG_9 );


     int               pipe_1[2];
     int               pipe_2[2];
//     int               socket[2];
     int               fds_server[2];
     int               fds_client[2];
     VoodooLink        voodoo_link_server;
     VoodooLink        voodoo_link_client;
     VoodooManager    *manager_server;
     VoodooManager    *manager_client;
     VoodooInstanceID  instance;

//     socketpair( PF_LOCAL, SOCK_STREAM, 0, fd );

     res = pipe( pipe_1 );
     res = pipe( pipe_2 );

     fds_server[0] = pipe_1[0];
     fds_server[1] = pipe_2[1];

     fds_client[0] = pipe_2[0];
     fds_client[1] = pipe_1[1];


     voodoo_link_init_fd( &voodoo_link_server, fds_server );
     voodoo_manager_create( &voodoo_link_server, NULL, NULL, &manager_server );

     voodoo_manager_register_local( manager_server, VOODOO_INSTANCE_NONE, NULL, NULL, Dispatch, &instance );


     voodoo_link_init_fd( &voodoo_link_client, fds_client );
     voodoo_manager_create( &voodoo_link_client, NULL, NULL, &manager_client );



     direct_clock_start( &clock );

#if !BENCH_SYNC
     do {
          voodoo_manager_request( manager_client, instance,
                                  VOODOOTEST_METHOD_ID_Push, VREQ_NONE, NULL,
                                  VMBT_INT, counter++,
                                  VMBT_NONE );
     } while (counter < NUM_ITEMS);
#else
     do {
          VoodooResponseMessage *response;

          voodoo_manager_request( manager_client, instance,
                                  VOODOOTEST_METHOD_ID_Sync, VREQ_RESPOND, &response,
                                  VMBT_NONE );

          voodoo_manager_finish_request( manager_client, response );

          counter++;
     } while (counter < NUM_ITEMS);
#endif

     {
          VoodooResponseMessage *response;

          voodoo_manager_request( manager_client, instance,
                                  VOODOOTEST_METHOD_ID_Sync, VREQ_RESPOND, &response,
                                  VMBT_NONE );

          voodoo_manager_finish_request( manager_client, response );
     }

     direct_clock_stop( &clock );


     D_INFO( "Voodoo/Test: Stopped after %lld.%03lld seconds... (%lld items/sec)\n",
             DIRECT_CLOCK_DIFF_SEC_MS( &clock ), NUM_ITEMS * 1000000ULL / direct_clock_diff( &clock ) );


     /* Shutdown libdirect. */
     direct_shutdown();

     return 0;
}
Beispiel #6
0
int
main( int argc, char *argv[] )
{
     DirectClock clock;
     int         counter = 0;

     dfb_config_init( &argc, &argv );

     /* Initialize libdirect. */
     direct_initialize();


     VoodooLink        link;
     VoodooManager    *manager;
     const char       *hostname = argv[1] ?: "127.0.0.1";


     voodoo_link_init_connect( &link, hostname, 23239, false );

     voodoo_manager_create( &link, NULL, NULL, &manager );



     direct_clock_start( &clock );

#if !BENCH_SYNC
     do {
          voodoo_manager_request( manager, 1,
                                  VOODOOTEST_METHOD_ID_Push, VREQ_QUEUE, NULL,
                                  VMBT_INT, counter++,
                                  VMBT_NONE );
     } while (counter < NUM_ITEMS);
#else
     do {
          VoodooResponseMessage *response;

          voodoo_manager_request( manager, 1,
                                  VOODOOTEST_METHOD_ID_Sync, VREQ_RESPOND, &response,
                                  VMBT_NONE );

          voodoo_manager_finish_request( manager, response );

          counter++;
     } while (counter < NUM_ITEMS);
#endif

     {
          VoodooResponseMessage *response;

          voodoo_manager_request( manager, 1,
                                  VOODOOTEST_METHOD_ID_Sync, VREQ_RESPOND, &response,
                                  VMBT_NONE );

          voodoo_manager_finish_request( manager, response );
     }

     direct_clock_stop( &clock );


     D_INFO( "Voodoo/Test: Stopped after %lld.%03lld seconds... (%lld items/sec)\n",
             DIRECT_CLOCK_DIFF_SEC_MS( &clock ), NUM_ITEMS * 1000000LL / direct_clock_diff( &clock ) );


     /* Shutdown libdirect. */
     direct_shutdown();

     return 0;
}
Beispiel #7
0
int
main( int argc, char *argv[] )
{
     int            i;
     DirectResult   ret;
     DirectLogType  log_type  = DLT_STDERR;
     const char    *log_param = NULL;
     DirectLog     *log;


     for (i=1; i<argc; i++) {
          if (!strcmp( argv[i], "-f" )) {
               if (++i < argc) {
                    log_type  = DLT_FILE;
                    log_param = argv[i];
               }
               else
                    return show_usage(argv[0]);
          }
          else if (!strcmp( argv[i], "-u" )) {
               if (++i < argc) {
                    log_type  = DLT_UDP;
                    log_param = argv[i];
               }
               else
                    return show_usage(argv[0]);
          }
          else
               return show_usage(argv[0]);
     }

     /* Initialize logging. */
     ret = direct_log_create( log_type, log_param, &log );
     if (ret)
          return -1;

     /* Set default log to use. */
     direct_log_set_default( log );


     /* Test memory leak detector by not freeing this one. */
     D_MALLOC( 1351 );

     D_INFO( "Direct/Test: Application starting...\n" );


     /* Initialize libdirect. */
     direct_initialize();


     D_INFO( "Direct/Test: Application stopping...\n" );

     /* Shutdown libdirect. */
     direct_shutdown();


     D_INFO( "Direct/Test: You should see a leak message with debug-mem turned on...\n" );

     /* Shutdown logging. */
     direct_log_destroy( log );

     direct_config->debug = true;
     direct_print_memleaks();

     return 0;
}
Beispiel #8
0
DFBResult
dfb_core_create( CoreDFB **ret_core )
{
     int      ret;
#if FUSION_BUILD_MULTI
     char     buf[16];
#endif
     CoreDFB       *core   = NULL;
     CoreDFBShared *shared = NULL;

     D_ASSERT( ret_core != NULL );
     D_ASSERT( dfb_config != NULL );

     D_DEBUG_AT( DirectFB_Core, "%s...\n", __FUNCTION__ );

     pthread_mutex_lock( &core_dfb_lock );

     D_ASSERT( core_dfb == NULL || core_dfb->refs > 0 );

     if (core_dfb) {
          D_MAGIC_ASSERT( core_dfb, CoreDFB );

          core_dfb->refs++;

          *ret_core = core_dfb;

          pthread_mutex_unlock( &core_dfb_lock );

          return DFB_OK;
     }

     direct_initialize();


     D_INFO( "DirectFB/Core: %s Application Core. ("BUILDTIME") %s%s\n",
             FUSION_BUILD_MULTI ? "Multi" : "Single",
             DIRECT_BUILD_DEBUG ? "[ DEBUG ]" : "",
             DIRECT_BUILD_TRACE ? "[ TRACE ]" : "" );


#if defined(DFB_DYNAMIC_LINKING) && defined(SOPATH)
     if (!dfb_lib_handle)
#ifdef RTLD_GLOBAL
          dfb_lib_handle = dlopen(SOPATH, RTLD_GLOBAL|RTLD_LAZY);
#else
          /* RTLD_GLOBAL is not defined on OpenBSD */
          dfb_lib_handle = dlopen(SOPATH, RTLD_LAZY);
#endif
#endif

     ret = dfb_system_lookup();
     if (ret)
          goto error;


     /* Allocate local core structure. */
     core = D_CALLOC( 1, sizeof(CoreDFB) );
     if (!core) {
          ret = D_OOM();
          goto error;
     }

     core->refs = 1;

     core->init_handler = direct_thread_add_init_handler( dfb_core_thread_init_handler, core );

#if FUSION_BUILD_MULTI
     dfb_system_thread_init();
#endif

     direct_find_best_memcpy();

     D_MAGIC_SET( core, CoreDFB );

     core_dfb = core;

     ret = fusion_enter( dfb_config->session, DIRECTFB_CORE_ABI, FER_ANY, &core->world );
     if (ret)
          goto error;

     core->fusion_id = fusion_id( core->world );

#if FUSION_BUILD_MULTI
     D_DEBUG_AT( DirectFB_Core, "world %d, fusion id %d\n", fusion_world_index(core->world), core->fusion_id );

     snprintf( buf, sizeof(buf), "%d", fusion_world_index(core->world) );

     setenv( "DIRECTFB_SESSION", buf, true );
#endif

     if (dfb_config->sync) {
          D_INFO( "DirectFB/Core: calling sync()...\n" );
          direct_sync();
     }

     if (dfb_config->core_sighandler)
          direct_signal_handler_add( DIRECT_SIGNAL_ANY, dfb_core_signal_handler, core, &core->signal_handler );

     if (fusion_arena_enter( core->world, "DirectFB/Core",
                             dfb_core_arena_initialize, dfb_core_arena_join,
                             core, &core->arena, &ret ) || ret)
     {
          ret = ret ? ret : DFB_FUSION;
          goto error;
     }

     shared = core->shared;
     D_MAGIC_ASSERT( shared, CoreDFBShared );

     if (dfb_config->block_all_signals)
          direct_signals_block_all();

     if (dfb_config->deinit_check)
          direct_cleanup_handler_add( dfb_core_deinit_check, NULL, &core->cleanup_handler );


     fusion_skirmish_prevail( &shared->lock );

     if (!core->master) {
          while (!shared->active)
               fusion_skirmish_wait( &shared->lock, 0 );
     }

     fusion_skirmish_dismiss( &shared->lock );

     dfb_font_manager_create( core, &core->font_manager );

     *ret_core = core;

     pthread_mutex_unlock( &core_dfb_lock );

     D_DEBUG_AT( DirectFB_Core, "Core successfully created.\n" );

     return DFB_OK;


error:
     if (core) {
          if (core->world)
               fusion_exit( core->world, false );

          if (core->init_handler)
               direct_thread_remove_init_handler( core->init_handler );

          if (core->signal_handler)
               direct_signal_handler_remove( core->signal_handler );

          D_MAGIC_CLEAR( core );

          D_FREE( core );
          core_dfb = NULL;
     }

     pthread_mutex_unlock( &core_dfb_lock );

     direct_shutdown();

     return ret;
}
Beispiel #9
0
/*
 * Programs have to call this to get the super interface
 * which is needed to access other functions
 */
DFBResult
DirectFBCreate( IDirectFB **interface )
{
     DFBResult  ret;
     IDirectFB *dfb;
     CoreDFB   *core_dfb;

     if (!dfb_config) {
          /*  don't use D_ERROR() here, it uses dfb_config  */
          direct_log_printf( NULL, "(!) DirectFBCreate: DirectFBInit "
                             "has to be called before DirectFBCreate!\n" );
          return DFB_INIT;
     }

     if (!interface)
          return DFB_INVARG;

     if (idirectfb_singleton) {
          idirectfb_singleton->AddRef( idirectfb_singleton );
          *interface = idirectfb_singleton;
          return DFB_OK;
     }

     direct_initialize();

     if ( !(direct_config->quiet & DMT_BANNER) && dfb_config->banner) {
          direct_log_printf( NULL,
                             "\n"
                             "   ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB " DIRECTFB_VERSION " |~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
                             "        (c) 2001-2009  The world wide DirectFB Open Source Community\n"
                             "        (c) 2000-2004  Convergence (integrated media) GmbH\n"
                             "      ----------------------------------------------------------------\n"
                             "\n" );
     }

     if (dfb_config->remote.host)
          return CreateRemote( dfb_config->remote.host, dfb_config->remote.session, interface );

     ret = dfb_core_create( &core_dfb );
     if (ret)
          return ret;

     DIRECT_ALLOCATE_INTERFACE( dfb, IDirectFB );

     ret = IDirectFB_Construct( dfb, core_dfb );
     if (ret) {
          dfb_core_destroy( core_dfb, false );
          return ret;
     }

     if (dfb_core_is_master( core_dfb )) {
          /* not fatal */
          ret = dfb_wm_post_init( core_dfb );
          if (ret)
               D_DERROR( ret, "DirectFBCreate: Post initialization of WM failed!\n" );

          dfb_core_activate( core_dfb );
     }

     *interface = idirectfb_singleton = dfb;

     return DFB_OK;
}
Beispiel #10
0
int
fusion_init( int world, int abi_version, int *world_ret )
{
     char        buf[20];
     FusionEnter enter;

     /* Check against multiple initialization. */
     if (_fusion_id) {
          /* Increment local reference counter. */
          fusion_refs++;

          return _fusion_id;
     }

     direct_initialize();

     /* Open Fusion Kernel Device. */
     if (world < 0) {
          for (world=0; world<256; world++) {
               snprintf( buf, sizeof(buf), "/dev/fusion/%d", world );

               _fusion_fd = open (buf, O_RDWR | O_NONBLOCK | O_EXCL);
               if (_fusion_fd < 0) {
                    if (errno == EBUSY)
                         continue;

                    D_PERROR( "Fusion/Init: opening '%s' failed!\n", buf );
                    direct_shutdown();
                    return -1;
               }
               else
                    break;
          }
     }
     else {
          snprintf( buf, sizeof(buf), "/dev/fusion/%d", world );

          _fusion_fd = open (buf, O_RDWR | O_NONBLOCK);
          if (_fusion_fd < 0) {
               D_PERROR( "Fusion/Init: opening '%s' failed!\n", buf );
               direct_shutdown();
               return -1;
          }
     }

     enter.api.major = FUSION_API_MAJOR;
     enter.api.minor = FUSION_API_MINOR;
     enter.fusion_id = 0;

     /* Get our Fusion ID. */
     if (ioctl( _fusion_fd, FUSION_ENTER, &enter )) {
          D_PERROR( "Fusion/Init: FUSION_ENTER failed!\n" );
          goto error;
     }

     if (!enter.fusion_id) {
          D_ERROR( "Fusion/Init: Got no ID from FUSION_ENTER! Kernel module might be too old.\n" );
          goto error;
     }

     _fusion_id = enter.fusion_id;


     /* Initialize local reference counter. */
     fusion_refs = 1;

     /* Initialize shmalloc part. */
     if (!__shmalloc_init( world, _fusion_id == 1 )) {
          D_ERROR( "Fusion/Init: Shared memory initialization failed.\n"
                   "\n"
                   "Please make sure that a tmpfs mount point with at least 4MB of free space\n"
                   "is available for read/write, see the DirectFB README for more instructions.\n" );
          goto error;
     }

     if (_fusion_id == 1) {
          _fusion_shared = __shmalloc_allocate_root( sizeof(FusionShared) );

          _fusion_shared->abi_version = abi_version;

          fusion_skirmish_init( &_fusion_shared->arenas_lock,     "Fusion Arenas" );
          fusion_skirmish_init( &_fusion_shared->reactor_globals, "Fusion Reactor Globals" );

          _sheap->reactor = fusion_reactor_new( sizeof(long), "Shared Memory Heap" );
          if (!_sheap->reactor) {
               __shmalloc_exit( true, true );
               goto error_reactor;
          }

          gettimeofday( &_fusion_shared->start_time, NULL );
     }
     else {
          _fusion_shared = __shmalloc_get_root();

          if (_fusion_shared->abi_version != abi_version) {
               D_ERROR( "Fusion/Init: ABI version mismatch (my: %d, their: %d)\n",
                        abi_version, _fusion_shared->abi_version );
               __shmalloc_exit( false, false );
               goto error;
          }
     }

     __shmalloc_attach();

     direct_clock_set_start( &_fusion_shared->start_time );

     direct_signal_handler_add( SIGSEGV, fusion_signal_handler, NULL, &signal_handler );

     read_loop = direct_thread_create( DTT_MESSAGING, fusion_read_loop, NULL, "Fusion Dispatch" );

     if (world_ret)
          *world_ret = world;

     return _fusion_id;


error_reactor:
     fusion_skirmish_destroy( &_fusion_shared->arenas_lock );
     fusion_skirmish_destroy( &_fusion_shared->reactor_globals );

error:
     _fusion_shared = NULL;
     _fusion_id = 0;

     close( _fusion_fd );
     _fusion_fd = -1;
     direct_shutdown();
     return -1;
}
Beispiel #11
0
int
main( int argc, char *argv[] )
{
     int             ret;
     int             fd;
     struct stat     stat;
     void           *ptr  = MAP_FAILED;
     Entity::vector  faces;
     DGIFFHeader     header = {
          magic: { 'D', 'G', 'I', 'F', 'F' },
          major: 0,
          minor: 0,
          flags: DGIFF_FLAG_LITTLE_ENDIAN,
          num_faces: 0
     };

     direct_initialize();

     direct_debug_config_domain( "mkdgiff", true );

     direct_config->debug    = true;
     direct_config->debugmem = true;

     /* Parse the command line. */
     if (!parse_command_line( argc, argv ))
          return -1;


     /* Open the file. */
     fd = open( filename, O_RDONLY );
     if (fd < 0) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during open() of '%s'!\n", filename );
          return ret;
     }

     /* Query file size etc. */
     if (fstat( fd, &stat ) < 0) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during fstat() of '%s'!\n", filename );
          goto out;
     }

     /* Memory map the file. */
     ptr = mmap( NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0 );
     if (ptr == MAP_FAILED) {
          ret = errno2result( errno );
          D_PERROR( "Font/DGIFF: Failure during mmap() of '%s'!\n", filename );
          goto out;
     }


     get_entities( (const char*) ptr, stat.st_size, faces );

     header.num_faces = faces.size();



     fwrite( &header, sizeof(header), 1, stdout );

     for (Entity::vector::const_iterator iter = faces.begin(); iter != faces.end(); iter++) {
          const Face *face = dynamic_cast<const Face*>( *iter );

          face->Dump();

          ret = do_face( face );
          if (ret)
               goto out;
     }


out:
     if (ptr != MAP_FAILED)
          munmap( ptr, stat.st_size );

     close( fd );

     direct_print_memleaks();

     direct_shutdown();

     return ret;
}