]> Creatis software - creaImageIO.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Mon, 16 Feb 2009 09:47:02 +0000 (09:47 +0000)
committerguigues <guigues>
Mon, 16 Feb 2009 09:47:02 +0000 (09:47 +0000)
appli/gimmick/gimmick.ggo
appli/gimmick/gimmick_ggo.c
appli/gimmick/gimmick_ggo.h
appli/gimmick/main.cxx
src2/creaImageIOGimmick.cpp
src2/creaImageIOGimmick.h
src2/creaImageIOSQLiteTreeHandler.cpp
src2/creaImageIOSystem.h

index d67d7ee4e81f448ffac1401fb5f09e5293508661..f698d5b064db19224da5ecc4b23959f9a93bd1b2 100644 (file)
@@ -13,6 +13,7 @@ option "recurse" r "Recurse into sub-directories" flag off dependon="dir"
 
 section "OPTIONS" 
 option "verbose" v "Verbosity level" int default="1" optional
+option "debug" D "Debug messages level" int default="0" optional
 
 #package "<packname>"
 #     version "<version>"
index 6f5e74da593d2da70e578e55f9a6067115d61a60..72e99f47bb23d07fcd6f426582121dd9c60c766e 100644 (file)
@@ -37,6 +37,7 @@ const char *gengetopt_args_info_help[] = {
   "  -r, --recurse           Recurse into sub-directories  (default=off)",
   "\nOPTIONS:",
   "  -v, --verbose=INT       Verbosity level  (default=`1')",
+  "  -D, --debug=INT         Debug messages level  (default=`0')",
     0
 };
 
@@ -95,6 +96,7 @@ void clear_given (struct gengetopt_args_info *args_info)
   args_info->dir_given = 0 ;
   args_info->recurse_given = 0 ;
   args_info->verbose_given = 0 ;
+  args_info->debug_given = 0 ;
 }
 
 static
@@ -108,6 +110,8 @@ void clear_args (struct gengetopt_args_info *args_info)
   args_info->recurse_flag = 0;
   args_info->verbose_arg = 1;
   args_info->verbose_orig = NULL;
+  args_info->debug_arg = 0;
+  args_info->debug_orig = NULL;
   
 }
 
@@ -123,6 +127,7 @@ void init_args_info(struct gengetopt_args_info *args_info)
   args_info->dir_help = gengetopt_args_info_help[5] ;
   args_info->recurse_help = gengetopt_args_info_help[6] ;
   args_info->verbose_help = gengetopt_args_info_help[8] ;
+  args_info->debug_help = gengetopt_args_info_help[9] ;
   
 }
 
@@ -209,6 +214,7 @@ cmdline_parser_release (struct gengetopt_args_info *args_info)
   free_string_field (&(args_info->dir_arg));
   free_string_field (&(args_info->dir_orig));
   free_string_field (&(args_info->verbose_orig));
+  free_string_field (&(args_info->debug_orig));
   
   
   for (i = 0; i < args_info->inputs_num; ++i)
@@ -257,6 +263,8 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
     write_into_file(outfile, "recurse", 0, 0 );
   if (args_info->verbose_given)
     write_into_file(outfile, "verbose", args_info->verbose_orig, 0);
+  if (args_info->debug_given)
+    write_into_file(outfile, "debug", args_info->debug_orig, 0);
   
 
   i = EXIT_SUCCESS;
@@ -540,10 +548,11 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf
         { "dir",       1, NULL, 'd' },
         { "recurse",   0, NULL, 'r' },
         { "verbose",   1, NULL, 'v' },
+        { "debug",     1, NULL, 'D' },
         { NULL,        0, NULL, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVpf:d:rv:", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVpf:d:rv:D:", long_options, &option_index);
 
       if (c == -1) break;      /* Exit from `while (1)' loop.  */
 
@@ -615,6 +624,18 @@ cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_inf
             goto failure;
         
           break;
+        case 'D':      /* Debug messages level.  */
+        
+        
+          if (update_arg( (void *)&(args_info->debug_arg), 
+               &(args_info->debug_orig), &(args_info->debug_given),
+              &(local_args_info.debug_given), optarg, 0, "0", ARG_INT,
+              check_ambiguity, override, 0, 0,
+              "debug", 'D',
+              additional_error))
+            goto failure;
+        
+          break;
 
         case 0:        /* Long option with no short option */
         case '?':      /* Invalid option.  */
index db36397d086bb7590566ef23e9eec06e6d128ed8..f7889764bc0ce8f2909a83a56d325d7238bd2bc8 100644 (file)
@@ -47,6 +47,9 @@ struct gengetopt_args_info
   int verbose_arg;     /**< @brief Verbosity level (default='1').  */
   char * verbose_orig; /**< @brief Verbosity level original value given at command line.  */
   const char *verbose_help; /**< @brief Verbosity level help description.  */
+  int debug_arg;       /**< @brief Debug messages level (default='0').  */
+  char * debug_orig;   /**< @brief Debug messages level original value given at command line.  */
+  const char *debug_help; /**< @brief Debug messages level help description.  */
   
   unsigned int help_given ;    /**< @brief Whether help was given.  */
   unsigned int version_given ; /**< @brief Whether version was given.  */
@@ -55,6 +58,7 @@ struct gengetopt_args_info
   unsigned int dir_given ;     /**< @brief Whether dir was given.  */
   unsigned int recurse_given ; /**< @brief Whether recurse was given.  */
   unsigned int verbose_given ; /**< @brief Whether verbose was given.  */
+  unsigned int debug_given ;   /**< @brief Whether debug was given.  */
 
   char **inputs ; /**< @brief unamed options (options without names) */
   unsigned inputs_num ; /**< @brief unamed options number */
index 516dfd45c312412751fe82ef6a9ce37e95fbc743..0a3a81085906d3f11c265ba4f16717341ff8136b 100644 (file)
@@ -9,6 +9,7 @@ int main(int argc, char* argv[])
      
   creaImageIO::Gimmick g;
   if (args.verbose_given) g.SetMessageLevel(args.verbose_arg);
+  if (args.debug_given) g.SetDebugMessageLevel(args.debug_arg);
     
   bool something_to_do = 
     args.dir_given |
@@ -23,7 +24,7 @@ int main(int argc, char* argv[])
 
   try
     {
-      if (!g.Initialize()) return 1;
+      g.Initialize();
       
       if (args.file_given) 
        {
@@ -40,7 +41,7 @@ int main(int argc, char* argv[])
          g.PrintLocalDatabase();
        }
       
-      if (!g.Finalize()) return 1;
+      g.Finalize();
     }
   catch (crea::Exception e)
     {
index a9f72644144b8171a78cf9fbea4e736e3246bd48..64099e589c651e2bbf37fe4fefa1667cfcc7ef0a 100644 (file)
@@ -1,6 +1,6 @@
 #include <creaImageIOGimmick.h>
 
-#include <creaMessageManager.h>
+#include <creaImageIOSystem.h>
 #include <creaImageIOImageFinder.h>
 
 #include <boost/filesystem.hpp>
@@ -14,6 +14,8 @@ namespace creaImageIO
   {    
     crea::MessageManager::RegisterMessageType("Gimmick!",
                                              "Gimmick",1);
+    crea::MessageManager::RegisterMessageType("Gimmick! DEBUG",
+                                             "Gimmick",0);
   }
   //==============================================================
 
@@ -28,10 +30,10 @@ namespace creaImageIO
   
 
   //==============================================================
-  bool Gimmick::Initialize()
+  void Gimmick::Initialize()
   {
     // Create the UserSettings dir if does not exist
-    if (!CreateUserSettingsDirectory()) return false;
+    CreateUserSettingsDirectory();
     // Sets the current directory to the home dir
     mCurrentDirectory =  GetHomeDirectory();
 
@@ -40,44 +42,38 @@ namespace creaImageIO
     // Create or open local database
     if (! boost::filesystem::exists( GetLocalDatabasePath() ) )
       {
-       creaMessage("Gimmick!",1,
-                   "[Gimmick!] Local database '"<<GetLocalDatabasePath()<<"' "
-                   << "does not exist : creating it"<<std::endl);
-
+       std::string mess = "Local database '";
+       mess += GetLocalDatabasePath();
+       mess += "' does not exist : creating it";
+       GimmickMessage(1,mess<<std::endl);
+       
        // CREATING DEFAULT DB STRUCTURE
        mLocalDatabase->GetTree().GetDescriptor().CreateDefault();
        
        if ( ! mLocalDatabase->Create(true) )
          {
-           creaMessage("Gimmick!",1,
-                       "[Gimmick!] !! ERROR CREATING '"<<GetLocalDatabasePath()<<"'");
-           return false;
+           GimmickError("ERROR CREATING '"<<GetLocalDatabasePath()<<"'");
          }
        mLocalDatabase->SetAttribute(0,"Name","Local database");
       }
     else 
       {
        /// Open and test it
-       creaMessage("Gimmick!",1,
-                   "[Gimmick!] Opening local database '"
-                   <<GetLocalDatabasePath()<<"' "
-                   <<std::endl);
+       GimmickMessage(1,"Opening local database '"
+                      <<GetLocalDatabasePath()<<"' "
+                      <<std::endl);
        if ( ! mLocalDatabase->Open(true) )
          {
-           creaMessage("Gimmick!",1,
-                       "[Gimmick!] !! ERROR OPENING '"<<GetLocalDatabasePath()<<"'");
-           return false;
+           GimmickError("ERROR OPENING '"<<GetLocalDatabasePath()<<"'");
          }
        
       }
-    return true;
-
   }
   //================================================================
 
 
   //==============================================================
-  bool Gimmick::Finalize()
+  void Gimmick::Finalize()
   {
     delete mLocalDatabase;
   }
@@ -138,22 +134,18 @@ namespace creaImageIO
   //========================================================================
 
   //========================================================================
-  bool Gimmick::CreateUserSettingsDirectory()
+  void Gimmick::CreateUserSettingsDirectory()
   {
     if (! boost::filesystem::is_directory( GetUserSettingsDirectory() ) )
       {
-       creaMessage("Gimmick!",1,
-                   "[Gimmick!] Directory '"<<GetUserSettingsDirectory()<<"' "
-                   << "does not exist : creating it"<<std::endl);
+       GimmickMessage(1,"Directory '"<<GetUserSettingsDirectory()<<"' "
+                      << "does not exist : creating it"<<std::endl);
        
        if ( ! boost::filesystem::create_directory( GetUserSettingsDirectory() ) )
          {
-           creaMessage("Gimmick!",1,
-                       "[Gimmick!] !! ERROR CREATING '"<<GetUserSettingsDirectory()<<"'");
-           return false;
+           GimmickError("ERROR CREATING '"<<GetUserSettingsDirectory()<<"'");
          }
       }
-    return true;
   }
   //========================================================================
 
@@ -166,13 +158,27 @@ namespace creaImageIO
   }
   //========================================================================
 
+  //========================================================================
+  /// Sets message level
+  void Gimmick::SetDebugMessageLevel(int l)
+  {
+    crea::MessageManager::SetMessageLevel("Gimmick! DEBUG",l);
+  }
+  //========================================================================
+
   //========================================================================
   /// Add a file to the local database
   void Gimmick::AddFileToLocalDatabase(const std::string& f)
   {
     ImageFinder finder(mLocalDatabase);
-    if (finder.IsHandledFile(f)) finder.AddFile(f);
-    
+    if (finder.IsHandledFile(f)) 
+      {
+       finder.AddFile(f);
+      }
+    else
+      {
+       GimmickError("File '"<<f<<"' does not exist or is not handled");
+      }    
   }
   //========================================================================
 
index 9cd56660bcef50bb7cb325c181180865b88119db..cebcbd5870602d58eb82e6b094fd3ee963456f2b 100644 (file)
@@ -30,13 +30,15 @@ namespace creaImageIO
     ~Gimmick();
     
     /// Initialize (read/creates databases, etc.)
-    bool Initialize();
+    void Initialize();
     
     /// Finalize (closes databases, etc.)
-    bool Finalize();
+    void Finalize();
 
     /// Sets level for messages "Gimmick!" 
     void SetMessageLevel(int level);
+   /// Sets level for debug messages "Gimmick! DEBUG" 
+    void SetDebugMessageLevel(int level);
 
     /// Add a file to the local database
     void AddFileToLocalDatabase(const std::string&);
@@ -54,7 +56,7 @@ namespace creaImageIO
     /// 
     const std::string& GetHomeDirectory();
     const std::string& GetUserSettingsDirectory();
-    bool CreateUserSettingsDirectory();
+    void CreateUserSettingsDirectory();
     const std::string& GetLocalDatabasePath();
 
   private:
index 3bea907f3f31abae26fd805192186c6992ef3b59..c35ae61bc64ac33b5eee140997c2c24f7062c150 100644 (file)
@@ -253,7 +253,7 @@ namespace creaImageIO
        return false;
       }
 
-    GimmickMessage(1,"Opening SQLite database '"<<GetFileName()
+    GimmickDebugMessage(1,"Opening SQLite database '"<<GetFileName()
                   <<"' ... OK"<<std::endl);
     return true;
   }
index 9b8900218550be4bbee296d7aa2ca70812c6ed44..f56b10b598bf84fbd83b50f579c0ac70666972fb 100644 (file)
@@ -19,7 +19,7 @@
 #define GimmickMessage(LEV,MESS) \
   creaMessage("Gimmick!",LEV,"[Gimmick!] "<<MESS);
 #define GimmickDebugMessage(LEV,MESS) \
-  creaDebugMessage("Gimmick!",LEV,"[Gimmick!] "<<MESS);
+  creaDebugMessage("Gimmick! DEBUG",LEV,"[Gimmick!] DEBUG: "<<MESS);
 #define GimmickError(MESS)                             \
   creaError("[Gimmick!] "<<MESS);
 #endif