User | Revision | Line number | New contents of line |
mbed714 |
0:d616ece2d859
|
1
|
|
mbed714 |
0:d616ece2d859
|
2
|
/*
|
mbed714 |
0:d616ece2d859
|
3
|
Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
|
mbed714 |
0:d616ece2d859
|
4
|
|
mbed714 |
0:d616ece2d859
|
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
mbed714 |
0:d616ece2d859
|
6
|
of this software and associated documentation files (the "Software"), to deal
|
mbed714 |
0:d616ece2d859
|
7
|
in the Software without restriction, including without limitation the rights
|
mbed714 |
0:d616ece2d859
|
8
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
mbed714 |
0:d616ece2d859
|
9
|
copies of the Software, and to permit persons to whom the Software is
|
mbed714 |
0:d616ece2d859
|
10
|
furnished to do so, subject to the following conditions:
|
mbed714 |
0:d616ece2d859
|
11
|
|
mbed714 |
0:d616ece2d859
|
12
|
The above copyright notice and this permission notice shall be included in
|
mbed714 |
0:d616ece2d859
|
13
|
all copies or substantial portions of the Software.
|
mbed714 |
0:d616ece2d859
|
14
|
|
mbed714 |
0:d616ece2d859
|
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
mbed714 |
0:d616ece2d859
|
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
mbed714 |
0:d616ece2d859
|
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
mbed714 |
0:d616ece2d859
|
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
mbed714 |
0:d616ece2d859
|
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
mbed714 |
0:d616ece2d859
|
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
mbed714 |
0:d616ece2d859
|
21
|
THE SOFTWARE.
|
mbed714 |
0:d616ece2d859
|
22
|
*/
|
mbed714 |
0:d616ece2d859
|
23
|
|
mbed714 |
0:d616ece2d859
|
24
|
#include "netudpsocket.h"
|
mbed714 |
0:d616ece2d859
|
25
|
|
mbed714 |
0:d616ece2d859
|
26
|
//#define __DEBUG
|
mbed714 |
0:d616ece2d859
|
27
|
#include "dbg/dbg.h"
|
mbed714 |
0:d616ece2d859
|
28
|
|
mbed714 |
0:d616ece2d859
|
29
|
NetUdpSocket::NetUdpSocket() : m_host(), m_client(), m_refs(0), m_closed(false), m_removed(false), m_pCbItem(NULL), m_pCbMeth(NULL), m_events()
|
mbed714 |
0:d616ece2d859
|
30
|
{
|
mbed714 |
0:d616ece2d859
|
31
|
Net::registerNetUdpSocket(this);
|
mbed714 |
0:d616ece2d859
|
32
|
}
|
mbed714 |
0:d616ece2d859
|
33
|
|
mbed714 |
0:d616ece2d859
|
34
|
NetUdpSocket::~NetUdpSocket() //close()
|
mbed714 |
0:d616ece2d859
|
35
|
{
|
mbed714 |
0:d616ece2d859
|
36
|
Net::unregisterNetUdpSocket(this);
|
mbed714 |
0:d616ece2d859
|
37
|
}
|
mbed714 |
0:d616ece2d859
|
38
|
|
mbed714 |
0:d616ece2d859
|
39
|
|
mbed714 |
0:d616ece2d859
|
40
|
//Callbacks
|
mbed714 |
0:d616ece2d859
|
41
|
#if 0 //Just for info
|
mbed714 |
0:d616ece2d859
|
42
|
void NetUdpSocket::setOnEvent()
|
mbed714 |
0:d616ece2d859
|
43
|
{
|
mbed714 |
0:d616ece2d859
|
44
|
m_pCbItem = (CDummy*) pItem;
|
mbed714 |
0:d616ece2d859
|
45
|
m_pCbMeth = (void (CDummy::*)(NetUdpSocketEvent)) pMethod;
|
mbed714 |
0:d616ece2d859
|
46
|
}
|
mbed714 |
0:d616ece2d859
|
47
|
#endif
|
mbed714 |
0:d616ece2d859
|
48
|
|
mbed714 |
0:d616ece2d859
|
49
|
void NetUdpSocket::resetOnEvent()
|
mbed714 |
0:d616ece2d859
|
50
|
{
|
mbed714 |
0:d616ece2d859
|
51
|
m_pCbItem = NULL;
|
mbed714 |
0:d616ece2d859
|
52
|
m_pCbMeth = NULL;
|
mbed714 |
0:d616ece2d859
|
53
|
}
|
mbed714 |
0:d616ece2d859
|
54
|
|
mbed714 |
0:d616ece2d859
|
55
|
void NetUdpSocket::queueEvent(NetUdpSocketEvent e)
|
mbed714 |
0:d616ece2d859
|
56
|
{
|
mbed714 |
0:d616ece2d859
|
57
|
m_events.push(e);
|
mbed714 |
0:d616ece2d859
|
58
|
}
|
mbed714 |
0:d616ece2d859
|
59
|
|
mbed714 |
0:d616ece2d859
|
60
|
void NetUdpSocket::discardEvents()
|
mbed714 |
0:d616ece2d859
|
61
|
{
|
mbed714 |
0:d616ece2d859
|
62
|
while( !m_events.empty() )
|
mbed714 |
0:d616ece2d859
|
63
|
{
|
mbed714 |
0:d616ece2d859
|
64
|
m_events.pop();
|
mbed714 |
0:d616ece2d859
|
65
|
}
|
mbed714 |
0:d616ece2d859
|
66
|
}
|
mbed714 |
0:d616ece2d859
|
67
|
|
mbed714 |
0:d616ece2d859
|
68
|
void NetUdpSocket::flushEvents() //To be called during polling
|
mbed714 |
0:d616ece2d859
|
69
|
{
|
mbed714 |
0:d616ece2d859
|
70
|
while( !m_events.empty() )
|
mbed714 |
0:d616ece2d859
|
71
|
{
|
mbed714 |
0:d616ece2d859
|
72
|
onEvent(m_events.front());
|
mbed714 |
0:d616ece2d859
|
73
|
m_events.pop();
|
mbed714 |
0:d616ece2d859
|
74
|
}
|
mbed714 |
0:d616ece2d859
|
75
|
}
|
mbed714 |
0:d616ece2d859
|
76
|
|
mbed714 |
0:d616ece2d859
|
77
|
void NetUdpSocket::onEvent(NetUdpSocketEvent e) //To be called during polling
|
mbed714 |
0:d616ece2d859
|
78
|
{
|
mbed714 |
0:d616ece2d859
|
79
|
if(m_pCbItem && m_pCbMeth)
|
mbed714 |
0:d616ece2d859
|
80
|
(m_pCbItem->*m_pCbMeth)(e);
|
mbed714 |
0:d616ece2d859
|
81
|
}
|
mbed714 |
0:d616ece2d859
|
82
|
|