示例#1
0
/** @brief callback function called on structure definition in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   struct <structure-name> {
            <structure-member-1>;
            ...              ...
            <structure-member-n>;
        };
   @endverbatim
 *
 * @param scope Current scope (and scope of the structure definition)
 * @param name Name of the structure
 * @param structSpec Specification of the struct holding the amount of members
 */
static idl_action
idl_structureOpen(
    idl_scope scope,
    const char *name,
    idl_typeStruct structSpec,
    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;
    }
    /* setup iterator to hold field 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");
    }
    /* public final class <struct-name> { */
    idl_fileOutPrintf(idl_fileCur(), "public final class %s {\n\n", idl_javaId(name));
    /* return idl_explore to indicate that the rest of the structure needs to be processed */
    return idl_explore;
}
示例#2
0
/** @brief callback function called on structure definition in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   struct <structure-name> {
            <structure-member-1>;
            ...              ...
            <structure-member-n>;
        };
   @endverbatim
 *
 * @param scope Current scope (and scope of the structure definition)
 * @param name Name of the structure
 * @param structSpec Specification of the struct holding the amount of members
 */
static idl_action
idl_structureOpen(
    idl_scope scope,
    const char *name,
    idl_typeStruct structSpec,
    void *userData)
{
    int nameLen = strlen(idl_javaId(name)) + strlen("Holder") + 1;
    char *holderName;

    holderName = os_malloc(nameLen);
    snprintf(holderName, nameLen, "%sHolder", idl_javaId(name));

    /* Open file for used scope, if needed create the directories */
    idl_openJavaPackage(scope, holderName);
    if (idl_fileCur() == NULL) {
        return idl_abort;
    }
    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(), "public final class %s\n{\n\n", holderName);
    idl_fileOutPrintf(
        idl_fileCur(),
        "    public %s value = null;\n\n",
        idl_scopeStackJava(scope, ".", idl_javaId(name)));
    idl_fileOutPrintf(idl_fileCur(), "    public %s () { }\n\n", holderName);

    idl_fileOutPrintf(
        idl_fileCur(),
        "    public %s (%s initialValue)\n",
        holderName,
        idl_scopeStackJava(scope, ".", idl_javaId(name)));
    idl_fileOutPrintf(idl_fileCur(), "    {\n");
    idl_fileOutPrintf(idl_fileCur(), "        value = initialValue;\n");
    idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
    idl_fileOutPrintf(idl_fileCur(), "}\n");
    /* close file */
    idl_closeJavaPackage();

    /* return idl_abort to indicate that the rest of the structure does not need to be processed */
    return idl_abort;
}
示例#3
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;
}
示例#4
0
/** @brief callback function called on definition of an enumeration.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   enum <enum-name> {
            <enum-element-1>;
            ...          ...
            <enum-element-n>;
        };
   @endverbatim
 *
 * @param scope Current scope
 * @param name Name of the enumeration
 * @param enumSpec Specifies the number of elements in the enumeration
 */
static idl_action
idl_enumerationOpen(
    idl_scope scope,
    const char *name,
    idl_typeEnum enumSpec,
    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;
    }
    /* 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 <enumeration-name> { */
    idl_fileOutPrintf(idl_fileCur(), "public class %s {\n\n", idl_javaId(name));
    idl_fileOutPrintf(idl_fileCur(), "    private int __value;\n");
    idl_fileOutPrintf(
        idl_fileCur(),
        "    private static int __size = %d;\n",
        idl_typeEnumNoElements (enumSpec));
    enum_def = idl_scopeStackJava(scope, ".", name);
    idl_fileOutPrintf(
        idl_fileCur(),
        "    private static %s[] __array = new %s[__size];\n\n",
        enum_def,
        enum_def);
    enum_element = 0;
    /* return idl_explore to indicate that the rest of the structure needs to be processed */
    return idl_explore;
}
示例#5
0
static void
idl_constantOpenClose(
    idl_scope scope,
    idl_constSpec constantSpec,
    void *userData)
{
    /* Open file for used scope, if needed create the directories */
    idl_openJavaPackage(scope, idl_javaId(idl_constSpecName(constantSpec)));
    /* 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(), "public interface %s {\n",
	idl_constSpecName(constantSpec));

    if (idl_typeSpecType(idl_constSpecTypeGet(constantSpec)) == idl_tbasic &&
        idl_typeBasicType(idl_typeBasic(idl_constSpecTypeGet(constantSpec))) == idl_string) {
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public static final %s value = %s;\n",
            idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)),
            idl_constSpecImage (constantSpec));
    } else {
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public static final %s value = (%s)(%s);\n",
            idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)),
            idl_corbaJavaTypeFromTypeSpec(idl_constSpecTypeGet(constantSpec)),
            idl_constSpecImage(constantSpec));
    }
    idl_fileOutPrintf(idl_fileCur(), "}\n");
}
示例#6
0
static int
idl_genInterface(
    idl_scope scope,
    const char *name,
    char *class_base,
    idl_typeSpec typeSpec,
    c_bool generateInterfaceClass)
{
    idl_tmplExp te;
    c_char tmplFileName[1024];
    c_char pname[1024];
    c_char *tmplPath;
    c_char *orbPath;
    int tmplFile;
    struct os_stat_s tmplStat;
    unsigned int nRead;
    os_char *redirects;
    char *scopedMetaTypeName;
    const char *internalTypeName;
    const char *keyList;
    char *scopeStackJavaDot = idl_scopeStackJava(scope, ".", name);
    char *scopeStackJavaSlash = idl_scopeStackJava(scope, "/", name);
    char *typeSpecName = idl_typeSpecName(typeSpec);
    char *javaId = idl_javaId(name);
    int result = 0;
    tmplPath = os_getenv("OSPL_TMPL_PATH");
    orbPath = os_getenv("OSPL_ORB_PATH");
    if (tmplPath == NULL) {
        printf("OSPL_TMPL_PATH not defined\n");
        result = -1;
        goto err_exit;
    }
    if (orbPath == NULL) {
        printf("OSPL_ORB_PATH not defined\n");
        result = -1;
        goto err_exit;
    }

    idlpp_macroSet = idl_macroSetNew();
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type-name", javaId));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("actual-type-name", typeSpecName));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-type-name", scopeStackJavaDot));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-class-name", scopeStackJavaSlash));

    redirects = idl_packageRedirects ();
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-package-redirects", redirects));
    os_free(redirects);

    scopedMetaTypeName = idl_scopeStack(scope, "::", name);
    internalTypeName = idl_internalTypeNameForBuiltinTopic(scopedMetaTypeName);
    keyList = idl_keyResolve(idl_keyDefDefGet(), scope, name);
    if ((strlen(internalTypeName) != 0) &&
        ((keyList == NULL) ||
         (strcmp(keyList,"key") == 0))) {
        keyList = "key.localId,key.systemId";
    }
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-meta-type-name", scopedMetaTypeName));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("internal-type-name", internalTypeName));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-actual-type-name", idl_corbaJavaTypeFromTypeSpec(typeSpec)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("key-list", keyList));
    os_free(scopedMetaTypeName);

    /* Generate only in standalone mode */
    if (idl_getCorbaMode() == IDL_MODE_STANDALONE) {
        snprintf(pname, sizeof (pname), "%s%s", javaId, class_base);
        idl_openJavaPackage(scope, pname);
        if (idl_fileCur() == NULL) {
            result = -1;
            goto err_exit;
        }
        /* Prepare Interface class */
        if (generateInterfaceClass) {
            snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%s.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
            /* QAC EXPECT 3416; No side effects here */
            if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
                (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
                printf ("No template found or protection violation (%s)\n", tmplFileName);
                result = -1;
                goto err_exit;
            }
            /* QAC EXPECT 5007; will not use wrapper */
            idlpp_template = os_malloc(tmplStat.stat_size+1);
            tmplFile = open(tmplFileName, O_RDONLY);
            nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
            memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
            close(tmplFile);
            idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
            idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

            te = idl_tmplExpNew(idlpp_macroSet);
            idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
            idl_streamInFree(idlpp_inStream);
            idl_tmplExpFree(te);
            os_free(idlpp_template);
        }
        idl_closeJavaPackage();

        snprintf(pname, sizeof(pname), "%s%sHolder", javaId, class_base);
        idl_openJavaPackage(scope, pname);
        if (idl_fileCur() == NULL) {
            result = -1;
            goto err_exit;
        }
        /* Prepare typeSupportHolder class */
        snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sHolder.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
        /* QAC EXPECT 3416; No side effects here */
        if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
            (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
            printf ("No template found or protection violation (%s)\n", tmplFileName);
            result = -1;
            goto err_exit;
        }
        /* QAC EXPECT 5007; will not use wrapper */
        idlpp_template = os_malloc(tmplStat.stat_size+1);
        tmplFile = open(tmplFileName, O_RDONLY);
        nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
        memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
        close(tmplFile);
        idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
        idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);
        os_free(idlpp_template);

        te = idl_tmplExpNew(idlpp_macroSet);
        idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
        idl_streamInFree(idlpp_inStream);
        idl_tmplExpFree(te);
        idl_closeJavaPackage();

        snprintf(pname, sizeof(pname), "%s%sHelper", javaId, class_base);
        idl_openJavaPackage(scope, pname);
        if (idl_fileCur() == NULL) {
            result = -1;
            goto err_exit;
        }
        /* Prepare typeSupportHelper class */
        snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sHelper.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
        /* QAC EXPECT 3416; No side effects here */
        if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
            (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
            printf ("No template found or protection violation (%s)\n", tmplFileName);
            result = -1;
            goto err_exit;
        }
        /* QAC EXPECT 5007; will not use wrapper */
        idlpp_template = os_malloc(tmplStat.stat_size+1);
        tmplFile = open(tmplFileName, O_RDONLY);
        nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
        memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
        close(tmplFile);
        idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
        idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);
        os_free(idlpp_template);

        te = idl_tmplExpNew(idlpp_macroSet);
        idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
        idl_streamInFree(idlpp_inStream);
        idl_tmplExpFree(te);
        idl_closeJavaPackage();

        snprintf(pname, sizeof(pname), "%s%sOperations", javaId, class_base);
        idl_openJavaPackage(scope, pname);
        if (idl_fileCur() == NULL) {
            result = idl_abort;
            goto err_exit;
        }
        /* Prepare typeSupportOperations class */
        snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sOperations.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
        /* QAC EXPECT 3416; No side effects here */
        if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
            (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
            printf ("No template found or protection violation (%s)\n", tmplFileName);
            result = -1;
            goto err_exit;
        }
        /* QAC EXPECT 5007; will not use wrapper */
        idlpp_template = os_malloc(tmplStat.stat_size+1);
        tmplFile = open(tmplFileName, O_RDONLY);
        nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
        memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
        close(tmplFile);
        idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
        idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);
        os_free(idlpp_template);

        te = idl_tmplExpNew(idlpp_macroSet);
        idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
        idl_streamInFree(idlpp_inStream);
        idl_tmplExpFree(te);
        idl_closeJavaPackage();
    }

    if (generateInterfaceClass) {
        /* Implementation with Impl extension */
        snprintf(pname, sizeof(pname), "%s%sImpl", javaId, class_base);
    } else {
        /* Implementation without Impl extension */
        snprintf(pname, sizeof(pname), "%s%s", javaId, class_base);
    }
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        result = -1;
        goto err_exit;
    }
    /* Prepare typeSupportStub class */
    snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmpl%sImpl.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf("No template found or protection violation (%s)\n", tmplFileName);
        result = idl_abort;
        goto err_exit;
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc(tmplStat.stat_size+1);
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);
    os_free(idlpp_template);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();
err_exit:    
    os_free(javaId);
    os_free(scopeStackJavaDot);
    os_free(scopeStackJavaSlash);
    

    return result;
}
示例#7
0
static int
idl_genTypeSeqHolder(
    idl_scope scope,
    const char *name,
    idl_typeSpec typeSpec)
{
    idl_tmplExp te;
    c_char tmplFileName[1024];
    c_char pname[1024];
    c_char *tmplPath;
    c_char *orbPath;
    int tmplFile;
    struct os_stat_s tmplStat;
    unsigned int nRead;

    tmplPath = os_getenv("OSPL_TMPL_PATH");
    orbPath = os_getenv("OSPL_ORB_PATH");
    if (tmplPath == NULL) {
        printf("OSPL_TMPL_PATH not defined\n");
        return -1;
    }
    if (orbPath == NULL) {
        printf("OSPL_ORB_PATH not defined\n");
        return -1;
    }

    idlpp_macroSet = idl_macroSetNew();
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type-name", idl_javaId(name)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("actual-type-name", idl_typeSpecName(typeSpec)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-type-name", idl_scopeStackJava(scope, ".", name)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-actual-type-name", idl_corbaJavaTypeFromTypeSpec(typeSpec)));

    snprintf(pname, sizeof (pname), "%sSeqHolder", idl_javaId(name));
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return -1;
    }

    /* Prepare typeSupport class */
    snprintf(tmplFileName, sizeof(tmplFileName), "%s%c%s%ctmplSeqHolder.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf("No template found or protection violation (%s)\n", tmplFileName);
        return -1;
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc(tmplStat.stat_size+1);
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, tmplStat.stat_size+1-nRead);
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();

    return 0;
}
示例#8
0
/** @brief callback function called on definition of a named type in the IDL input file.
 *
 * Generate code for the following IDL construct:
 * @verbatim
   =>   typedef <type-name> <name>;
   @endverbatim
 *
 * @param scope Current scope
 * @param name Specifies the name of the type
 * @param defSpec Specifies the type of the named type
 */
static void
idl_typedefOpenClose(
    idl_scope scope,
    const char *name,
    idl_typeDef defSpec,
    void *userData)
{
    int nameLen = strlen(idl_javaId(name)) + strlen("Holder") + 1;
    char *holderName;


    if (idl_typeSpecType(idl_typeDefRefered (defSpec)) == idl_tseq) {
        holderName = os_malloc(nameLen);
        snprintf(holderName, nameLen, "%sHolder", idl_javaId(name));
        /* Open file for used scope, if needed create the directories */
        idl_openJavaPackage(scope, holderName);
        if (idl_fileCur() == NULL) {
            return;
        }
        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(), "public final class %s\n{\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s value = null;\n\n",
            idl_corbaJavaTypeFromTypeSpec(idl_typeSeqActual(idl_typeSeq(idl_typeDefRefered(defSpec)))),
            idl_sequenceIndexString (idl_typeSeq (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    public %s () { }\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s (%s%s initialValue)\n",
            holderName,
            idl_corbaJavaTypeFromTypeSpec(idl_typeSeqActual(idl_typeSeq(idl_typeDefRefered(defSpec)))),
            idl_sequenceIndexString(idl_typeSeq (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    {\n");
        idl_fileOutPrintf(idl_fileCur(), "        value = initialValue;\n");
        idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
        idl_fileOutPrintf(idl_fileCur(), "}\n");
        /* close file */
        idl_closeJavaPackage();
    } else if (idl_typeSpecType(idl_typeDefRefered (defSpec)) == idl_tarray) {
        holderName = os_malloc(nameLen);
        snprintf(holderName, nameLen, "%sHolder", idl_javaId(name));
        /* Open file for used scope, if needed create the directories */
        idl_openJavaPackage(scope, holderName);
        if (idl_fileCur() == NULL) {
            return;
        }
        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(), "public final class %s\n{\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s%s value = null;\n\n",
            idl_corbaJavaTypeFromTypeSpec(idl_typeArrayActual(idl_typeArray(idl_typeDefRefered(defSpec)))),
            idl_arrayJavaIndexString (idl_typeArray (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    public %s () { }\n\n", holderName);
        idl_fileOutPrintf(
            idl_fileCur(),
            "    public %s (%s%s initialValue)\n",
            holderName,
            idl_corbaJavaTypeFromTypeSpec(idl_typeArrayActual(idl_typeArray(idl_typeDefRefered(defSpec)))),
            idl_arrayJavaIndexString(idl_typeArray (idl_typeDefRefered (defSpec))));
        idl_fileOutPrintf(idl_fileCur(), "    {\n");
        idl_fileOutPrintf(idl_fileCur(), "        value = initialValue;\n");
        idl_fileOutPrintf(idl_fileCur(), "    }\n\n");
        idl_fileOutPrintf(idl_fileCur(), "}\n");
        /* close file */
        idl_closeJavaPackage();
    }
}
static int
idl_genInterface(
    idl_scope scope,
    const char *name,
    char *class_base,
    idl_typeSpec typeSpec,
    c_bool generateInterfaceClass)
{
    idl_tmplExp te;
    c_char tmplFileName[1024];
    c_char pname[1024];
    c_char *tmplPath;
    c_char *orbPath;
    int tmplFile;
    struct os_stat tmplStat;
    unsigned int nRead;

    tmplPath = os_getenv("OSPL_TMPL_PATH");
    orbPath = os_getenv("OSPL_ORB_PATH");
    if (tmplPath == NULL) {
        printf("OSPL_TMPL_PATH not defined\n");
        return -1;
    }
    if (orbPath == NULL) {
        printf("OSPL_ORB_PATH not defined\n");
        return -1;
    }

    idlpp_macroSet = idl_macroSetNew();
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("type-name", idl_javaId(name)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("actual-type-name", idl_typeSpecName(typeSpec)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-type-name", idl_scopeStackJava(scope, ".", name)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-class-name", idl_scopeStackJava(scope, "/", name)));
    if(idl_genJavaHelperGetOrgPName())
    {
        idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-org-package-name", idl_genJavaHelperGetOrgPName()));
    } else
    {
        idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-org-package-name", "null"));
    }
    if(idl_genJavaHelperGetTgtPName())
    {
        idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-tgt-package-name", idl_genJavaHelperGetTgtPName()));
    } else
    {
        idl_macroSetAdd(idlpp_macroSet, idl_macroNew("java-tgt-package-name", "null"));
    }
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-meta-type-name", idl_scopeStack(scope, "::", name)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("scoped-actual-type-name", idl_corbaJavaTypeFromTypeSpec(typeSpec)));
    idl_macroSetAdd(idlpp_macroSet, idl_macroNew("key-list", idl_keyResolve(idl_keyDefDefGet(), scope, name)));

    snprintf(pname, sizeof (pname), "%s%s", idl_javaId(name), class_base);
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return -1;
    }
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava (scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    /* Prepare Interface class */
    if (generateInterfaceClass) {
        snprintf(tmplFileName, (size_t)sizeof(tmplFileName), "%s%c%s%ctmpl%s.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
        /* QAC EXPECT 3416; No side effects here */
        if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
            (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
            printf ("No template found or protection violation (%s)\n", tmplFileName);
            return -1;
        }
        /* QAC EXPECT 5007; will not use wrapper */
        idlpp_template = os_malloc((size_t)((int)tmplStat.stat_size+1));
        tmplFile = open(tmplFileName, O_RDONLY);
        nRead = (unsigned int)read(tmplFile, idlpp_template, (size_t)tmplStat.stat_size);
        memset(&idlpp_template[nRead], 0, (size_t)((int)tmplStat.stat_size+1-nRead));
        close(tmplFile);
        idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
        idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

        te = idl_tmplExpNew(idlpp_macroSet);
        idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
        idl_streamInFree(idlpp_inStream);
        idl_tmplExpFree(te);
    }
    idl_closeJavaPackage();

    snprintf(pname, sizeof(pname), "%s%sHolder", idl_javaId(name), class_base);
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return -1;
    }
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava(scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    /* Prepare typeSupportHolder class */
    snprintf(tmplFileName, (size_t)sizeof(tmplFileName), "%s%c%s%ctmpl%sHolder.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf ("No template found or protection violation (%s)\n", tmplFileName);
        return -1;
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc((size_t)((int)tmplStat.stat_size+1));
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, (size_t)tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, (size_t)((int)tmplStat.stat_size+1-nRead));
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();

    snprintf(pname, sizeof(pname), "%s%sHelper", idl_javaId(name), class_base);
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return -1;
    }
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava(scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    /* Prepare typeSupportHelper class */
    snprintf(tmplFileName, (size_t)sizeof(tmplFileName), "%s%c%s%ctmpl%sHelper.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf ("No template found or protection violation (%s)\n", tmplFileName);
        return -1;
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc((size_t)((int)tmplStat.stat_size+1));
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, (size_t)tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, (size_t)((int)tmplStat.stat_size+1-nRead));
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();

    snprintf(pname, sizeof(pname), "%s%sOperations", idl_javaId(name), class_base);
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return (idl_abort);
    }
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava(scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    /* Prepare typeSupportOperations class */
    snprintf(tmplFileName, (size_t)sizeof(tmplFileName), "%s%c%s%ctmpl%sOperations.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf ("No template found or protection violation (%s)\n", tmplFileName);
        return -1;
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc((size_t)((int)tmplStat.stat_size+1));
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, (size_t)tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, (size_t)((int)tmplStat.stat_size+1-nRead));
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();

    if (generateInterfaceClass) {
        /* Implementation with Impl extension */
        snprintf(pname, sizeof(pname), "%s%sImpl", idl_javaId(name), class_base);
    } else {
        /* Implementation without Impl extension */
        snprintf(pname, sizeof(pname), "%s%s", idl_javaId(name), class_base);
    }
    idl_openJavaPackage(scope, pname);
    if (idl_fileCur() == NULL) {
        return -1;
    }
    if (idl_scopeStackSize(scope) > 0) {
        idl_fileOutPrintf(idl_fileCur(), "package %s;\n", idl_scopeStackJava(scope, ".", NULL));
        idl_fileOutPrintf(idl_fileCur(), "\n");
    }
    /* Prepare typeSupportStub class */
    snprintf(tmplFileName, (size_t)sizeof(tmplFileName), "%s%c%s%ctmpl%sImpl.java", tmplPath, OS_FILESEPCHAR, orbPath, OS_FILESEPCHAR, class_base);
    /* QAC EXPECT 3416; No side effects here */
    if ((os_stat(tmplFileName, &tmplStat) != os_resultSuccess) ||
        (os_access(tmplFileName, OS_ROK) != os_resultSuccess)) {
        printf("No template found or protection violation (%s)\n", tmplFileName);
        return (idl_abort);
    }
    /* QAC EXPECT 5007; will not use wrapper */
    idlpp_template = os_malloc((size_t)((int)tmplStat.stat_size+1));
    tmplFile = open(tmplFileName, O_RDONLY);
    nRead = (unsigned int)read(tmplFile, idlpp_template, (size_t)tmplStat.stat_size);
    memset(&idlpp_template[nRead], 0, (size_t)((int)tmplStat.stat_size+1-nRead));
    close(tmplFile);
    idlpp_macroAttrib = idl_macroAttribNew(IDL_TOKEN_START, IDL_TOKEN_OPEN, IDL_TOKEN_CLOSE);
    idlpp_inStream = idl_streamInNew(idlpp_template, idlpp_macroAttrib);

    te = idl_tmplExpNew(idlpp_macroSet);
    idl_tmplExpProcessTmpl(te, idlpp_inStream, idl_fileCur());
    idl_streamInFree(idlpp_inStream);
    idl_tmplExpFree(te);
    idl_closeJavaPackage();

    return 0;
}