00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef __UPNPUTIL_H__
00014 #define __UPNPUTIL_H__
00015
00016 #include <QStringList>
00017 #include <QMap>
00018
00019 #include "compat.h"
00020
00022
00024
00025 template <class T> inline const T& Min( const T &x, const T &y )
00026 {
00027 return( ( x < y ) ? x : y );
00028 }
00029
00030 template <class T> inline const T& Max( const T &x, const T &y )
00031 {
00032 return( ( x > y ) ? x : y );
00033 }
00035
00037
00038 typedef struct timeval TaskTime;
00039 typedef QMap< QString, QString > QStringMap;
00040
00041
00043
00044 class NameValue;
00045 class NameValues;
00046 class NameValue
00047 {
00048 public:
00049 QString sName;
00050 QString sValue;
00051
00052 NameValues *pAttributes;
00053
00054 public:
00055 NameValue() :
00056 sName(), sValue(), pAttributes(NULL) { }
00057 NameValue(const QString &name, const QString &value) :
00058 sName(name), sValue(value), pAttributes(NULL) { }
00059 NameValue(const QString &name, const char *value) :
00060 sName(name), sValue(value), pAttributes(NULL) { }
00061 NameValue(const QString &name, int value) :
00062 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00063 NameValue(const QString &name, long value) :
00064 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00065 NameValue(const QString &name, qlonglong value) :
00066 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00067 NameValue(const QString &name, uint value) :
00068 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00069 NameValue(const QString &name, ulong value) :
00070 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00071 NameValue(const QString &name, qulonglong value) :
00072 sName(name), sValue(QString::number(value)), pAttributes(NULL) { }
00073 NameValue(const QString &name, bool value) :
00074 sName(name), sValue((value) ? "1" : "0"), pAttributes(NULL) { }
00075 inline NameValue(const NameValue &nv);
00076 inline NameValue& operator=(const NameValue &nv);
00077
00078 inline ~NameValue();
00079
00080 inline void AddAttribute(const QString &name, const QString &value);
00081 };
00082 class NameValues : public QList<NameValue> {};
00083
00084 inline NameValue::NameValue(const NameValue &nv) :
00085 sName(nv.sName), sValue(nv.sValue), pAttributes(NULL)
00086 {
00087 if (nv.pAttributes)
00088 {
00089 pAttributes = new NameValues;
00090 *pAttributes = *nv.pAttributes;
00091 }
00092 }
00093
00094 inline NameValue& NameValue::operator=(const NameValue &nv)
00095 {
00096 if (this == &nv)
00097 return *this;
00098
00099 sName = nv.sName;
00100 sValue = nv.sValue;
00101
00102 if (nv.pAttributes)
00103 {
00104 pAttributes = new NameValues;
00105 *pAttributes = *nv.pAttributes;
00106 }
00107 else
00108 {
00109 pAttributes = NULL;
00110 }
00111
00112 return *this;
00113 }
00114
00115 inline NameValue::~NameValue()
00116 {
00117 if (pAttributes)
00118 {
00119 delete pAttributes;
00120 pAttributes = NULL;
00121 }
00122 }
00123
00124 inline void NameValue::AddAttribute(const QString &name, const QString &value)
00125 {
00126 if (!pAttributes)
00127 pAttributes = new NameValues();
00128
00129 pAttributes->push_back(NameValue(name, value));
00130 }
00131
00133
00135
00136 QString LookupUDN ( QString sDeviceType );
00137 long GetIPAddressList ( QStringList &sStrList );
00138
00139 bool operator< ( TaskTime t1, TaskTime t2 );
00140 bool operator== ( TaskTime t1, TaskTime t2 );
00141
00142 void AddMicroSecToTaskTime( TaskTime &t, suseconds_t uSecs );
00143 void AddSecondsToTaskTime ( TaskTime &t, long nSecs );
00144
00145 QByteArray gzipCompress( const QByteArray &data );
00146
00147 #endif