Beispiel #1
0
    const string SuperComponent::checkForCommandLinePassedConfigurationFileOrDefaultConfigurationFile(const int &argc, char **argv) {
        string configurationFile = "configuration";
        CommandLineParser cmdParser;
        cmdParser.addCommandLineArgument("configuration");

        cmdParser.parse(argc, argv);

        CommandLineArgument cmdArgumentCONFIGURATION = cmdParser.getCommandLineArgument("configuration");

        // Check the centrally maintained managed level.
        if (cmdArgumentCONFIGURATION.isSet()) {
            configurationFile = cmdArgumentCONFIGURATION.getValue<string>();
            core::strings::StringToolbox::trim(configurationFile);
        }
        return configurationFile;
    }
        void AbstractCIDModule::parseCommandLine(const int32_t &argc, char **argv) throw (InvalidArgumentException) {
            if (argc <= 1) {
                errno = 0;
                OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                              "Invalid number of arguments. At least a conference group id (--cid=) needed.");
            }

            CommandLineParser cmdParser;
            cmdParser.addCommandLineArgument("id");
            cmdParser.addCommandLineArgument("cid");
            cmdParser.addCommandLineArgument("freq");
            cmdParser.addCommandLineArgument("verbose");
            cmdParser.addCommandLineArgument("profiling");

            cmdParser.parse(argc, argv);

            CommandLineArgument cmdArgumentID = cmdParser.getCommandLineArgument("id");
            CommandLineArgument cmdArgumentCID = cmdParser.getCommandLineArgument("cid");
            CommandLineArgument cmdArgumentFREQ = cmdParser.getCommandLineArgument("freq");
            CommandLineArgument cmdArgumentVERBOSE = cmdParser.getCommandLineArgument("verbose");
            CommandLineArgument cmdArgumentPROFILING = cmdParser.getCommandLineArgument("profiling");

            if (cmdArgumentID.isSet()) {
                m_identifier = cmdArgumentID.getValue<string>();
            }

            if (cmdArgumentFREQ.isSet()) {
                m_frequency = cmdArgumentFREQ.getValue<float>();

                if ( fabs(m_frequency) < 1e-5  ) {
                    errno = 0;
                    OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                  "Runtime frequency must be greater than 0.");
                }
            }
            else {
                clog << "No runtime frequency set. Assuming a frequency of 1 Hz." << endl;
            }

            if (cmdArgumentCID.isSet()) {
                m_CID = cmdArgumentCID.getValue<int>();

                if ( (m_CID <= 1) || (m_CID >= 254) ) {
                    errno = 0;
                    OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                  "The conference group id has to be in range [2, 254].");
                }

                m_mulitcastGroup = "225.0.0." + cmdArgumentCID.getValue<string>();
            } else {
                errno = 0;
                OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                              "No conference group id specified");
            }

            if (cmdArgumentVERBOSE.isSet()) {
                m_verbose = true;
            }

            if (cmdArgumentPROFILING.isSet()) {
                m_profiling = true;
            }
        }
            void AbstractCIDModule::parseCommandLine(const int32_t &argc, char **argv) throw (InvalidArgumentException) {
                if (argc <= 1) {
                    errno = 0;
                    OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                  "Invalid number of arguments. At least a conference group id (--cid=) needed.");
                }

                CommandLineParser cmdParser;
                cmdParser.addCommandLineArgument("id");
                cmdParser.addCommandLineArgument("cid");
                cmdParser.addCommandLineArgument("freq");
                cmdParser.addCommandLineArgument("verbose");
                cmdParser.addCommandLineArgument("profiling");
                cmdParser.addCommandLineArgument("realtime");

                cmdParser.parse(argc, argv);

                CommandLineArgument cmdArgumentID = cmdParser.getCommandLineArgument("id");
                CommandLineArgument cmdArgumentCID = cmdParser.getCommandLineArgument("cid");
                CommandLineArgument cmdArgumentFREQ = cmdParser.getCommandLineArgument("freq");
                CommandLineArgument cmdArgumentVERBOSE = cmdParser.getCommandLineArgument("verbose");
                CommandLineArgument cmdArgumentPROFILING = cmdParser.getCommandLineArgument("profiling");
                CommandLineArgument cmdArgumentREALTIME = cmdParser.getCommandLineArgument("realtime");

                if (cmdArgumentVERBOSE.isSet()) {
                    AbstractCIDModule::m_verbose = cmdArgumentVERBOSE.getValue<int32_t>();;
                }

                if (cmdArgumentID.isSet()) {
                    m_identifier = cmdArgumentID.getValue<string>();
                }

                if (cmdArgumentFREQ.isSet()) {
                    m_frequency = cmdArgumentFREQ.getValue<float>();

                    if ( fabs(m_frequency) < 1e-5  ) {
                        errno = 0;
                        OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                      "Runtime frequency must be greater than 0.");
                    }
                }
                else {
                    CLOG << "No runtime frequency set. Assuming a frequency of 1 Hz." << endl;
                }

                if (cmdArgumentCID.isSet()) {
                    m_CID = cmdArgumentCID.getValue<int>();

                    if ( (m_CID <= 1) || (m_CID >= 254) ) {
                        errno = 0;
                        OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                      "The conference group id has to be in range [2, 254].");
                    }

                    m_multicastGroup = "225.0.0." + cmdArgumentCID.getValue<string>();
                } else {
                    errno = 0;
                    OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                  "No conference group id specified");
                }

                if (cmdArgumentPROFILING.isSet()) {
                    m_profiling = true;
                }

                if (cmdArgumentREALTIME.isSet()) {
                    errno = 0;
#ifdef HAVE_LINUX_RT
                    int val = cmdArgumentREALTIME.getValue<int>();

                    if ( (val < 1) || (val > 49) ) {
                        OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                      "The realtime scheduling priority has to be in range [1, 49].");
                    }

                    m_realtime = true;
                    m_realtimePriority = val;
#else
                    OPENDAVINCI_CORE_THROW_EXCEPTION(InvalidArgumentException,
                                                  "Realtime is only available on Linux with rt-preempt.");
#endif
                }
            }
Beispiel #4
0
    void SuperComponent::parseAdditionalCommandLineParameters(const int &argc, char **argv) {
        CommandLineParser cmdParser;
        cmdParser.addCommandLineArgument("managed");
        cmdParser.addCommandLineArgument("logfile");
        cmdParser.addCommandLineArgument("loglevel");

        cmdParser.parse(argc, argv);

        CommandLineArgument cmdArgumentLOGFILE = cmdParser.getCommandLineArgument("logfile");
        CommandLineArgument cmdArgumentLOGLEVEL = cmdParser.getCommandLineArgument("loglevel");
        CommandLineArgument cmdArgumentMANAGED = cmdParser.getCommandLineArgument("managed");

        // Check the log level.
        if (cmdArgumentLOGLEVEL.isSet()) {
            string logLevel = cmdArgumentLOGLEVEL.getValue<string>();

            if (core::strings::StringToolbox::equalsIgnoreCase(logLevel, "none")) {
                m_logLevel = coredata::LogMessage::NONE;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(logLevel, "info")) {
                m_logLevel = coredata::LogMessage::INFO;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(logLevel, "warn")) {
                m_logLevel = coredata::LogMessage::WARN;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(logLevel, "debug")) {
                m_logLevel = coredata::LogMessage::DEBUG;
            }
        }

        // Create a log file.
        if (cmdArgumentLOGFILE.isSet()) {
            string logFilename = cmdArgumentLOGFILE.getValue<string>();

            if (m_logLevel > 0) {
                OPENDAVINCI_CORE_DELETE_POINTER(m_logFile);

                m_logFile = new fstream();
                if (m_logFile != NULL) {
                    m_logFile->open(logFilename.c_str(), ios::out | ios::app);

                    if ((m_logFile != NULL) && !m_logFile->good()) {
                        OPENDAVINCI_CORE_DELETE_POINTER(m_logFile);
                    }
                }
            }
        }

        // Check the centrally maintained managed level.
        if (cmdArgumentMANAGED.isSet()) {
            string managedLevel = cmdArgumentMANAGED.getValue<string>();
            core::strings::StringToolbox::trim(managedLevel);

            if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "none")) {
                m_managedLevel = coredata::dmcp::ServerInformation::ML_NONE;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "pulse")) {
                m_managedLevel = coredata::dmcp::ServerInformation::ML_PULSE;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "pulse_shift")) {
                m_managedLevel = coredata::dmcp::ServerInformation::ML_PULSE_SHIFT;

                m_shiftMicroseconds = 10 * 1000;
                try {
                    m_shiftMicroseconds = m_configuration.getValue<uint32_t>("odsupercomponent.pulseshift.shift");
                }
                catch(...) {
                    CLOG1 << "[odsupercomponent]: Value for 'odsupercomponent.pulseshift.shift' not found in configuration, using " << m_shiftMicroseconds << " as default." << endl;
                }
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "pulse_time")) {
                m_managedLevel = coredata::dmcp::ServerInformation::ML_PULSE_TIME;
            }
            if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "pulse_time_ack") || core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "simulation") || core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "simulation_rt")) {
                if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "pulse_time_ack")) {
                    m_managedLevel = coredata::dmcp::ServerInformation::ML_PULSE_TIME_ACK;
                }
                if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "simulation")) {
                    m_managedLevel = coredata::dmcp::ServerInformation::ML_SIMULATION;
                }
                if (core::strings::StringToolbox::equalsIgnoreCase(managedLevel, "simulation_rt")) {
                    m_managedLevel = coredata::dmcp::ServerInformation::ML_SIMULATION_RT;
                }

                m_timeoutACKMilliseconds = 1000;
                m_yieldMicroseconds = 5 * 1000;

                try {
                    m_timeoutACKMilliseconds = m_configuration.getValue<uint32_t>("odsupercomponent.pulsetimeack.timeout");
                }
                catch(...) {
                    CLOG1 << "[odsupercomponent]: Value for 'odsupercomponent.pulsetimeack.timeout' not found in configuration, using " << m_timeoutACKMilliseconds << " as default." << endl;
                }

                try {
                    m_yieldMicroseconds = m_configuration.getValue<uint32_t>("odsupercomponent.pulsetimeack.yield");
                }
                catch(...) {
                    CLOG1 << "[odsupercomponent]: Value for 'odsupercomponent.pulsetimeack.yield' not found in configuration, using " << m_yieldMicroseconds << " as default." << endl;
                }

                try {
                    string s = m_configuration.getValue<string>("odsupercomponent.pulsetimeack.exclude");
                    transform(s.begin(), s.end(), s.begin(), ::tolower);

                    m_modulesToIgnore = core::strings::StringToolbox::split(s, ',');
                }
                catch(...) {
                    // If "odsupercomponent.pulsetimeack.exclude" is not specified, just ignore exception.
                }

            }
        }
    }