Fork of NetServicesMin with some warnings removed
Fork of NetServicesMin by
if/lwip/LwipNetIf.cpp@0:8b387bed54c2, 2011-01-10 (annotated)
- Committer:
- hlipka
- Date:
- Mon Jan 10 21:03:11 2011 +0000
- Revision:
- 0:8b387bed54c2
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hlipka | 0:8b387bed54c2 | 1 | |
hlipka | 0:8b387bed54c2 | 2 | /* |
hlipka | 0:8b387bed54c2 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
hlipka | 0:8b387bed54c2 | 4 | |
hlipka | 0:8b387bed54c2 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
hlipka | 0:8b387bed54c2 | 6 | of this software and associated documentation files (the "Software"), to deal |
hlipka | 0:8b387bed54c2 | 7 | in the Software without restriction, including without limitation the rights |
hlipka | 0:8b387bed54c2 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
hlipka | 0:8b387bed54c2 | 9 | copies of the Software, and to permit persons to whom the Software is |
hlipka | 0:8b387bed54c2 | 10 | furnished to do so, subject to the following conditions: |
hlipka | 0:8b387bed54c2 | 11 | |
hlipka | 0:8b387bed54c2 | 12 | The above copyright notice and this permission notice shall be included in |
hlipka | 0:8b387bed54c2 | 13 | all copies or substantial portions of the Software. |
hlipka | 0:8b387bed54c2 | 14 | |
hlipka | 0:8b387bed54c2 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
hlipka | 0:8b387bed54c2 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
hlipka | 0:8b387bed54c2 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
hlipka | 0:8b387bed54c2 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
hlipka | 0:8b387bed54c2 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
hlipka | 0:8b387bed54c2 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
hlipka | 0:8b387bed54c2 | 21 | THE SOFTWARE. |
hlipka | 0:8b387bed54c2 | 22 | */ |
hlipka | 0:8b387bed54c2 | 23 | |
hlipka | 0:8b387bed54c2 | 24 | #include "LwipNetIf.h" |
hlipka | 0:8b387bed54c2 | 25 | #include "lwip/init.h" |
hlipka | 0:8b387bed54c2 | 26 | #include "lwip/tcp_impl.h" |
hlipka | 0:8b387bed54c2 | 27 | #include "lwip/dns.h" |
hlipka | 0:8b387bed54c2 | 28 | |
hlipka | 0:8b387bed54c2 | 29 | #include "lwipNetTcpSocket.h" |
hlipka | 0:8b387bed54c2 | 30 | #include "lwipNetUdpSocket.h" |
hlipka | 0:8b387bed54c2 | 31 | #include "lwipNetDnsRequest.h" |
hlipka | 0:8b387bed54c2 | 32 | |
hlipka | 0:8b387bed54c2 | 33 | #include "netCfg.h" |
hlipka | 0:8b387bed54c2 | 34 | #if NET_LWIP_STACK |
hlipka | 0:8b387bed54c2 | 35 | |
hlipka | 0:8b387bed54c2 | 36 | //See doc/rawapi.txt for details |
hlipka | 0:8b387bed54c2 | 37 | |
hlipka | 0:8b387bed54c2 | 38 | LwipNetIf::LwipNetIf() : NetIf(), m_tcpTimer(), m_dnsTimer(), m_init(false) |
hlipka | 0:8b387bed54c2 | 39 | { |
hlipka | 0:8b387bed54c2 | 40 | |
hlipka | 0:8b387bed54c2 | 41 | } |
hlipka | 0:8b387bed54c2 | 42 | |
hlipka | 0:8b387bed54c2 | 43 | |
hlipka | 0:8b387bed54c2 | 44 | LwipNetIf::~LwipNetIf() |
hlipka | 0:8b387bed54c2 | 45 | { |
hlipka | 0:8b387bed54c2 | 46 | |
hlipka | 0:8b387bed54c2 | 47 | } |
hlipka | 0:8b387bed54c2 | 48 | |
hlipka | 0:8b387bed54c2 | 49 | void LwipNetIf::init() |
hlipka | 0:8b387bed54c2 | 50 | { |
hlipka | 0:8b387bed54c2 | 51 | if(m_init) |
hlipka | 0:8b387bed54c2 | 52 | return; |
hlipka | 0:8b387bed54c2 | 53 | m_init=true; |
hlipka | 0:8b387bed54c2 | 54 | lwip_init(); //init lwip, see init.c for details |
hlipka | 0:8b387bed54c2 | 55 | |
hlipka | 0:8b387bed54c2 | 56 | //Setup Clocks |
hlipka | 0:8b387bed54c2 | 57 | m_tcpTimer.start(); |
hlipka | 0:8b387bed54c2 | 58 | m_dnsTimer.start(); |
hlipka | 0:8b387bed54c2 | 59 | //m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h |
hlipka | 0:8b387bed54c2 | 60 | //m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h |
hlipka | 0:8b387bed54c2 | 61 | } |
hlipka | 0:8b387bed54c2 | 62 | |
hlipka | 0:8b387bed54c2 | 63 | NetTcpSocket* LwipNetIf::tcpSocket() //Create a new tcp socket |
hlipka | 0:8b387bed54c2 | 64 | { |
hlipka | 0:8b387bed54c2 | 65 | return new LwipNetTcpSocket(); |
hlipka | 0:8b387bed54c2 | 66 | } |
hlipka | 0:8b387bed54c2 | 67 | |
hlipka | 0:8b387bed54c2 | 68 | NetUdpSocket* LwipNetIf::udpSocket() //Create a new udp socket |
hlipka | 0:8b387bed54c2 | 69 | { |
hlipka | 0:8b387bed54c2 | 70 | return new LwipNetUdpSocket(); |
hlipka | 0:8b387bed54c2 | 71 | } |
hlipka | 0:8b387bed54c2 | 72 | |
hlipka | 0:8b387bed54c2 | 73 | NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object |
hlipka | 0:8b387bed54c2 | 74 | { |
hlipka | 0:8b387bed54c2 | 75 | return new LwipNetDnsRequest(hostname); |
hlipka | 0:8b387bed54c2 | 76 | } |
hlipka | 0:8b387bed54c2 | 77 | |
hlipka | 0:8b387bed54c2 | 78 | NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object |
hlipka | 0:8b387bed54c2 | 79 | { |
hlipka | 0:8b387bed54c2 | 80 | return new LwipNetDnsRequest(pHost); |
hlipka | 0:8b387bed54c2 | 81 | } |
hlipka | 0:8b387bed54c2 | 82 | |
hlipka | 0:8b387bed54c2 | 83 | void LwipNetIf::poll() |
hlipka | 0:8b387bed54c2 | 84 | { |
hlipka | 0:8b387bed54c2 | 85 | if(m_init && m_tcpTimer.read_ms() >= TCP_TMR_INTERVAL) |
hlipka | 0:8b387bed54c2 | 86 | { |
hlipka | 0:8b387bed54c2 | 87 | m_tcpTimer.reset(); |
hlipka | 0:8b387bed54c2 | 88 | tcp_tmr(); //Poll LwIP |
hlipka | 0:8b387bed54c2 | 89 | } |
hlipka | 0:8b387bed54c2 | 90 | if(m_init && m_dnsTimer.read_ms() >= DNS_TMR_INTERVAL) |
hlipka | 0:8b387bed54c2 | 91 | { |
hlipka | 0:8b387bed54c2 | 92 | m_dnsTimer.reset(); |
hlipka | 0:8b387bed54c2 | 93 | dns_tmr(); |
hlipka | 0:8b387bed54c2 | 94 | } |
hlipka | 0:8b387bed54c2 | 95 | //Do some stuff... |
hlipka | 0:8b387bed54c2 | 96 | } |
hlipka | 0:8b387bed54c2 | 97 | |
hlipka | 0:8b387bed54c2 | 98 | #endif |