Esempio n. 1
0
/** @brief callback function called on definition of a union in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   union <union-name> switch(<switch-type>) {
            case label1.1; .. case label1.n;
                <union-case-1>;
            case label2.1; .. case label2.n;
                ...        ...
            case labeln.1; .. case labeln.n;
                <union-case-n>;
            default:
                <union-case-m>;
        };
   @endverbatim
 *
 * @param scope Current scope
 * @param name Name of the union
 * @param unionSpec Specifies the number of union cases and the union switch type
 */
static idl_action
idl_unionOpen(
    idl_scope scope,
    const char *name,
    idl_typeUnion unionSpec,
    void *userData)
{
    /* Open file for used scope, if needed create the directories */
    idl_openJavaPackage(scope, idl_javaId(name));
    if (idl_fileCur() == NULL) {
        return idl_abort;
    }
    unionSwitchType = idl_corbaJavaTypeFromTypeSpec(idl_typeUnionSwitchKind(unionSpec));

    /* setup iterator to hold case names and correcsponding type names */
    map = idl_mapNew(NULL, 1, 1);

    /* Write package name */
#if 0
    idl_fileOutPrintf(idl_fileCur(), "/*\n");
    idl_fileOutPrintf(idl_fileCur(), " * Generated by OpenSpliceDDS "OSPL_VERSION_STR"\n");
    idl_fileOutPrintf(idl_fileCur(), " */\n\n");
#endif
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava(scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    idl_fileOutPrintf(idl_fileCur(), "import org.opensplice.dds.dcps.Utilities;\n\n");
    /* public final class <struct-name> { */
    idl_fileOutPrintf(idl_fileCur(), "public final class %s {\n\n", idl_javaId(name));
    idl_fileOutPrintf(idl_fileCur(), "    private %s _d;\n\n", unionSwitchType);
    if(idl_unionHasCase((c_union)idl_typeSpecDef((idl_typeSpec)unionSpec), "discriminator")) {
        idl_fileOutPrintf(idl_fileCur(), "    public %s _discriminator ()\n", unionSwitchType);
    }else {
        idl_fileOutPrintf(idl_fileCur(), "    public %s discriminator ()\n", unionSwitchType);
    }
    idl_fileOutPrintf(idl_fileCur(), "    {\n");
    idl_fileOutPrintf(idl_fileCur(), "        return _d;\n");
    idl_fileOutPrintf(idl_fileCur(), "    }\n\n");

    labelsUsedIter = os_iterNew(NULL);
    /* return idl_explore to indicate that the rest of the enumeration needs to be processed */
    return idl_explore;
}
Esempio n. 2
0
static void
newMeta(
    idl_scope scope,
    const char *name,
    idl_typeSpec typeSpec)
{
    idl_meta meta;

    meta = os_malloc(C_SIZEOF(idl_meta));
    if (meta) {
        meta->scope = idl_scopeDup(scope);
        meta->name = os_strdup(name);
        if (idl_typeSpecType(typeSpec) == idl_ttypedef) {
            meta->actual_name = idl_typeSpecName(idl_typeDefActual(idl_typeDef(typeSpec)));
        } else {
            meta->actual_name = idl_typeSpecName(typeSpec);
        }
        meta->type = idl_typeSpecDef(typeSpec);
    }
    idlpp_metaList = os_iterAppend(idlpp_metaList, meta);
}