| 76 | } |
| 77 | |
| 78 | smileres_t smile_initialize(smileobj_t *smileobj, const char *configFile, int nOptions, const smileopt_t *options, int loglevel, int debug, int consoleOutput, const char *logFile) |
| 79 | { |
| 80 | if (smileobj == NULL) |
| 81 | SMILE_FAIL_WITH(SMILE_INVALID_ARG, "smileobj argument must not be null"); |
| 82 | if (configFile == NULL) |
| 83 | SMILE_FAIL_WITH(SMILE_INVALID_ARG, "configFile argument must not be null"); |
| 84 | if (smileobj->state != SMILE_UNINITIALIZED) |
| 85 | SMILE_FAIL_WITH(SMILE_INVALID_STATE, "openSMILE has already been initialized"); |
| 86 | |
| 87 | try { |
| 88 | // this is required to ensure config files are parsed with the correct locale |
| 89 | // however, it overrides the locale globally in the whole application |
| 90 | // we should adapt the config file parser to make use of the improved locale handling in C++ |
| 91 | smileCommon_fixLocaleEnUs(); |
| 92 | |
| 93 | std::unique_ptr<cSmileLogger> logger { new cSmileLogger(1) }; |
| 94 | |
| 95 | logger->useForCurrentThread(); |
| 96 | logger->setLogFile(logFile, 0); |
| 97 | logger->setConsoleOutput(consoleOutput); |
| 98 | logger->setColoredOutput(false); |
| 99 | logger->setLogLevel(loglevel); |
| 100 | #ifdef DEBUG |
| 101 | if (!debug) |
| 102 | logger->setLogLevel(LOG_DEBUG, 0); |
| 103 | #endif |
| 104 | logger->setCallback([=](int type, int level, const char *text, const char *module) { |
| 105 | // copy smileobj->logCallback to avoid race condition |
| 106 | auto logCallback = smileobj->logCallback; |
| 107 | if (logCallback != NULL) { |
| 108 | smilelogmsg_t message{static_cast<smilelogtype_t>(type), level, text, module}; |
| 109 | logCallback(smileobj, message, smileobj->logCallbackParam); |
| 110 | } |
| 111 | }); |
| 112 | |
| 113 | // convert 'options' to the format that cCommandlineParser expects (SMILExtract -key1 value1 ...) |
| 114 | std::vector<std::string> cmdArgs; |
| 115 | cmdArgs.reserve(nOptions * 2 + 1); |
| 116 | cmdArgs.push_back("SMILExtract"); |
| 117 | for (int i = 0; i < nOptions; i++) { |
| 118 | cmdArgs.push_back("-" + std::string(options[i].name)); |
| 119 | if (options[i].value != NULL) |
| 120 | cmdArgs.push_back(std::string(options[i].value)); |
| 121 | } |
| 122 | // convert elements in cmdArgs to const char * |
| 123 | std::vector<const char *> cmdArgs2; |
| 124 | cmdArgs2.reserve(cmdArgs.size()); |
| 125 | for (const auto &arg : cmdArgs) |
| 126 | cmdArgs2.push_back(arg.c_str()); |
| 127 | |
| 128 | cCommandlineParser cmdline(cmdArgs2.size(), cmdArgs2.data()); |
| 129 | if (cmdline.parse() == -1) { |
| 130 | SMILE_FAIL_WITH(SMILE_FAIL, "command-line could not be parsed"); |
| 131 | } |
| 132 | |
| 133 | SMILE_MSG(2,"openSMILE starting!"); |
| 134 | SMILE_MSG(2,"config file is: %s", configFile); |
| 135 |
nothing calls this directly
no test coverage detected