summaryrefslogtreecommitdiff
path: root/plugins/!NotAdopted/WinterSpeak/speak/announce/protocol_information.cpp
blob: b3d9752bd427e44a8256343e009231a0b3b657d2 (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
//==============================================================================
// 	Miranda Speak Plugin, © 2002 Ryan Winter
//==============================================================================

#pragma warning(disable:4786)

#include "protocol_information.h"

#include <general/debug/debug.h>

//------------------------------------------------------------------------------
ProtocolInformation *ProtocolInformation::m_instance = 0;

//------------------------------------------------------------------------------
// public:
//------------------------------------------------------------------------------
ProtocolInformation::ProtocolInformation()
    :
    m_protocol_timeout()
{
	CLASSCERR("ProtocolInformation::ProtocolInformation");

    m_instance = this;
}

//------------------------------------------------------------------------------
ProtocolInformation::~ProtocolInformation()
{
	CLASSCERR("ProtocolInformation::~ProtocolInformation");

    m_instance = 0;

    // kill all the timers
    for (ProtocolTimeoutQueue::const_iterator iter = m_protocol_timeout.begin();
        iter != m_protocol_timeout.end();
        ++iter)
    {
        KillTimer(NULL, (*iter).second);
    }
}

//------------------------------------------------------------------------------
void 
ProtocolInformation::disable(const char *protocol)
{
	CLASSCERR("ProtocolInformation::disable(" << protocol << ")");
    
    if (NULL == protocol)
    {
        return;
    }

    const unsigned int TIMEOUT = 10000;

	unsigned int t 
        = SetTimer(NULL, NULL, TIMEOUT, ProtocolInformation::timeout);
    m_protocol_timeout.push_back(std::make_pair(protocol, t));
}

//------------------------------------------------------------------------------
bool 
ProtocolInformation::isDisabled(const char *protocol) const
{
	CLASSCERR("ProtocolInformation::isDisable(" << protocol << ")");

    if (NULL == protocol)
    {
        return false;
    }

    // iterate through the list and see if the protocol has a timer callback
    for (ProtocolTimeoutQueue::const_iterator iter = m_protocol_timeout.begin();
        iter != m_protocol_timeout.end();
        ++iter)
    {
        if (0 == (*iter).first.compare(protocol))
        {
            return true;
        }
    }

    return false;
}

//------------------------------------------------------------------------------
// private:
//------------------------------------------------------------------------------
void CALLBACK 
ProtocolInformation::timeout(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
	CERR("ProtocolInformation::timeout(,,,)");

    ProtocolTimeout pt = m_instance->m_protocol_timeout.front();    
    
    KillTimer(NULL, pt.second);

    m_instance->m_protocol_timeout.pop_front();
}

//==============================================================================