DFBResult dfb_vt_detach( bool force ) { D_DEBUG_AT( VT, "%s()\n", __FUNCTION__ ); if (dfb_config->vt_switch || force) { int fd; struct vt_stat vt_state; fd = open( "/dev/tty", O_RDONLY | O_NOCTTY ); if (fd < 0) { if (errno == ENXIO) return DFB_OK; D_PERROR( "DirectFB/VT: Opening /dev/tty failed!\n" ); return errno2result( errno ); } if (ioctl( fd, VT_GETSTATE, &vt_state )) { close( fd ); return DFB_OK; } if (ioctl( fd, TIOCNOTTY )) { D_PERROR( "DirectFB/VT: TIOCNOTTY on /dev/tty failed\n" ); close( fd ); return errno2result( errno ); } close( fd ); } return DFB_OK; }
static DirectResult init_udp( DirectLog *log, const char *hostport ) { DirectResult ret; int fd; struct addrinfo *addr; ret = parse_host_addr( hostport, &addr ); if (ret) return ret; fd = socket( addr->ai_family, SOCK_DGRAM, 0 ); if (fd < 0) { ret = errno2result( errno ); D_PERROR( "Direct/Log: Could not create a UDP socket!\n" ); freeaddrinfo( addr ); return ret; } ret = connect( fd, addr->ai_addr, addr->ai_addrlen ); freeaddrinfo( addr ); if (ret) { ret = errno2result( errno ); D_PERROR( "Direct/Log: Could not connect UDP socket to '%s'!\n", hostport ); close( fd ); return ret; } log->fd = fd; return DR_OK; }
static DirectResult common_log_flush( DirectLog *log, bool sync ) { if (log->type == DLT_STDERR && fflush( stderr )) return errno2result( errno ); if (sync) { if (fsync( (long) log->data )) return errno2result( errno ); } return DR_OK; }
DirectResult voodoo_play_get_broadcast( VoodooPlayAddress **ret_addr, size_t *ret_num ) { DirectResult ret = DR_OK; VoodooPlayAddress *addr; // Get local host name char szHostName[128] = ""; if (gethostname(szHostName, sizeof(szHostName))) { ret = errno2result( errno ); D_PERROR( "Voodoo/Win32: gethostname() failed!\n" ); return ret; } // Get local IP addresses struct hostent *pHost = 0; pHost = gethostbyname(szHostName); if (!pHost) { ret = errno2result( errno ); D_PERROR( "Voodoo/Win32: gethostbyname('%s') failed!\n", szHostName ); return ret; } size_t iCnt, iTotal = 0; for (iCnt = 0; pHost->h_addr_list[iCnt]; ++iCnt) iTotal++; addr = D_CALLOC( iTotal, sizeof(VoodooPlayAddress) ); if (!addr) return D_OOM(); for (iCnt = 0; pHost->h_addr_list[iCnt]; ++iCnt) { struct sockaddr_in SocketAddress; memcpy(&SocketAddress.sin_addr, pHost->h_addr_list[iCnt], pHost->h_length); voodoo_play_from_inet_addr( &addr[iCnt], SocketAddress.sin_addr.s_addr ); } *ret_addr = addr; *ret_num = iTotal; return DR_OK; }
DirectResult fusion_skirmish_destroy (FusionSkirmish *skirmish) { D_ASSERT( skirmish != NULL ); D_DEBUG_AT( Fusion_Skirmish, "fusion_skirmish_destroy( %p [%d] )\n", skirmish, skirmish->multi.id ); if (skirmish->single) { int retval; pthread_cond_broadcast( &skirmish->single->cond ); pthread_cond_destroy( &skirmish->single->cond ); retval = pthread_mutex_destroy( &skirmish->single->lock ); D_FREE( skirmish->single ); return errno2result( retval ); } while (ioctl( _fusion_fd( skirmish->multi.shared ), FUSION_SKIRMISH_DESTROY, &skirmish->multi.id )) { switch (errno) { case EINTR: continue; case EINVAL: D_ERROR ("Fusion/Lock: invalid skirmish\n"); return DR_DESTROYED; } D_PERROR ("FUSION_SKIRMISH_DESTROY"); return DR_FUSION; } return DR_OK; }
DirectResult fusion_skirmish_dismiss (FusionSkirmish *skirmish) { D_ASSERT( skirmish != NULL ); if (skirmish->single) { skirmish->single->count--; if (pthread_mutex_unlock( &skirmish->single->lock )) return errno2result( errno ); return DR_OK; } while (ioctl (_fusion_fd( skirmish->multi.shared ), FUSION_SKIRMISH_DISMISS, &skirmish->multi.id)) { switch (errno) { case EINTR: continue; case EINVAL: D_ERROR ("Fusion/Lock: invalid skirmish\n"); return DR_DESTROYED; } D_PERROR ("FUSION_SKIRMISH_DISMISS"); return DR_FUSION; } return DR_OK; }
DirectResult fusion_skirmish_swoop( FusionSkirmish *skirmish ) { D_ASSERT( skirmish != NULL ); if (skirmish->single) { if (pthread_mutex_trylock( &skirmish->single->lock )) return errno2result( errno ); skirmish->single->count++; return DR_OK; } while (ioctl (_fusion_fd( skirmish->multi.shared ), FUSION_SKIRMISH_SWOOP, &skirmish->multi.id)) { switch (errno) { case EINTR: continue; case EAGAIN: return DR_BUSY; case EINVAL: D_ERROR ("Fusion/Lock: invalid skirmish\n"); return DR_DESTROYED; } D_PERROR ("FUSION_SKIRMISH_SWOOP"); return DR_FUSION; } return DR_OK; }
DirectResult direct_futex( int *uaddr, int op, int val, const struct timespec *timeout, int *uaddr2, int val3 ) { int ret; unsigned int count; switch (op) { case FUTEX_WAIT: count = D_SYNC_ADD_AND_FETCH( &__Direct_Futex_Wait_Count, 1 ); D_DEBUG_AT( Direct_Futex, "## ## WAIT FOR --> %p <-- %d (<-%d) ## ## ## ## * %u\n", uaddr, *uaddr, val, count ); break; case FUTEX_WAKE: count = D_SYNC_ADD_AND_FETCH( &__Direct_Futex_Wake_Count, 1 ); D_DEBUG_AT( Direct_Futex, "### WAKE UP =--> %p <--= %d (->%d) ### ### ### * %u\n", uaddr, *uaddr, val, count ); break; default: D_DEBUG_AT( Direct_Futex, "# # UNKNOWN FUTEX OP # #\n" ); } ret = -ENOSYS;//sys_futex( uaddr, op, val, (void*) timeout, uaddr2, val3 ); if (ret < 0) { schedule_timeout_uninterruptible( 1 ); // FIXME return errno2result( -ret ); } return DR_OK; }
DFBResult pxa3xxEngineSync( void *drv, void *dev ) { DFBResult ret = DFB_OK; PXA3XXDriverData *pdrv = drv; PXA3XXGfxSharedArea *shared = pdrv->gfx_shared; D_DEBUG_AT( PXA3XX_BLT, "%s()\n", __FUNCTION__ ); DUMP_INFO(); while (shared->hw_running && ioctl( pdrv->gfx_fd, PXA3XX_GCU_IOCTL_WAIT_IDLE ) < 0) { if (errno == EINTR) continue; ret = errno2result( errno ); D_PERROR( "PXA3XX/BLT: PXA3XX_GCU_IOCTL_WAIT_IDLE failed!\n" ); direct_log_printf( NULL, " -> %srunning, hw %d-%d, next %d-%d - %svalid\n", \ pdrv->gfx_shared->hw_running ? "" : "not ", \ pdrv->gfx_shared->hw_start, \ pdrv->gfx_shared->hw_end, \ pdrv->gfx_shared->next_start, \ pdrv->gfx_shared->next_end, \ pdrv->gfx_shared->next_valid ? "" : "not " ); break; } if (ret == DFB_OK) { D_ASSERT( !shared->hw_running ); } return ret; }
DirectResult voodoo_link_init_fd( VoodooLink *link, int fd[2] ) { Link *l; int ret; ret = read( fd[0], &link->code, sizeof(link->code) ); if (ret != 4) { D_ERROR( "Voodoo/Link: Coult not read initial four bytes! (errno=%d ret=%d)\n", errno, ret ); close (fd[0] ); return DR_IO; } l = D_CALLOC( 1, sizeof(Link) ); if (!l) return D_OOM(); l->fd[0] = fd[0]; l->fd[1] = fd[1]; if (pipe( l->wakeup_fds )) return errno2result( errno ); link->priv = l; link->Close = Close; link->Read = Read; link->Write = Write; link->SendReceive = SendReceive; link->WakeUp = WakeUp; link->WaitForData = WaitForData; return DR_OK; }
DirectResult direct_mutex_init( DirectMutex *mutex ) { if (pthread_mutex_init( &mutex->lock, NULL )) return errno2result( errno ); return DR_OK; }
DirectResult direct_kill( pid_t pid, int sig ) { if (kill( pid, sig )) return errno2result( errno ); return DR_OK; }
DirectResult direct_mutex_deinit( DirectMutex *mutex ) { if (pthread_mutex_destroy( &mutex->lock )) return errno2result( errno ); return DR_OK; }
DirectResult direct_socketpair( int __domain, int __type, int __protocol, int __fds[2] ) { if (socketpair( __domain, __type, __protocol, __fds )) return errno2result( errno ); return DR_OK; }
DirectResult direct_mutex_trylock( DirectMutex *mutex ) { if (pthread_mutex_trylock( &mutex->lock )) return errno2result( errno ); return DR_OK; }
DirectResult direct_file_unmap( DirectFile *file, void *addr, size_t bytes ) { if (munmap( addr, bytes )) return errno2result( errno ); return DR_OK; }
static DFBResult Construct( IDirectFBImageProvider *thiz, ... ) { DFBResult ret; struct stat info; void *ptr; IDirectFBDataBuffer_data *buffer_data; IDirectFBDataBuffer *buffer; CoreDFB *core; va_list tag; DIRECT_ALLOCATE_INTERFACE_DATA(thiz, IDirectFBImageProvider_ANDROID) va_start( tag, thiz ); buffer = va_arg( tag, IDirectFBDataBuffer * ); core = va_arg( tag, CoreDFB * ); va_end( tag ); D_MAGIC_ASSERT( (IAny*) buffer, DirectInterface ); buffer_data = buffer->priv; if (!buffer_data) { ret = DFB_DEAD; goto error; } if (buffer_data->filename) { data->path = D_STRDUP( buffer_data->filename ); if (stat( buffer_data->filename, &info ) < 0) { ret = errno2result( errno ); D_PERROR( "ImageProvider/ANDROID: Failure during fstat() of '%s'!\n", buffer_data->filename ); goto error; } } data->base.ref = 1; data->base.core = core; data->base.buffer = buffer; buffer->AddRef( buffer ); data->base.Destruct = IDirectFBImageProvider_ANDROID_Destruct; thiz->RenderTo = IDirectFBImageProvider_ANDROID_RenderTo; thiz->GetImageDescription = IDirectFBImageProvider_ANDROID_GetImageDescription; thiz->GetSurfaceDescription = IDirectFBImageProvider_ANDROID_GetSurfaceDescription; return DFB_OK; error: DIRECT_DEALLOCATE_INTERFACE(thiz); return ret; }
static DirectResult stderr_log_set_buffer( DirectLog *log, char *buffer, size_t bytes ) { if (setvbuf( stderr, buffer, _IOLBF, bytes )) return errno2result( errno ); return DR_OK; }
DirectResult direct_file_seek_to( DirectFile *file, off_t offset ) { D_ASSERT( file != NULL ); if (lseek( file->fd, offset, SEEK_SET ) < 0) return errno2result( errno ); return DR_OK; }
static DirectResult WakeUp( VoodooLink *link ) { Link *l = link->priv; char c = 0; if (write( l->wakeup_fds[1], &c, 1 )) return errno2result( errno ); return DR_OK; }
DirectResult direct_sigaction( int signum, const struct sigaction *act, struct sigaction *oldact ) { D_DEBUG_LOG( Direct_Signals, 3, "%s( %d, %p, %p )\n", __FUNCTION__, signum, act, oldact ); if (sigaction( signum, act, oldact ) < 0) return errno2result( errno ); return DR_OK; }
DirectResult direct_tgkill( int tgid, int tid, int sig ) { #if defined(__NR_tgkill) /* present on linux >= 2.5.75 */ if (syscall(__NR_tgkill) < 0) #else #warning no tgkill #endif return errno2result( errno ); return DR_OK; }
DirectResult direct_access( const char *name, int flags ) { int ret; D_ASSERT( name != NULL ); ret = access( name, flags ); if (ret < 0) return errno2result( errno ); return DR_OK; }
DirectResult direct_file_open( DirectFile *file, const char *name, int flags, mode_t mode ) { D_ASSERT( file != NULL ); D_ASSERT( name != NULL ); file->file = NULL; file->fd = open( name, flags, mode ); if (file->fd < 0) return errno2result( errno ); return DR_OK; }
DirectResult direct_popen( DirectFile *file, const char *name, int flags ) { D_ASSERT( file != NULL ); D_ASSERT( name != NULL ); file->file = popen( name, (flags & O_WRONLY) ? "w" : (flags & O_RDWR) ? "rw" : "r" ); if (!file->file) return errno2result( errno ); file->fd = fileno( file->file ); return DR_OK; }
DirectResult direct_file_get_info( DirectFile *file, DirectFileInfo *ret_info ) { struct stat st; D_ASSERT( file != NULL ); D_ASSERT( ret_info != NULL ); if (fstat( file->fd, &st )) return errno2result( errno ); ret_info->flags = DFIF_SIZE; ret_info->size = st.st_size; return DR_OK; }
DirectResult direct_readlink( const char *name, char *buf, size_t length, size_t *ret_length ) { int ret; D_ASSERT( name != NULL ); ret = readlink( name, buf, length ); if (ret < 0) return errno2result( errno ); if (ret_length) *ret_length = ret; return DR_OK; }
DirectResult direct_file_write( DirectFile *file, const void *buffer, size_t bytes, size_t *ret_bytes ) { ssize_t num; D_ASSERT( file != NULL ); D_ASSERT( buffer != NULL ); num = write( file->fd, buffer, bytes ); if (num < 0) return errno2result( errno ); if (ret_bytes) *ret_bytes = num; return DR_OK; }
DirectResult direct_pclose( DirectFile *file ) { int ret; D_ASSERT( file != NULL ); D_ASSERT( file->file != NULL ); ret = fclose( file->file ); close( file->fd ); if (ret < 0) return errno2result( errno ); return DR_OK; }
static DirectResult init_file( DirectLog *log, const char *filename ) { DirectResult ret; int fd; fd = open( filename, O_WRONLY | O_CREAT | O_APPEND, 0664 ); if (fd < 0) { ret = errno2result( errno ); D_PERROR( "Direct/Log: Could not open '%s' for writing!\n", filename ); return ret; } log->fd = fd; return DR_OK; }