~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/oscar/liboscar/rateclass.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    rateclass.h  -  Oscar Rate Limiting Implementation
 
3
 
 
4
    Copyright (c) 2004 by Tom Linsky <twl6@po.cwru.edu>
 
5
    Copyright (c) 2004 by Matt Rogers <mattr@k
 
6
    Kopete    (c) 2002-2003 by the Kopete developers  <kopete-devel@kde.org>
 
7
 
 
8
    *************************************************************************
 
9
    *                                                                       *
 
10
    * This program is free software; you can redistribute it and/or modify  *
 
11
    * it under the terms of the GNU General Public License as published by  *
 
12
    * the Free Software Foundation; either version 2 of the License, or     *
 
13
    * (at your option) any later version.                                   *
 
14
    *                                                                       *
 
15
    *************************************************************************
 
16
*/
 
17
 
 
18
#ifndef RATECLASS_H
 
19
#define RATECLASS_H
 
20
 
 
21
#include "oscartypes.h"
 
22
#include <qobject.h>
 
23
#include <QList>
 
24
#include <qdatetime.h>
 
25
#include <qpair.h>
 
26
#include "liboscar_export.h"
 
27
 
 
28
const int RATE_SAFETY_TIME = 50;
 
29
 
 
30
struct SnacPair
 
31
{
 
32
        int family;
 
33
        int subtype;
 
34
};
 
35
 
 
36
class Transfer;
 
37
 
 
38
class LIBOSCAR_EXPORT RateClass : public QObject
 
39
{
 
40
        Q_OBJECT
 
41
public:
 
42
        RateClass( QObject* parent = 0 );
 
43
        ~RateClass();
 
44
 
 
45
        /** Accessor for classid */
 
46
        Oscar::WORD id() const;
 
47
 
 
48
        /** Sets rate information */
 
49
        void setRateInfo( Oscar::RateInfo newRateInfo );
 
50
        
 
51
        /** Gets rate information */
 
52
        Oscar::RateInfo getRateInfo();
 
53
 
 
54
        /** Add a SNAC to the rate class */
 
55
        void addMember( const Oscar::SNAC& s );
 
56
 
 
57
        /** Adds rate class members */
 
58
        void addMember( Oscar::WORD family, Oscar::WORD subtype );
 
59
 
 
60
        /** Tells whether the passed snac is a member of this rate class */
 
61
        bool isMember( const Oscar::SNAC& s ) const;
 
62
 
 
63
        /**
 
64
         * Tells whether the passed family and subtype combo is a member
 
65
         * of this rate class
 
66
         */
 
67
        bool isMember( Oscar::WORD family, Oscar::WORD subtype ) const;
 
68
 
 
69
        /** Add a packet to the queue */
 
70
        void enqueue( Transfer* );
 
71
 
 
72
        /** Takes a packet off the front of the queue */
 
73
        void dequeue();
 
74
 
 
75
        /** Check if the queue is empty */
 
76
        bool queueIsEmpty() const;
 
77
 
 
78
        /**
 
79
         * Calulate the time until we can send again
 
80
         * Uses the first packet on the queue to determine the time since that's
 
81
         * the packet that will get sent.
 
82
         * \return the time in milliseconds that we need to wait
 
83
         */
 
84
        int timeToNextSend();
 
85
        
 
86
        /**
 
87
         * Calulate the time until we get to initial level
 
88
         * \return the time in milliseconds that we need to wait
 
89
         */
 
90
        int timeToInitialLevel();
 
91
        
 
92
        /**
 
93
         * Calculates a new rate level and updates the rate class' current level
 
94
         * to match
 
95
         */
 
96
        void updateRateInfo();
 
97
        
 
98
        /**
 
99
         * Dump the current packet queue. These packets will not be sent. Used
 
100
         * on disconnection
 
101
         */
 
102
        void dumpQueue();
 
103
 
 
104
signals:
 
105
 
 
106
        /** Tell the rate class manager we're ready to send */
 
107
        void dataReady( Transfer* );
 
108
 
 
109
private:
 
110
        
 
111
        /** Calculate our new rate level */
 
112
        Oscar::DWORD calcNewLevel( int timeDifference ) const;
 
113
 
 
114
        /** sets up the timer for the transfer just added to the queue */
 
115
        void setupTimer();
 
116
 
 
117
private slots:
 
118
        /**
 
119
         * Send the packet. Basically emits dataReady for the first transfer
 
120
         */
 
121
        void slotSend();
 
122
        
 
123
private:
 
124
 
 
125
        Oscar::RateInfo m_rateInfo;
 
126
        QList<SnacPair> m_members;
 
127
        QList<Transfer*> m_packetQueue;
 
128
        QTime m_packetTimer;
 
129
        
 
130
        // we are waiting for the QTimer::singleShot() to send 
 
131
        bool m_waitingToSend;
 
132
};
 
133
 
 
134
#endif
 
135
 
 
136
//kate: tab-width 4; indent-mode csands;