Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
m2mreporthandler.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef M2MREPORTHANDLER_H 00017 #define M2MREPORTHANDLER_H 00018 00019 // Support for std args 00020 #include <stdint.h> 00021 #include "mbed-client/m2mconfig.h" 00022 #include "mbed-client/m2mbase.h" 00023 #include "mbed-client/m2mtimerobserver.h" 00024 #include "mbed-client/m2mresourceinstance.h" 00025 #include "mbed-client/m2mvector.h" 00026 #include "mbed-client/m2mtimer.h" 00027 00028 //FORWARD DECLARATION 00029 class M2MReportObserver; 00030 class M2MTimer; 00031 class M2MResourceInstance; 00032 00033 /** 00034 * @brief M2MReportHandler. 00035 * This class is handles all the observation related operations. 00036 */ 00037 class M2MReportHandler: public M2MTimerObserver 00038 { 00039 private: 00040 // Prevents the use of assignment operator by accident. 00041 M2MReportHandler& operator=( const M2MReportHandler& /*other*/ ); 00042 00043 public: 00044 00045 M2MReportHandler(M2MReportObserver &observer); 00046 00047 public: 00048 00049 /** 00050 * Enum defining which write attributes are set. 00051 */ 00052 enum { 00053 Cancel = 1, 00054 Pmin = 2, 00055 Pmax = 4, 00056 Lt = 8, 00057 Gt = 16, 00058 St = 32 00059 }; 00060 00061 /** 00062 * Destructor 00063 */ 00064 virtual ~M2MReportHandler(); 00065 00066 /** 00067 * @brief Sets that object is under observation. 00068 * @param Value for the observation. 00069 * @param handler, Handler object for sending 00070 * observation callbacks. 00071 */ 00072 void set_under_observation(bool observed); 00073 00074 /** 00075 * @brief Sets the value of the given resource. 00076 * @param value, Value of the observed resource. 00077 */ 00078 void set_value(float value); 00079 00080 /** 00081 * @brief Sets notification trigger. 00082 * @param obj_instance_id, Object instance id that has changed 00083 */ 00084 void set_notification_trigger(uint16_t obj_instance_id = 0); 00085 00086 /** 00087 * @brief Parses the received query for notification 00088 * attribute. 00089 * @param query Query to be parsed for attributes. 00090 * @param type Type of the Base Object. 00091 * @param resource_type Type of the Resource. 00092 * @return true if required attributes are present else false. 00093 */ 00094 bool parse_notification_attribute(const char *query, 00095 M2MBase::BaseType type, 00096 M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE); 00097 00098 /** 00099 * @brief Set back to default values. 00100 */ 00101 void set_default_values(); 00102 00103 /** 00104 * @brief Return write attribute flags. 00105 */ 00106 uint8_t attribute_flags() const; 00107 00108 /** 00109 * \brief Sets the observation token value. 00110 * \param token A pointer to the token of the resource. 00111 * \param length The length of the token pointer. 00112 */ 00113 void set_observation_token(const uint8_t *token, const uint8_t length); 00114 00115 /** 00116 * \brief Provides a copy of the observation token of the object. 00117 * \param value[OUT] A pointer to the value of the token. 00118 * \param value_length[OUT] The length of the token pointer. 00119 */ 00120 void get_observation_token(uint8_t *token, uint8_t &token_length) const; 00121 00122 /** 00123 * \brief Returns the observation number. 00124 * \return The observation number of the object. 00125 */ 00126 uint16_t observation_number() const; 00127 00128 /** 00129 * \brief Adds the observation level for the object. 00130 * \param observation_level The level of observation. 00131 */ 00132 void add_observation_level(M2MBase::Observation obs_level); 00133 00134 /** 00135 * \brief Removes the observation level for the object. 00136 * \param observation_level The level of observation. 00137 */ 00138 void remove_observation_level(M2MBase::Observation obs_level); 00139 00140 /** 00141 * \brief Returns the observation level of the object. 00142 * \return The observation level of the object. 00143 */ 00144 M2MBase::Observation observation_level() const; 00145 00146 /** 00147 * @brief Returns whether this resource is under observation or not. 00148 * @return True if the resource is under observation, else false, 00149 */ 00150 bool is_under_observation() const; 00151 00152 /** 00153 * @brief Schedule a report, if the pmin is exceeded 00154 * report immediately, otherwise store the state to be 00155 * reported once the time fires. 00156 * 00157 * @param in_queue If the message is queued message then it must be send even if 00158 * current and last values are the same. 00159 */ 00160 void schedule_report(bool in_queue = false); 00161 00162 /** 00163 * @brief Set flag that new notification needs to be send. 00164 * 00165 * @param to_queue If True then notification is marked to be send 00166 */ 00167 void set_notification_in_queue(bool to_queue); 00168 00169 /** 00170 * @brief Returns whether notification needs to be send or not. 00171 * 00172 * @return Is notification sending needed or not. 00173 */ 00174 bool notification_in_queue() const; 00175 00176 /** 00177 * @brief Set flag that new notification needs to be send. 00178 * 00179 * @param to_queue If True then notification is marked to be send 00180 */ 00181 void set_notification_send_in_progress(bool progress); 00182 00183 /** 00184 * @brief Returns whether notification send is in progress or not. 00185 * 00186 * @return Is notification sending ongoing or not. 00187 */ 00188 bool notification_send_in_progress() const; 00189 00190 /** 00191 * @brief Sets whether notification will be sent using blockwise or not. 00192 * 00193 * @param blockwise_notify If True then notification is sent using blockwise. 00194 */ 00195 void set_blockwise_notify(bool blockwise_notify); 00196 00197 /** 00198 * @brief Returns whether notification is sent using blockwise or not. 00199 * 00200 * @return Is notification sent using blockwise. 00201 */ 00202 bool blockwise_notify() const; 00203 00204 protected : // from M2MTimerObserver 00205 00206 virtual void timer_expired(M2MTimerObserver::Type type = 00207 M2MTimerObserver::Notdefined); 00208 00209 private: 00210 00211 bool set_notification_attribute(const char* option, 00212 M2MBase::BaseType type, 00213 M2MResourceInstance::ResourceType resource_type); 00214 00215 /** 00216 * @brief Reports a sample that satisfies the reporting criteria. 00217 * 00218 * @param in_queue If the message is queued message then it must be send even 00219 * current and last values are the same. 00220 */ 00221 void report(bool in_queue = false); 00222 00223 /** 00224 * @brief Manage timers for pmin and pmax. 00225 */ 00226 void handle_timers(); 00227 00228 /** 00229 * @brief Check whether notification params can be accepted. 00230 */ 00231 bool check_attribute_validity() const; 00232 00233 /** 00234 * @brief Stop pmin & pmax timers. 00235 */ 00236 void stop_timers(); 00237 00238 /** 00239 * @brief Check if current value match threshold values. 00240 * @return True if notify can be send otherwise false. 00241 */ 00242 bool check_threshold_values() const; 00243 00244 /** 00245 * @brief Check whether current value matches with GT & LT. 00246 * @return True if current value match with GT or LT values. 00247 */ 00248 bool check_gt_lt_params() const; 00249 00250 /** 00251 * \brief Allocate (size + 1) amount of memory, copy size bytes into 00252 * it and add zero termination. 00253 * \param source The source string to copy, may not be NULL. 00254 * \param size The size of memory to be reserved. 00255 */ 00256 static uint8_t* alloc_string_copy(const uint8_t* source, uint32_t size); 00257 00258 private: 00259 M2MReportObserver &_observer; 00260 bool _is_under_observation : 1; 00261 M2MBase::Observation _observation_level : 4; 00262 uint8_t _attribute_state; 00263 unsigned _token_length : 8; 00264 bool _notify : 1; 00265 bool _pmin_exceeded : 1; 00266 bool _pmax_exceeded : 1; 00267 unsigned _observation_number : 24; 00268 M2MTimer _pmin_timer; 00269 M2MTimer _pmax_timer; 00270 uint8_t *_token; 00271 int32_t _pmax; 00272 int32_t _pmin; 00273 float _current_value; 00274 float _gt; 00275 float _lt; 00276 float _st; 00277 float _high_step; 00278 float _low_step; 00279 float _last_value; 00280 m2m::Vector<uint16_t> _changed_instance_ids; 00281 bool _notification_send_in_progress : 1; 00282 bool _notification_in_queue : 1; 00283 bool _blockwise_notify : 1; 00284 bool _pmin_quiet_period : 1; 00285 00286 friend class Test_M2MReportHandler; 00287 00288 }; 00289 00290 #endif // M2MREPORTHANDLER_H
Generated on Tue Jul 12 2022 16:24:15 by
1.7.2