diff options
author | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-16 22:50:37 +0000 |
---|---|---|
committer | LarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b> | 2005-03-16 22:50:37 +0000 |
commit | ae1a9c9f16c5e93c72fcfaae1ad14f3662b252cb (patch) | |
tree | 2075885d9b67cb281dcef64729a106f680c94eb9 | |
parent | 283a4201828edde1cf92e59ccbb0395a0f894538 (diff) | |
download | vdr-plugin-muggle-ae1a9c9f16c5e93c72fcfaae1ad14f3662b252cb.tar.gz vdr-plugin-muggle-ae1a9c9f16c5e93c72fcfaae1ad14f3662b252cb.tar.bz2 |
Import now runs threaded when executed from VDR menu
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@572 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | mg_setup.c | 1 | ||||
-rw-r--r-- | mg_setup.h | 2 | ||||
-rw-r--r-- | mg_sync.c | 6 | ||||
-rw-r--r-- | mg_sync.h | 8 | ||||
-rw-r--r-- | mg_thread_sync.c | 63 | ||||
-rw-r--r-- | mg_thread_sync.h | 39 | ||||
-rw-r--r-- | vdr_actions.c | 9 | ||||
-rw-r--r-- | vdr_setup.c | 21 |
9 files changed, 133 insertions, 18 deletions
@@ -57,7 +57,7 @@ DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' -DMYSQLCLIENTVERSION=' ### The object files (add further files here): -OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_mysql.o mg_sync.o mg_order.o mg_content.o mg_selection.o vdr_actions.o vdr_menu.o mg_tools.o \ +OBJS = $(PLUGIN).o i18n.o mg_valmap.o mg_mysql.o mg_sync.o mg_thread_sync.o mg_order.o mg_content.o mg_selection.o vdr_actions.o vdr_menu.o mg_tools.o \ vdr_decoder_mp3.o vdr_stream.o vdr_decoder.o vdr_player.o \ vdr_setup.o mg_setup.o @@ -33,4 +33,5 @@ mgSetup::mgSetup () ToplevelDir = "/mnt/music/"; DbHost = "localhost"; DbName = "GiantDisc"; + DeleteStaleReferences = false; } @@ -51,6 +51,8 @@ class mgSetup char PathPrefix[MAX_STRING_LEN]; + int DeleteStaleReferences; + public: mgSetup (void); @@ -152,7 +152,7 @@ mgSync::mgSync() mgSync::~mgSync() { - if (m_genre_rows) mysql_free_result(m_genre_rows); + if (m_genre_rows) mysql_free_result(m_genre_rows); } void @@ -296,8 +296,8 @@ mgSync::SyncFile(const char *filename) void mgSync::Sync(char * const * path_argv, bool delete_missing) { - if (!m_db.Connected()) - return; + if (!m_db.Connected()) + return; unsigned int count=0; m_db.CreateFolderFields(); chdir(the_setup.ToplevelDir); @@ -21,8 +21,9 @@ class mgSync { public: - mgSync(); + mgSync(); ~mgSync(); + //! \brief drop and create the data base GiantDisc void Create(); @@ -33,8 +34,8 @@ class mgSync * \par delete_missing if the file does not exist, delete the * data base entry. If the file is unreadable, do not delete. */ - void Sync(char * const * path_argv, bool delete_missing=false); - + void Sync(char * const * path_argv, bool delete_missing = false); + private: mgmySql m_db; char *sql_Cstring(TagLib::String s,char *buf=0); @@ -48,6 +49,7 @@ class mgSync map<string,string> m_Genres; MYSQL_RES* m_genre_rows; + char c_album[520]; // at least 256 * 2 + 2 for VARCHAR(255), see sql_string() char c_artist[520]; char c_title[520]; diff --git a/mg_thread_sync.c b/mg_thread_sync.c new file mode 100644 index 0000000..85b55a6 --- /dev/null +++ b/mg_thread_sync.c @@ -0,0 +1,63 @@ + +#include <mysql/mysql.h> + +#include "mg_thread_sync.h" +#include "mg_sync.h" + +static mgThreadSync* the_instance = NULL; + +mgThreadSync* mgThreadSync::get_instance() +{ + if( !the_instance ) + { + the_instance = new mgThreadSync(); + } + + + if( the_instance->Active() ) + { + return NULL; + } + else + { + return the_instance; + } +} + +void mgThreadSync::SetArguments( char * const * path_argv, bool delete_missing ) +{ + m_path = path_argv; + m_delete = delete_missing; +} + +bool mgThreadSync::Sync(char * const * path_argv, bool delete_missing ) +{ + mgThreadSync *s = mgThreadSync::get_instance(); + if( s ) + { + s->SetArguments( path_argv, delete_missing ); + s->Start(); + + return true; + } + else + { + return false; + } +} + +void +mgThreadSync::Action() +{ + mysql_thread_init(); + + if( m_path ) + { + mgSync s; + s.Sync( m_path, m_delete ); + } + + mysql_thread_end(); +} + + diff --git a/mg_thread_sync.h b/mg_thread_sync.h new file mode 100644 index 0000000..d9a2e3f --- /dev/null +++ b/mg_thread_sync.h @@ -0,0 +1,39 @@ +/*! + * \file mg_sync.h + * \brief synchronization between SQL and filesystem + * + * \version $Revision: 1.0 $ + * \date $Date: 2004-12-07 10:10:35 +0200 (Tue, 07 Dec 2004) $ + * \author Wolfgang Rohdewald + * \author Responsible author: $Author: wr $ + * + */ + +#ifndef _MG_THREADSYNC_H +#define _MG_THREADSYNC_H + +#include <thread.h> + +class mgThreadSync : public cThread +{ + public: + + static mgThreadSync* get_instance(); + + bool Sync(char * const * path_argv, bool delete_missing ); + + protected: + /*! \brief Runs the import routine as a separate thread + */ + virtual void Action(); + + private: + + void SetArguments( char * const * path_argv, bool delete_missing ); + + char * const *m_path; + bool m_delete; + +}; + +#endif diff --git a/vdr_actions.c b/vdr_actions.c index 4ab8483..1c12689 100644 --- a/vdr_actions.c +++ b/vdr_actions.c @@ -29,7 +29,7 @@ #define DEBUG #include "mg_tools.h" #include "mg_order.h" -#include "mg_sync.h" +#include "mg_thread_sync.h" static bool IsEntry(mgActions i) @@ -709,8 +709,11 @@ mgCmdSync::ProcessKey(eKeys key) void mgCmdSync::Execute() { - mgSync s; - s.Sync(sync_args); + mgThreadSync *s = mgThreadSync::get_instance(); + if( s ) + { + s->Sync( sync_args, (bool) the_setup.DeleteStaleReferences ); + } } //! \brief sets the default collection selection diff --git a/vdr_setup.c b/vdr_setup.c index c2f442e..df10c0d 100644 --- a/vdr_setup.c +++ b/vdr_setup.c @@ -36,8 +36,8 @@ mgMenuSetup::mgMenuSetup () cMenuEditBoolItem (tr ("Setup.Muggle$Initial loop mode"), &m_data.InitLoopMode)); Add (new - cMenuEditBoolItem (tr ("Setup.Muggle$Initial shuffle mode"), - &m_data.InitShuffleMode)); + cMenuEditBoolItem (tr ("Setup.Muggle$Initial shuffle mode"), + &m_data.InitShuffleMode)); Add (new cMenuEditBoolItem (tr ("Setup.Muggle$Audio mode"), &m_data.AudioMode, tr ("Round"), tr ("Dither"))); @@ -56,12 +56,16 @@ mgMenuSetup::mgMenuSetup () Add (new cMenuEditIntItem (tr ("Setup.Muggle$Limiter level"), &m_data.LimiterLevel, MIN_LIMITER_LEVEL, 100)); - - mgAction *a = actGenerate(actSync); - const char *mn = a->MenuName(); - a->SetText(mn); - free(const_cast<char*>(mn)); - Add(dynamic_cast<cOsdItem*>(a)); + Add (new + cMenuEditBoolItem (tr ("Setup.Muggle$Delete stale references"), + &m_data.DeleteStaleReferences)); + + + mgAction *a = actGenerate(actSync); + const char *mn = a->MenuName(); + a->SetText(mn); + free(const_cast<char*>(mn)); + Add(dynamic_cast<cOsdItem*>(a)); } @@ -78,5 +82,6 @@ mgMenuSetup::Store (void) SetupStore ("TargetLevel", the_setup.TargetLevel); SetupStore ("LimiterLevel", the_setup.LimiterLevel); SetupStore ("Only48kHz", the_setup.Only48kHz); + SetupStore ("DeleteStaleReferences", the_setup.DeleteStaleReferences); } |