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

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Command/CommandDispatcherTest.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           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 //
    00010
    00011 #include "CommandDispatcher.h"
    00012 #include <Mers/Interfaces/ExecutionInterface.h>
    00013 #include <Mers/Models/Base/Io/Mof/BaseModelReader.h>
    00014 #include <Mers/Models/Base/BaseModel.h>
    00015
    00017
    00018 using namespace Mers::Executives::DeductiveController::Command;
    00019 using Mers::Models::Base::BaseModel;
    00020 using Mers::Models::Base::Io::Mof::BaseModelReader;
    00021 using Mers::Models::Base::BaseModelVariableArray;
    00022 using Mers::Models::Base::BaseModelVariable;
    00023 using Mers::Models::Base::BaseModelValue;
    00024 using Mers::Models::Base::BaseModelDomain;
    00025 using Mers::Interfaces::ExecutionInterface;
    00026 using std::fprintf;
    00027
    00029
    00033 void printUse(char const * progName)
    00034 {
    00035         fprintf(stderr, "Use: %s <Base Model File> <CD Config File> [<log4cplus Config File>]\n"
    00036                 "<Base Model File>: Contains the variable symbols\n"
    00037                 "<CD Config File>: Contains the Command Dispatcher configuration\n",
    00038                 "<log4cplus Config File>: Contains logging settings for this test\n",
    00039                 progName);
    00040 }
    00041
    00045 int main(int argc, char * argv[])
    00046 {
    00047         if(argc != 3 && argc != 4){
    00048                 printUse(argv[0]);
    00049                 return 1;
    00050         }
    00051
    00052         // load our config file
    00053         if(argc == 3) {
    00054                 log4cplus::BasicConfigurator::doConfigure();
    00055         } else {
    00056                 log4cplus::PropertyConfigurator::doConfigure(argv[3]);
    00057         }
    00058
    00059         BaseModel * model = new BaseModel(argv[1]);
    00060         fprintf(stderr, "Loading Base Model file '%s'...\n", argv[1]);
    00061         if(FAILED(BaseModelReader::loadBaseModel(argv[1], model))){
    00062                 return 1;
    00063         }
    00064
    00065         CommandDispatcher * cDisp = new CommandDispatcher();
    00066         cDisp->setModel(model);
    00067
    00068         ExecutionInterface * dispCon = new ExecutionInterface( NULL );
    00069         fprintf(stderr, "Loading Config file '%s'...\n", argv[2]);
    00070         if(FAILED(cDisp->addConnection(dispCon, argv[2]))){
    00071                 return 1;
    00072         }
    00073
    00074         BaseModelVariableArray const &vars = *(model->getVariables());
    00075         for(unsigned int x = 0; x < vars.getLength(); x++){
    00076                 BaseModelVariable const &var = *(vars[x]);
    00077                 if(var.getVariableType() == BaseModelVariable::Control){
    00078                         BaseModelDomain const &vals = *(var.getDomain());
    00079
    00080                         for(unsigned int y = 0; y < vals.getLength(); y++){
    00081                                 BaseModelValue const &val = *(vals[y]);
    00082                                 fprintf(stderr, "\nFor (%s[%d] = %s[%d]):\n",
    00083                                         var.getName(), var.getUID(), val.getName(), val.getUID());
    00084                                 cDisp->issueCommand(var.getUID(), val.getUID());
    00085                         }
    00086                 }
    00087         }
    00088
    00089         delete cDisp;
    00090         delete dispCon;
    00091         delete model;
    00092         return 0;
    00093 }
    00094