MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Utility Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00030 // DBImage.cpp: implementation of the CDBImage class. 00031 00032 00033 00034 // 00035 00036 00038 00039 #include "DBImage.h" 00040 00042 // Construction/Destruction 00044 00045 bool CDBImage::Set(MOOSMSG_LIST & InMail) 00046 { 00047 MOOSMSG_LIST::iterator p; 00048 00049 00050 m_Lock.Lock(); 00051 //MOOSTrace("Rx'd %d \n",InMail.size()); 00052 00053 for(p = InMail.begin();p!=InMail.end();p++) 00054 { 00055 CMOOSMsg & rMsg= *p; 00056 //MOOSTrace("Rx'd %s \n",rMsg.m_sKey.c_str()); 00057 00058 if(!m_Mask.empty() && m_Mask.find(rMsg.GetSource())!=m_Mask.end()) 00059 { 00060 continue; 00061 } 00062 00063 if(rMsg.IsDataType(MOOS_NOT_SET) && !m_bShowPending) 00064 { 00065 continue; 00066 } 00067 00068 int nNdx = GetIndex(rMsg.m_sKey); 00069 if(nNdx<0) 00070 { 00071 m_IndexMap[rMsg.m_sKey] = m_DBData.size(); 00072 m_DBData.push_back(CVar(rMsg)); 00073 } 00074 else 00075 { 00076 bool bChanging = !( rMsg.GetTime()==m_DBData[nNdx].GetTimeVal()); 00077 m_DBData[nNdx]= CVar(rMsg); 00078 m_DBData[nNdx].Changed(bChanging); 00079 } 00080 } 00081 m_Lock.UnLock(); 00082 00083 return true; 00084 00085 } 00086 00087 00088 00089 00090 00091 00092 00093 00094 int CDBImage::GetIndex(const std::string & sName) 00095 { 00096 std::map<std::string,int>::iterator q = m_IndexMap.find(sName); 00097 00098 if(q!=m_IndexMap.end()) 00099 { 00100 int n = q->second; 00101 return n; 00102 } 00103 else 00104 { 00105 return -1; 00106 } 00107 00108 } 00109 00110 bool CDBImage:: HasChanged(int n) 00111 { 00112 if(n >= static_cast<int> (m_DBData.size()) || n<0) 00113 return false; 00114 return m_DBData[n].IsChanged(); 00115 } 00116 00117 00118 bool CDBImage::Get(CVar & rVar, int n) 00119 { 00120 m_Lock.Lock(); 00121 00122 if(n>=static_cast<int> (m_DBData.size()) || n<0) 00123 { 00124 m_Lock.UnLock(); 00125 return false; 00126 } 00127 00128 rVar = m_DBData[n]; 00129 00130 m_Lock.UnLock(); 00131 00132 return true; 00133 } 00134 00135 00136 bool CDBImage::SetProcInfo(MOOSMSG_LIST & InMail) 00137 { 00138 m_Lock.Lock(); 00139 // TODO: Add your control notification handler code here 00140 m_nClients = InMail.size(); 00141 m_Processes.clear(); 00142 MOOSMSG_LIST::iterator p; 00143 for(p=InMail.begin();p!=InMail.end();p++) 00144 { 00145 00146 CMOOSMsg & rMsg = *p; 00147 std::string sTmp = rMsg.m_sVal; 00148 std::string sWho = MOOSChomp(sTmp,":"); 00149 00150 if(m_Processes.find(sWho)==m_Processes.end()) 00151 { 00152 ProcInfo Info; 00153 m_Processes[sWho] = Info; 00154 } 00155 00156 std::string sSubscribed,sPublished; 00157 sSubscribed = MOOSChomp(sTmp,"PUBLISHED="); 00158 sPublished = sTmp; 00159 MOOSChomp(sSubscribed,"SUBSCRIBED="); 00160 00161 while(!sSubscribed.empty()) 00162 { 00163 sTmp = MOOSChomp(sSubscribed,","); 00164 if(!sTmp.empty()) 00165 { 00166 m_Processes[sWho].m_Subscribed.push_front(sTmp); 00167 } 00168 } 00169 00170 while(!sPublished.empty()) 00171 { 00172 sTmp = MOOSChomp(sPublished,","); 00173 if(!sTmp.empty()) 00174 { 00175 m_Processes[sWho].m_Published.push_front(sTmp); 00176 } 00177 } 00178 } 00179 m_Lock.UnLock(); 00180 return true; 00181 } 00182 00183 bool CDBImage::GetProcInfo(const std::string & sWhat,STRING_LIST & sSubs,STRING_LIST & sPubs) 00184 { 00185 bool bRes = false; 00186 m_Lock.Lock(); 00187 PROC_INFO_MAP::iterator q = m_Processes.find(sWhat); 00188 if(q!=m_Processes.end()) 00189 { 00190 sSubs = q->second.m_Subscribed; 00191 sPubs = q->second.m_Published; 00192 bRes = true; 00193 } 00194 m_Lock.UnLock(); 00195 return bRes; 00196 00197 } 00198 00199 bool CDBImage::GetProcesses(STRING_LIST & sProcs) 00200 { 00201 m_Lock.Lock(); 00202 00203 sProcs.clear(); 00204 00205 PROC_INFO_MAP::iterator q; 00206 for(q=m_Processes.begin();q!=m_Processes.end();q++) 00207 { 00208 sProcs.push_back(q->first.c_str()); 00209 } 00210 m_Lock.UnLock(); 00211 00212 return true; 00213 } 00214 00215 00216 bool CDBImage::SetMask(std::set<std::string> Mask) 00217 { 00218 m_Mask = Mask; 00219 return true; 00220 } 00221 00222 bool CDBImage::Clear() 00223 { 00224 m_Lock.Lock(); 00225 m_DBData.clear(); 00226 m_IndexMap.clear(); 00227 m_Lock.UnLock(); 00228 00229 return true; 00230 }