@@ -1531,6 +1531,70 @@ int lesp_initialize(void)
15311531 return 0 ;
15321532}
15331533
1534+ /****************************************************************************
1535+ * Name: lesp_finalize
1536+ *
1537+ * Description:
1538+ * finalize Esp8266 class.
1539+ * - destroy worker thread
1540+ * - close port
1541+ *
1542+ * Input Parameters:
1543+ * None
1544+ *
1545+ * Returned Value:
1546+ * 0 on success, -1 in case of error.
1547+ *
1548+ ****************************************************************************/
1549+
1550+ int lesp_finalize (void )
1551+ {
1552+ int i ;
1553+
1554+ ninfo ("Finalizing Esp8266...\n" );
1555+
1556+ pthread_mutex_lock (& g_lesp_state .mutex );
1557+
1558+ if (!g_lesp_state .is_initialized )
1559+ {
1560+ pthread_mutex_unlock (& g_lesp_state .mutex );
1561+ ninfo ("Esp8266 already finalized\n" );
1562+ return 0 ;
1563+ }
1564+
1565+ pthread_mutex_lock (& g_lesp_state .worker .mutex );
1566+
1567+ for (i = 0 ; i < SOCKET_NBR ; i ++ )
1568+ {
1569+ if ((g_lesp_state .sockets [i ].flags & FLAGS_SOCK_USED ) != 0 )
1570+ {
1571+ nerr ("ERROR: Exist opened socket\n" );
1572+ pthread_mutex_unlock (& g_lesp_state .worker .mutex );
1573+ pthread_mutex_unlock (& g_lesp_state .mutex );
1574+ return -1 ;
1575+ }
1576+ }
1577+
1578+ /* Destroy worker thread */
1579+
1580+ g_lesp_state .worker .running = false;
1581+ pthread_kill (g_lesp_state .worker .thread , SIGTERM );
1582+ pthread_join (g_lesp_state .worker .thread , NULL );
1583+
1584+ if (g_lesp_state .fd > 0 )
1585+ {
1586+ close (g_lesp_state .fd );
1587+ g_lesp_state .fd = -1 ;
1588+ }
1589+
1590+ g_lesp_state .is_initialized = false;
1591+
1592+ pthread_mutex_unlock (& g_lesp_state .worker .mutex );
1593+ pthread_mutex_unlock (& g_lesp_state .mutex );
1594+
1595+ return 0 ;
1596+ }
1597+
15341598/****************************************************************************
15351599 * Name: lesp_soft_reset
15361600 *
0 commit comments