struct hb_handle_s
{
+ int id;
+
/* The "Check for update" thread */
int build;
char version[32];
hb_lock_t *hb_avcodec_lock;
hb_work_object_t * hb_objects = NULL;
+int hb_instance_counter = 0;
int hb_process_initialized = 0;
static void thread_func( void * );
*/
hb_handle_t * hb_init( int verbose, int update_check )
{
- if (!hb_process_initialized)
- {
+ if (!hb_process_initialized)
+ {
#ifdef USE_PTHREAD
#if defined( _WIN32 ) || defined( __MINGW32__ )
- pthread_win32_process_attach_np();
+ pthread_win32_process_attach_np();
#endif
#endif
- hb_process_initialized =1;
- }
-
+ hb_process_initialized =1;
+ }
+
hb_handle_t * h = calloc( sizeof( hb_handle_t ), 1 );
uint64_t date;
global_verbosity_level = verbose;
if( verbose )
putenv( "HB_DEBUG=1" );
-
+
+ h->id = hb_instance_counter++;
+
/* Check for an update on the website if asked to */
h->build = -1;
#ifdef __APPLE__
hb_register( &hb_encca_aac );
#endif
-
+
return h;
}
putenv( "HB_DEBUG=1" );
}
+ h->id = hb_instance_counter++;
+
/* Check for an update on the website if asked to */
h->build = -1;
struct dirent * entry;
memset( dirname, 0, 1024 );
- hb_get_tempory_directory( h, dirname );
+ hb_get_temporary_directory( dirname );
dir = opendir( dirname );
if (dir == NULL) return;
for( i = 0; i < count; i++ )
{
title = hb_list_item( h->list_title, i );
- len = snprintf( filename, 1024, "%" PRIxPTR, (intptr_t) title );
+ len = snprintf( filename, 1024, "%d_%d", h->id, title->index );
if (strncmp(entry->d_name, filename, len) == 0)
{
snprintf( filename, 1024, "%s/%s", dirname, entry->d_name );
memset( filename, 0, 1024 );
- hb_get_tempory_filename( h, filename, "%" PRIxPTR "%d",
- (intptr_t) title, picture );
+ hb_get_tempory_filename( h, filename, "%d_%d_%d",
+ h->id, title->index, picture );
file = fopen( filename, "rb" );
if( !file )
hb_title_t * title;
h->die = 1;
+
hb_thread_close( &h->main_thread );
while( ( title = hb_list_item( h->list_title, 0 ) ) )
hb_list_close( &h->jobs );
hb_lock_close( &h->state_lock );
hb_lock_close( &h->pause_lock );
+
free( h );
*_h = NULL;
+}
+
+/**
+ * Cleans up libhb at a process level. Call before the app closes. Removes preview directory.
+ */
+void hb_global_close()
+{
+ char dirname[1024];
+ DIR * dir;
+ struct dirent * entry;
+
+ /* Find and remove temp folder */
+ memset( dirname, 0, 1024 );
+ hb_get_temporary_directory( dirname );
+ dir = opendir( dirname );
+ if (dir)
+ {
+ while( ( entry = readdir( dir ) ) )
+ {
+ char filename[1024];
+ if( entry->d_name[0] == '.' )
+ {
+ continue;
+ }
+ memset( filename, 0, 1024 );
+ snprintf( filename, 1023, "%s/%s", dirname, entry->d_name );
+ unlink( filename );
+ }
+ closedir( dir );
+ rmdir( dirname );
+ }
}
/**
{
hb_handle_t * h = (hb_handle_t *) _h;
char dirname[1024];
- DIR * dir;
- struct dirent * entry;
h->pid = getpid();
/* Create folder for temporary files */
memset( dirname, 0, 1024 );
- hb_get_tempory_directory( h, dirname );
+ hb_get_temporary_directory( dirname );
hb_mkdir( dirname );
hb_snooze( 50 );
}
+ if( h->scan_thread )
+ {
+ hb_scan_stop( h );
+ hb_thread_close( &h->scan_thread );
+ }
if( h->work_thread )
{
hb_stop( h );
hb_thread_close( &h->work_thread );
}
-
- /* Remove temp folder */
- dir = opendir( dirname );
- if (dir)
- {
- while( ( entry = readdir( dir ) ) )
- {
- char filename[1024];
- if( entry->d_name[0] == '.' )
- {
- continue;
- }
- memset( filename, 0, 1024 );
- snprintf( filename, 1023, "%s/%s", dirname, entry->d_name );
- unlink( filename );
- }
- closedir( dir );
- rmdir( dirname );
- }
+ hb_remove_previews( h );
}
/**
return h->pid;
}
+/**
+ * Returns the id for the given instance.
+ * @param h Handle to hb_handle_t
+ */
+int hb_get_instance_id( hb_handle_t * h )
+{
+ return h->id;
+}
+
/**
* Sets the current state.
* @param h Handle to hb_handle_t
#endif
#include <stddef.h>
+#include <unistd.h>
#include "hb.h"
}
/************************************************************************
- * Get a tempory directory for HB
+ * Get a temporary directory for HB
***********************************************************************/
-void hb_get_tempory_directory( hb_handle_t * h, char path[512] )
+void hb_get_temporary_directory( char path[512] )
{
char base[512];
if( base[strlen(base)-1] == '/' )
base[strlen(base)-1] = '\0';
- snprintf( path, 512, "%s/hb.%d", base, hb_get_pid( h ) );
+ snprintf( path, 512, "%s/hb.%d", base, getpid() );
}
/************************************************************************
{
va_list args;
- hb_get_tempory_directory( h, name );
+ hb_get_temporary_directory( name );
strcat( name, "/" );
va_start( args, fmt );