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 
33 public:
34 
40  typedef enum {
41  ERROR_NONE = 0,
42  ERROR_GENERIC = -1,
43  CONNECTION_ERROR_WANTS_READ = -2,
44  CONNECTION_ERROR_WANTS_WRITE = -3,
45  SSL_PEER_CLOSE_NOTIFY = -4,
46  MEMORY_ALLOCATION_FAILED = -5,
47  SSL_CONNECTION_ERROR = -6,
48  SOCKET_READ_ERROR = -7,
49  SOCKET_SEND_ERROR = -8,
50  SOCKET_ABORT = -9,
51  DNS_RESOLVING_ERROR = -10,
52  SSL_HANDSHAKE_ERROR = -11,
53  FAILED_TO_READ_CREDENTIALS = -12,
55 
56 public:
57 
65 
70 
76  bool bind_connection(const uint16_t listen_port);
77 
88  bool resolve_server_address(const String& server_address,
89  const uint16_t server_port,
91  const M2MSecurity* security);
92 
100  bool send_data(uint8_t *data_ptr,
101  uint16_t data_len,
102  sn_nsdl_addr_s *address_ptr);
103 
109 
113  void stop_listening();
114 
119  void force_close();
120 
125  void handle_connection_error(int error);
126 
134  void set_platform_network_handler(void *handler = NULL);
135 
140  void claim_mutex();
141 
146  void release_mutex();
147 
152 
153 private:
154 
155  M2MConnectionObserver &_observer;
156  M2MConnectionHandlerPimpl *_private_impl;
157 
158 friend class Test_M2MConnectionHandler;
159 friend class Test_M2MConnectionHandler_mbed;
160 friend class Test_M2MConnectionHandler_linux;
161 friend class M2MConnection_TestObserver;
162 };
163 
164 #endif //M2M_CONNECTION_HANDLER_H__
165 
ServerType
Definition: m2mconnectionobserver.h:35
Definition: m2mconnectionhandler.h:32
~M2MConnectionHandler()
Destructor.
void unregister_network_handler()
Unregisters the network interface handler that is set in 'set_platform_network_handler'.
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:114
Definition: m2msecurity.h:31
M2MInterface. This class provides an interface for handling all mbed Client interface operations defi...
Definition: m2mstring.h:33
NetworkStack
An enum defining different kinds of network stacks that can be used by mbed Client.
Definition: m2minterface.h:131
ConnectionError
Definition: m2mconnectionhandler.h:40
Definition: m2mconnectionsecurity.h:36
void force_close()
Closes the open connection.
void stop_listening()
Stops listening to the incoming data.
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:26
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.
bool resolve_server_address(const String &server_address, const uint16_t server_port, M2MConnectionObserver::ServerType server_type, const M2MSecurity *security)
This resolves the server address. The output is returned through a callback.
M2MConnectionObserver. The observer class for passing the socket activity to the state machine...