Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 353686b

Browse files
authored
Merge branch 'master' into porting-guide-doc
2 parents e21167c + 909f2dc commit 353686b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1107
-524
lines changed

mbed-client/m2mbase.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
#include <stdint.h>
2121
#include "mbed-client/m2mconfig.h"
2222
#include "mbed-client/m2mreportobserver.h"
23+
#include "mbed-client/functionpointer.h"
2324

2425
//FORWARD DECLARATION
2526
struct sn_coap_hdr_;
2627
typedef sn_coap_hdr_ sn_coap_hdr_s;
2728
struct nsdl_s;
2829

30+
typedef FP1<void, const char*> value_updated_callback;
31+
typedef void(*value_updated_callback2) (const char* object_name);
2932
class M2MObservationHandler;
3033
class M2MReportHandler;
3134

@@ -369,6 +372,32 @@ class M2MBase : public M2MReportObserver {
369372
*/
370373
virtual bool is_under_observation() const;
371374

375+
/**
376+
* @brief Sets the function that is executed when this
377+
* object receives a PUT or POST command.
378+
* @param callback The function pointer that is called.
379+
*/
380+
virtual void set_value_updated_function(value_updated_callback callback);
381+
382+
/**
383+
* @brief Sets the function that is executed when this
384+
* object receives a PUT or POST command.
385+
* @param callback The function pointer that is called.
386+
*/
387+
virtual void set_value_updated_function(value_updated_callback2 callback);
388+
389+
/**
390+
* @brief Returns whether callback function is set or not.
391+
* @return True if the callback function is set, else false.
392+
*/
393+
virtual bool is_value_updated_function_set();
394+
395+
/**
396+
* @brief Calls the function that is set in "set_value_updated_function".
397+
* @param name Name of the object.
398+
*/
399+
virtual void execute_value_updated(const String& name);
400+
372401
protected : // from M2MReportObserver
373402

374403
virtual void observation_to_be_sent(m2m::Vector<uint16_t> changed_instance_ids,
@@ -458,6 +487,8 @@ protected : // from M2MReportObserver
458487
bool _observable;
459488
bool _register_uri;
460489
bool _is_under_observation;
490+
value_updated_callback _value_updated_callback;
491+
FP1<void, const char*> *_function_pointer;
461492

462493
friend class Test_M2MBase;
463494

mbed-client/m2mconstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const float REDUCTION_FACTOR = 0.75f;
3636

3737
#define COAP "coap://"
3838
#define COAPS "coaps://"
39+
#define BOOTSTRAP_URI "bs"
3940
// PUT attributes to be checked from server
4041
#define EQUAL "="
4142
#define AMP "&"

mbed-client/m2msecurity.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ friend class M2MNsdlInterface;
211211
private:
212212

213213
M2MResource* get_resource(SecurityResource resource) const;
214+
void clear_resources();
214215

215216
private:
216217

@@ -223,6 +224,7 @@ friend class M2MNsdlInterface;
223224
friend class Test_M2MConnectionHandlerPimpl_linux;
224225
friend class Test_M2MConnectionHandlerPimpl_mbed;
225226
friend class Test_M2MConnectionSecurityPimpl;
227+
friend class Test_M2MNsdlInterface;
226228
};
227229

228230
#endif // M2M_SECURITY_H

mbed-client/m2mtimerobserver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class M2MTimerObserver
3535
PMaxTimer,
3636
Dtls,
3737
QueueSleep,
38-
RetryTimer
38+
RetryTimer,
39+
BootstrapTimer
3940
}Type;
4041

4142
/**

mbed-client/m2mvector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class Vector
138138
void erase(int position) {
139139
if(position < _size) {
140140
_object_template[position] = 0;
141-
for(int k = position; k < _size; k++) {
142-
_object_template[k] = _object_template[k+1];
141+
for(int k = position; k + 1 < _size; k++) {
142+
_object_template[k] = _object_template[k + 1];
143143
}
144144
_size--;
145145
}

module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mbed-client",
3-
"version": "1.12.5",
3+
"version": "1.13.1",
44
"description": "mbed Client C++ API",
55
"keywords": [],
66
"author": "Yogesh Pande <[email protected]>",

run_unit_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ mkdir results
2929
mkdir coverage
3030

3131
find ./build -name '*.xml' | xargs cp -t ./results/
32-
find ./build -name '*.gcno' | xargs cp -t ./coverage/
33-
find ./build -name '*.gcda' | xargs cp -t ./coverage/
32+
find ./build/x86-linux-native-coverage/test -name '*.gcno' | xargs cp -t ./coverage/
33+
find ./build/x86-linux-native-coverage/test -name '*.gcda' | xargs cp -t ./coverage/
3434
touch coverage/*.gcda
3535
exclude_files="${PWD}/test/"
3636
gcovr -r ./ --gcov-filter='.*source*.' --exclude-unreachable-branches --exclude $exclude_files --object-directory ./coverage -x -o ./results/gcovr.xml

source/include/m2minterfaceimpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ friend class M2MInterfaceFactory;
382382
const int _max_states;
383383
bool _event_generated;
384384
EventData *_event_data;
385-
386-
String _endpoint_name;
387385
String _endpoint_type;
388386
String _domain;
389387
int32_t _life_time;
@@ -398,6 +396,7 @@ friend class M2MInterfaceFactory;
398396
bool _update_register_ongoing;
399397
M2MTimer *_queue_sleep_timer;
400398
M2MTimer *_retry_timer;
399+
M2MTimer *_bootstrap_timer;
401400
callback_handler _callback_handler;
402401
M2MSecurity *_security;
403402
uint8_t _retry_count;

source/include/m2mnsdlinterface.h

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class M2MNsdlInterface : public M2MTimerObserver,
102102
* @param address Bootstrap address.
103103
* @return true if created and sent successfully else false.
104104
*/
105-
bool create_bootstrap_resource(sn_nsdl_addr_s *address);
105+
bool create_bootstrap_resource(sn_nsdl_addr_s *address, const String &bootstrap_endpoint_name);
106106

107107
/**
108108
* @brief Sends the register message to the server.
@@ -182,12 +182,6 @@ class M2MNsdlInterface : public M2MTimerObserver,
182182
sn_nsdl_addr_s *address,
183183
sn_nsdl_capab_e nsdl_capab);
184184

185-
/**
186-
* @brief Callback when the bootstrap information is received from bootstrap server.
187-
* @param server_info, Server information received from bootstrap server.
188-
*/
189-
void bootstrap_done_callback(sn_nsdl_oma_server_info_t *server_info);
190-
191185
/**
192186
* @brief Callback when there is data received from server and needs to be processed.
193187
* @param data, data received from server.
@@ -210,6 +204,12 @@ class M2MNsdlInterface : public M2MTimerObserver,
210204
*/
211205
nsdl_s* get_nsdl_handle();
212206

207+
/**
208+
* @brief Get endpoint name
209+
* @return endpoint name
210+
*/
211+
const String& endpoint_name() const;
212+
213213
protected: // from M2MTimerObserver
214214

215215
virtual void timer_expired(M2MTimerObserver::Type type);
@@ -298,41 +298,82 @@ class M2MNsdlInterface : public M2MTimerObserver,
298298
const String &uri_path);
299299

300300
/**
301-
* \brief Allocate (size + 1) amount of memory, copy size bytes into
301+
* @brief Allocate (size + 1) amount of memory, copy size bytes into
302302
* it and add zero termination.
303-
* \param source Source string to copy, may not be NULL.
304-
* \param size The size of memory to be reserved.
303+
* @param source Source string to copy, may not be NULL.
304+
* @param size The size of memory to be reserved.
305305
*/
306306
uint8_t* alloc_string_copy(const uint8_t* source, uint16_t size);
307307

308308
/**
309-
* \brief Utility method to convert given lifetime int to ascii
309+
* @brief Utility method to convert given lifetime int to ascii
310310
* and allocate a buffer for it and set it to _endpoint->lifetime_ptr.
311-
* \param lifetime A new value for lifetime.
311+
* @param lifetime A new value for lifetime.
312312
*/
313313
void set_endpoint_lifetime_buffer(int lifetime);
314314

315+
/**
316+
* @brief Handle incoming bootstrap PUT message.
317+
* @param coap_header, Received CoAP message
318+
* @param address, Server address
319+
*/
320+
void handle_bootstrap_put_message(sn_coap_hdr_s *coap_header, sn_nsdl_addr_s *address);
321+
322+
/**
323+
* @brief Handle bootstrap finished message.
324+
* @param coap_header, Received CoAP message
325+
* @param address, Server address
326+
*/
327+
void handle_bootstrap_finished(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address);
328+
329+
/**
330+
* @brief Handle bootstrap delete message.
331+
* @param coap_header, Received CoAP message
332+
* @param address, Server address
333+
*/
334+
void handle_bootstrap_delete(sn_coap_hdr_s *coap_header,sn_nsdl_addr_s *address);
335+
336+
/**
337+
* @brief Parse bootstrap TLV message.
338+
* @param coap_header, Received CoAP message
339+
* @return True if parsing was succesful else false
340+
*/
341+
bool parse_bootstrap_message(sn_coap_hdr_s *coap_header, bool is_security_object);
342+
343+
/**
344+
* @brief Parse bootstrap TLV message.
345+
* @param coap_header, Received CoAP message
346+
* @return True if parsing was succesful else false
347+
*/
348+
bool validate_security_object();
349+
350+
/**
351+
* @brief Handle bootstrap errors.
352+
*/
353+
void handle_bootstrap_error();
354+
315355
private:
316356

317357
M2MNsdlObserver &_observer;
318358
M2MObjectList _object_list;
319-
M2MServer *_server;
359+
M2MServer *_server; // Not owned
360+
M2MSecurity *_security; // Not owned
320361
M2MTimer *_nsdl_exceution_timer;
321362
M2MTimer *_registration_timer;
322363
sn_nsdl_ep_parameters_s *_endpoint;
323364
sn_nsdl_resource_info_s *_resource;
324-
sn_nsdl_bs_ep_info_t _bootstrap_endpoint;
325-
sn_nsdl_oma_device_t _bootstrap_device_setup;
326365
sn_nsdl_addr_s _sn_nsdl_address;
327366
nsdl_s *_nsdl_handle;
328367
uint32_t _counter_for_nsdl;
329368
uint16_t _bootstrap_id;
330369
bool _register_ongoing;
331370
bool _unregister_ongoing;
332371
bool _update_register_ongoing;
372+
String _endpoint_name;
333373

334374
friend class Test_M2MNsdlInterface;
335375

336376
};
337377

338378
#endif // M2MNSDLINTERFACE_H
379+

source/include/nsdlaccesshelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle,
4040
uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle,
4141
sn_coap_hdr_s *coap_header,
4242
sn_nsdl_addr_s *address_ptr);
43-
void __nsdl_c_bootstrap_done(sn_nsdl_oma_server_info_t *server_info_ptr, struct nsdl_s * nsdl_handle);
43+
4444
void *__socket_malloc( void * context, size_t size);
4545
void __socket_free(void * context, void * ptr);
4646

source/m2mbase.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ M2MBase::M2MBase(const M2MBase& other) :
8181
_observation_level(other._observation_level),
8282
_observable(other._observable),
8383
_register_uri(other._register_uri),
84-
_is_under_observation(other._is_under_observation)
84+
_is_under_observation(other._is_under_observation),
85+
_function_pointer(NULL)
8586
{
8687

8788
if(other._token) {
@@ -105,12 +106,13 @@ M2MBase::M2MBase(const String & resource_name,
105106
_token(NULL),
106107
_token_length(0),
107108
_coap_content_type(0),
108-
_operation(M2MBase::NOT_ALLOWED),
109+
_operation(M2MBase::NOT_ALLOWED),
109110
_mode(mde),
110111
_observation_level(M2MBase::None),
111112
_observable(false),
112113
_register_uri(true),
113-
_is_under_observation(false)
114+
_is_under_observation(false),
115+
_function_pointer(NULL)
114116
{
115117
if(is_integer(_name) && _name.size() <= MAX_ALLOWED_STRING_LENGTH) {
116118
_name_id = strtoul(_name.c_str(), NULL, 10);
@@ -126,6 +128,7 @@ M2MBase::~M2MBase()
126128
{
127129
delete _report_handler;
128130
free(_token);
131+
delete _function_pointer;
129132
}
130133

131134
void M2MBase::set_operation(M2MBase::Operation opr)
@@ -450,3 +453,27 @@ bool M2MBase::is_under_observation() const
450453
{
451454
return _is_under_observation;
452455
}
456+
457+
void M2MBase::set_value_updated_function(value_updated_callback callback)
458+
{
459+
_value_updated_callback = callback;
460+
}
461+
462+
void M2MBase::set_value_updated_function(value_updated_callback2 callback)
463+
{
464+
delete _function_pointer;
465+
_function_pointer = new FP1<void, const char*>(callback);
466+
set_value_updated_function(value_updated_callback(_function_pointer,
467+
&FP1<void, const char*>::call));
468+
}
469+
bool M2MBase::is_value_updated_function_set()
470+
{
471+
return (_value_updated_callback) ? true : false;
472+
}
473+
474+
void M2MBase::execute_value_updated(const String& name)
475+
{
476+
if(_value_updated_callback) {
477+
_value_updated_callback(name.c_str());
478+
}
479+
}

0 commit comments

Comments
 (0)