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

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Rtapi/MR/MR_rtapi.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 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "MR_rtapi.h"
    00015
    00016 #include <cassert>
    00017 #include "MR_dispatcher.h"
    00018 #include <Mers/Reconfiguration/Discrete/MR_connection.h>
    00019
    00021
    00022 using namespace Mers::Executives::DeductiveController::Rtapi::MR;
    00023 using Mers::Executives::DeductiveController::Rtapi::RTAPICallback;
    00024 using Mers::Executives::DeductiveController::Rtapi::RTAPIMessage;
    00025 using Mers::Executives::DeductiveController::Rtapi::ThreadSafeObjectQueue;
    00026 using Mers::Reconfiguration::Discrete::MR_connection;
    00027
    00029
    00030 // constructors and deconstructors
    00031
    00032 MR_rtapi::MR_rtapi(MR_connection *mr_con, RTAPICallback *mr_callback)
    00033         : thequeue(*(new ThreadSafeObjectQueue()))
    00034 {
    00035         thequeue.addReference();
    00036
    00037         themr_con = mr_con;
    00038         themr_callback = mr_callback;
    00039         dispatcher = new MR_dispatcher(&thequeue, themr_con, themr_callback);
    00040         assert(dispatcher);
    00041         active = true;
    00042 }
    00043
    00044 //-----------------------------------------------------------------------------
    00045 MR_rtapi::~MR_rtapi()
    00046 {
    00047         active = false;
    00048
    00049         RTAPIMessage * msg = new RTAPIMessage(RTAPIMessage::QUIT);
    00050         thequeue.enqueue(msg);
    00051
    00052         thequeue.waitForEmpty();
    00053         // kill dispatcher process and delete object
    00054         // the dispatcher object may or may not be suspended when arriving here
    00055         // the dispatcher will have exited at this point
    00056         // dispatcher->wait_for_exit();
    00057         // delete dispatcher;
    00058
    00059         // printf("Removing MR_rtapi Reference\n");
    00060         thequeue.removeReference();
    00061 }
    00062 //-----------------------------------------------------------------------------
    00063
    00064 // methods
    00065
    00066 int
    00067 MR_rtapi::queue_state_update(unsigned int state_index, unsigned int value_index)
    00068 {
    00069         if(!active)
    00070                 return -1;
    00071         RTAPIMessage *msg = new RTAPIMessage(RTAPIMessage::STATE_UPDATE, state_index, value_index);
    00072         assert(msg);
    00073         return thequeue.enqueue(msg);
    00074 }
    00075 //-----------------------------------------------------------------------------
    00076 int
    00077 MR_rtapi::queue_goal(unsigned int goal_var_index, unsigned int value_index)
    00078 {
    00079         if(!active)
    00080                 return -1;
    00081         RTAPIMessage *msg = new RTAPIMessage(RTAPIMessage::GOAL, goal_var_index, value_index);
    00082         assert(msg);
    00083         return thequeue.enqueue(msg);
    00084 }
    00085 //-----------------------------------------------------------------------------
    00086 int
    00087 MR_rtapi::queue_request_MR(void)
    00088 {
    00089         if(!active)
    00090                 return -1;
    00091         RTAPIMessage *msg = new RTAPIMessage(RTAPIMessage::MR_REQUEST, 0, 0);
    00092         assert(msg);
    00093         return thequeue.enqueue(msg);
    00094 }
    00095 //-----------------------------------------------------------------------------