/** @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; }
/* Translate an IDL identifier into a language specific identifier. The IDL specification states that all identifiers that match a language keyword must be prepended by a language specific prefix. */ c_char * idl_languageId( const char *identifier) { c_char *id = NULL; switch (lang) { case IDL_LANG_C: id = idl_cId (identifier); break; case IDL_LANG_CXX: id = idl_cxxId (identifier); break; case IDL_LANG_CS: id = idl_CsharpId (identifier, FALSE, FALSE); break; case IDL_LANG_JAVA: id = idl_javaId (identifier); break; case IDL_LANG_UNKNOWN: default: break; } return id; }
/** @brief callback function called on closure of an enumeration in the IDL input file. * * Generate code for the following IDL construct: * @verbatim enum <enum-name> { <enum-element-1>; ... ... <enum-element-n>; => }; @endverbatim * * @param name Name of the enumeration */ static void idl_enumerationClose( const char *name, void *userData) { idl_fileOutPrintf(idl_fileCur(), " public int value ()\n"); idl_fileOutPrintf(idl_fileCur(), " {\n"); idl_fileOutPrintf(idl_fileCur(), " return __value;\n"); idl_fileOutPrintf(idl_fileCur(), " }\n\n"); idl_fileOutPrintf( idl_fileCur(), " public static %s from_int (int value)\n", enum_def); idl_fileOutPrintf(idl_fileCur(), " {\n"); idl_fileOutPrintf(idl_fileCur(), " if (value >= 0 && value < __size) {\n"); idl_fileOutPrintf(idl_fileCur(), " return __array[value];\n"); idl_fileOutPrintf(idl_fileCur(), " } else {\n"); idl_fileOutPrintf(idl_fileCur(), " throw Utilities.createException(Utilities.EXCEPTION_TYPE_BAD_OPERATION, null);\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); idl_fileOutPrintf(idl_fileCur(), " }\n\n"); idl_fileOutPrintf( idl_fileCur(), " protected %s (int value)\n", idl_javaId(name)); idl_fileOutPrintf(idl_fileCur(), " {\n"); idl_fileOutPrintf(idl_fileCur(), " __value = value;\n"); idl_fileOutPrintf(idl_fileCur(), " __array[__value] = this;\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); /* close class */ idl_fileOutPrintf(idl_fileCur(), "}\n"); /* close file */ idl_closeJavaPackage(); }
/** @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; }
/** @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; }
/** @brief callback function called on definition of an enumeration element in the IDL input file. * * Generate code for the following IDL construct: * @verbatim enum <enum-name> { => <enum-element-1>, => ... ... => <enum-element-n> }; @endverbatim * * For the last element generate: * @verbatim <element-name> @endverbatim * For any but the last element generate: * @verbatim <element-name>, @endverbatim * * @param scope Current scope * @param name Name of the enumeration element */ static void idl_enumerationElementOpenClose ( idl_scope scope, const char *name, void *userData) { idl_fileOutPrintf( idl_fileCur(), " public static final int _%s = %d;\n", idl_javaId(name), enum_element); idl_fileOutPrintf( idl_fileCur(), " public static final %s %s = new %s(_%s);\n\n", enum_def, idl_javaId(name), enum_def, idl_javaId(name)); enum_element++; }
/** @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; }
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"); }
/* Build a textual presenation of the provided scope stack taking the Java keyword identifier translation into account. Further the function equals "idl_scopeStack". */ c_char * idl_scopeStackJava ( idl_scope scope, const char *scopeSepp, const char *name) { c_long si; c_long sz; c_char *scopeStack; c_char *Id; if(orgLastSubstituted) { os_free(orgLastSubstituted); orgLastSubstituted = NULL; } if(tarLastSubstituted) { os_free(tarLastSubstituted); tarLastSubstituted = NULL; } si = 0; sz = idl_scopeStackSize(scope); if (si < sz) { /* The scope stack is not empty */ /* Copy the first scope element name */ scopeStack = os_strdup(idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si)))); si++; while (si < sz) { /* Translate the scope name to a C identifier */ Id = idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si))); /* allocate space for the current scope stack + the separator and the next scope name */ /* QAC EXPECT 5007; will not use wrapper */ scopeStack = os_realloc(scopeStack, (size_t)( (int)strlen(scopeStack)+ (int)strlen(scopeSepp)+ (int)strlen(Id)+1)); /* Concatenate the separator */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat(scopeStack, scopeSepp); /* Concatenate the scope name */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat (scopeStack, Id); si++; } if(strlen(scopeStack) > 0) { os_char* ptr; os_char* ptr2; os_char* ptr3; /* es, dds1540: The following code is not pretty, but time limitations * required it's implementation. To ensure * proper substitution of for example package name 'Chat' with * 'org.opensplice.Chat' without substitution class names like * 'ChatMessage' to 'org.opensplice.ChatMessage' we need to take some * special arrangements. We need to allow the user to state he wants to * replace 'Chat.' with ''org.opensplice.Chat.', as this would resolve * the previously stated problem. * However this function for getting the scope stack is called in a * special way if only the package names are required (without the * specific class at the end). In these cases package Chat would become * in string format 'Chat' instead of 'Chat.'. And this would cause * problems when doing the substitution for the directory names and * package directives. So to ensure substitution always goes correctly * we added the scopeSepp to the end of the scopeStack and input that * into the substitution algorithm. After the algorithm we remove the * added scopeSepp again. * So not that nicely solved, but lack of time to do it more nicely * (which would be to support regular expression type things) --> No. */ ptr = os_malloc(strlen(scopeStack)+ strlen(scopeSepp) + 1); os_strcpy(ptr, scopeStack); os_strncat(ptr, scopeSepp, strlen(scopeSepp)); ptr2 = idl_genJavaHelperApplyPackageSubstitute(ptr, scopeSepp); memset(ptr, 0, strlen(ptr)); os_free(ptr); ptr3 = strrchr(ptr2, *scopeSepp); if(ptr3) { *ptr3 = '\0'; } ptr = os_strdup(ptr2); memset(ptr2, 0, strlen(ptr2)); os_free(ptr2); memset(scopeStack, 0, strlen(scopeStack)); os_free(scopeStack); scopeStack = ptr; } if (name) { /* A user identifier is specified */ /* Translate the user identifier to a Java identifier */ Id = idl_javaId(name); /* allocate space for the current scope stack + the separator and the user identifier */ /* QAC EXPECT 5007; will not use wrapper */ scopeStack = os_realloc(scopeStack, (size_t)( (int)strlen(scopeStack)+ (int)strlen(scopeSepp)+ (int)strlen(Id)+1)); /* Concatenate the separator */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat(scopeStack, scopeSepp); /* Concatenate the user identifier */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat (scopeStack, Id); } } else { /* The stack is empty */ if (name) { /* A user identifier is specified */ scopeStack = os_strdup(idl_javaId(name)); } else { /* make the stack represenation empty */ scopeStack = os_strdup(""); } } /* return the scope stack representation */ return scopeStack; }
c_char * idl_genJavaLiteralValueImage( c_value literal, c_type type) { c_char * valueImg = NULL; c_char *val2; int i; if (c_baseObject(type)->kind != M_ENUMERATION) { switch (literal.kind) { case V_OCTET: valueImg = os_malloc (40); snprintf(valueImg, 40, "%d", literal.is.Octet); break; case V_FLOAT: case V_DOUBLE: val2 = os_malloc(45); valueImg = os_malloc(45); snprintf(val2, 45, "%40.17g", literal.is.Double); i = 0; while (val2[i] == ' ') { i++; } os_strncpy(valueImg, &val2[i], 40); os_free(val2); if ((strchr(valueImg, '.') == NULL) && (strchr(valueImg, 'E') == NULL)) { strcat(valueImg, ".0"); } break; case V_STRING: valueImg = os_malloc(strlen(literal.is.String)+3); snprintf(valueImg, strlen(literal.is.String)+3, "\"%s\"", literal.is.String); break; case V_BOOLEAN: valueImg = os_malloc(40); if (literal.is.Boolean) { snprintf(valueImg, 40, "true"); } else { snprintf (valueImg, 40, "false"); } break; case V_LONGLONG: valueImg = os_malloc(40); switch (c_primitive(type)->kind) { case P_SHORT: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%hu", (c_short)literal.is.LongLong); break; case P_USHORT: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%hd", (c_short)literal.is.LongLong); break; case P_LONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%u", (c_long)literal.is.LongLong); break; case P_ULONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%d", (c_long)literal.is.LongLong); break; case P_LONGLONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ snprintf(valueImg, 40, "%"PA_PRIu64"L", (c_longlong)literal.is.LongLong); break; case P_ULONGLONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ snprintf(valueImg, 40, "%"PA_PRId64"L", (c_longlong)literal.is.LongLong); break; case P_CHAR: snprintf(valueImg, 40, "%d", (unsigned char)literal.is.LongLong); break; case P_OCTET: snprintf(valueImg, 40, "%d", (unsigned char)literal.is.LongLong); break; case P_ADDRESS: snprintf(valueImg, 40, PA_ADDRFMT, (PA_ADDRCAST)literal.is.LongLong); break; case P_UNDEFINED: case P_BOOLEAN: case P_WCHAR: case P_FLOAT: case P_DOUBLE: case P_VOIDP: case P_MUTEX: case P_LOCK: case P_COND: case P_COUNT: case P_PA_UINT32: case P_PA_UINTPTR: case P_PA_VOIDP: /* Do nothing */ break; } break; case V_SHORT: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%hu", literal.is.Short); break; case V_LONG: /* Apply unsigned version, since sign will be applied later as additional minus operand. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%u", (c_long)literal.is.Long); break; case V_USHORT: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%hd", (c_short)literal.is.UShort); break; case V_ULONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%d", (c_long)literal.is.ULong); break; case V_ULONGLONG: /* Apply signed version, since Java has no unsigned types and therefore needs to * overflow into the negative range. */ valueImg = os_malloc(40); snprintf(valueImg, 40, "%" PA_PRId64, (c_longlong)literal.is.ULongLong); break; case V_ADDRESS: valueImg = os_malloc(40); snprintf(valueImg, 40, PA_ADDRFMT, (PA_ADDRCAST)literal.is.Address); break; case V_CHAR: valueImg = os_malloc(40); snprintf(valueImg, 40, "%u", (unsigned char)literal.is.Char); break; case V_UNDEFINED: case V_WCHAR: case V_WSTRING: case V_FIXED: case V_VOIDP: case V_OBJECT: case V_COUNT: /* Invalid types for literal constants*/ /* FALL THROUGH */ default: valueImg = NULL; break; } } else { const char *ENUM_TEMPLATE = "%s.%s"; char *javaEnumTp = idl_javaId(c_metaObject(type)->name); char *javaEnumLabel = idl_javaId(c_metaObject(c_enumeration(type)->elements[literal.is.Long])->name); size_t valLen = strlen(javaEnumTp) + strlen(javaEnumLabel) + strlen(ENUM_TEMPLATE) + 1; valueImg = os_malloc(valLen); snprintf(valueImg, valLen, ENUM_TEMPLATE, javaEnumTp, javaEnumLabel); os_free(javaEnumTp); os_free(javaEnumLabel); } return valueImg; }
/* Build a textual presentation of the provided scope stack taking the * Java keyword identifier translation into account. Further the function * equals "idl_scopeStack". */ c_char * idl_scopeStackJava ( idl_scope scope, const char *scopeSepp, const char *name) { c_long si; c_long sz; c_char *scopeStack = NULL; c_char *Id; os_char *substitute; os_char *module, *package; os_uint32 cnt, rlen; idl_packageRedirect redirect; assert (scopeSepp != NULL); scopeStack = os_strdup (""); for (si = 0, sz = idl_scopeStackSize(scope); si < sz; si++) { size_t slen; /* Translate the scope name to a C identifier */ Id = idl_javaId(idl_scopeJavaElementName(idl_scopeIndexed(scope, si))); /* allocate space for the current scope stack + the separator *and the next scope name */ /* QAC EXPECT 5007; will not use wrapper */ slen = strlen (scopeStack) + strlen (scopeSepp) + strlen (Id); scopeStack = os_realloc(scopeStack, slen + 1); /* Concatenate the separator */ /* QAC EXPECT 5007; will not use wrapper */ if (strlen(scopeStack)) { os_strcat(scopeStack, scopeSepp); } /* Concatenate the scope name */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat (scopeStack, Id); } /* idl_genJavaHelperPackageRedirects must be sorted */ substitute = scopeStack; rlen = os_iterLength (idl_genJavaHelperPackageRedirects); for (cnt = 0; cnt < rlen && substitute == scopeStack; cnt++) { redirect = idl_packageRedirect ( os_iterObject (idl_genJavaHelperPackageRedirects, cnt)); assert (redirect != NULL); package = os_str_replace (redirect->package, ".", scopeSepp, 0); if (package != NULL) { if (redirect->module != NULL) { module = os_str_replace (redirect->module, ".", scopeSepp, 0); if (module == NULL) { substitute = NULL; } else { substitute = os_str_word_replace ( scopeStack, scopeSepp, module, package, 1); if (module != redirect->module) { os_free (module); } } } else { substitute = os_malloc ( strlen (package) + strlen (scopeSepp) + strlen (scopeStack) + 1 /* '\0' */); if (substitute != NULL) { (void)strcpy (substitute, package); if (strlen (scopeStack)) { (void)os_strcat (substitute, scopeSepp); (void)os_strcat (substitute, scopeStack); } } } if (package != redirect->package) { os_free (package); } } } if (substitute != scopeStack) { os_free (scopeStack); scopeStack = substitute; } if (name) { /* A user identifier is specified */ /* Translate the user identifier to a Java identifier */ Id = idl_javaId(name); /* allocate space for the current scope stack + the separator * and the user identifier */ /* QAC EXPECT 5007; will not use wrapper */ scopeStack = os_realloc(scopeStack, strlen(scopeStack)+strlen(scopeSepp)+strlen(Id)+1); /* Concatenate the separator */ /* QAC EXPECT 5007; will not use wrapper */ if (strlen(scopeStack)) { os_strcat(scopeStack, scopeSepp); } /* Concatenate the user identifier */ /* QAC EXPECT 5007; will not use wrapper */ os_strcat (scopeStack, Id); } /* return the scope stack representation */ return scopeStack; }
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; }
/** @brief callback function called on definition of a structure member 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 * @param name Name of the structure member * @param typeSpec Type specification of the structure member */ static void idl_structureMemberOpenClose( idl_scope scope, const char *name, idl_typeSpec typeSpec, void *userData) { /* Dereference possible typedefs first. */ while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } /* generate type-name and field-name attribute */ if ((idl_typeSpecType(typeSpec) == idl_tbasic)) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_string) { idl_fileOutPrintf( idl_fileCur(), " public %s %s = \"\";\n", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(name)); } else { idl_fileOutPrintf( idl_fileCur(), " public %s %s;\n", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(name)); } } else if (idl_typeSpecType(typeSpec) == idl_tseq) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); /* Inline sequence definition */ idl_fileOutPrintf( idl_fileCur(), " public %s%s %s = new %s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_sequenceIndexString(idl_typeSeq(typeSpec)), idl_javaId(name), idl_corbaJavaTypeFromTypeSpec(typeSpec)); java_arrayDimensions(typeSpec); idl_fileOutPrintf (idl_fileCur(), ";\n"); } else if (idl_typeSpecType(typeSpec) == idl_tarray) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); /* Inline array definition */ idl_fileOutPrintf( idl_fileCur(), " public %s%s %s = new %s", idl_corbaJavaTypeFromTypeSpec (typeSpec), idl_arrayJavaIndexString(idl_typeArray(typeSpec)), idl_javaId(name), idl_corbaJavaTypeFromTypeSpec (typeSpec)); java_arrayDimensions(typeSpec); idl_fileOutPrintf (idl_fileCur(), ";\n"); } else if (idl_typeSpecType(typeSpec) == idl_tstruct) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); idl_fileOutPrintf( idl_fileCur(), " public %s %s = new %s();\n", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(name), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else if (idl_typeSpecType(typeSpec) == idl_tenum) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); idl_fileOutPrintf( idl_fileCur(), " public %s %s = %s.from_int(0);\n", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(name), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else if (idl_typeSpecType (typeSpec) == idl_tunion) { /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); idl_fileOutPrintf( idl_fileCur(), " public %s %s = new %s();\n", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(name), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else { printf("idl_genSajType.c:idl_structureMemberOpenClose: Unexpected type %d\n", idl_typeSpecType(typeSpec)); } }
/** @brief callback function called on end of a 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 * * The structure is closed: * @verbatim }; @endverbatim * * @param name Name of the structure (not used) */ static void idl_structureClose( const char *name, void *userData) { idl_mapIter mapIter; idl_typeSpec typeSpec; char *memberName; /* build constructor <type-name> () {} */ idl_fileOutPrintf(idl_fileCur(), "\n"); idl_fileOutPrintf(idl_fileCur(), " public %s() {\n", idl_javaId(name)); mapIter = idl_mapFirst(map); while (idl_mapIterObject(mapIter)) { typeSpec = idl_mapIterObject(mapIter); memberName = idl_mapIterKey(mapIter); idl_ifArrayInitializeElements(typeSpec, memberName); idl_mapIterNext(mapIter); } idl_fileOutPrintf(idl_fileCur(), " }\n\n"); /* build constructor <type-name> (<arglist>) { <assignment-list> } */ idl_fileOutPrintf(idl_fileCur(), " public %s(\n", idl_javaId(name)); mapIter = idl_mapFirst(map); while (idl_mapIterObject(mapIter)) { typeSpec = idl_mapIterObject(mapIter); memberName = idl_mapIterKey(mapIter); if (idl_typeSpecType(typeSpec) == idl_tbasic) { idl_fileOutPrintf( idl_fileCur(), " %s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), memberName); } else if (idl_typeSpecType(typeSpec) == idl_tseq) { idl_fileOutPrintf( idl_fileCur(), " %s%s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_sequenceIndexString(idl_typeSeq(typeSpec)), memberName); } else if (idl_typeSpecType(typeSpec) == idl_tarray) { idl_fileOutPrintf( idl_fileCur(), " %s%s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_arrayJavaIndexString(idl_typeArray(typeSpec)), memberName); } else { if (idl_typeSpecType(typeSpec) == idl_ttypedef) { if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tbasic) { idl_fileOutPrintf( idl_fileCur(), " %s _%s", idl_corbaJavaTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec))), memberName); } else if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tseq) { idl_fileOutPrintf( idl_fileCur(), " %s%s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_sequenceIndexString(idl_typeSeq(idl_typeDefActual(idl_typeDef(typeSpec)))), memberName); } else if (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tarray) { idl_fileOutPrintf( idl_fileCur(), " %s%s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_arrayJavaIndexString(idl_typeArray(idl_typeDefActual(idl_typeDef(typeSpec)))), memberName); } else { if ((idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tstruct) || (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tunion) || (idl_typeSpecType(idl_typeDefActual(idl_typeDef(typeSpec))) == idl_tenum)) { idl_fileOutPrintf( idl_fileCur(), " %s _%s", idl_corbaJavaTypeFromTypeSpec(idl_typeDefActual(idl_typeDef(typeSpec))), idl_javaId(memberName)); } else { printf("idl_genSajType.c:idl_structureClose: Unexpected type %d\n", idl_typeSpecType (typeSpec)); } } } else { if ((idl_typeSpecType(typeSpec) == idl_tstruct) || (idl_typeSpecType(typeSpec) == idl_tunion) || (idl_typeSpecType(typeSpec) == idl_tenum)) { idl_fileOutPrintf( idl_fileCur(), " %s _%s", idl_corbaJavaTypeFromTypeSpec(typeSpec), idl_javaId(memberName)); } else { printf("idl_genSajType.c:idl_structureClose: Unexpected type %d\n", idl_typeSpecType(typeSpec)); } } } idl_mapIterNext(mapIter); if (idl_mapIterObject(mapIter)) { idl_fileOutPrintf(idl_fileCur(), ",\n"); } else { idl_fileOutPrintf(idl_fileCur(), ")\n"); } } idl_mapIterFree(mapIter); idl_fileOutPrintf(idl_fileCur(), " {\n"); mapIter = idl_mapFirst(map); while (idl_mapIterObject(mapIter)) { idl_fileOutPrintf( idl_fileCur(), " %s = _%s;\n", idl_mapIterKey(mapIter), idl_mapIterKey(mapIter)); idl_mapIterNext (mapIter); } idl_mapIterFree(mapIter); idl_fileOutPrintf(idl_fileCur(), " }\n\n"); /* close class */ idl_fileOutPrintf(idl_fileCur(), "}\n"); /* close file */ idl_closeJavaPackage(); /* remove iterator */ idl_mapFree(map); }
/** @brief callback function called on closure 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 * * The union is closed: * @verbatim } _u; }; @endverbatim * @param name Name of the union */ static void idl_unionClose( const char *name, void *userData) { idl_mapIter mapIter; idl_typeSpec typeSpec; char *memberName; mapIter = idl_mapFirst(map); typeSpec = idl_mapIterObject(mapIter); memberName = idl_mapIterKey(mapIter); idl_fileOutPrintf(idl_fileCur(), " public %s () {\n", idl_javaId(name)); while (idl_typeSpecType(typeSpec) == idl_ttypedef) { typeSpec = idl_typeDefRefered(idl_typeDef(typeSpec)); } if (idl_typeSpecType(typeSpec) == idl_tbasic) { if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_string) { idl_fileOutPrintf( idl_fileCur(), " __%s = \"\";\n", idl_javaId(memberName)); } else if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_boolean) { idl_fileOutPrintf( idl_fileCur(), " __%s = false;\n", idl_javaId(memberName)); } else if (idl_typeBasicType(idl_typeBasic (typeSpec)) == idl_char) { idl_fileOutPrintf( idl_fileCur(), " __%s = '\\0';\n", idl_javaId(memberName)); } else { idl_fileOutPrintf( idl_fileCur(), " __%s = 0;\n", idl_javaId(memberName)); } } else if (idl_typeSpecType(typeSpec) == idl_tseq || idl_typeSpecType(typeSpec) == idl_tarray) { int __memberNameLength; char *__memberName; __memberNameLength = strlen(memberName) + 2 + 1; __memberName = os_malloc(__memberNameLength); snprintf(__memberName, __memberNameLength, "__%s", memberName); idl_fileOutPrintf( idl_fileCur(), " __%s = new %s", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); java_arrayDimensions(typeSpec); idl_fileOutPrintf(idl_fileCur(), ";\n"); idl_ifArrayInitializeElements(typeSpec, __memberName); os_free(__memberName); } else if (idl_typeSpecType(typeSpec) == idl_tstruct || idl_typeSpecType(typeSpec) == idl_tunion) { idl_fileOutPrintf( idl_fileCur(), " __%s = new %s();\n", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } else if (idl_typeSpecType(typeSpec) == idl_tenum) { idl_fileOutPrintf( idl_fileCur(), " __%s = %s.from_int(0);\n", idl_javaId(memberName), idl_corbaJavaTypeFromTypeSpec(typeSpec)); } idl_fileOutPrintf(idl_fileCur(), " _d = (%s)%s;\n", unionSwitchType, union1stCaseValue); idl_fileOutPrintf(idl_fileCur(), " }\n"); idl_mapIterFree(mapIter); idl_mapFree(map); union1stCaseValue = NULL; /* close class */ idl_fileOutPrintf(idl_fileCur(), "}\n"); /* close file */ idl_closeJavaPackage(); }
/** @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(); } }
/** @brief callback function called on definition of a union case 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 (the union the union case is defined in) * @param name Name of the union case * @param typeSpec Specifies the type of the union case */ static void idl_unionCaseOpenClose( idl_scope scope, const char *name, idl_typeSpec typeSpec, void *userData) { char *labelImage; long nrElements, i; /* store type-name and field-name in iterator (append) */ idl_mapAdd(map, idl_javaId(name), typeSpec); /* Obtain name of first label and total number of labels. */ nrElements = os_iterLength(labelIter); labelImage = os_iterObject(labelIter, 0); /* Save the 1st case label for usage with the default constructor. */ if (!union1stCaseValue) { union1stCaseValue = os_iterObject(labelIter, 0); } idl_fileOutPrintf( idl_fileCur(), " private %s __%s;\n\n", idl_unionCaseTypeFromTypeSpec(typeSpec), idl_javaId(name)); idl_fileOutPrintf( idl_fileCur(), " public %s %s ()\n", idl_unionCaseTypeFromTypeSpec (typeSpec), idl_javaId(name)); idl_fileOutPrintf(idl_fileCur(), " {\n"); if (caseIsDefault == FALSE) { idl_fileOutPrintf(idl_fileCur(), " if (_d != %s", labelImage); for (i = 1; i < nrElements; i++) { labelImage = os_iterObject(labelIter, i); idl_fileOutPrintf(idl_fileCur(), " &&\n _d != %s", labelImage); } idl_fileOutPrintf(idl_fileCur(), ") {\n"); idl_fileOutPrintf(idl_fileCur(), " throw Utilities.createException(Utilities.EXCEPTION_TYPE_BAD_OPERATION, null);\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); } else { if(os_iterLength(labelsUsedIter)) { labelImage = os_iterObject(labelsUsedIter, 0); idl_fileOutPrintf(idl_fileCur(), " if (_d == %s", labelImage); nrElements = os_iterLength(labelsUsedIter); for (i = 1; i < nrElements; i++) { labelImage = os_iterObject(labelsUsedIter, i); idl_fileOutPrintf(idl_fileCur(), " ||\n _d == %s", labelImage); } idl_fileOutPrintf(idl_fileCur(), ") {\n"); idl_fileOutPrintf(idl_fileCur(), " throw Utilities.createException(Utilities.EXCEPTION_TYPE_BAD_OPERATION, null);\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); } } idl_fileOutPrintf(idl_fileCur(), " return __%s;\n", idl_javaId(name)); idl_fileOutPrintf(idl_fileCur(), " }\n\n"); idl_fileOutPrintf( idl_fileCur(), " public void %s (%s val)\n", idl_javaId(name), idl_unionCaseTypeFromTypeSpec(typeSpec)); idl_fileOutPrintf(idl_fileCur(), " {\n"); idl_fileOutPrintf(idl_fileCur(), " __%s = val;\n", idl_javaId(name)); labelImage = os_iterObject(labelIter, 0); if (labelImage) { idl_fileOutPrintf(idl_fileCur(), " _d = (%s)%s;\n", unionSwitchType, labelImage); } else { /* Theoretically this branch should never be reached: also the code underneath doesn't make any sense. That's why an assert has now been substituted. labelImage = os_iterObject(labelsUsedIter, 0); idl_fileOutPrintf(idl_fileCur(), " _d = (%s)%s;\n", unionSwitchType, labelImage); */ assert(FALSE); } idl_fileOutPrintf(idl_fileCur(), " }\n\n"); idl_fileOutPrintf( idl_fileCur(), " public void %s (%s d, %s val)\n", idl_javaId(name), unionSwitchType, idl_unionCaseTypeFromTypeSpec (typeSpec)); idl_fileOutPrintf(idl_fileCur(), " {\n"); if (caseIsDefault == FALSE) { labelImage = os_iterTakeFirst(labelIter); idl_fileOutPrintf(idl_fileCur(), " if (d != (%s)%s", unionSwitchType, labelImage); labelImage = os_iterTakeFirst(labelIter); while (labelImage) { idl_fileOutPrintf(idl_fileCur(), " &&\n d != (%s)%s", unionSwitchType, labelImage); labelImage = os_iterTakeFirst (labelIter); } idl_fileOutPrintf(idl_fileCur(), ") {\n"); idl_fileOutPrintf(idl_fileCur(), " throw Utilities.createException(Utilities.EXCEPTION_TYPE_BAD_OPERATION, null);\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); } else { if(os_iterLength(labelsUsedIter)) { labelImage = os_iterTakeFirst(labelsUsedIter); idl_fileOutPrintf(idl_fileCur(), " if (d == (%s)%s", unionSwitchType, labelImage); labelImage = os_iterTakeFirst(labelsUsedIter); while (labelImage) { idl_fileOutPrintf(idl_fileCur(), " ||\n d == (%s)%s", unionSwitchType, labelImage); labelImage = os_iterTakeFirst(labelsUsedIter); } idl_fileOutPrintf(idl_fileCur(), ") {\n"); idl_fileOutPrintf(idl_fileCur(), " throw Utilities.createException(Utilities.EXCEPTION_TYPE_BAD_OPERATION, null);\n"); idl_fileOutPrintf(idl_fileCur(), " }\n"); } } idl_fileOutPrintf(idl_fileCur(), " __%s = val;\n", idl_javaId(name)); idl_fileOutPrintf(idl_fileCur(), " _d = d;\n"); idl_fileOutPrintf(idl_fileCur(), " }\n\n"); }
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; }
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; }