reSIProcate/rutil  9694
TransportType.cxx
Go to the documentation of this file.
00001 #include <string>
00002 #include "rutil/TransportType.hxx"
00003 
00004 namespace resip
00005 {
00006 
00007 static const Data transportNames[MAX_TRANSPORT] =
00008 {
00009    Data("UNKNOWN_TRANSPORT"),
00010    Data("TLS"),
00011    Data("TCP"),
00012    Data("UDP"),
00013    Data("SCTP"),
00014    Data("DCCP"),
00015    Data("DTLS")
00016 };
00017 
00018 static const Data transportNamesLower[MAX_TRANSPORT] =
00019 {
00020    Data("UNKNOWN_TRANSPORT"),
00021    Data("tls"),
00022    Data("tcp"),
00023    Data("udp"),
00024    Data("sctp"),
00025    Data("dccp"),
00026    Data("dtls")
00027 };
00028 
00029 TransportType 
00030 getTransportTypeFromName(const std::string& transportName)
00031 {
00032     return toTransportType(transportName.c_str());
00033 }
00034 
00035 TransportType 
00036 toTransportType(const resip::Data& transportName)
00037 {
00038    for (TransportType i = UNKNOWN_TRANSPORT; i < MAX_TRANSPORT; 
00039         i = static_cast<TransportType>(i + 1))
00040     {
00041       if (isEqualNoCase(transportName, transportNames[i]))
00042     {
00043          return i;
00044     }
00045     }
00046     return UNKNOWN_TRANSPORT;
00047 }
00048 
00049 std::string 
00050 getTransportNameFromType(const TransportType typeEnum)
00051 {
00052    return toData(typeEnum).c_str();
00053 }
00054 
00055 std::string 
00056 getTransportNameFromTypeLower(const TransportType typeEnum)
00057 {
00058    return toDataLower(typeEnum).c_str();
00059 }
00060 
00061 const resip::Data& 
00062 toData(const TransportType typeEnum)
00063 {
00064    assert(typeEnum >= UNKNOWN_TRANSPORT && typeEnum < MAX_TRANSPORT);
00065    return transportNames[typeEnum];
00066 }
00067 
00068 const resip::Data& 
00069 toDataLower(const TransportType typeEnum)
00070 {
00071    assert(typeEnum >= UNKNOWN_TRANSPORT && typeEnum < MAX_TRANSPORT);
00072    return transportNamesLower[typeEnum];
00073 }
00074 
00075 bool
00076 isReliable(TransportType type)
00077 {
00078    switch(type)
00079    {
00080       case TLS:
00081       case TCP:
00082       case SCTP:
00083          return true;
00084       case UDP:
00085       case DCCP:
00086       case DTLS:
00087       default:
00088          return false;
00089    }
00090 }
00091 
00092 }
00093 
00094 /* ====================================================================
00095  * The Vovida Software License, Version 1.0 
00096  * 
00097  * Copyright (c) 2000-2005 Vovida Networks, Inc.  All rights reserved.
00098  * 
00099  * Redistribution and use in source and binary forms, with or without
00100  * modification, are permitted provided that the following conditions
00101  * are met:
00102  * 
00103  * 1. Redistributions of source code must retain the above copyright
00104  *    notice, this list of conditions and the following disclaimer.
00105  * 
00106  * 2. Redistributions in binary form must reproduce the above copyright
00107  *    notice, this list of conditions and the following disclaimer in
00108  *    the documentation and/or other materials provided with the
00109  *    distribution.
00110  * 
00111  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00112  *    and "Vovida Open Communication Application Library (VOCAL)" must
00113  *    not be used to endorse or promote products derived from this
00114  *    software without prior written permission. For written
00115  *    permission, please contact vocal@vovida.org.
00116  *
00117  * 4. Products derived from this software may not be called "VOCAL", nor
00118  *    may "VOCAL" appear in their name, without prior written
00119  *    permission of Vovida Networks, Inc.
00120  * 
00121  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00122  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00123  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00124  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00125  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00126  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00127  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00128  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00129  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00130  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00131  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00132  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00133  * DAMAGE.
00134  * 
00135  * ====================================================================
00136  * 
00137  * This software consists of voluntary contributions made by Vovida
00138  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00139  * Inc.  For more information on Vovida Networks, Inc., please see
00140  * <http://www.vovida.org/>.
00141  *
00142  */