Commit 2ca9a2a5 authored by Garcia's avatar Garcia
Browse files

Add RFC 5985 - HELD support

parent f4b464a9
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@ class BITSTRING; //! Declare TITAN class
 * \abstract
 */
template<typename TPDUEnc, typename TPDUDec>
class codec
{
class codec {
protected:
  params* _params; //! Reference to params stack
                   // \todo Use smart pointer std::unique_ptr<params>
+46 −0
Original line number Diff line number Diff line
/*!
 * \file      codec_factory.hh
 * \brief     Header file for ITS abstract protocol codec definition.
 * \author    ETSI STF525
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */
#pragma once

#include <string>
#include <map>
#include <vector>
#include <algorithm>

#include "codec.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class codec_factory
 * \brief  This class provides a factory class to create codec class instances
 * \abstract
 */
class codec_factory {
public: //! \publicsection
  /*!
   * \fn codec();
   * \brief  Default constructor
   */
  codec_factory() { };
  /*!
   * \fn codec* create_codec(const std::string & type, const std::string & param);
   * \brief  Create the codecs stack based on the provided codecs stack description (cf. remark)
   * \param[in] p_type The provided codecs stack description
   * \param[in] p_params Optional parameters
   * \return 0 on success, -1 otherwise
   * \remark The description below introduces codecs stack in case of ITS project:
   *     HTTP(codecs=xml:held_codec;html:html_codec,json:json_codec)/TCP(debug=1,server=httpbin.org,port=80,use_ssl=0)
   * \pure
   */
  virtual codec<Record_Type, Record_Type>* create_codec() = 0;
}; // End of class codec_factory
+74 −0
Original line number Diff line number Diff line
/*!
 * \file      codec_stack_builder.hh
 * \brief     Header file for ITS protocol stack builder.
 * \author    ETSI STF525
 * \copyright ETSI Copyright Notification
 *            No part may be reproduced except as authorized by written permission.
 *            The copyright and the foregoing restriction extend to reproduction in all media.
 *            All rights reserved.
 * \version   0.1
 */
#pragma once

#include "codec_factory.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class codec_stack_builder
 * \brief  This class provides a factory class to create Codec class instances
 */
class codec_stack_builder {
private: //! \privatesection
  static codec_stack_builder* _instance;         //! Smart pointer to the unique instance of the logger framework
  std::map<std::string, codec_factory*> _codecs; //! The list of the registered \see t_codec factories

  /*!
   * \brief Default constructor
   *        Create a new instance of the codec_stack_builder class
   * \private
   */
  codec_stack_builder() { }; // can not be created manually
public: //! \publicsection
  /*!
   * \fn codec_stack_builder* get_instance();
   * \brief Accessor for the unique instance of the logger framework
   * \static
   */
  static codec_stack_builder* get_instance() { return _instance ? _instance : _instance = new codec_stack_builder(); };

  /*!
   * \fn void register_codec_factory(const std::string & p_type, codec_factory<TPDUEnc, TPDUDec>* p_codec_factory);
   * \brief Add a new codec factory
   * \param[in] p_type          The codec identifier (e.g. GN for the GeoNetworking codec...)
   * \param[in] p_codec_factory A reference to the \see codec_factory
   * \static
   */
  static void register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory) { codec_stack_builder::get_instance()->_register_codec_factory(p_type, p_codec_factory); };

private: //! \privatesection
  /*!
   * \fn void _register_codec_factory(const std::string & p_type, codec_factory<TPDUEnc, TPDUDec>* p_codec_factory);
   * \brief Add a new codec factory
   * \param[in] p_type          The codec identifier (e.g. GN for the GeoNetworking codec...)
   * \param[in] p_codec_factory A reference to the \see codec_factory
   */
  void _register_codec_factory(const std::string & p_type, codec_factory* p_codec_factory) { _codecs[p_type] = p_codec_factory; };

public: //! \publicsection
  /*!
   * \fn codec* get_codec(const char* p_codec_name);
   * \brief Retrieve the specified codec name from the list of the registered codecs
   * \param[in] p_codec_name The codec indentifier
   * \return The pointer to the codec object on success, nullptr otherwise
   */
  inline codec<Record_Type, Record_Type>* get_codec(const char* p_codec_name) { // NOTE A virtual method cannot not be a template ==> polymorphism required here
    typename std::map<std::string, codec_factory*>::const_iterator it = _codecs.find(p_codec_name);
    if (it != _codecs.cend()) {
      return it->second->create_codec();
    }

    return nullptr;
  }
}; // End of class codec_stack_builder
+3 −1
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ public: //! \publicsection
  static const std::string& sip_version;
  static const std::string& payload;               //! UpperLayer Payload parameter name

  static const std::string& codecs;                //! List of codecs to use for HTTP application layers

  /*!
   * \brief Default constructor
   *        Create a new instance of the params class
@@ -76,7 +78,7 @@ public: //! \publicsection

  /*!
   * \static
   * \fn void convert(params& p_param, const std::string& p_parameters);
   * \fn void convert(params& p_param, const std::string p_parameters);
   * \brief Create a new instance of a params object by converting a list of ITS parameters in string format (t1=v1,T2=(v0,v1v2)...)
   * \return a new instance of a params object
   */
+4 −0
Original line number Diff line number Diff line
#include "codec_stack_builder.hh"

codec_stack_builder* codec_stack_builder::_instance = NULL;
Loading