Mistake on this page? Email us
m2mconnectionhandler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef M2M_CONNECTION_HANDLER_H__
17 #define M2M_CONNECTION_HANDLER_H__
18 
20 #include "mbed-client/m2mconfig.h"
22 #include "nsdl-c/sn_nsdl.h"
23 
25 class M2MConnectionHandlerPimpl;
26 
31 public:
32 
38  typedef enum {
39  ERROR_NONE = 0,
40  ERROR_GENERIC = -1,
41  CONNECTION_ERROR_WANTS_READ = -2,
42  CONNECTION_ERROR_WANTS_WRITE = -3,
43  SSL_PEER_CLOSE_NOTIFY = -4,
44  MEMORY_ALLOCATION_FAILED = -5,
45  SSL_CONNECTION_ERROR = -6,
46  SOCKET_READ_ERROR = -7,
47  SOCKET_SEND_ERROR = -8,
48  SOCKET_ABORT = -9,
49  DNS_RESOLVING_ERROR = -10,
50  SSL_HANDSHAKE_ERROR = -11,
51  FAILED_TO_READ_CREDENTIALS = -12,
52  SOCKET_TIMEOUT = -13,
54 
60  typedef enum {
61  DEFAULT_PRIORITY = 0,
62  HIGH_PRIORITY = 10,
63  ALERT_PRIORITY = 46
65 
66 public:
67 
75 
80 
86  bool bind_connection(const uint16_t listen_port);
87 
99  bool resolve_server_address(const String &server_address,
100  const uint16_t server_port,
102  const M2MSecurity *security,
103  bool is_server_ping = false);
104 
112  bool send_data(uint8_t *data_ptr,
113  uint16_t data_len,
114  sn_nsdl_addr_s *address_ptr);
115 
121 
125  void stop_listening();
126 
131  void force_close();
132 
137  void handle_connection_error(int error);
138 
146  void set_platform_network_handler(void *handler = NULL);
147 
152  void claim_mutex();
153 
158  void release_mutex();
159 
164 
170 
174  void store_cid();
175 
179  void remove_cid();
180 
185  bool is_cid_available();
186 
192  void set_cid_value(const uint8_t *data_ptr, const size_t data_len);
193 
194 private:
195 
196  M2MConnectionObserver &_observer;
197  M2MConnectionHandlerPimpl *_private_impl;
198 
199  friend class Test_M2MConnectionHandler;
200  friend class Test_M2MConnectionHandler_mbed;
201  friend class Test_M2MConnectionHandler_linux;
202  friend class M2MConnection_TestObserver;
203 };
204 
205 #endif //M2M_CONNECTION_HANDLER_H__
206 
ServerType
Definition: m2mconnectionobserver.h:33
Definition: m2mconnectionhandler.h:30
~M2MConnectionHandler()
Destructor.
void unregister_network_handler()
Unregisters the network interface handler that is set in 'set_platform_network_handler'.
void store_cid()
Stores CID persistently for DTLS connections.
bool resolve_server_address(const String &server_address, const uint16_t server_port, M2MConnectionObserver::ServerType server_type, const M2MSecurity *security, bool is_server_ping=false)
This resolves the server address. The output is returned through a callback.
bool start_listening_for_data()
Listens to the incoming data from a remote server.
void release_mutex()
Releases mutex to prevent thread clashes in multithreaded environment.
void set_cid_value(const uint8_t *data_ptr, const size_t data_len)
Internal test function. Set CID for current tls session.
BindingMode
An enum defining different kinds of binding modes handled for client operations.
Definition: m2minterface.h:121
Definition: m2msecurity.h:31
header for M2MInterface
NetworkStack
An enum defining different kinds of network stacks that can be used by mbed Client.
Definition: m2minterface.h:138
ConnectionError
Definition: m2mconnectionhandler.h:38
Definition: m2mconnectionsecurity.h:36
void remove_cid()
Removes CID for DTLS connections.
SocketPriority
Definition: m2mconnectionhandler.h:60
void force_close()
Closes the open connection.
void stop_listening()
Stops listening to the incoming data.
bool is_cid_available()
Status of CID availability in client.
bool bind_connection(const uint16_t listen_port)
This binds the socket connection.
void claim_mutex()
Claims mutex to prevent thread clashes in multithreaded environment.
bool set_socket_priority(M2MConnectionHandler::SocketPriority priority)
Set socket priority.
File defining all system build time configuration used by mbed-client.
bool send_data(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr)
Sends data to the connected server.
void handle_connection_error(int error)
Error handling for DTLS connectivity.
Definition: m2mconnectionobserver.h:24
void set_platform_network_handler(void *handler=NULL)
Sets the network interface handler that is used by the client to connect to a network over IP...
M2MConnectionHandler(M2MConnectionObserver &observer, M2MConnectionSecurity *sec, M2MInterface::BindingMode mode, M2MInterface::NetworkStack stack)
Constructor.
header for M2MConnectionObserver.