summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/opietooth2/OTSDPAttribute.h
blob: e79e33df77b30da851041b7b6d97d303ded61179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//-*-c++-*-
/***************************************************************************
 *   Copyright (C) 2003 by Fred Schaettgen                                 *
 *   kdebluetooth@schaettgen.de                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef OTATTRIBUTE_H
#define OTATTRIBUTE_H

#include <stdio.h>
#include <qstring.h>
#include <qarray.h>
#include <qvector.h>
#include <bluezlib.h>
#include <OTUUID.h>

namespace Opietooth2 {

class OTSDPAttribute;
class OTUUID;

typedef QVector<OTSDPAttribute> AttributeVector;

/**
@author Fred Schaettgen
*/
class OTSDPAttribute {

public:

    enum AttrType {
        INVALID     = 0,  
        NIL         = 1, 
        UINT        = 2, 
        INT         = 3, 
        UUID        = 4, 
        BOOLEAN     = 5, 
        STRING      = 6,
        SEQUENCE    = 7, 
        ALTERNATIVE = 8, 
        URL         = 9, 
        UNKNOWN     = 10
    };

    class int128_t {
    public :
        int128_t(int64_t l=0, int64_t h=0) {
            hi = h;
            lo = l;
        }
        int128_t(const OTSDPAttribute::int128_t & l) {
            hi = l.hi;
            lo = l.lo;
        }
        QString toString() const {
          char Buf[50];
          sprintf( Buf, "%lld%lld", hi, lo );
          return QString( Buf );
        }
        int64_t hi;
        int64_t lo;
    };

    class uint128_t {
    public :
        uint128_t( uint64_t l=0, uint64_t h=0) {
            hi = h;
            lo = l;
        }
        uint128_t( const OTSDPAttribute::uint128_t & l) {
            hi = l.hi;
            lo = l.lo;
        }
        QString toString() const {
          char Buf[50];
          sprintf( Buf, "%llu%llu", hi, lo );
          return QString( Buf );
        }
        uint64_t hi;
        uint64_t lo;
    };

public:

    OTSDPAttribute();
    OTSDPAttribute( sdp_data_t * D );
    ~OTSDPAttribute();

    QString toString( void );

    void setNil();
    void setInt(const OTSDPAttribute::int128_t & val);
    void setUInt(const OTSDPAttribute::uint128_t & val);
    void setUUID( const OTUUID & val);
    void setBool(bool val);
    void setString(const QString & val);
    void setURL(const QString & val);
    void setSequence(const AttributeVector& val);
    void setAlternative(const AttributeVector& val);

    QString getString();
    QString getURL();
    const OTSDPAttribute::int128_t & getInt();
    const OTSDPAttribute::uint128_t & getUInt();
    const OTUUID & getUUID();
    bool getBool();
    AttributeVector * getSequence();
    AttributeVector * getAlternative();

    UUIDVector getAllUUIDs();

    inline AttrType getType()
      { return type; }

    //QString getValString();
    const char * getTypeString();

private:

    AttrType  type;

    union {
      OTSDPAttribute::int128_t * intVal;
      OTSDPAttribute::uint128_t * uintVal;
      OTUUID *  uuidVal;
      bool      boolVal;
      QString * stringVal;     // strings and urls
      AttributeVector * sequenceVal;   // sequences and alternatives
    } Value;

};

}

#endif