- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Reconfiguration/Discrete/mrInterface.cpp

    00001 //=============================================================================
    00002 //
    00003 // Copyright (c) 2001           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Author:                      Seung H. Chung
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 // mrInterface class
    00014 //
    00015 //=============================================================================
    00016 #include <cstdlib>
    00017 #include <cstdio>
    00018 #include <cassert>
    00019 #include <Mers/Utils/Containers/intList.h>
    00020 #include "mrInterface.h"
    00021 using namespace std;
    00022
    00024
    00025 using Mers::Utils::Lang::String;
    00026 using Mers::Utils::Containers::intList;
    00027 using std::list;
    00028
    00030 // Constructors, Copy Constructors, & Destructors
    00032
    00033 mrInterface::mrInterface(modeReconfiguration &_modeReconfiguration)
    00034 {
    00035         _modeReconfiguration_p = &_modeReconfiguration;
    00036 }
    00037 mrInterface::~mrInterface()
    00038 {
    00039         _modeReconfiguration_p = NULL;
    00040 }
    00041
    00042 //------------------------------------------------------------------------------
    00043 // Public Function Members
    00044 //------------------------------------------------------------------------------
    00045
    00046 void
    00047 mrInterface::setDebug(bool debugState)
    00048 {
    00049         debug = debugState;
    00050         _modeReconfiguration_p->setDebug(debugState);
    00051 }
    00052
    00053
    00054 bool
    00055 mrInterface::getDebug()  const
    00056 {
    00057         return debug;
    00058 }
    00059
    00060
    00061 void
    00062 mrInterface::update_current_state(unsigned int variable_id,
    00063                                   unsigned int value_id)  const
    00064 {
    00065         _modeReconfiguration_p->update_current_state(variable_id, value_id);
    00066 }
    00067
    00068
    00069 void
    00070 mrInterface::update_current_state(String variable_name,
    00071                                   String value_name)  const
    00072 {
    00073         _modeReconfiguration_p->update_current_state(variable_name, value_name);
    00074 }
    00075
    00076 intList
    00077 mrInterface::generate_reachable_states()
    00078 {
    00079         intList const * const il_p = _modeReconfiguration_p->generate_reachable_states_intList_p();
    00080         return intList(*il_p);
    00081 }
    00082
    00083 intList
    00084 mrInterface::generate_commands(intList &goal_intList)
    00085 {
    00086         //if (debug)
    00087         //      cout << "generate_commands starting." << endl;
    00088         unsigned int                                    variable_id;
    00089         _modeReconfiguration_p->clear_goal();
    00090         intList::const_iterator                 intList_const_it;
    00091         for (intList_const_it = goal_intList.begin();
    00092              intList_const_it != goal_intList.end();
    00093              intList_const_it++)
    00094         {
    00095                 variable_id = *intList_const_it;
    00096                 if (++intList_const_it == goal_intList.end())
    00097                 {
    00098                         break;
    00099                 } else
    00100                 {
    00101                         _modeReconfiguration_p->update_goal(variable_id, *intList_const_it);
    00102                 }
    00103         }
    00104         if (debug)
    00105                 cout << "generate_commands updated the goal." << endl;
    00106         /*# hack for now to remove pointer passing from external interface: */
    00107         intList const * const il_p = _modeReconfiguration_p->generate_next_command_intList_p();
    00108         if (debug)
    00109                 cout << "got new commands." << endl;
    00110         if (!il_p)  // the next command list was empty - unreachable...
    00111         {
    00112                 if (debug)
    00113                         cout << "null command generated!" << endl;
    00114                 return intList();  // -1, -1 ???
    00115         }
    00116         return intList(*il_p);
    00117 }
    00118
    00119
    00120 list<String>
    00121 mrInterface::generate_commands(list<String> const & goal_list)
    00122 {
    00123         //if (debug)
    00124         //      cout << "generate_commands starting." << endl;
    00125         String    variable_name;
    00126         _modeReconfiguration_p->clear_goal();
    00127         list<String>::const_iterator                    g_const_it;
    00128         for (g_const_it = goal_list.begin(); g_const_it != goal_list.end(); g_const_it++)
    00129         {
    00130                 variable_name = *g_const_it;
    00131                 if (++g_const_it == goal_list.end())
    00132                 {
    00133                         cerr << "Error: mrInterface given odd-length goal list!" << endl;
    00134                         break;
    00135                 } else
    00136                 {
    00137                         _modeReconfiguration_p->update_goal(variable_name, *g_const_it);
    00138                 }
    00139         }
    00140         if (debug)
    00141                 cout << "generate_commands updated the goal." << endl;
    00142
    00143         list<String> sl_p = _modeReconfiguration_p->generate_next_command_stringlist();
    00144         if (debug)
    00145                 cout << "got new commands." << endl;
    00146         if (sl_p.empty())  // the next command list was empty - unreachable...
    00147         {
    00148                 if (debug)
    00149                         cout << "null command generated!" << endl;
    00150                 return sl_p;
    00151         }
    00152         return sl_p;
    00153 }
    00154
    00155
    00156 void
    00157 mrInterface::showVariables()  const
    00158 {
    00159         _modeReconfiguration_p->showVariables();
    00160 }
    00161
    00162
    00163 //------------------------------------------------------------------------------
    00164 // Public Operators
    00165 //------------------------------------------------------------------------------
    00166
    00167 std::ostream &
    00168 operator<<(std::ostream &_ostream, mrInterface const &_mrInterface)
    00169 {
    00170         _ostream << *_mrInterface._modeReconfiguration_p;
    00171         return _ostream;
    00172 }
    00173
    00174 //------------------------------------------------------------------------------
    00175 // Private Function Members
    00176 //------------------------------------------------------------------------------
    00177
    00178
    00179