Commit fbae3c52 authored by Yann Garcia's avatar Yann Garcia
Browse files

Bug fixed in f_create_user_location_event_subscription; Initiate JSON codec re-organization

parent 86f7a2de
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,12 @@ bool http_codec_mec::encode_body_json(const LibHttp__JsonMessageBodyTypes::JsonB
bool http_codec_mec::decode_body_json(const OCTETSTRING &p_data, LibHttp__JsonMessageBodyTypes::JsonBody &p_json_body, const std::string &p_content_type, params* p_params) {
  loggers::get_instance().log(">>> http_codec_mec::decode_body_json");

  loggers::get_instance().log("http_codec_mec::decode_body_json: len=%d", _codecs.size());
  loggers::get_instance().log("http_codec_mec::decode_body_json: first=%s", _codecs.cbegin()->first.c_str());
  loggers::get_instance().log("http_codec_mec::decode_body_json: second=%p", _codecs.cbegin()->second.get());
  loggers::get_instance().log("http_codec_mec::decode_body_json: pointer=%p", _codecs["json"].get());


  if (_codecs["json"].get() != nullptr) {
    loggers::get_instance().log("http_codec::decode_body_json: Call 'json_codec'");
    if (_codecs["json"]->decode(p_data, (Record_Type&)p_json_body, p_params) == -1) {
+1 −112
Original line number Diff line number Diff line
@@ -20,26 +20,6 @@ int json_codec::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTE
    const UEidentityAPI__TypesAndValues::UeIdentityTagInfo& ue_identity_tag_info = msg.ueIdentityTagInfo();
    ue_identity_tag_info.encode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_userLocationEventSubscription)) {
    const LocationAPI__TypesAndValues::UserLocationEventSubscription& user_location_event_subscription = msg.userLocationEventSubscription();
    user_location_event_subscription.encode(LocationAPI__TypesAndValues::UserLocationEventSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"userLocationEventSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_userLocationPeriodicSubscription)) {
    const LocationAPI__TypesAndValues::UserLocationPeriodicSubscription& user_location_periodic_subscription = msg.userLocationPeriodicSubscription();
    user_location_periodic_subscription.encode(LocationAPI__TypesAndValues::UserLocationPeriodicSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"userLocationPeriodicSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_zoneLocationEventSubscription)) {
    const LocationAPI__TypesAndValues::ZoneLocationEventSubscription& zone_location_event_subscription = msg.zoneLocationEventSubscription();
    zone_location_event_subscription.encode(LocationAPI__TypesAndValues::ZoneLocationEventSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"zoneLocationEventSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_userAreaSubscription)) {
    const LocationAPI__TypesAndValues::UserAreaSubscription& notif = msg.userAreaSubscription();
    notif.encode(LocationAPI__TypesAndValues::UserAreaSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"userAreaSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_userDistanceSubscription)) {
    const LocationAPI__TypesAndValues::UserDistanceSubscription& notif = msg.userDistanceSubscription();
    notif.encode(LocationAPI__TypesAndValues::UserDistanceSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"userDistanceSubscription\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_cellChangeSubscription)) {
    const RnisAPI__TypesAndValues::CellChangeSubscription& cell_change_subscription = msg.cellChangeSubscription();
    cell_change_subscription.encode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
@@ -163,98 +143,7 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes
  loggers::get_instance().log("json_codec::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str());
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));

  if (it->second.find("\"userList\"") != std::string::npos) { // Be careful to the order
    // TODO To be refined, find("\"userList\"") is not optimal
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserList user_list;
    user_list.decode(LocationAPI__TypesAndValues::UserList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userList() = user_list;
  } else if (it->second.find("\"accessPointList\"") != std::string::npos) { // Be careful to the order
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::AccessPointList access_point_list;
    access_point_list.decode(LocationAPI__TypesAndValues::AccessPointList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.accessPointList() = access_point_list;
  } else if (it->second.find("\"userLocationEventSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserLocationEventSubscription user_location_event_subscription;
    user_location_event_subscription.decode(LocationAPI__TypesAndValues::UserLocationEventSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userLocationEventSubscription() = user_location_event_subscription;



  } else if (it->second.find("\"notificationSubscriptionList\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::NotificationSubscriptionList notification_subscription_list;
    notification_subscription_list.decode(LocationAPI__TypesAndValues::NotificationSubscriptionList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.notificationSubscriptionList() = notification_subscription_list;



  } else if (it->second.find("\"userLocationPeriodicSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserLocationPeriodicSubscription user_location_periodic_subscription;
    user_location_periodic_subscription.decode(LocationAPI__TypesAndValues::UserLocationPeriodicSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userLocationPeriodicSubscription() = user_location_periodic_subscription;
  } else if (it->second.find("\"zoneLocationEventSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::ZoneLocationEventSubscription zone_location_event_subscription;
    zone_location_event_subscription.decode(LocationAPI__TypesAndValues::ZoneLocationEventSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.zoneLocationEventSubscription() = zone_location_event_subscription;
  } else if (it->second.find("\"userLocationPeriodicSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserLocationPeriodicSubscription periodic_tracking_subscription;
    periodic_tracking_subscription.decode(LocationAPI__TypesAndValues::UserLocationPeriodicSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userLocationPeriodicSubscription() = periodic_tracking_subscription;
  } else if (it->second.find("\"accessPointId\"") != std::string::npos) {
    LocationAPI__TypesAndValues::UserInfo user_info;
    user_info.decode(LocationAPI__TypesAndValues::UserInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userInfo() = user_info;
  } else if (it->second.find("\"terminalDistance\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::TerminalDistance terminal_distance;
    terminal_distance.decode(LocationAPI__TypesAndValues::TerminalDistance_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.terminalDistance() = terminal_distance;
  } else if (it->second.find("\"enteringLeavingCriteria\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserAreaSubscription notif;
    notif.decode(LocationAPI__TypesAndValues::UserAreaSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userAreaSubscription() = notif;
  } else if (it->second.find("\"userDistanceSubscription\"") != std::string::npos) {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    LocationAPI__TypesAndValues::UserDistanceSubscription notif;
    notif.decode(LocationAPI__TypesAndValues::UserDistanceSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.userDistanceSubscription() = notif;
  } else if (it->second.find("\"ueIdentityTagInfo\"") != std::string::npos) {
  if (it->second.find("\"ueIdentityTagInfo\"") != std::string::npos) {
    UEidentityAPI__TypesAndValues::UeIdentityTagInfo ue_identity_tag_info;
    ue_identity_tag_info.decode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.ueIdentityTagInfo() = ue_identity_tag_info;
+46 −0
Original line number Diff line number Diff line
/*!
 * \file      json_codec_factory_mec013.hh
 * \brief     Header file for ITS JSON/IP protocol codec factory.
 * \author    ETSI STF569 / TTF T027
 * \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_stack_builder.hh"

#include "json_codec_mec013.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class json_codec_factory_mec013
 * \brief  This class provides a factory class to create an json_codec class instance
 */
class json_codec_factory_mec013: public codec_factory {
  static json_codec_factory_mec013 _f; //! Reference to the unique instance of this class
public: //! \publicsection
  /*!
   * \brief Default constructor
   *        Create a new instance of the json_codec_factory_mec013 class
   * \remark The HELD/IP codec identifier is HELD
   */
  json_codec_factory_mec013() {
    // register factory
    codec_stack_builder::register_codec_factory("json_codec_mec013", this);
  };
  /*!
   * \fn codec* create_codec(const std::string & type, const std::string & param);
   * \brief  Create the codecs stack based on the provided codecs stack description
   * \param[in] p_type The provided codecs stack description
   * \param[in] p_params Optional parameters
   * \return 0 on success, -1 otherwise
   * \inline
   */
  inline virtual codec_gen<Record_Type, Record_Type>* create_codec() {
    return (codec_gen<Record_Type, Record_Type>*)new json_codec_mec013();
  };
}; // End of class json_codec_factory_mec013
+46 −0
Original line number Diff line number Diff line
/*!
 * \file      json_codec_factory_mec030.hh
 * \brief     Header file for ITS JSON/IP protocol codec factory.
 * \author    ETSI STF569 / TTF T027
 * \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_stack_builder.hh"

#include "json_codec_mec030.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class json_codec_factory_mec030
 * \brief  This class provides a factory class to create an json_codec_mec030 class instance
 */
class json_codec_factory_mec030: public codec_factory {
  static json_codec_factory_mec030 _f; //! Reference to the unique instance of this class
public: //! \publicsection
  /*!
   * \brief Default constructor
   *        Create a new instance of the json_codec_factory_mec030 class
   * \remark The HELD/IP codec identifier is HELD
   */
  json_codec_factory_mec030() {
    // register factory
    codec_stack_builder::register_codec_factory("json_codec_mec030", this);
  };
  /*!
   * \fn codec* create_codec(const std::string & type, const std::string & param);
   * \brief  Create the codecs stack based on the provided codecs stack description
   * \param[in] p_type The provided codecs stack description
   * \param[in] p_params Optional parameters
   * \return 0 on success, -1 otherwise
   * \inline
   */
  inline virtual codec_gen<Record_Type, Record_Type>* create_codec() {
    return (codec_gen<Record_Type, Record_Type>*)new json_codec_mec030();
  };
}; // End of class json_codec_factory_mec030
+177 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading