Libbarrett  1.2.4
include/barrett/standard_main_function.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2009-2014 Barrett Technology <support@barrett.com>
00003 
00004         This file is part of libbarrett.
00005 
00006         This version of libbarrett is free software: you can redistribute it
00007         and/or modify it under the terms of the GNU General Public License as
00008         published by the Free Software Foundation, either version 3 of the
00009         License, or (at your option) any later version.
00010 
00011         This version of libbarrett is distributed in the hope that it will be
00012         useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00013         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014         GNU General Public License for more details.
00015 
00016         You should have received a copy of the GNU General Public License along
00017         with this version of libbarrett.  If not, see
00018         <http://www.gnu.org/licenses/>.
00019 
00020 */
00021 
00048 #ifndef BARRETT_STANDARD_MAIN_FUNCTION_H_
00049 #define BARRETT_STANDARD_MAIN_FUNCTION_H_
00050 
00051 
00052 #include <barrett/exception.h>
00053 #include <barrett/products/product_manager.h>
00054 #include <barrett/systems/wam.h>
00055 
00056 
00057 #ifdef BARRETT_SMF_VALIDATE_ARGS
00058         bool validate_args(int argc, char** argv);
00059 #endif
00060 
00061 #ifdef BARRETT_SMF_CONFIGURE_PM
00062         bool configure_pm(int argc, char** argv, ::barrett::ProductManager& pm);
00063 #endif
00064 
00065 #ifndef BARRETT_SMF_NO_DECLARE
00066         template<size_t DOF> int wam_main(int argc, char** argv, ::barrett::ProductManager& pm, ::barrett::systems::Wam<DOF>& wam);
00067 #endif
00068 
00069 #ifndef BARRETT_SMF_DONT_WAIT_FOR_SHIFT_ACTIVATE
00070 #  define BARRETT_SMF_WAIT_FOR_SHIFT_ACTIVATE true
00071 #else
00072 #  define BARRETT_SMF_WAIT_FOR_SHIFT_ACTIVATE false
00073 #endif
00074 
00075 #ifndef BARRETT_SMF_DONT_PROMPT_ON_ZEROING
00076 #  define BARRETT_SMF_PROMPT_ON_ZEROING true
00077 #else
00078 #  define BARRETT_SMF_PROMPT_ON_ZEROING false
00079 #endif
00080 
00081 #ifndef BARRETT_SMF_WAM_CONFIG_PATH
00082 #  define BARRETT_SMF_WAM_CONFIG_PATH NULL
00083 #endif
00084 
00085 
00086 int main(int argc, char** argv) {
00087         // Give us pretty stack-traces when things die
00088         ::barrett::installExceptionHandler();
00089 
00090 
00091 #ifdef BARRETT_SMF_VALIDATE_ARGS
00092         if ( !validate_args(argc, argv) ) {
00093                 return 1;
00094         }
00095 #endif
00096 
00097 
00098         ::barrett::ProductManager pm;
00099 #ifdef BARRETT_SMF_CONFIGURE_PM
00100         if ( !configure_pm(argc, argv, pm) ) {
00101                 return 1;
00102         }
00103 #endif
00104 
00105         pm.waitForWam(BARRETT_SMF_PROMPT_ON_ZEROING);
00106         pm.wakeAllPucks();
00107         // TODO(JH): Rehab Update implement and test
00108         if (pm.foundWam3()) {
00109                 return wam_main(argc, argv, pm, *pm.getWam3(BARRETT_SMF_WAIT_FOR_SHIFT_ACTIVATE, BARRETT_SMF_WAM_CONFIG_PATH));
00110         } else if (pm.foundWam4()) {
00111                 return wam_main(argc, argv, pm, *pm.getWam4(BARRETT_SMF_WAIT_FOR_SHIFT_ACTIVATE, BARRETT_SMF_WAM_CONFIG_PATH));
00112         } else if (pm.foundWam7()) {
00113                 return wam_main(argc, argv, pm, *pm.getWam7(BARRETT_SMF_WAIT_FOR_SHIFT_ACTIVATE, BARRETT_SMF_WAM_CONFIG_PATH));
00114         } else {
00115                 printf(">>> ERROR: No WAM was found. Perhaps you have found a bug in ProductManager::waitForWam().\n");
00116                 return 1;
00117         }
00118 }
00119 
00120 
00121 #endif /* BARRETT_STANDARD_MAIN_FUNCTION_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines