From 8f4acc14ca8f4cdf95214d5934674f1e9a06e319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Wed, 29 Aug 2018 09:31:35 +0300 Subject: [PATCH] Cellular: CellularDevice:get_default_instance() implemented Removed copy-paste code from targets by creating implementation methods to override. --- .../easy_cellular/CellularConnectionFSM.cpp | 29 ++-- .../easy_cellular/CellularConnectionFSM.h | 14 +- .../easy_cellular/EasyCellularConnection.cpp | 2 +- .../cellular/framework/API/CellularDevice.h | 44 +++++- .../framework/AT/AT_CellularDevice.cpp | 132 ++++++++++++------ .../cellular/framework/AT/AT_CellularDevice.h | 53 +++++-- .../framework/device/CellularDevice.cpp | 52 +++++++ .../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 13 +- .../GEMALTO/CINTERION/GEMALTO_CINTERION.h | 5 +- .../targets/QUECTEL/BC95/QUECTEL_BC95.cpp | 39 +----- .../targets/QUECTEL/BC95/QUECTEL_BC95.h | 9 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.cpp | 13 +- .../targets/QUECTEL/BG96/QUECTEL_BG96.h | 5 +- .../targets/QUECTEL/UG96/QUECTEL_UG96.cpp | 20 +-- .../targets/QUECTEL/UG96/QUECTEL_UG96.h | 7 +- .../targets/TELIT/HE910/TELIT_HE910.cpp | 26 +--- .../targets/TELIT/HE910/TELIT_HE910.h | 7 +- .../framework/targets/UBLOX/AT/UBLOX_AT.cpp | 26 +--- .../framework/targets/UBLOX/AT/UBLOX_AT.h | 10 +- .../framework/targets/UBLOX/PPP/UBLOX_PPP.cpp | 26 +--- .../framework/targets/UBLOX/PPP/UBLOX_PPP.h | 7 +- 21 files changed, 301 insertions(+), 238 deletions(-) create mode 100644 features/cellular/framework/device/CellularDevice.cpp diff --git a/features/cellular/easy_cellular/CellularConnectionFSM.cpp b/features/cellular/easy_cellular/CellularConnectionFSM.cpp index 657b734ae3..43aa21dc1e 100644 --- a/features/cellular/easy_cellular/CellularConnectionFSM.cpp +++ b/features/cellular/easy_cellular/CellularConnectionFSM.cpp @@ -24,6 +24,8 @@ #endif #include "CellularLog.h" #include "CellularCommon.h" +#include "CellularDevice.h" +#include "CellularUtil.h" // timeout to wait for AT responses #define TIMEOUT_POWER_ON (1*1000) @@ -42,7 +44,7 @@ namespace mbed { CellularConnectionFSM::CellularConnectionFSM() : _serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0), _queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1), - _at_queue(8 * EVENTS_EVENT_SIZE), _event_id(0), _plmn(0), _command_success(false), _plmn_network_found(false) + _at_queue(0), _event_id(0), _plmn(0), _command_success(false), _plmn_network_found(false) { memset(_sim_pin, 0, sizeof(_sim_pin)); #if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0 @@ -82,12 +84,20 @@ void CellularConnectionFSM::stop() _queue_thread = NULL; } - delete _cellularDevice; - _cellularDevice = NULL; - // _cellularDevice closes all interfaces in destructor - _power = NULL; - _network = NULL; - _sim = NULL; + if (_power) { + _cellularDevice->close_power(); + _power = NULL; + } + + if (_network) { + _cellularDevice->close_network(); + _network = NULL; + } + + if (_sim) { + _cellularDevice->close_sim(); + _sim = NULL; + } _state = STATE_INIT; _next_state = _state; @@ -96,7 +106,7 @@ void CellularConnectionFSM::stop() nsapi_error_t CellularConnectionFSM::init() { tr_info("CELLULAR_DEVICE: %s", CELLULAR_STRINGIFY(CELLULAR_DEVICE)); - _cellularDevice = new CELLULAR_DEVICE(_at_queue); + _cellularDevice = CellularDevice::get_default_instance(); if (!_cellularDevice) { stop(); return NSAPI_ERROR_NO_MEMORY; @@ -120,7 +130,8 @@ nsapi_error_t CellularConnectionFSM::init() return NSAPI_ERROR_NO_MEMORY; } - _at_queue.chain(&_queue); + _at_queue = _cellularDevice->get_queue(); + _at_queue->chain(&_queue); _retry_count = 0; _state = STATE_INIT; diff --git a/features/cellular/easy_cellular/CellularConnectionFSM.h b/features/cellular/easy_cellular/CellularConnectionFSM.h index ba9f4cf218..680833e450 100644 --- a/features/cellular/easy_cellular/CellularConnectionFSM.h +++ b/features/cellular/easy_cellular/CellularConnectionFSM.h @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef _CELLULAR_CONNECTION_UTIL_H -#define _CELLULAR_CONNECTION_UTIL_H +#ifndef _CELLULAR_CONNECTION_FSM_H +#define _CELLULAR_CONNECTION_FSM_H #include "CellularTargets.h" #if defined(CELLULAR_DEVICE) || defined(DOXYGEN_ONLY) @@ -29,13 +29,11 @@ #include "CellularNetwork.h" #include "CellularPower.h" #include "CellularSIM.h" -#include "CellularUtil.h" - -// modem type is defined as CELLULAR_DEVICE macro -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) namespace mbed { +class CellularDevice; + const int PIN_SIZE = 8; const int MAX_RETRY_ARRAY_SIZE = 10; @@ -209,7 +207,7 @@ private: uint16_t _retry_timeout_array[MAX_RETRY_ARRAY_SIZE]; int _retry_array_length; - events::EventQueue _at_queue; + events::EventQueue *_at_queue; char _st_string[20]; int _event_id; const char *_plmn; @@ -221,4 +219,4 @@ private: #endif // CELLULAR_DEVICE || DOXYGEN -#endif /* _CELLULAR_CONNECTION_UTIL_H */ +#endif // _CELLULAR_CONNECTION_FSM_H diff --git a/features/cellular/easy_cellular/EasyCellularConnection.cpp b/features/cellular/easy_cellular/EasyCellularConnection.cpp index 204e4b7bff..c0e31468d2 100644 --- a/features/cellular/easy_cellular/EasyCellularConnection.cpp +++ b/features/cellular/easy_cellular/EasyCellularConnection.cpp @@ -23,7 +23,7 @@ #endif #include "CellularConnectionFSM.h" -#include "CellularUtil.h" +#include "CellularDevice.h" #include "EasyCellularConnection.h" #include "CellularLog.h" diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index 46b6f9d731..d065feb123 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -18,17 +18,22 @@ #ifndef CELLULAR_DEVICE_H_ #define CELLULAR_DEVICE_H_ -#include "FileHandle.h" +#include "CellularTargets.h" +#include "EventQueue.h" +#include "nsapi_types.h" +#include "PlatformMutex.h" -#include "CellularSIM.h" -#include "CellularNetwork.h" -#include "CellularSMS.h" -#include "CellularPower.h" -#include "CellularInformation.h" -#include "NetworkStack.h" +class NetworkStack; namespace mbed { +class CellularPower; +class CellularSMS; +class CellularSIM; +class CellularInformation; +class CellularNetwork; +class FileHandle; + /** * Class CellularDevice * @@ -37,6 +42,24 @@ namespace mbed { */ class CellularDevice { public: + + /** Return singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not + * defined then returns NULL. Implementation is marked as weak. + * + * @return CellularDevice* instance if any + */ + static CellularDevice *get_default_instance(); + + /** Get event queue that can be chained to main event queue. EventQueue is created in get_default_instance() or + * given to CELLULAR_DEVICE (for example TELIT_HE910 class). + * @return event queue + */ + virtual events::EventQueue *get_queue() const; + + /** Default constructor + */ + CellularDevice(); + /** virtual Destructor */ virtual ~CellularDevice() {} @@ -124,6 +147,13 @@ public: * @return 0 on success */ virtual nsapi_error_t init_module(FileHandle *fh) = 0; + +protected: + int _network_ref_count; + int _sms_ref_count; + int _power_ref_count; + int _sim_ref_count; + int _info_ref_count; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 0d8477e273..11280fa7ec 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -16,6 +16,12 @@ */ #include "AT_CellularDevice.h" +#include "AT_CellularInformation.h" +#include "AT_CellularNetwork.h" +#include "AT_CellularPower.h" +#include "AT_CellularSIM.h" +#include "AT_CellularSMS.h" +#include "ATHandler.h" using namespace events; using namespace mbed; @@ -44,6 +50,11 @@ AT_CellularDevice::~AT_CellularDevice() } } +events::EventQueue *AT_CellularDevice::get_queue() const +{ + return &_queue; +} + // each parser is associated with one filehandle (that is UART) ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) { @@ -60,13 +71,11 @@ ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) } atHandler = new ATHandler(fileHandle, _queue, _default_timeout, "\r", get_send_delay()); - if (atHandler) { - if (_modem_debug_on) { - atHandler->set_debug(_modem_debug_on); - } - atHandler->_nextATHandler = _atHandlers; - _atHandlers = atHandler; + if (_modem_debug_on) { + atHandler->set_debug(_modem_debug_on); } + atHandler->_nextATHandler = _atHandlers; + _atHandlers = atHandler; return atHandler; } @@ -103,12 +112,12 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) if (!_network) { ATHandler *atHandler = get_at_handler(fh); if (atHandler) { - _network = new AT_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } + _network = open_network_impl(*atHandler); } } + if (_network) { + _network_ref_count++; + } return _network; } @@ -117,12 +126,12 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) if (!_sms) { ATHandler *atHandler = get_at_handler(fh); if (atHandler) { - _sms = new AT_CellularSMS(*atHandler); - if (!_sms) { - release_at_handler(atHandler); - } + _sms = open_sms_impl(*atHandler); } } + if (_sms) { + _sms_ref_count++; + } return _sms; } @@ -131,12 +140,12 @@ CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) if (!_sim) { ATHandler *atHandler = get_at_handler(fh); if (atHandler) { - _sim = new AT_CellularSIM(*atHandler); - if (!_sim) { - release_at_handler(atHandler); - } + _sim = open_sim_impl(*atHandler); } } + if (_sim) { + _sim_ref_count++; + } return _sim; } @@ -145,12 +154,12 @@ CellularPower *AT_CellularDevice::open_power(FileHandle *fh) if (!_power) { ATHandler *atHandler = get_at_handler(fh); if (atHandler) { - _power = new AT_CellularPower(*atHandler); - if (!_power) { - release_at_handler(atHandler); - } + _power = open_power_impl(*atHandler); } } + if (_power) { + _power_ref_count++; + } return _power; } @@ -159,56 +168,97 @@ CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) if (!_information) { ATHandler *atHandler = get_at_handler(fh); if (atHandler) { - _information = new AT_CellularInformation(*atHandler); - if (!_information) { - release_at_handler(atHandler); - } + _information = open_information_impl(*atHandler); } } + if (_information) { + _info_ref_count++; + } return _information; } +AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at) +{ + return new AT_CellularNetwork(at); +} + +AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at) +{ + return new AT_CellularSMS(at); +} + +AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) +{ + return new AT_CellularPower(at); +} + +AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at) +{ + return new AT_CellularSIM(at); +} + +AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) +{ + return new AT_CellularInformation(at); +} + void AT_CellularDevice::close_network() { if (_network) { - release_at_handler(&_network->get_at_handler()); - delete _network; - _network = NULL; + _network_ref_count--; + if (_network_ref_count == 0) { + release_at_handler(&_network->get_at_handler()); + delete _network; + _network = NULL; + } } } void AT_CellularDevice::close_sms() { if (_sms) { - release_at_handler(&_sms->get_at_handler()); - delete _sms; - _sms = NULL; + _sms_ref_count--; + if (_sms_ref_count == 0) { + release_at_handler(&_sms->get_at_handler()); + delete _sms; + _sms = NULL; + } } } + void AT_CellularDevice::close_power() { if (_power) { - release_at_handler(&_power->get_at_handler()); - delete _power; - _power = NULL; + _power_ref_count--; + if (_power_ref_count == 0) { + release_at_handler(&_power->get_at_handler()); + delete _power; + _power = NULL; + } } } void AT_CellularDevice::close_sim() { if (_sim) { - release_at_handler(&_sim->get_at_handler()); - delete _sim; - _sim = NULL; + _sim_ref_count--; + if (_sim_ref_count == 0) { + release_at_handler(&_sim->get_at_handler()); + delete _sim; + _sim = NULL; + } } } void AT_CellularDevice::close_information() { if (_information) { - release_at_handler(&_information->get_at_handler()); - delete _information; - _information = NULL; + _info_ref_count--; + if (_info_ref_count == 0) { + release_at_handler(&_information->get_at_handler()); + delete _information; + _information = NULL; + } } } diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 1a5bea3f55..21c373ee73 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -20,16 +20,15 @@ #include "CellularDevice.h" -#include "AT_CellularNetwork.h" -#include "AT_CellularSIM.h" -#include "AT_CellularSMS.h" -#include "AT_CellularPower.h" -#include "AT_CellularInformation.h" - -#include "ATHandler.h" - namespace mbed { +class ATHandler; +class AT_CellularInformation; +class AT_CellularNetwork; +class AT_CellularPower; +class AT_CellularSIM; +class AT_CellularSMS; + /** * Class AT_CellularDevice * @@ -53,6 +52,9 @@ protected: void release_at_handler(ATHandler *at_handler); public: // CellularDevice + + virtual events::EventQueue *get_queue() const; + virtual CellularNetwork *open_network(FileHandle *fh); virtual CellularSMS *open_sms(FileHandle *fh); @@ -84,6 +86,41 @@ public: // CellularDevice virtual nsapi_error_t init_module(FileHandle *fh); protected: + /** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation. + * + * @param at ATHandler reference for communication with the modem. + * @return new instance of class AT_CellularNetwork + */ + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + + /** Create new instance of AT_CellularSMS or if overridden, modem specific implementation. + * + * @param at ATHandler reference for communication with the modem. + * @return new instance of class AT_CellularSMS + */ + virtual AT_CellularSMS *open_sms_impl(ATHandler &at); + + /** Create new instance of AT_CellularPower or if overridden, modem specific implementation. + * + * @param at ATHandler reference for communication with the modem. + * @return new instance of class AT_CellularPower + */ + virtual AT_CellularPower *open_power_impl(ATHandler &at); + + /** Create new instance of AT_CellularSIM or if overridden, modem specific implementation. + * + * @param at ATHandler reference for communication with the modem. + * @return new instance of class AT_CellularSIM + */ + virtual AT_CellularSIM *open_sim_impl(ATHandler &at); + + /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation. + * + * @param at ATHandler reference for communication with the modem. + * @return new instance of class AT_CellularInformation + */ + virtual AT_CellularInformation *open_information_impl(ATHandler &at); + AT_CellularNetwork *_network; AT_CellularSMS *_sms; AT_CellularSIM *_sim; diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp new file mode 100644 index 0000000000..0a4856731b --- /dev/null +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CellularDevice.h" +#include "EventQueue.h" +#include "CellularUtil.h" + +#ifdef CELLULAR_DEVICE +#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) +#endif // CELLULAR_DEVICE + +namespace mbed { + +#ifdef CELLULAR_DEVICE +MBED_WEAK CellularDevice *CellularDevice::get_default_instance() +{ + static events::EventQueue event_queue(4 * EVENTS_EVENT_SIZE); + static CELLULAR_DEVICE device(event_queue); + return &device; +} +#else +MBED_WEAK CellularDevice *CellularDevice::get_default_instance() +{ + return NULL; +} +#endif // CELLULAR_DEVICE + +CellularDevice::CellularDevice() : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0), + _info_ref_count(0) +{ +} + +events::EventQueue *CellularDevice::get_queue() const +{ + return NULL; +} + +} diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 4b9a94131c..2799055f23 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -32,18 +32,9 @@ GEMALTO_CINTERION::~GEMALTO_CINTERION() { } -CellularNetwork *GEMALTO_CINTERION::open_network(FileHandle *fh) +AT_CellularNetwork *GEMALTO_CINTERION::open_network_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new GEMALTO_CINTERION_CellularNetwork(*get_at_handler(fh)); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new GEMALTO_CINTERION_CellularNetwork(at); } nsapi_error_t GEMALTO_CINTERION::init_module(FileHandle *fh) diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h index e8bf822831..68efa1fcc0 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.h @@ -28,8 +28,9 @@ public: GEMALTO_CINTERION(events::EventQueue &queue); virtual ~GEMALTO_CINTERION(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); +public: virtual nsapi_error_t init_module(FileHandle *fh); }; diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index 84f446542f..94b6b635c1 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -39,44 +39,17 @@ QUECTEL_BC95::~QUECTEL_BC95() { } -CellularNetwork *QUECTEL_BC95::open_network(FileHandle *fh) +AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new QUECTEL_BC95_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new QUECTEL_BC95_CellularNetwork(at); } -CellularPower *QUECTEL_BC95::open_power(FileHandle *fh) +AT_CellularPower *QUECTEL_BC95::open_power_impl(ATHandler &at) { - if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = new QUECTEL_BC95_CellularPower(*atHandler); - if (!_power) { - release_at_handler(atHandler); - } - } - } - return _power; + return new QUECTEL_BC95_CellularPower(at); } -CellularSIM *QUECTEL_BC95::open_sim(FileHandle *fh) +AT_CellularSIM *QUECTEL_BC95::open_sim_impl(ATHandler &at) { - if (!_sim) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _sim = new QUECTEL_BC95_CellularSIM(*atHandler); - if (!_sim) { - release_at_handler(atHandler); - } - } - } - return _sim; + return new QUECTEL_BC95_CellularSIM(at); } diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index aaa9a8afc2..ed2ce89b61 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -24,14 +24,13 @@ namespace mbed { class QUECTEL_BC95 : public AT_CellularDevice { public: - QUECTEL_BC95(events::EventQueue &queue); virtual ~QUECTEL_BC95(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); - virtual CellularPower *open_power(FileHandle *fh); - virtual CellularSIM *open_sim(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularPower *open_power_impl(ATHandler &at); + virtual AT_CellularSIM *open_sim_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index ef86806127..30af0ad939 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -43,16 +43,7 @@ QUECTEL_BG96::~QUECTEL_BG96() { } -CellularNetwork *QUECTEL_BG96::open_network(FileHandle *fh) +AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new QUECTEL_BG96_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new QUECTEL_BG96_CellularNetwork(at); } diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 725b14c2a1..5c1b6b2338 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -24,12 +24,11 @@ namespace mbed { class QUECTEL_BG96 : public AT_CellularDevice { public: - QUECTEL_BG96(events::EventQueue &queue); virtual ~QUECTEL_BG96(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 960757c182..881c561751 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -37,24 +37,12 @@ QUECTEL_UG96::~QUECTEL_UG96() { } -CellularNetwork *QUECTEL_UG96::open_network(FileHandle *fh) +AT_CellularNetwork *QUECTEL_UG96::open_network_impl(ATHandler &at) { - if (!_network) { - _network = new QUECTEL_UG96_CellularNetwork(*get_at_handler(fh)); - } - return _network; + return new QUECTEL_UG96_CellularNetwork(at); } -CellularPower *QUECTEL_UG96::open_power(FileHandle *fh) +AT_CellularPower *QUECTEL_UG96::open_power_impl(ATHandler &at) { - if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = new QUECTEL_UG96_CellularPower(*atHandler); - if (!_power) { - release_at_handler(atHandler); - } - } - } - return _power; + return new QUECTEL_UG96_CellularPower(at); } diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h index 0a130f1e60..06b9cacd0d 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.h @@ -32,13 +32,12 @@ namespace mbed { class QUECTEL_UG96 : public AT_CellularDevice { public: - QUECTEL_UG96(events::EventQueue &queue); virtual ~QUECTEL_UG96(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); - virtual CellularPower *open_power(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularPower *open_power_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index 308a9f9422..8e317b4d69 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -36,32 +36,14 @@ TELIT_HE910::~TELIT_HE910() { } -CellularPower *TELIT_HE910::open_power(FileHandle *fh) +AT_CellularNetwork *TELIT_HE910::open_network_impl(ATHandler &at) { - if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = new TELIT_HE910_CellularPower(*atHandler); - if (!_power) { - release_at_handler(atHandler); - } - } - } - return _power; + return new TELIT_HE910_CellularNetwork(at); } -CellularNetwork *TELIT_HE910::open_network(FileHandle *fh) +AT_CellularPower *TELIT_HE910::open_power_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new TELIT_HE910_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new TELIT_HE910_CellularPower(at); } uint16_t TELIT_HE910::get_send_delay() diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h index 72a71102b9..2830782876 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.h @@ -26,14 +26,15 @@ namespace mbed { class TELIT_HE910 : public AT_CellularDevice { - public: TELIT_HE910(events::EventQueue &queue); virtual ~TELIT_HE910(); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularPower *open_power_impl(ATHandler &at); + public: // from CellularDevice - virtual CellularPower *open_power(FileHandle *fh); - virtual CellularNetwork *open_network(FileHandle *fh); virtual uint16_t get_send_delay(); }; } // namespace mbed diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index c525557050..1064743f54 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -30,30 +30,12 @@ UBLOX_AT::~UBLOX_AT() { } -CellularNetwork *UBLOX_AT::open_network(FileHandle *fh) +AT_CellularNetwork *UBLOX_AT::open_network_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new UBLOX_AT_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new UBLOX_AT_CellularNetwork(at); } -CellularPower *UBLOX_AT::open_power(FileHandle *fh) +AT_CellularPower *UBLOX_AT::open_power_impl(ATHandler &at) { - if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = new UBLOX_AT_CellularPower(*atHandler); - if (!_power) { - release_at_handler(atHandler); - } - } - } - return _power; + return new UBLOX_AT_CellularPower(at); } diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h index 1f47e249fc..2b12557651 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.h @@ -23,16 +23,14 @@ namespace mbed { -class UBLOX_AT : public AT_CellularDevice -{ - +class UBLOX_AT : public AT_CellularDevice { public: UBLOX_AT(events::EventQueue &queue); virtual ~UBLOX_AT(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); - virtual CellularPower *open_power(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularPower *open_power_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 734274edd5..3aa486f752 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -30,30 +30,12 @@ UBLOX_PPP::~UBLOX_PPP() { } -CellularNetwork *UBLOX_PPP::open_network(FileHandle *fh) +AT_CellularNetwork *UBLOX_PPP::open_network_impl(ATHandler &at) { - if (!_network) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _network = new UBLOX_PPP_CellularNetwork(*atHandler); - if (!_network) { - release_at_handler(atHandler); - } - } - } - return _network; + return new UBLOX_PPP_CellularNetwork(at); } -CellularPower *UBLOX_PPP::open_power(FileHandle *fh) +AT_CellularPower *UBLOX_PPP::open_power_impl(ATHandler &at) { - if (!_power) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _power = new UBLOX_PPP_CellularPower(*get_at_handler(fh)); - if (!_power) { - release_at_handler(atHandler); - } - } - } - return _power; + return new UBLOX_PPP_CellularPower(at); } diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h index 4164ba8adb..0241ec8aa4 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.h @@ -23,14 +23,13 @@ namespace mbed { class UBLOX_PPP : public AT_CellularDevice { - public: UBLOX_PPP(events::EventQueue &queue); virtual ~UBLOX_PPP(); -public: // CellularDevice - virtual CellularNetwork *open_network(FileHandle *fh); - virtual CellularPower *open_power(FileHandle *fh); +protected: // AT_CellularDevice + virtual AT_CellularNetwork *open_network_impl(ATHandler &at); + virtual AT_CellularPower *open_power_impl(ATHandler &at); }; MBED_DEPRECATED_SINCE("mbed-os-5.9", "This API will be deprecated, Use UBLOX_PPP instead of UBLOX_LISA_U.")