Libbarrett  1.2.4
include/barrett/products/detail/puck_group-inl.h
00001 
00026 /*
00027  * @file puck_group-inl.h
00028  * @date 11/1/2010
00029  * @author Dan Cody
00030  * 
00031  */
00032 
00033 #include <barrett/os.h>
00034 #include <boost/thread/locks.hpp>
00035 
00036 
00037 namespace barrett {
00038 
00039 
00040 inline void PuckGroup::getProperty(enum Puck::Property prop, int results[], bool realtime) const
00041 {
00042         getProperty<Puck::StandardParser>(prop, results, realtime);
00043 }
00044 template<typename Parser> void PuckGroup::getProperty(enum Puck::Property prop, typename Parser::result_type results[], bool realtime) const
00045 {
00046         boost::unique_lock<thread::Mutex> ul(bus.getMutex(), boost::defer_lock);
00047         if (realtime) {
00048                 ul.lock();
00049         }
00050 
00051         int propId = getPropertyId(prop);
00052         sendGetPropertyRequest(propId);
00053         receiveGetPropertyReply<Parser>(propId, results, realtime);
00054 }
00055 
00056 inline void PuckGroup::setProperty(enum Puck::Property prop, int value) const
00057 {
00058         Puck::setProperty(bus, id, getPropertyId(prop), value);
00059 }
00060 
00061 inline void PuckGroup::sendGetPropertyRequest(int propId) const
00062 {
00063         int ret = Puck::sendGetPropertyRequest(bus, id, propId);
00064         if (ret != 0) {
00065                 (logMessage("PuckGroup::%s(): Failed to send request. "
00066                                 "Puck::sendGetPropertyRequest() returned error %d.")
00067                                 % __func__ % ret).raise<std::runtime_error>();
00068         }
00069 }
00070 template<typename Parser>
00071 void PuckGroup::receiveGetPropertyReply(int propId, typename Parser::result_type results[], bool realtime) const
00072 {
00073         int ret;
00074         for (size_t i = 0; i < numPucks(); ++i) {
00075                 ret = Puck::receiveGetPropertyReply<Parser>(bus, pucks[i]->getId(), propId, &results[i], true, realtime);
00076                 if (ret != 0) {
00077                         (logMessage("PuckGroup::%s(): Failed to receive reply. "
00078                                         "Puck::receiveGetPropertyReply() returned error %d while receiving message from ID=%d (group reply %d of %d).")
00079                                         % __func__ % ret % pucks[i]->getId() % (i+1) % numPucks()).template raise<std::runtime_error>();
00080                 }
00081         }
00082 }
00083 
00084 
00085 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines