All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cpp_interface_internal.remoteClass_internal_cpp.ftl Maven / Gradle / Ivy

Go to download

Tool that generates code for RPC between the Kurento Media Server and remote libraries.

There is a newer version: 7.1.0
Show newest version
${remoteClass.name}Internal.cpp
/* Autogenerated with kurento-module-creator */

#include 
#include "${remoteClass.name}Internal.hpp"
#include 
#include 
<#list typeDependencies(remoteClass) as dependency>
#include "${dependency.name}.hpp"


<#list module.code.implementation["cppNamespace"]?split("::") as namespace>
namespace ${namespace}
{


<#list remoteClass.methods as method><#rt>
${getCppObjectType(method.return, false)} ${remoteClass.name}Method${method.name?cap_first}::invoke (std::shared_ptr<${remoteClass.name}> obj)
{
  if (!obj) {
    throw KurentoException (MEDIA_OBJECT_NOT_FOUND, "Invalid object while invoking method ${remoteClass.name}::${method.name}");
  }

  <#list method.params?reverse as param>
  <#if param.optional>
  <#assign optionalParam = param>
  if (<#assign stop_if = false><#assign first = true><#list method.params as param_if><#rt>
      <#lt><#if stop_if><#break><#rt>
      <#lt><#if param_if.name == param.name><#assign stop_if = true><#if !first> && <#rt>
      <#lt><#if param_if.optional>__isSet${param_if.name?cap_first}<#assign first =
      false>) {
    return obj->${method.name} (<#assign stop_call = false><#rt>
      <#lt><#list method.params as param_call><#if stop_call><#break>
      <#lt><#if param_call.name == param.name><#assign stop_call = true>
      <#lt><#if param_call_index != 0>, ${param_call.name}<#rt>
      <#lt>);
  }

  
  
  return obj->${method.name} (<#rt>
    <#lt><#list method.params as param>
      <#lt><#if param.optional><#break><#if param_index != 0>, ${param.name}<#rt>
    <#lt>);
}

void ${remoteClass.name}Method${method.name?cap_first}::Serialize (kurento::JsonSerializer &s)
{
  if (s.IsWriter) {
  <#list method.params as param>
    <#if param.optional>
    if (__isSet${param.name?cap_first}) {
      s.SerializeNVP (${param.name});
    }

    <#else>
    s.SerializeNVP (${param.name});

    
  
  } else {
  <#assign requiredParams = false>
  <#list method.params as param>
    <#if !param.optional>
    <#assign requiredParams = true>
    
  
  <#if requiredParams>
    if (s.JsonValue.isNull ()) {
      throw KurentoException (MARSHALL_ERROR,
                              "'operationParams' is required");
    } else if (!s.JsonValue.isObject ()){
      throw KurentoException (MARSHALL_ERROR,
                              "'operationParams' should be an object");
    }
  <#else>
    if (!s.JsonValue.isNull () && !s.JsonValue.isObject ()) {
      throw KurentoException (MARSHALL_ERROR,
                              "'operationParams' should be an object");
    }
  

  <#list method.params as param>
    <#assign jsonData = getJsonCppTypeData(param.type)>
    <#if param.optional>
    if (s.JsonValue.isMember ("${param.name}") ) {
      if (s.JsonValue["${param.name}"].isConvertibleTo (Json::ValueType::${jsonData.getJsonValueType()}) ) {
        __isSet${param.name?cap_first} = true;
        s.SerializeNVP (${param.name});
      } else {
        throw KurentoException (MARSHALL_ERROR,
                                "'${param.name}' parameter should be a ${jsonData.getTypeDescription()}");
      }
    }

    <#else>
    if (!s.JsonValue.isMember ("${param.name}") || !s.JsonValue["${param.name}"].isConvertibleTo (Json::ValueType::${jsonData.getJsonValueType()}) ) {
      throw KurentoException (MARSHALL_ERROR,
                              "'${param.name}' parameter should be a ${jsonData.getTypeDescription()}");
    }

    s.SerializeNVP (${param.name});

    
  
  }
}


<#if remoteClass.constructor??><#rt>
<#list remoteClass.constructor.params as param>
${getCppObjectType (param.type, false)} ${remoteClass.name}Constructor::get${param.name?cap_first} ()
{
  <#if param.optional>
  <#if param.defaultValue?? >
  if (!__isSet${param.name?cap_first} && !__isSetDefault${param.name?cap_first}) {
    try {
      kurento::JsonSerializer s (false);
      Json::Reader reader;
      std::string defaultValue = "${escapeString (param.defaultValue)}";

      reader.parse (defaultValue, s.JsonValue["${param.name}"]);
      s.SerializeNVP (${param.name});
      __isSetDefault${param.name?cap_first} = true;
    } catch (std::exception &e) {
      std::cerr << "Unexpected exception deserializing default value ${param.name} of ${remoteClass.name} constructor, check your module: " << e.what() << std::endl;
    }
  }

  <#else>
#error "${param.name} optional param must have a default value"
  
  
  return ${param.name};
}


void ${remoteClass.name}Constructor::Serialize (kurento::JsonSerializer &s)
{
  if (s.IsWriter) {
  <#list remoteClass.constructor.params as param>
    <#if param.optional>
    if (__isSet${param.name?cap_first}) {
      s.SerializeNVP (${param.name});
    }

    <#else>
    s.SerializeNVP (${param.name});

    
  
  } else {
  <#assign requiredParams = false>
  <#list remoteClass.constructor.params as param>
    <#if !param.optional>
    <#assign requiredParams = true>
    
  
  <#if requiredParams>
    if (s.JsonValue.isNull ()) {
      throw KurentoException (MARSHALL_ERROR,
                              "'constructorParams' is required");
    } else if (!s.JsonValue.isObject ()){
      throw KurentoException (MARSHALL_ERROR,
                              "'constructorParams' should be an object");
    }
  <#else>
    if (!s.JsonValue.isNull () && !s.JsonValue.isObject ()) {
      throw KurentoException (MARSHALL_ERROR,
                              "'constructorParams' should be an object");
    }
  

  <#list remoteClass.constructor.params as param>
    <#assign jsonData = getJsonCppTypeData(param.type)>
    <#if param.optional>
    if (s.JsonValue.isMember ("${param.name}") ) {
      if (s.JsonValue["${param.name}"].isConvertibleTo (Json::ValueType::${jsonData.getJsonValueType()}) ) {
        __isSet${param.name?cap_first} = true;
        s.SerializeNVP (${param.name});
      } else {
        throw KurentoException (MARSHALL_ERROR,
                                "'${param.name}' parameter should be a ${jsonData.getTypeDescription()}");
      }
    }

    <#else>
    if (!s.JsonValue.isMember ("${param.name}") || !s.JsonValue["${param.name}"].isConvertibleTo (Json::ValueType::${jsonData.getJsonValueType()}) ) {
      throw KurentoException (MARSHALL_ERROR,
                              "'${param.name}' parameter should be a ${jsonData.getTypeDescription()}");
    }

    s.SerializeNVP (${param.name});

    
  
  }
}


<#list module.code.implementation["cppNamespace"]?split("::")?reverse as namespace>
} /* ${namespace} */





© 2015 - 2024 Weber Informatics LLC | Privacy Policy