Beispiel #1
0
/** Print out the JSON exception information */
static int printJsonExceptionV(struct jsonException *exc, int noPrintFlags,
                               const char *fmt, va_list ap)
{
    char *javaClassName = NULL;
    int excErrno = EINTERNAL, shouldPrint = 0;
    if (!exc) {
        fprintf(stderr, "printJsonExceptionV: the jsonException is NULL\n");
        return EINTERNAL;
    }
    javaClassName = strdup(exc->javaClassName);
    if (!javaClassName) {
        fprintf(stderr, "printJsonExceptionV: internal out of memory error\n");
        return EINTERNAL;
    }
    dotsToSlashes(javaClassName);
    getExceptionInfo(javaClassName, noPrintFlags, &excErrno, &shouldPrint);
    free(javaClassName);
    
    if (shouldPrint) {
        vfprintf(stderr, fmt, ap);
        fprintf(stderr, " error:\n");
        fprintf(stderr, "Exception: %s\nJavaClassName: %s\nMessage: %s\n",
                exc->exception, exc->javaClassName, exc->message);
    }
    
    free(exc);
    return excErrno;
}
Beispiel #2
0
int emitCpp(ZCMGen& zcm)
{
    // iterate through all defined message types
    for (auto& ls : zcm.structs) {
        string tn = dotsToSlashes(ls.structname.fullname);

        // compute the target filename
        string hpath = zcm.gopt->getString("cpp-hpath");
        string headerName = hpath + (hpath.size() > 0 ? "/" : ":") + tn +".hpp";

        // generate code if needed
        if (zcm.needsGeneration(ls.zcmfile, headerName)) {
            FileUtil::makeDirsForFile(headerName);
            Emit E{zcm, ls, headerName};
            if (!E.good())
                return -1;
            E.emitHeader();

        }
    }

    return 0;
}
Beispiel #3
0
    void emitHeaderStart()
    {
        const char *tn = ls.structname.fullname.c_str();
        const char *sn = ls.structname.shortname.c_str();
        string tnDots = dotsToUnderscores(ls.structname.fullname);
        const char *tn_ = tnDots.c_str();

        emitAutoGeneratedWarning();

        emit(0, "#include <zcm/zcm_coretypes.h>");
        emit(0, "");
        emit(0, "#ifndef __%s_hpp__", tn_);
        emit(0, "#define __%s_hpp__", tn_);
        emit(0, "");

        // do we need to #include <vector> and/or <string>?
        bool emitIncludeVector = false;
        bool emitIncludeString = false;
        for (auto& lm : ls.members) {
            if (!emitIncludeVector &&
                lm.dimensions.size() != 0 && !lm.isConstantSizeArray()) {
                emit(0, "#include <vector>");
                emitIncludeVector = true;
            }
            if (!emitIncludeString &&
                lm.type.fullname == "string") {
                emit(0, "#include <string>");
                emitIncludeString = true;
            }
        }

        // include header files for other ZCM types
        for (auto& lm : ls.members) {
            auto& mtn = lm.type.fullname;
            if (!ZCMGen::isPrimitiveType(mtn) && mtn != tn) {
                emit(0, "#include \"%s%s%s.hpp\"",
                     zcm.gopt->getString("cpp-include").c_str(),
                     zcm.gopt->getString("cpp-include").size()>0 ? "/":"",
                     dotsToSlashes(mtn).c_str());
            }
        }

        emit(0, "\n");
        emitPackageNamespaceStart();

        // define the class
        emitComment(0, ls.comment);
        emit(0, "class %s", sn);
        emit(0, "{");

        // data members
        if(ls.members.size() > 0) {
            emit(1, "public:");
            for (auto& lm : ls.members) {
                auto& mtn = lm.type.fullname;
                emitComment(2, lm.comment);
                string mappedTypename = mapTypeName(mtn);
                int ndim = (int)lm.dimensions.size();
                if (ndim == 0) {
                    emit(2, "%-10s %s;", mappedTypename.c_str(), lm.membername.c_str());
                } else {
                    if (lm.isConstantSizeArray()) {
                        emitStart(2, "%-10s %s", mappedTypename.c_str(), lm.membername.c_str());
                        for (auto& ld : lm.dimensions)
                            emitContinue("[%s]", ld.size.c_str());
                        emitEnd(";");
                    } else {
                        emitStart(2, "");
                        for (int d = 0; d < ndim; d++)
                            emitContinue("std::vector< ");
                        emitContinue("%s", mappedTypename.c_str());
                        for (int d = 0; d < ndim; d++)
                            emitContinue(" >");
                        emitEnd(" %s;", lm.membername.c_str());
                    }
                }
                emit(0, "");
            }
        }

        // constants
        if (ls.constants.size() > 0) {
            emit(1, "public:");
            emit(2, "#if __cplusplus > 199711L /* if c++11 */");
            for (auto& lc : ls.constants) {
                assert(ZCMGen::isLegalConstType(lc.type));
                emitComment(2, lc.comment);
                string mt = mapTypeName(lc.type);
                const char *suffix = lc.type == "int64_t" ? "LL" : "";
                emit(2, "static constexpr %-8s %s = %s%s;", mt.c_str(),
                        lc.membername.c_str(), lc.valstr.c_str(), suffix);
            }
            emit(2, "#else");
            for (auto& lc : ls.constants) {
                assert(ZCMGen::isLegalConstType(lc.type));
                string mt = mapTypeName(lc.type);
                const char *suffix = lc.type == "int64_t" ? "LL" : "";
                emit(2, "static const     %-8s %s = %s%s;", mt.c_str(),
                        lc.membername.c_str(), lc.valstr.c_str(), suffix);
            }
            emit(2, "#endif");
            emit(0, "");
        }

        emit(1, "public:");
        emit(2, "/**");
        emit(2, " * Destructs a message properly if anything inherits from it");
        emit(2, "*/");
        emit(2, "virtual ~%s() {}", ls.structname.shortname.c_str());
        emit(0, "");
        emit(2, "/**");
        emit(2, " * Encode a message into binary form.");
        emit(2, " *");
        emit(2, " * @param buf The output buffer.");
        emit(2, " * @param offset Encoding starts at thie byte offset into @p buf.");
        emit(2, " * @param maxlen Maximum number of bytes to write.  This should generally be");
        emit(2, " *  equal to getEncodedSize().");
        emit(2, " * @return The number of bytes encoded, or <0 on error.");
        emit(2, " */");
        emit(2, "inline int encode(void *buf, int offset, int maxlen) const;");
        emit(0, "");
        emit(2, "/**");
        emit(2, " * Check how many bytes are required to encode this message.");
        emit(2, " */");
        emit(2, "inline int getEncodedSize() const;");
        emit(0, "");
        emit(2, "/**");
        emit(2, " * Decode a message from binary form into this instance.");
        emit(2, " *");
        emit(2, " * @param buf The buffer containing the encoded message.");
        emit(2, " * @param offset The byte offset into @p buf where the encoded message starts.");
        emit(2, " * @param maxlen The maximum number of bytes to reqad while decoding.");
        emit(2, " * @return The number of bytes decoded, or <0 if an error occured.");
        emit(2, " */");
        emit(2, "inline int decode(const void *buf, int offset, int maxlen);");
        emit(0, "");
        emit(2, "/**");
        emit(2, " * Retrieve the 64-bit fingerprint identifying the structure of the message.");
        emit(2, " * Note that the fingerprint is the same for all instances of the same");
        emit(2, " * message type, and is a fingerprint on the message type definition, not on");
        emit(2, " * the message contents.");
        emit(2, " */");
        emit(2, "inline static int64_t getHash();");
        emit(0, "");
        emit(2, "/**");
        emit(2, " * Returns \"%s\"", ls.structname.shortname.c_str());
        emit(2, " */");
        emit(2, "inline static const char* getTypeName();");

        emit(0, "");
        emit(2, "// ZCM support functions. Users should not call these");
        emit(2, "inline int _encodeNoHash(void *buf, int offset, int maxlen) const;");
        emit(2, "inline int _getEncodedSizeNoHash() const;");
        emit(2, "inline int _decodeNoHash(const void *buf, int offset, int maxlen);");
        emit(2, "inline static uint64_t _computeHash(const __zcm_hash_ptr *p);");
        emit(0, "};");
        emit(0, "");
    }