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 
55 public:
56 
64 
69 
75  bool bind_connection(const uint16_t listen_port);
76 
88  bool resolve_server_address(const String& server_address,
89  const uint16_t server_port,
91  const M2MSecurity* security,
92  bool is_server_ping = false);
93 
101  bool send_data(uint8_t *data_ptr,
102  uint16_t data_len,
103  sn_nsdl_addr_s *address_ptr);
104 
110 
114  void stop_listening();
115 
120  void force_close();
121 
126  void handle_connection_error(int error);
127 
135  void set_platform_network_handler(void *handler = NULL);
136 
141  void claim_mutex();
142 
147  void release_mutex();
148 
153 
157  void store_cid();
158 
162  void remove_cid();
163 
168  bool is_cid_available();
169 
170 
171 
172 private:
173 
174  M2MConnectionObserver &_observer;
175  M2MConnectionHandlerPimpl *_private_impl;
176 
177 friend class Test_M2MConnectionHandler;
178 friend class Test_M2MConnectionHandler_mbed;
179 friend class Test_M2MConnectionHandler_linux;
180 friend class M2MConnection_TestObserver;
181 };
182 
183 #endif //M2M_CONNECTION_HANDLER_H__
184 
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.
BindingMode
An enum defining different kinds of binding modes handled for client operations.
Definition: m2minterface.h:119
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:136
ConnectionError
Definition: m2mconnectionhandler.h:38
Definition: m2mconnectionsecurity.h:36
void remove_cid()
Removes CID for DTLS connections.
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. return true if CID is available else false. ...
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.
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.