Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m2mconnectionhandler.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef M2M_CONNECTION_HANDLER_H__ 00017 #define M2M_CONNECTION_HANDLER_H__ 00018 00019 #include "mbed-client/m2mconnectionobserver.h" 00020 #include "mbed-client/m2mconfig.h" 00021 #include "mbed-client/m2minterface.h" 00022 #include "nsdl-c/sn_nsdl.h" 00023 00024 class M2MConnectionSecurity; 00025 class M2MConnectionHandlerPimpl; 00026 00027 /*! \file m2mconnectionhandler.h 00028 * \brief M2MConnectionHandler. 00029 * This class handles the socket connection for the LWM2M Client. 00030 */ 00031 00032 class M2MConnectionHandler { 00033 public: 00034 00035 /** 00036 * @enum ConnectionError 00037 * This enum defines an error that can come from the 00038 * socket read and write operation. 00039 */ 00040 typedef enum { 00041 ERROR_NONE = 0, 00042 ERROR_GENERIC = -1, 00043 CONNECTION_ERROR_WANTS_READ = -2, 00044 CONNECTION_ERROR_WANTS_WRITE = -3, 00045 SSL_PEER_CLOSE_NOTIFY = -4, 00046 MEMORY_ALLOCATION_FAILED = -5, 00047 SSL_CONNECTION_ERROR = -6, 00048 SOCKET_READ_ERROR = -7, 00049 SOCKET_SEND_ERROR = -8, 00050 SOCKET_ABORT = -9, 00051 DNS_RESOLVING_ERROR = -10, 00052 SSL_HANDSHAKE_ERROR = -11, 00053 FAILED_TO_READ_CREDENTIALS = -12, 00054 } ConnectionError; 00055 00056 public: 00057 00058 /** 00059 * \brief Constructor 00060 */ 00061 M2MConnectionHandler(M2MConnectionObserver &observer, 00062 M2MConnectionSecurity* sec, 00063 M2MInterface::BindingMode mode, 00064 M2MInterface::NetworkStack stack); 00065 00066 /** 00067 * \brief Destructor 00068 */ 00069 ~M2MConnectionHandler(); 00070 00071 /** 00072 * \brief This binds the socket connection. 00073 * \param listen_port The port to be listened to for an incoming connection. 00074 * \return True if successful, else false. 00075 */ 00076 bool bind_connection(const uint16_t listen_port); 00077 00078 /** 00079 * \brief This resolves the server address. The output is 00080 * returned through a callback. 00081 * \param String The server address. 00082 * \param uint16_t The server port. 00083 * \param ServerType The server type to be resolved. 00084 * \param security The M2MSecurity object that determines which 00085 * type of secure connection is used by the socket. 00086 * \return True if the address is valid, else false. 00087 */ 00088 bool resolve_server_address(const String& server_address, 00089 const uint16_t server_port, 00090 M2MConnectionObserver::ServerType server_type, 00091 const M2MSecurity* security); 00092 00093 /** 00094 * \brief Sends data to the connected server. 00095 * \param data_ptr The data to be sent. 00096 * \param data_len The length of data to be sent. 00097 * \param address_ptr The address structure to which the data needs to be sent. 00098 * \return True if data is sent successfully, else false. 00099 */ 00100 bool send_data(uint8_t *data_ptr, 00101 uint16_t data_len, 00102 sn_nsdl_addr_s *address_ptr); 00103 00104 /** 00105 * \brief Listens to the incoming data from a remote server. 00106 * \return True if successful, else false. 00107 */ 00108 bool start_listening_for_data(); 00109 00110 /** 00111 * \brief Stops listening to the incoming data. 00112 */ 00113 void stop_listening(); 00114 00115 /** 00116 * \brief Closes the open connection. 00117 * \note This must be called from the same event loop context! 00118 */ 00119 void force_close(); 00120 00121 /** 00122 * \brief Error handling for DTLS connectivity. 00123 * \param error An error code from the TLS library. 00124 */ 00125 void handle_connection_error(int error); 00126 00127 /** 00128 * \brief Sets the network interface handler that is used by the client to connect 00129 * to a network over IP. 00130 * \param handler A network interface handler that is used by the client to connect. 00131 * This API is optional but it provides a mechanism for different platforms to 00132 * manage the usage of underlying network interface by client. 00133 */ 00134 void set_platform_network_handler(void *handler = NULL); 00135 00136 /** 00137 * \brief Claims mutex to prevent thread clashes 00138 * in multithreaded environment. 00139 */ 00140 void claim_mutex(); 00141 00142 /** 00143 * \brief Releases mutex to prevent thread clashes 00144 * in multithreaded environment. 00145 */ 00146 void release_mutex(); 00147 00148 /** 00149 * \brief Unregisters the network interface handler that is set in 'set_platform_network_handler'. 00150 */ 00151 void unregister_network_handler(); 00152 00153 private: 00154 00155 M2MConnectionObserver &_observer; 00156 M2MConnectionHandlerPimpl *_private_impl; 00157 00158 friend class Test_M2MConnectionHandler; 00159 friend class Test_M2MConnectionHandler_mbed; 00160 friend class Test_M2MConnectionHandler_linux; 00161 friend class M2MConnection_TestObserver; 00162 }; 00163 00164 #endif //M2M_CONNECTION_HANDLER_H__ 00165
Generated on Mon Aug 29 2022 19:53:39 by
