예제 #1
0
def NpapiFromNPVariant(scope, type_defn, input_expr, variable, success,
                       exception_context, npp):
    """Gets the string to get a value from a NPVariant.

  This function creates a string containing a C++ code snippet that is used to
  retrieve a value from a NPVariant. If an error occurs, like if the NPVariant
  is not of the correct type, the snippet will set the success status variable
  to false.

  Args:
    scope: a Definition for the scope in which the glue will be written.
    type_defn: a Definition, representing the type of the value.
    input_expr: an expression representing the NPVariant to get the value from.
    variable: a string, representing a name of a variable that can be used to
      store a reference to the value.
    success: the name of a bool variable containing the current success status.
    exception_context: the name of a string containing context information, for
      use in exception reporting.
    npp: a string, representing the name of the variable that holds the pointer
      to the NPP instance.

  Returns:
    a (string, string) pair, the first string being the code snippet and the
    second one being the expression to access that value.
  """
    (scope, npp) = (scope, npp)  # silence gpylint.
    glue_namespace = npapi_utils.GetGlueFullNamespace(type_defn)
    text = _from_npvariant_template.substitute(ClassGlueNS=glue_namespace,
                                               variable=variable,
                                               input=input_expr,
                                               success=success,
                                               context=exception_context)
    return (text, '%s->value()' % variable)
예제 #2
0
def NpapiFromNPVariant(scope, type_defn, input_expr, variable, success,
                       exception_context, npp):
    """Gets the string to get a value from a NPVariant.

  This function creates a string containing a C++ code snippet that is used to
  retrieve a value from a NPVariant. If an error occurs, like if the NPVariant
  is not of the correct type, the snippet will set the success status variable
  to false.

  Args:
    scope: a Definition for the scope in which the glue will be written.
    type_defn: a Definition, representing the type of the value.
    input_expr: an expression representing the NPVariant to get the value from.
    variable: a string, representing a name of a variable that can be used to
      store a reference to the value.
    success: the name of a bool variable containing the current success status.
    exception_context: the name of a string containing context information, for
      use in exception reporting.
    npp: a string, representing the name of the variable that holds the pointer
      to the NPP instance.

  Returns:
    a (string, string) pair, the first string being the code snippet and the
    second one being the expression to access that value.
  """
    npp = npp  # silence gpylint.
    class_name = cpp_utils.GetScopedName(scope, type_defn)
    glue_namespace = npapi_utils.GetGlueFullNamespace(type_defn)
    marshaling_attributes = GetMarshalingAttributes(type_defn)

    # If the value type has marshaling getter then the C++ type is never exposed
    # to JavaScript and we don't need to check. Otherwise, assume that we might
    # see a wrapped C++ type or an alternative JavaScript representation.
    if 'getter' in marshaling_attributes:
        template = _from_npvariant_template_marshaled
    else:
        if 'setter' in marshaling_attributes:
            template = _from_npvariant_template_dual_interface
        else:
            template = _from_npvariant_template

    text = template.substitute(npp=npp,
                               Class=class_name,
                               ClassGlueNS=glue_namespace,
                               variable=variable,
                               input=input_expr,
                               success=success,
                               context=exception_context)
    return (text, variable)
예제 #3
0
def PpapiExprToPPVar(scope, type_defn, variable, expression, output, success,
                     npp):
    """Gets the string to store a value into a pp::Var.

  This function creates a string containing a C++ code snippet that is used to
  store a value into a pp::Var. That operation takes two phases, one that
  allocates necessary PPAPI resources, and that can fail, and one that actually
  sets the pp::Var (that can't fail). If an error occurs, the snippet will
  set the success status variable to false.

  Args:
    scope: a Definition for the scope in which the glue will be written.
    type_defn: a Definition, representing the type of the value.
    variable: a string, representing a name of a variable that can be used to
      store a reference to the value.
    expression: a string representing the expression that yields the value to
      be stored.
    output: an expression representing a pointer to the pp::Var to store the
      value into.
    success: the name of a bool variable containing the current success status.
    npp: a string, representing the name of the variable that holds the pointer
      to the pp::Instance.

  Returns:
    a (string, string) pair, the first string being the code snippet for the
    first phase, and the second one being the code snippet for the second phase.
  """
    class_name = cpp_utils.GetScopedName(scope, type_defn)
    glue_namespace = npapi_utils.GetGlueFullNamespace(type_defn)
    marshaling_attributes = GetMarshalingAttributes(type_defn)
    if 'getter' in marshaling_attributes:
        template = _ppapi_expr_to_ppvar_template_marshaled
    else:
        template = _ppapi_expr_to_ppvar_template
    text = template.substitute(Class=class_name,
                               ClassGlueNS=glue_namespace,
                               variable=variable,
                               output=output,
                               npp=npp,
                               expr=expression,
                               success=success)
    return (text, '')
예제 #4
0
def PpapiFromPPVar(scope, type_defn, input_expr, variable, success,
                   exception_context, npp):
    """Gets the string to get a value from a pp::Var.

  This function creates a string containing a C++ code snippet that is used to
  retrieve a value from a pp::Var. If an error occurs, like if the pp::Var
  is not of the correct type, the snippet will set the success status variable
  to false.

  Args:
    scope: a Definition for the scope in which the glue will be written.
    type_defn: a Definition, representing the type of the value.
    input_expr: an expression representing the pp::Var to get the value from.
    variable: a string, representing a name of a variable that can be used to
      store a reference to the value.
    success: the name of a bool variable containing the current success status.
    exception_context: the name of a string containing context information, for
      use in exception reporting.
    npp: a string, representing the name of the variable that holds the pointer
      to the pp::Instance.

  Returns:
    a (string, string) pair, the first string being the code snippet and the
    second one being the expression to access that value.
  """
    glue_class = type_defn.name + '_glue'
    type_name = cpp_utils.GetScopedName(scope, type_defn)
    callback_namespace = npapi_utils.GetGlueFullNamespace(type_defn)
    text = _ppapi_from_ppvar_template.substitute(success=success,
                                                 context=exception_context,
                                                 input_expr=input_expr,
                                                 type_name=type_name,
                                                 type_defn=type_defn,
                                                 variable=variable,
                                                 namespace=callback_namespace,
                                                 GlueClass=glue_class,
                                                 npp=npp)
    return text, variable
예제 #5
0
def NpapiExprToNPVariant(scope, type_defn, variable, expression, output,
                         success, npp):
    """Gets the string to store a value into a NPVariant.

  This function creates a string containing a C++ code snippet that is used to
  store a value into a NPVariant. That operation takes two phases, one that
  allocates necessary NPAPI resources, and that can fail, and one that actually
  sets the NPVariant (that can't fail). If an error occurs, the snippet will
  set the success status variable to false.

  Args:
    scope: a Definition for the scope in which the glue will be written.
    type_defn: a Definition, representing the type of the value.
    variable: a string, representing a name of a variable that can be used to
      store a reference to the value.
    expression: a string representing the expression that yields the value to
      be stored.
    output: an expression representing a pointer to the NPVariant to store the
      value into.
    success: the name of a bool variable containing the current success status.
    npp: a string, representing the name of the variable that holds the pointer
      to the NPP instance.

  Returns:
    a (string, string) pair, the first string being the code snippet for the
    first phase, and the second one being the code snippet for the second phase.
  """
    class_name = cpp_utils.GetScopedName(scope, type_defn)
    glue_namespace = npapi_utils.GetGlueFullNamespace(type_defn)
    text = _expr_to_npvariant_template.substitute(Class=class_name,
                                                  ClassGlueNS=glue_namespace,
                                                  variable=variable,
                                                  npp=npp,
                                                  expr=expression,
                                                  success=success)
    return (text, 'OBJECT_TO_NPVARIANT(%s, *%s);' % (variable, output))