My fork

Dependencies:   WncControllerK64F

Fork of WNCInterface by Jan Korycan

Files at this revision

API Documentation at this revision

Comitter:
JMF
Date:
Fri Oct 07 13:26:00 2016 +0000
Parent:
8:4b38bfb1704d
Child:
10:9d8b23b60fd6
Commit message:
Cleaned up WNC Error checking to ensure mutex was released when an error occurs.

Changed in this revision

Sms/IOTSMS.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/Endpoint.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
WNCInterface.cpp Show annotated file Show diff for this revision Revisions of this file
WNCInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/Sms/IOTSMS.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/Sms/IOTSMS.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -52,8 +52,7 @@
   //not completing our tasks wihin the timeperiod.  So stop the timer when
   //we come in and start it when we leave.
   //
-  if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-    FATAL_WNC_ERROR(void);
+  CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), void);
     
   m_SMStimer->stop();  //stop the timer while we check for SMS messages
   M_LOCK;       
@@ -87,8 +86,7 @@
 //
 int WNCSms::init(uint32_t p, void (*cb)(WNCSmsMsg& s)) {
 
-  if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-    FATAL_WNC_ERROR(fail);
+  CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
   
   if( WNCInterface::_pwnc == NULL )  //must have already initialized WNCInterface
     return -1;
@@ -139,8 +137,7 @@
   if( !m_smsinit )
     return -1;
 
-  if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-    FATAL_WNC_ERROR(fail);
+  CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
   M_LOCK;
   int ret = WNCInterface::_pwnc->readUnreadSMSText(&m_smsmsgs, true);
   M_ULOCK;
@@ -153,19 +150,14 @@
     string iccid_str;
     static string msisdn_str;
     
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-      FATAL_WNC_ERROR(null);
-
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
     M_LOCK;
     if( !WNCInterface::_pwnc->getICCID(&iccid_str) ) {
        M_ULOCK;
        return NULL;
        }
       
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ) {
-       M_ULOCK;
-       FATAL_WNC_ERROR(null);
-       }
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
 
     if( WNCInterface::_pwnc->convertICCIDtoMSISDN(iccid_str, &msisdn_str) )
         ret = (char*)msisdn_str.c_str();    
--- a/Socket/Endpoint.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/Socket/Endpoint.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -47,8 +47,7 @@
     char address[5];
     int rslt;
 
-   if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-       FATAL_WNC_ERROR(fail);
+   CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
 
    reset_address();
     _epAddr.port = port;  //go ahead and save the port 
--- a/Socket/Socket.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/Socket/Socket.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -63,8 +63,7 @@
   int rslt;
   char address[5];
   
-  if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-      FATAL_WNC_ERROR(fail);
+  CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
  
   // lets determine if they passed in an IP or a URL
   rslt = std::sscanf(url, "%3u.%3u.%3u.%3u",
@@ -94,8 +93,7 @@
   if( _sock_type<0 )
     return 0;  //nothing is connected currently
 
-  if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-      FATAL_WNC_ERROR(fail);
+  CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
   M_LOCK;
   int ret = !WNCInterface::_pwnc->closeSocket(0);
   M_ULOCK;
@@ -106,8 +104,7 @@
     blocking = blocking;
     timeout= timeout;
 
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-        FATAL_WNC_ERROR(void);
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), void);
     M_LOCK;
     WNCInterface::_pwnc->setReadRetryWait(0, 0);
     WNCInterface::_pwnc->setReadRetries(0, 0);
--- a/Socket/TCPSocketConnection.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/Socket/TCPSocketConnection.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -36,8 +36,7 @@
     _is_blocking = blocking;   // true if we want to wait for request
     _btimeout = timeout;       // user specs msec
 
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-        FATAL_WNC_ERROR(void);
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), void);
     M_LOCK;
     WNCInterface::_pwnc->setReadRetryWait(0, 0);
     WNCInterface::_pwnc->setReadRetries(0, 0);
@@ -60,8 +59,7 @@
     
     WncController_fk::WncController::WncState_e s = WNCInterface::_pwnc->getWncStatus();
 
-    if( s == FATAL_FLAG )
-        FATAL_WNC_ERROR(fail);
+    CHK_WNCFE(( s == FATAL_FLAG ), fail);
  
     if( s == WncController_fk::WncController::WNC_ON ) {
       M_LOCK;
@@ -78,10 +76,7 @@
     int ret=-1;
     WncController_fk::WncController::WncState_e s = WNCInterface::_pwnc->getWncStatus();
 
-    if( s  == FATAL_FLAG )
-        FATAL_WNC_ERROR(fail);
- 
-
+    CHK_WNCFE(( s  == FATAL_FLAG ), fail);
     if( s != WncController_fk::WncController::WNC_ON )
         return ret;
 
--- a/Socket/UDPSocket.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/Socket/UDPSocket.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -50,9 +50,7 @@
 int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) {
     int ret = -1;
     
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-        FATAL_WNC_ERROR(fail);
- 
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
     if( remote._epAddr.port ) {  //make sure the Endpoint has an port assoicated with it
         if( Socket::connect(remote._epAddr.IP,SOCK_DGRAM,remote._epAddr.port) ) {
             if( WNCInterface::_pwnc->write(0,packet,length) )
@@ -71,9 +69,7 @@
     _is_blocking = blocking;   // true or false
     _btimeout = timeout;       // user specifies in msec
  
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-        FATAL_WNC_ERROR(void);
- 
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), void);
     WNCInterface::_pwnc->setReadRetryWait(0, 0);
     WNCInterface::_pwnc->setReadRetries(0, 0);
 }
@@ -88,9 +84,7 @@
     if( !remote._epAddr.port )
       return -1;
 
-    if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-        FATAL_WNC_ERROR(fail);
- 
+    CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail);
     ret = Socket::connect(remote._epAddr.IP,SOCK_DGRAM,remote._epAddr.port);        
     
     t.start();
--- a/WNCInterface.cpp	Fri Oct 07 00:36:47 2016 +0000
+++ b/WNCInterface.cpp	Fri Oct 07 13:26:00 2016 +0000
@@ -135,8 +135,7 @@
 char * WNCInterface::getIPAddress() {
     M_LOCK;
     if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
-        if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-            FATAL_WNC_ERROR(null);
+        CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
         M_ULOCK;
         return &myNetStats.ip[0];
     }
@@ -150,8 +149,7 @@
 char * WNCInterface::getGateway() {
     M_LOCK;
     if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
-        if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-            FATAL_WNC_ERROR(null);
+        CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
         M_ULOCK;
         return &WNCInterface::myNetStats.gateway[0];
     }
@@ -165,8 +163,7 @@
 char * WNCInterface::getNetworkMask() {
     M_LOCK;
     if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
-        if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-            FATAL_WNC_ERROR(null);
+        CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
         M_ULOCK;    
         return &WNCInterface::myNetStats.mask[0];
     }
@@ -182,8 +179,7 @@
     
     M_LOCK;
     if( _pwnc->getICCID(&str) ) {
-        if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
-            FATAL_WNC_ERROR(null);
+        CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
         mac = str.substr(3,20);
         mac[2]=mac[5]=mac[8]=mac[11]=mac[14]=':';
         M_ULOCK;
--- a/WNCInterface.h	Fri Oct 07 00:36:47 2016 +0000
+++ b/WNCInterface.h	Fri Oct 07 13:26:00 2016 +0000
@@ -81,6 +81,7 @@
 
 #define M_LOCK  {extern Mutex _WNCLock; _WNCLock.lock();}
 #define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();}
+#define CHK_WNCFE(x,y)    if( x ){M_ULOCK; FATAL_WNC_ERROR(y);}
 
 // Because the WncController has intermixed socket & interface functionallity
 // will need to make the Socket class a friend of the Interface class. This