mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Merge pull request #9728 from AriParkkila/at-handler-clear-sigio
Cellular: Fix sigio to be released in ATHandler destructorpull/9745/head
						commit
						fdd2a9402a
					
				| 
						 | 
				
			
			@ -328,15 +328,6 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
 | 
			
		|||
    filehandle_stub_table = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio)
 | 
			
		||||
{
 | 
			
		||||
    EventQueue que;
 | 
			
		||||
    FileHandle_stub fh1;
 | 
			
		||||
 | 
			
		||||
    ATHandler at(&fh1, que, 0, ",");
 | 
			
		||||
    at.set_filehandle_sigio();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST_F(TestATHandler, test_ATHandler_flush)
 | 
			
		||||
{
 | 
			
		||||
    EventQueue que;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,7 +80,9 @@ public:
 | 
			
		|||
 | 
			
		||||
    virtual void sigio(Callback<void()> func)
 | 
			
		||||
    {
 | 
			
		||||
        func();
 | 
			
		||||
        if (func) {
 | 
			
		||||
            func();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    short short_value;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -62,7 +62,7 @@ static const uint8_t map_3gpp_errors[][2] =  {
 | 
			
		|||
 | 
			
		||||
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
 | 
			
		||||
    _nextATHandler(0),
 | 
			
		||||
    _fileHandle(fh),
 | 
			
		||||
    _fileHandle(NULL), // filehandle is set by set_file_handle()
 | 
			
		||||
    _queue(queue),
 | 
			
		||||
    _last_err(NSAPI_ERROR_OK),
 | 
			
		||||
    _last_3gpp_error(0),
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +74,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
 | 
			
		|||
    _last_response_stop(0),
 | 
			
		||||
    _oob_queued(false),
 | 
			
		||||
    _ref_count(1),
 | 
			
		||||
    _is_fh_usable(true),
 | 
			
		||||
    _is_fh_usable(false),
 | 
			
		||||
    _stop_tag(NULL),
 | 
			
		||||
    _delimiter(DEFAULT_DELIMITER),
 | 
			
		||||
    _prefix_matched(false),
 | 
			
		||||
| 
						 | 
				
			
			@ -119,6 +119,8 @@ bool ATHandler::get_debug() const
 | 
			
		|||
 | 
			
		||||
ATHandler::~ATHandler()
 | 
			
		||||
{
 | 
			
		||||
    set_file_handle(NULL);
 | 
			
		||||
 | 
			
		||||
    while (_oobs) {
 | 
			
		||||
        struct oob_t *oob = _oobs;
 | 
			
		||||
        _oobs = oob->next;
 | 
			
		||||
| 
						 | 
				
			
			@ -151,17 +153,26 @@ FileHandle *ATHandler::get_file_handle()
 | 
			
		|||
 | 
			
		||||
void ATHandler::set_file_handle(FileHandle *fh)
 | 
			
		||||
{
 | 
			
		||||
    if (_fileHandle) {
 | 
			
		||||
        set_is_filehandle_usable(false);
 | 
			
		||||
    }
 | 
			
		||||
    _fileHandle = fh;
 | 
			
		||||
    _fileHandle->set_blocking(false);
 | 
			
		||||
    set_filehandle_sigio();
 | 
			
		||||
    if (_fileHandle) {
 | 
			
		||||
        set_is_filehandle_usable(true);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATHandler::set_is_filehandle_usable(bool usable)
 | 
			
		||||
{
 | 
			
		||||
    _is_fh_usable = usable;
 | 
			
		||||
    if (usable) {
 | 
			
		||||
        // set file handle sigio and blocking mode back
 | 
			
		||||
        set_file_handle(_fileHandle);
 | 
			
		||||
    if (_fileHandle) {
 | 
			
		||||
        if (usable) {
 | 
			
		||||
            _fileHandle->set_blocking(false);
 | 
			
		||||
            _fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
 | 
			
		||||
        } else {
 | 
			
		||||
            _fileHandle->set_blocking(true); // set back to default state
 | 
			
		||||
            _fileHandle->sigio(NULL);
 | 
			
		||||
        }
 | 
			
		||||
        _is_fh_usable = usable;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -313,11 +324,6 @@ void ATHandler::process_oob()
 | 
			
		|||
    unlock();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATHandler::set_filehandle_sigio()
 | 
			
		||||
{
 | 
			
		||||
    _fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATHandler::reset_buffer()
 | 
			
		||||
{
 | 
			
		||||
    _recv_pos = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -190,10 +190,6 @@ public:
 | 
			
		|||
     */
 | 
			
		||||
    void process_oob();
 | 
			
		||||
 | 
			
		||||
    /** Set sigio for the current file handle. Sigio event goes through eventqueue so that it's handled in current thread.
 | 
			
		||||
     */
 | 
			
		||||
    void set_filehandle_sigio();
 | 
			
		||||
 | 
			
		||||
    /** Set file handle, which is used for reading AT responses and writing AT commands
 | 
			
		||||
     *
 | 
			
		||||
     *  @param fh file handle used for reading AT responses and writing AT commands
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue