Timothy Beight / Mbed 2 deprecated 6_songs-from-the-cloud

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of 6_songs-from-the-cloud by MakingMusicWorkshop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mtlvdeserializer.h Source File

m2mtlvdeserializer.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 #include "mbed-client/m2mvector.h"
00017 #include "mbed-client/m2mobject.h"
00018 #include "mbed-client/m2mobjectinstance.h"
00019 #include "mbed-client/m2mresource.h"
00020 
00021 /**
00022  * @brief M2MTLVDeserializer
00023  * TLV Deserialiser get the object instances and resources as binary data and 
00024  * builds the <code>lwm2m</code> representation from it. See OMA-LWM2M 
00025  * specification, chapter 6.1 for the resource model and chapter 6.3.3 for
00026  * the OMA-TLV specification.
00027  */
00028 class M2MTLVDeserializer {
00029 
00030 public :
00031 
00032     typedef enum {
00033         None,
00034         NotFound,
00035         NotAllowed,
00036         NotValid
00037     } Error;
00038 
00039     typedef enum {
00040         Put,
00041         Post
00042     } Operation;
00043 
00044 
00045     /**
00046     * Constructor.
00047     */
00048     M2MTLVDeserializer();
00049 
00050     /**
00051     * Destructor.
00052     */
00053     virtual ~M2MTLVDeserializer();
00054 
00055     /**
00056      * This method checks whether the given binary encodes an object instance
00057      * or something else. It returns <code>true</code> if bits 7-6 of the first
00058      * byte is "00".
00059      * @param tlv Binary to be checked as LWM2M object instance
00060      * @return <code>true</code> or <code>false</code>.
00061      */
00062     bool is_object_instance(uint8_t *tlv);
00063 
00064     
00065     /**
00066      * This method checks whether the given binary encodes a resource or 
00067      * something else. It returns <code>true</code> if bits 7-6 of the first
00068      * byte is "11".
00069      * @param tlv Binary to be checked as LWM2M resource.
00070      * @return <code>true</code> or <code>false</code>.
00071      */
00072     bool is_resource(uint8_t *tlv);
00073 
00074     /**
00075      * This method checks whether the given binary encodes a multiple resource
00076      * or something else. It returns <code>true</code> if bits 7-6 of the first
00077      * byte is "10".
00078      * @param tlv Binary to be checked as LWM2M multiple resource.
00079      * @return <code>true</code> or <code>false</code>.
00080      */
00081     bool is_multiple_resource(uint8_t *tlv);
00082     
00083     /**
00084      * This method checks whether the given binary encodes a resource instance
00085      * or something else. It returns <code>true</code> if bits 7-6 of the first
00086      * byte is "01".
00087      * @param tlv Binary to be checked as LWM2M resource instance.
00088      * @return <code>true</code> or <code>false</code>.
00089      */
00090     bool is_resource_instance(uint8_t *tlv);
00091 
00092     /**
00093      * Deserialises the given binary that must encode object instances. Binary
00094      * array can be checked before invoking this method with 
00095      */
00096     M2MTLVDeserializer::Error deserialise_object_instances(uint8_t* tlv,
00097                                                            uint32_t tlv_size,
00098                                                            M2MObject &object,
00099                                                            M2MTLVDeserializer::Operation operation);
00100 
00101     /**
00102      * Deserialises the given binary that must encode resources. Binary array 
00103      * can be checked before invoking this method.
00104      */
00105     M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
00106                                                     uint32_t tlv_size,
00107                                                     M2MObjectInstance &object_instance,
00108                                                     M2MTLVDeserializer::Operation operation);
00109 
00110     /**
00111      * Deserialises the given binary that must encode resource instances. Binary array
00112      * can be checked before invoking this method.
00113      */
00114     M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
00115                                                              uint32_t tlv_size,
00116                                                              M2MResource &resource,
00117                                                              M2MTLVDeserializer::Operation operation);
00118     /**
00119      * This method return object instance id or resource id.
00120      * @param tlv Binary to be checked
00121      * @return Object instance id or resource id.
00122      */
00123     uint16_t instance_id(uint8_t *tlv);
00124     
00125 private:
00126 
00127     M2MTLVDeserializer::Error deserialize_object_instances(uint8_t *tlv,
00128                                                            uint32_t tlv_size,
00129                                                            uint32_t offset,
00130                                                            M2MObject &object,
00131                                                            M2MTLVDeserializer::Operation operation,
00132                                                            bool update_value);
00133     
00134     M2MTLVDeserializer::Error deserialize_resources(uint8_t *tlv,
00135                                                     uint32_t tlv_size,
00136                                                     uint32_t offset,
00137                                                     M2MObjectInstance &object_instance,
00138                                                     M2MTLVDeserializer::Operation operation,
00139                                                     bool update_value);
00140 
00141     M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
00142                                                              uint32_t tlv_size,
00143                                                              uint32_t offset,
00144                                                              M2MResource &resource,
00145                                                              M2MObjectInstance &object_instance,
00146                                                              M2MTLVDeserializer::Operation operation,
00147                                                              bool update_value);
00148 
00149     M2MTLVDeserializer::Error deserialize_resource_instances(uint8_t *tlv,
00150                                                              uint32_t tlv_size,
00151                                                              uint32_t offset,
00152                                                              M2MResource &resource,
00153                                                              M2MTLVDeserializer::Operation operation,
00154                                                              bool update_value);
00155 
00156     bool is_object_instance(uint8_t *tlv, uint32_t offset);
00157     
00158     bool is_resource(uint8_t *tlv, uint32_t offset);
00159     
00160     bool is_multiple_resource(uint8_t *tlv, uint32_t offset);
00161     
00162     bool is_resource_instance(uint8_t *tlv, uint32_t offset);
00163 };
00164 
00165 class TypeIdLength {
00166 
00167 public:
00168 
00169     static TypeIdLength* createTypeIdLength(uint8_t *tlv, uint32_t offset);
00170 
00171     TypeIdLength* deserialize();
00172 
00173     void deserialiseID (uint32_t idLength);
00174 
00175     void deserialiseLength (uint32_t lengthType);
00176 
00177     uint8_t             *_tlv;
00178     uint32_t            _offset;
00179     uint32_t            _type;
00180     uint16_t            _id;
00181     uint32_t            _length;
00182 
00183     friend class Test_M2MTLVDeserializer;
00184 };