MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Core/MOOSDB/MOOSDBVar.cpp
Go to the documentation of this file.
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 Core 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 // MOOSDBVar.cpp: implementation of the CMOOSDBVar class.
00031 //
00033 #ifdef _WIN32
00034 #pragma warning(disable : 4786)
00035 #endif
00036 
00037 #include <MOOSGenLib/MOOSGenLib.h>
00038 #include "MOOSDBVar.h"
00039 #include <iostream>
00040 
00042 // Construction/Destruction
00044 
00045 CMOOSDBVar::CMOOSDBVar()
00046 {
00047     m_dfVal = -1.0;
00048     m_dfTime = -1.0;
00049     m_dfWriteFreq = 0.0;
00050     m_sVal = "";
00051     m_sWhoChangedMe = "";
00052     m_nWrittenTo = 0;
00053     m_dfWrittenTime = -1;
00054     m_nOverTicks = 0;
00055 }
00056 
00057 
00058 CMOOSDBVar::CMOOSDBVar(const string & sName)
00059 {
00060     m_sName = sName;
00061     m_dfVal = -1.0;
00062     m_dfTime = -1.0;
00063     m_sVal = "";
00064         m_sSrcAux = "";
00065     m_sWhoChangedMe = "";
00066     m_nWrittenTo = 0;
00067     m_dfWriteFreq = 0;
00068     m_dfWrittenTime = -1;
00069     m_nOverTicks = 0;
00070 
00071 }
00072 
00073 CMOOSDBVar::~CMOOSDBVar()
00074 {
00075 
00076 }
00077 
00078 bool CMOOSDBVar::AddSubscriber(string &sClient, double dfPeriod)
00079 {
00080     CMOOSRegisterInfo Info;
00081 
00082     if(sClient.empty())
00083     {
00084        MOOSTrace("MOOSDB: Failed to add subscription to \"%s\" for a client with empty name \n",m_sName.c_str());
00085        return false;
00086     }
00087     Info.m_dfPeriod = dfPeriod;
00088     Info.m_sClientName = sClient;
00089 
00090     m_Subscribers[sClient] = Info;
00091 
00092     MOOSTrace("MOOSDB: Adding subscription of \"%s\" to \"%s\"\n",sClient.c_str(),m_sName.c_str());
00093 
00094     return true;
00095 
00096 }
00097 
00098 void CMOOSDBVar::RemoveSubscriber(string &sWho)
00099 {
00100 
00101     REGISTER_INFO_MAP::iterator p = m_Subscribers.find(sWho);
00102     if(p!=m_Subscribers.end())
00103     {
00104     MOOSTrace("removing \"%s\"'s subscription to \"%s\"\n",sWho.c_str(),m_sName.c_str());
00105     m_Subscribers.erase(p);
00106     }
00107 }
00108 
00109 bool CMOOSDBVar::Reset()
00110 {
00111     m_dfTime = -1;
00112     m_dfVal = -1;
00113     m_sVal = "";
00114     m_sWhoChangedMe = "";
00115     m_Writers.clear();
00116     m_dfWrittenTime = -1;
00117     m_nWrittenTo = 0;
00118     m_dfWriteFreq = 0;
00119 
00120     return true;
00121 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines