main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include <rtabmap/core/Recovery.h>
00029 #include <rtabmap/core/ProgressState.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <stdlib.h>
00033 #include <signal.h>
00034 
00035 using namespace rtabmap;
00036 
00037 void showUsage()
00038 {
00039         printf("\nUsage:\n"
00040                         "rtabmap-recovery [-d] \"my_corrupted_map.db\""
00041                         "  Options:\n"
00042                         "     -d        Delete database backup on success (\"*.backup.db\").\n"
00043                         "\n");
00044         exit(1);
00045 }
00046 
00047 class RecoveryProgressState: public ProgressState
00048 {
00049         virtual bool callback(const std::string & msg) const
00050         {
00051                 if(!msg.empty())
00052                         printf("%s\n", msg.c_str());
00053                 return true;
00054         }
00055 };
00056 RecoveryProgressState state;
00057 
00058 // catch ctrl-c
00059 void sighandler(int sig)
00060 {
00061         printf("\nSignal %d caught...\n", sig);
00062         state.setCanceled(true);
00063 }
00064 
00065 int main(int argc, char * argv[])
00066 {
00067         signal(SIGABRT, &sighandler);
00068         signal(SIGTERM, &sighandler);
00069         signal(SIGINT, &sighandler);
00070 
00071         ULogger::setType(ULogger::kTypeConsole);
00072         ULogger::setLevel(ULogger::kError);
00073 
00074         if(argc < 2)
00075         {
00076                 showUsage();
00077         }
00078 
00079         bool keepBackup = true;
00080         for(int i=1; i<argc; ++i)
00081         {
00082                 if(strcmp(argv[i], "-d") == 0)
00083                 {
00084                         keepBackup = false;
00085                 }
00086         }
00087 
00088         std::string databasePath = argv[argc-1];
00089 
00090         std::string errorMsg;
00091         printf("Recovering \"%s\"\n", databasePath.c_str());
00092         if(!databaseRecovery(databasePath, keepBackup, &errorMsg, &state))
00093         {
00094                 printf("Error: %s\n", errorMsg.c_str());
00095                 return 1;
00096         }
00097 
00098         return 0;
00099 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20