MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Core/MOOSLIB/XPCGetProtocol.h
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 //
00029 //   The XPC classes in MOOS are modified versions of the source provided 
00030 //   in "Making UNIX and Windows NT Talk" by Mark Nadelson and Thomas Haga 
00031 //
00033 #ifndef _XPCGetProtocol
00034 #define _XPCGetprotocol
00035 
00036 #ifdef UNIX
00037     #include <netdb.h>
00038 #elif _WIN32
00039     #include <winsock2.h>
00040 #else
00041     #error "Looks like the build scripts didn't set the platform type"
00042 #endif
00043 
00044 #include "XPCException.h"
00045 
00046 class XPCGetProtocol
00047 {
00048 #ifdef UNIX
00049     char cIteratorFlag;        // Protocol database iteration flag
00050 #endif
00051     struct protoent *protocolPtr;    // Pointer to protocol database entry
00052 public:
00053 #ifdef UNIX
00054     // Default constructor.  Opens the protocol database
00055     XPCGetProtocol()
00056     {
00057         vOpenProtocolDb();
00058     }
00059 #endif
00060 
00061     // Constructor.  Returns the protoent structure given the protocol name.
00062     XPCGetProtocol(const char *_sName);
00063 
00064     // Constructor.  Returns the protoent structure given the protocol number
00065     XPCGetProtocol(int _iProtocol);
00066 
00067     // Desstructor closes the database connection  
00068         ~XPCGetProtocol()
00069         {
00070 #ifdef UNIX
00071                 endprotoent();
00072 #endif
00073         }
00074 
00075     // Opens the protocol database and sets the cIteratorFlag to true
00076 #ifdef UNIX
00077     void vOpenProtocolDb()
00078     {
00079         endprotoent();
00080         cIteratorFlag = 1;
00081         setprotoent(1);
00082     }    
00083 
00084     // Iterates through the list of protocols
00085     char cGetNextProtocol()
00086     {
00087         if (cIteratorFlag == 1)
00088         {
00089             if ((protocolPtr = getprotoent()) == NULL)
00090                 return 0;
00091             else
00092                 return 1;
00093         }
00094         return 0;
00095     } 
00096 #endif
00097 
00098     // Returns the protocol name
00099     char *sGetProtocolName() { return protocolPtr->p_name; }
00100 
00101     // Returns the protcol number
00102     int iGetProtocolNumber() { return protocolPtr->p_proto; }
00103 };
00104 
00105 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines