Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MySQLClient by
Revision 8:cdb6d1236f37, committed 2013-11-22
- Comitter:
- loc_tran17
- Date:
- Fri Nov 22 09:32:56 2013 +0000
- Parent:
- 7:f06820c3b8e8
- Commit message:
- try SQLClient
Changed in this revision
--- a/LPC1768/services/mysql/MySQLClient.cpp Fri Nov 22 09:16:20 2013 +0000 +++ b/LPC1768/services/mysql/MySQLClient.cpp Fri Nov 22 09:32:56 2013 +0000 @@ -103,16 +103,7 @@ m_pCbMeth = NULL; } -#if 0 //Ref only -template<class T> -void MySQLClient::setOnResult( T* pItem, void (T::*pMethod)(MySQLResult) ) -{ - m_pCb = NULL; - m_pCbItem = (CDummy*) pItem; - m_pCbMeth = (void (CDummy::*)(MySQLResult)) pMethod; -} -#endif - + void MySQLClient::setTimeout(int ms) { m_timeout = 1000*ms; @@ -143,9 +134,6 @@ return; m_state = MYSQL_HANDSHAKE; m_pTCPSocket = new TCPSocketConnection; -#if 0 - m_pTCPSocket->setOnEvent(this, &MySQLClient::onTCPSocketEvent); -#endif m_closed = false; } @@ -157,54 +145,23 @@ m_closed = true; //Prevent recursive calling or calling on an object being destructed by someone else m_watchdog.stop(); //Stop timeout m_watchdog.reset(); -#if 0 - m_pTCPSocket->resetOnEvent(); -#endif m_pTCPSocket->close(); delete m_pTCPSocket; m_pTCPSocket = NULL; -#if 0 - if( m_pDnsReq ) - { - m_pDnsReq->close(); - delete m_pDnsReq; - m_pDnsReq = NULL; - } -#endif } void MySQLClient::setup(const string& host, int port, const string& user, const string& password, const string& db) //Setup connection, make DNS Req if necessary { init(); //Initialize client in known state, create socket resetTimeout(); -#if 0 - m_host = host; - if(!host.getPort()) - host.setPort( MYSQL_PORT ); //Default port -#endif - + m_host = host; m_port = port; m_user = user; m_password = password; m_db = db; - -#if 0 - if( !host.getIp().isNull() ) - { - connect(); - } - else //Need to do a DNS Query... - { - printf("DNS Query...\n"); - m_pDnsReq = new DNSRequest(); - m_pDnsReq->setOnReply(this, &MySQLClient::onDNSReply); - m_pDnsReq->resolve(&m_host); - printf("MySQLClient : DNSRequest %p\n", m_pDnsReq); - } -#endif - connect(); + connect(); } void MySQLClient::connect() //Start Connection @@ -355,7 +312,7 @@ memcpy((char*)m_buf,token,9); m_len = 9; - #if 0 +#if 0 *((uint32_t*)&m_buf[0]) = htonl(clientFlags); *((uint32_t*)&m_buf[4]) = BUF_SIZE; //Max packets size m_buf[8] = 8; //latin1 charset @@ -366,7 +323,7 @@ memcpy((char*)&m_pPos[1],token+1,8); strcpy((char*)(m_pPos+9),m_db.c_str()); m_len = 32 + m_user.length() + 1 + 9 + m_db.length() + 1; - #endif +#endif printf("Writing data\n"); writeData(); @@ -449,75 +406,6 @@ m_len = 0;//FIXME... incomplete packets handling } -#if 0 -void MySQLClient::onTCPSocketEvent(TCPSocketEvent e) -{ - printf("Event %d in MySQLClient::onTCPSocketEvent()\n", e); - - if(m_closed) - { - printf("WARN: Discarded\n"); - return; - } - - switch(e) - { - case TCPSOCKET_READABLE: //Incoming data - resetTimeout(); - if(m_state == MYSQL_HANDSHAKE) - handleHandshake(); - else if(m_state == MYSQL_AUTH) - handleAuthResult(); - else if(m_state == MYSQL_COMMANDS) - handleCommandResult(); - break; - case TCPSOCKET_WRITEABLE: //We can send data - resetTimeout(); - break; - case TCPSOCKET_CONNECTED: //Connected, wait for handshake packet - resetTimeout(); - break; - case TCPSOCKET_CONTIMEOUT: - case TCPSOCKET_CONRST: - case TCPSOCKET_CONABRT: - case TCPSOCKET_ERROR: - printf("Connection error.\n"); - onResult(MYSQL_CONN); - case TCPSOCKET_DISCONNECTED: - //There might still be some data available for reading - //So if we are in a reading state, do not close the socket yet - if(m_state != MYSQL_CLOSED) - { - onResult(MYSQL_CONN); - } - printf("Connection closed by remote host.\n"); - break; - } -} - -void MySQLClient::onDNSReply(DNSReply r) -{ - if(m_closed) - { - printf("WARN: Discarded\n"); - return; - } - - if( r != DNS_FOUND ) - { - printf("Could not resolve hostname.\n"); - onResult(MYSQL_DNS); - return; - } - - printf("DNS Resolved to %d.%d.%d.%d.\n",m_host.getIp()[0],m_host.getIp()[1],m_host.getIp()[2],m_host.getIp()[3]); - //If no error, m_host has been updated by m_pDnsReq so we're set to go ! - m_pDnsReq->close(); - delete m_pDnsReq; - m_pDnsReq = NULL; - connect(); -} -#endif void MySQLClient::onResult(MySQLResult r) //Called when exchange completed or on failure {
--- a/LPC1768/services/mysql/MySQLClient.h Fri Nov 22 09:16:20 2013 +0000 +++ b/LPC1768/services/mysql/MySQLClient.h Fri Nov 22 09:32:56 2013 +0000 @@ -129,10 +129,6 @@ void readData(); //Copy to buf void writeData(); //Copy from buf -#if 0 - void onTCPSocketEvent(TCPSocketEvent e); - void onDNSReply(DNSReply r); -#endif void onResult(MySQLResult r); //Called when exchange completed or on failure void onTimeout(); //Connection has timed out @@ -142,17 +138,10 @@ void (*m_pCb)(MySQLResult); -#if 0 - TCPSocket* m_pTCPSocket; -#endif TCPSocketConnection* m_pTCPSocket; Timer m_watchdog; int m_timeout; -#if 0 - DNSRequest* m_pDnsReq; -#endif - bool m_closed; enum MySQLStep