Skip to content
helpers_externals.cc 2.9 KiB
Newer Older
#include "LibHelpers_Functions.hh"
#include <math.h>

#include "base_time.hh"
YannGarcia's avatar
YannGarcia committed
#include "converter.hh"
#include "loggers.hh"

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define earthRadius 6378137.0L
#define rbis = ((double)(earthRadius * M_PI / 180))

namespace LibHelpers__Functions {

  /**
   * @desc    This external function gets the current time since 01/01/1970 in UTC format
   * @return  The current time since 01/01/1970 in UTC format in milliseconds
   * @see     fx_getCurrentTimeUtc() return UInt64
   */
  INTEGER fx__getCurrentTimeUtc() {
    INTEGER i;
    i.set_long_long_val(base_time::get_instance().get_current_time_ms());
    loggers::get_instance().log_msg("<<< fx__getCurrentTimeUtc: ", i);
    return i;
  }
  /**
   * @desc    Gets the Minute of current UTC year
   * @return  MinuteOfTheYear - tenths of a second in the current or next hour in units of 1/10th second from UTC time
   * @see     function f_getMinuteOfTheYear() return MinuteOfTheYear
   */
  INTEGER fx__getMinuteOfTheYear() {
YannGarcia's avatar
YannGarcia committed
    //	TODO: this is just a skeleton. fill in the function
    return 0;
  }

  /**
   * @desc    Gets the milliseconds point in the current UTC minute
   * @return  DSecond - The milliseconds point in the current UTC minute (0..60000)
   * @see     function f_getDSecond() return DSecond
   */
  INTEGER fx__getDSecond() {
YannGarcia's avatar
YannGarcia committed
    //	TODO: this is just a skeleton. fill in the function
YannGarcia's avatar
YannGarcia committed
  /**
   * @desc    Encode into Base64
   * @return  p_to_encode - The buffer to be encoded
   * @see     function f_enc_base64(in octetstring p_to_encode) return octetstring
   */
  OCTETSTRING fx__enc__base64(const OCTETSTRING& p_to_encode) {
    loggers::get_instance().log_msg(">>> fx__enc__base64: ", p_to_encode);

    const std::vector<unsigned char> to_encode(static_cast<const unsigned char*>(p_to_encode), static_cast<const unsigned char*>(p_to_encode) + p_to_encode.lengthof());
    std::vector<unsigned char> b64 = converter::get_instance().buffer_to_base64(to_encode);
    OCTETSTRING os(b64.size(), b64.data());
    loggers::get_instance().log_msg("<<< fx__enc__base64: ", os);
    return os;
  }

  /**
   * @desc    Decode from Base64
   * @return  p_to_decode - The buffer to be decoded
   * @see     function f_dec_base64(in octetstring p_to_decode) return octetstring
   */
  OCTETSTRING fx__dec__base64(const OCTETSTRING& p_to_decode) {
    loggers::get_instance().log_msg(">>> fx__dec__base64: ", p_to_decode);

    const std::vector<unsigned char> to_decode(static_cast<const unsigned char*>(p_to_decode), static_cast<const unsigned char*>(p_to_decode) + p_to_decode.lengthof());
    std::vector<unsigned char> b64 = converter::get_instance().base64_to_buffer(to_decode);
    OCTETSTRING os(b64.size(), b64.data());
    loggers::get_instance().log_msg("<<< fx__dec__base64: ", os);
    return os;
  }

} // namespace LibHelpers__Functions