sandbox / mbed-client

Fork of mbed-client by Christopher Haster

Revision:
4:ae5178938864
Parent:
1:79b6cc67d8b4
--- a/source/m2mbase.cpp	Fri Feb 19 17:44:50 2016 +0000
+++ b/source/m2mbase.cpp	Sat Apr 02 00:31:13 2016 +0300
@@ -19,10 +19,12 @@
 #include "mbed-client/m2mtimer.h"
 #include "include/m2mreporthandler.h"
 #include "include/nsdllinker.h"
-#include "ns_trace.h"
+#include "mbed-trace/mbed_trace.h"
 #include <ctype.h>
 #include <string.h>
 
+#define TRACE_GROUP "mClt"
+
 M2MBase& M2MBase::operator=(const M2MBase& other)
 {
     if (this != &other) { // protect against invalid self-assignment
@@ -37,7 +39,9 @@
         _observation_number = other._observation_number;
         _observation_level = other._observation_level;
         _observation_handler = other._observation_handler;
-
+        _register_uri = other._register_uri;
+        _uri_path = other._uri_path;
+        _max_age = other._max_age;
         if(_token) {
             free(_token);
             _token = NULL;
@@ -79,7 +83,9 @@
     _observation_handler = other._observation_handler;
     _observation_number = other._observation_number;
     _observation_level = other._observation_level;
-
+    _register_uri = other._register_uri;
+    _uri_path = other._uri_path;
+    _max_age = other._max_age;
     _token_length = other._token_length;
     if(other._token) {
         _token = (uint8_t *)malloc(other._token_length+1);
@@ -107,7 +113,10 @@
   _observable(false),
   _observation_number(0),
   _token(NULL),
-  _token_length(0)
+  _token_length(0),
+  _register_uri(true),
+  _uri_path(""),
+  _max_age(0)
 {
     if(is_integer(_name) && _name.size() <= MAX_ALLOWED_STRING_LENGTH) {
         _name_id = strtoul(_name.c_str(), NULL, 10);
@@ -160,17 +169,17 @@
 
 void M2MBase::set_observable(bool observable)
 {
-   _observable = observable;
+    _observable = observable;
 }
 
-void M2MBase::add_observation_level(M2MBase::Observation observation_level)
+void M2MBase::add_observation_level(M2MBase::Observation obs_level)
 {
-    _observation_level = (M2MBase::Observation)(_observation_level | observation_level);
+    _observation_level = (M2MBase::Observation)(_observation_level | obs_level);
 }
 
-void M2MBase::remove_observation_level(M2MBase::Observation observation_level)
+void M2MBase::remove_observation_level(M2MBase::Observation obs_level)
 {
-    _observation_level = (M2MBase::Observation)(_observation_level ^ observation_level);
+    _observation_level = (M2MBase::Observation)(_observation_level ^ obs_level);
 }
 
 void M2MBase::set_under_observation(bool observed,
@@ -178,7 +187,7 @@
 {
 
     tr_debug("M2MBase::set_under_observation - observed: %d", observed);
-    tr_debug("M2MBase::set_under_observation - _base_type: %d", _base_type);
+    tr_debug("M2MBase::set_under_observation - base_type: %d", _base_type);
     _observation_handler = handler;
     if(handler) {
         if (_base_type != M2MBase::ResourceInstance) {
@@ -218,9 +227,14 @@
     _instance_id = inst_id;
 }
 
-void M2MBase::set_observation_number(const uint16_t observation_number)
+
+void M2MBase::set_observation_number(const uint16_t /*observation_number*/)
 {
-    _observation_number = observation_number;
+}
+
+void M2MBase::set_max_age(const uint32_t max_age)
+{
+    _max_age = max_age;
 }
 
 M2MBase::BaseType M2MBase::base_type() const
@@ -298,6 +312,11 @@
     return _observation_number;
 }
 
+uint32_t M2MBase::max_age() const
+{
+    return _max_age;
+}
+
 bool M2MBase::handle_observation_attribute(char *&query)
 {
     tr_debug("M2MBase::handle_observation_attribute");
@@ -315,11 +334,15 @@
     return success;
 }
 
-void M2MBase::observation_to_be_sent()
+void M2MBase::observation_to_be_sent(m2m::Vector<uint16_t> changed_instance_ids, bool send_object)
 {
     //TODO: Move this to M2MResourceInstance
-    if(_observation_handler) {
-       _observation_handler->observation_to_be_sent(this);
+    if(_observation_handler) {        
+       _observation_number++;
+       _observation_handler->observation_to_be_sent(this,
+                                                    _observation_number,
+                                                    changed_instance_ids,
+                                                    send_object);
     }
 }
 
@@ -352,7 +375,8 @@
 
 sn_coap_hdr_s* M2MBase::handle_put_request(nsdl_s */*nsdl*/,
                                            sn_coap_hdr_s */*received_coap_header*/,
-                                           M2MObservationHandler */*observation_handler*/)
+                                           M2MObservationHandler */*observation_handler*/,
+                                           bool &)
 {
     //Handled in M2MResource, M2MObjectInstance and M2MObject classes
     return NULL;
@@ -360,7 +384,8 @@
 
 sn_coap_hdr_s* M2MBase::handle_post_request(nsdl_s */*nsdl*/,
                                             sn_coap_hdr_s */*received_coap_header*/,
-                                            M2MObservationHandler */*observation_handler*/)
+                                            M2MObservationHandler */*observation_handler*/,
+                                            bool &)
 {
     //Handled in M2MResource, M2MObjectInstance and M2MObject classes
     return NULL;
@@ -390,6 +415,16 @@
     return _observation_handler;
 }
 
+void M2MBase::set_register_uri( bool register_uri)
+{
+    _register_uri = register_uri;
+}
+
+bool M2MBase::register_uri()
+{
+    return _register_uri;
+}
+
 bool M2MBase::is_integer(const String &value)
 {
     const char *s = value.c_str();
@@ -400,3 +435,14 @@
     strtol(value.c_str(), &p, 10);
     return (*p == 0);
 }
+
+void M2MBase::set_uri_path(const String &path)
+{
+    _uri_path = path;
+}
+
+
+const String& M2MBase::uri_path() const
+{
+    return _uri_path;
+}