@@ -528,24 +528,17 @@ sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *nsdl,
528
528
// process the POST if we have registered a callback for it
529
529
if (received_coap_header) {
530
530
if ((operation () & SN_GRS_POST_ALLOWED) != 0 ) {
531
- M2MResource::M2MExecuteParameter *exec_params = new M2MResource::M2MExecuteParameter ();
532
- if (exec_params) {
533
- exec_params->_object_name = object_name ();
534
- exec_params->_resource_name = name ();
535
- exec_params->_object_instance_id = object_instance_id ();
536
- }
531
+ M2MResource::M2MExecuteParameter exec_params (object_name (), name (), object_instance_id ());
532
+
537
533
uint16_t coap_content_type = 0 ;
538
534
if (received_coap_header->payload_ptr ) {
539
535
if (received_coap_header->content_format != COAP_CT_NONE) {
540
536
coap_content_type = received_coap_header->content_format ;
541
537
}
542
538
if (coap_content_type == 0 ) {
543
- if (exec_params){
544
- exec_params->_value = alloc_string_copy (received_coap_header->payload_ptr ,
545
- received_coap_header->payload_len );
546
- if (exec_params->_value ) {
547
- exec_params->_value_length = received_coap_header->payload_len ;
548
- }
539
+ exec_params._value = received_coap_header->payload_ptr ;
540
+ if (exec_params._value ) {
541
+ exec_params._value_length = received_coap_header->payload_len ;
549
542
}
550
543
} else {
551
544
msg_code = COAP_MSG_CODE_RESPONSE_UNSUPPORTED_CONTENT_FORMAT;
@@ -578,9 +571,9 @@ sn_coap_hdr_s* M2MResource::handle_post_request(nsdl_s *nsdl,
578
571
#ifndef DISABLE_DELAYED_RESPONSE
579
572
}
580
573
#endif
581
- execute (exec_params);
574
+ execute (& exec_params);
582
575
}
583
- delete exec_params;
576
+
584
577
} else { // if ((object->operation() & SN_GRS_POST_ALLOWED) != 0)
585
578
tr_error (" M2MResource::handle_post_request - COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED" );
586
579
msg_code = COAP_MSG_CODE_RESPONSE_METHOD_NOT_ALLOWED; // 4.05
@@ -619,21 +612,32 @@ const char* M2MResource::object_name() const
619
612
return parent_object.name ();
620
613
}
621
614
622
- M2MResource::M2MExecuteParameter::M2MExecuteParameter ()
615
+ #ifdef MEMORY_OPTIMIZED_API
616
+ M2MResource::M2MExecuteParameter::M2MExecuteParameter (const char *object_name, const char *resource_name,
617
+ uint16_t object_instance_id) :
618
+ _object_name (object_name),
619
+ _resource_name (resource_name),
620
+ _value (NULL ),
621
+ _value_length (0 ),
622
+ _object_instance_id (object_instance_id)
623
623
{
624
- _value = NULL ;
625
- _value_length = 0 ;
626
- _object_name = " " ;
627
- _resource_name = " " ;
628
- _object_instance_id = 0 ;
629
624
}
630
-
631
- M2MResource::M2MExecuteParameter::~M2MExecuteParameter ()
625
+ #else
626
+ M2MResource::M2MExecuteParameter::M2MExecuteParameter (const String &object_name, const String &resource_name,
627
+ uint16_t object_instance_id) :
628
+ _object_name (object_name),
629
+ _resource_name (resource_name),
630
+ _value (NULL ),
631
+ _value_length (0 ),
632
+ _object_instance_id (object_instance_id)
632
633
{
633
- free (_value);
634
634
}
635
+ #endif
635
636
636
- uint8_t *M2MResource::M2MExecuteParameter::get_argument_value () const
637
+ // These could be actually changed to be inline ones, as it would likely generate
638
+ // smaller code at application side.
639
+
640
+ const uint8_t *M2MResource::M2MExecuteParameter::get_argument_value () const
637
641
{
638
642
return _value;
639
643
}
@@ -643,6 +647,17 @@ uint16_t M2MResource::M2MExecuteParameter::get_argument_value_length() const
643
647
return _value_length;
644
648
}
645
649
650
+ #ifdef MEMORY_OPTIMIZED_API
651
+ const char * M2MResource::M2MExecuteParameter::get_argument_object_name () const
652
+ {
653
+ return _object_name;
654
+ }
655
+
656
+ const char * M2MResource::M2MExecuteParameter::get_argument_resource_name () const
657
+ {
658
+ return _resource_name;
659
+ }
660
+ #else
646
661
const String& M2MResource::M2MExecuteParameter::get_argument_object_name () const
647
662
{
648
663
return _object_name;
@@ -652,6 +667,7 @@ const String& M2MResource::M2MExecuteParameter::get_argument_resource_name() con
652
667
{
653
668
return _resource_name;
654
669
}
670
+ #endif
655
671
656
672
uint16_t M2MResource::M2MExecuteParameter::get_argument_object_instance_id () const
657
673
{
0 commit comments