Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
m2mblockmessage.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 M2MBLOCKMESSAGE_H 00017 #define M2MBLOCKMESSAGE_H 00018 00019 #include "ns_types.h" 00020 #include "sn_coap_header.h" 00021 00022 /*! \file m2mblockmessage.h 00023 * \brief M2MBlockMessage. 00024 * This class contains the data of an incoming block message. 00025 */ 00026 class M2MBlockMessage { 00027 00028 public: 00029 00030 /** 00031 * \brief An enum defining different kinds of errors 00032 * that can occur during the block-wise operation. 00033 */ 00034 typedef enum { 00035 ErrorNone = 0, 00036 EntityTooLarge 00037 }Error; 00038 00039 /** 00040 * Constructor. 00041 */ 00042 M2MBlockMessage(); 00043 00044 /** 00045 * Destructor. 00046 */ 00047 virtual ~M2MBlockMessage(); 00048 00049 /** 00050 * \brief Store the data from a CoAP message. 00051 * \param coap_header The message to parse. 00052 */ 00053 void set_message_info(sn_coap_hdr_s *coap_header); 00054 00055 /** 00056 * \brief Clear values. 00057 */ 00058 void clear_values(); 00059 00060 /** 00061 * \brief Check if the message is a block message. 00062 * \param coap_header The message to check. 00063 * \return True if block message, else false. 00064 */ 00065 bool is_block_message() const; 00066 00067 /** 00068 * \brief Returns the number of an incoming block. 00069 * \return Block number, starting from 0. 00070 */ 00071 uint16_t block_number() const; 00072 00073 /** 00074 * \brief Returns the total size of the message. 00075 * \return The total size in bytes. 00076 */ 00077 uint32_t total_message_size() const; 00078 00079 /** 00080 * \brief Check if last block. 00081 * \return True if last block, else false. 00082 */ 00083 bool is_last_block() const; 00084 00085 /** 00086 * \brief Returns the payload of the message. 00087 * \return The message payload. 00088 */ 00089 uint8_t* block_data() const; 00090 00091 /** 00092 * \brief Returns the length of the payload. 00093 * \return The payload length. 00094 */ 00095 uint32_t block_data_len() const; 00096 00097 /** 00098 * \brief Returns an error code. 00099 * \return Error code. 00100 */ 00101 Error error_code() const; 00102 00103 private: 00104 uint8_t *_block_data_ptr; 00105 uint32_t _total_message_size; 00106 uint16_t _block_data_len; 00107 uint16_t _block_number; 00108 Error _error_code; 00109 bool _is_last_block; 00110 bool _is_block_message; 00111 }; 00112 00113 #endif // M2MBLOCKMESSAGE_H
Generated on Tue Jul 12 2022 19:12:12 by 1.7.2