Skip to content

Commit fdd2a94

Browse files
author
Cruz Monrreal
authored
Merge pull request #9728 from AriParkkila/at-handler-clear-sigio
Cellular: Fix sigio to be released in ATHandler destructor
2 parents 7dbe541 + 0c697f4 commit fdd2a94

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,6 @@ TEST_F(TestATHandler, test_ATHandler_process_oob)
328328
filehandle_stub_table = NULL;
329329
}
330330

331-
TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio)
332-
{
333-
EventQueue que;
334-
FileHandle_stub fh1;
335-
336-
ATHandler at(&fh1, que, 0, ",");
337-
at.set_filehandle_sigio();
338-
}
339-
340331
TEST_F(TestATHandler, test_ATHandler_flush)
341332
{
342333
EventQueue que;

UNITTESTS/stubs/FileHandle_stub.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class FileHandle_stub : public FileHandle {
8080

8181
virtual void sigio(Callback<void()> func)
8282
{
83-
func();
83+
if (func) {
84+
func();
85+
}
8486
}
8587

8688
short short_value;

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const uint8_t map_3gpp_errors[][2] = {
6262

6363
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
6464
_nextATHandler(0),
65-
_fileHandle(fh),
65+
_fileHandle(NULL), // filehandle is set by set_file_handle()
6666
_queue(queue),
6767
_last_err(NSAPI_ERROR_OK),
6868
_last_3gpp_error(0),
@@ -74,7 +74,7 @@ ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const
7474
_last_response_stop(0),
7575
_oob_queued(false),
7676
_ref_count(1),
77-
_is_fh_usable(true),
77+
_is_fh_usable(false),
7878
_stop_tag(NULL),
7979
_delimiter(DEFAULT_DELIMITER),
8080
_prefix_matched(false),
@@ -119,6 +119,8 @@ bool ATHandler::get_debug() const
119119

120120
ATHandler::~ATHandler()
121121
{
122+
set_file_handle(NULL);
123+
122124
while (_oobs) {
123125
struct oob_t *oob = _oobs;
124126
_oobs = oob->next;
@@ -151,17 +153,26 @@ FileHandle *ATHandler::get_file_handle()
151153

152154
void ATHandler::set_file_handle(FileHandle *fh)
153155
{
156+
if (_fileHandle) {
157+
set_is_filehandle_usable(false);
158+
}
154159
_fileHandle = fh;
155-
_fileHandle->set_blocking(false);
156-
set_filehandle_sigio();
160+
if (_fileHandle) {
161+
set_is_filehandle_usable(true);
162+
}
157163
}
158164

159165
void ATHandler::set_is_filehandle_usable(bool usable)
160166
{
161-
_is_fh_usable = usable;
162-
if (usable) {
163-
// set file handle sigio and blocking mode back
164-
set_file_handle(_fileHandle);
167+
if (_fileHandle) {
168+
if (usable) {
169+
_fileHandle->set_blocking(false);
170+
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
171+
} else {
172+
_fileHandle->set_blocking(true); // set back to default state
173+
_fileHandle->sigio(NULL);
174+
}
175+
_is_fh_usable = usable;
165176
}
166177
}
167178

@@ -313,11 +324,6 @@ void ATHandler::process_oob()
313324
unlock();
314325
}
315326

316-
void ATHandler::set_filehandle_sigio()
317-
{
318-
_fileHandle->sigio(Callback<void()>(this, &ATHandler::event));
319-
}
320-
321327
void ATHandler::reset_buffer()
322328
{
323329
_recv_pos = 0;

features/cellular/framework/AT/ATHandler.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ class ATHandler {
190190
*/
191191
void process_oob();
192192

193-
/** Set sigio for the current file handle. Sigio event goes through eventqueue so that it's handled in current thread.
194-
*/
195-
void set_filehandle_sigio();
196-
197193
/** Set file handle, which is used for reading AT responses and writing AT commands
198194
*
199195
* @param fh file handle used for reading AT responses and writing AT commands

0 commit comments

Comments
 (0)