summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2021-04-21 17:37:57 +0300
committerTor Lillqvist <tml@collabora.com>2021-04-23 13:11:18 +0200
commit002b7a87b3b3edf0a28cc910510f766ae01bcb99 (patch)
treefe29ddacd77beab3f604964bb46c3ac0578a480a
parentf05ecc6d6518da976854455996db3fe9144c6bf0 (diff)
Add API to LibreOfficeKit to set arbitrary run-time options in core
Add setOption(const char*, const char*) At the moment this enables starting and stopping the ProfileZone event recording and overriding the SAL_LOG environment variable. Change-Id: Ic3a934bb4246c755a91eee8a8343fafc15815116 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114439 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r--desktop/source/lib/init.cxx30
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h3
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx33
-rw-r--r--include/sal/log.hxx2
-rw-r--r--sal/osl/all/log.cxx63
-rw-r--r--sal/util/sal.map1
6 files changed, 106 insertions, 26 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3f55f9bfbf8e..b646356a9365 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2086,6 +2086,8 @@ static void lo_sendDialogEvent(LibreOfficeKit* pThis,
unsigned long long int nLOKWindowId,
const char* pArguments);
+static void lo_setOption(LibreOfficeKit* pThis, const char* pOption, const char* pValue);
+
LibLibreOffice_Impl::LibLibreOffice_Impl()
: m_pOfficeClass( gOfficeClass.lock() )
, maThread(nullptr)
@@ -2111,6 +2113,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
m_pOfficeClass->signDocument = lo_signDocument;
m_pOfficeClass->runLoop = lo_runLoop;
m_pOfficeClass->sendDialogEvent = lo_sendDialogEvent;
+ m_pOfficeClass->setOption = lo_setOption;
gOfficeClass = m_pOfficeClass;
}
@@ -3858,6 +3861,33 @@ static void lo_sendDialogEvent(LibreOfficeKit* /*pThis*/, unsigned long long int
lcl_sendDialogEvent(nWindowId, pArguments);
}
+static void lo_setOption(LibreOfficeKit* /*pThis*/, const char *pOption, const char* pValue)
+{
+ static char* pCurrentSalLogOverride = nullptr;
+
+ if (strcmp(pOption, "profilezonerecording") == 0)
+ {
+ if (strcmp(pValue, "start") == 0)
+ comphelper::ProfileZone::startRecording();
+ else if (strcmp(pValue, "stop") == 0)
+ comphelper::ProfileZone::stopRecording();
+ }
+ else if (strcmp(pOption, "sallogoverride") == 0)
+ {
+ if (pCurrentSalLogOverride != nullptr)
+ free(pCurrentSalLogOverride);
+ if (pValue == nullptr)
+ pCurrentSalLogOverride = nullptr;
+ else
+ pCurrentSalLogOverride = strdup(pValue);
+
+ if (pCurrentSalLogOverride == nullptr || strlen(pCurrentSalLogOverride) == 0)
+ sal_detail_set_log_selector(nullptr);
+ else
+ sal_detail_set_log_selector(pCurrentSalLogOverride);
+ }
+}
+
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pCommand, const char* pArguments, bool bNotifyWhenFinished)
{
comphelper::ProfileZone aZone("doc_postUnoCommand");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 2279260d0e90..82738d65ff93 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -115,6 +115,9 @@ struct _LibreOfficeKitClass
void (*sendDialogEvent) (LibreOfficeKit* pThis,
unsigned long long int nLOKWindowId,
const char* pArguments);
+
+ /// @see lok::Office::setOption
+ void (*setOption) (LibreOfficeKit* pThis, const char* pOption, const char* pValue);
};
#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index ad2d887aa99a..4a58c4f2ee9d 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -993,6 +993,39 @@ public:
{
mpThis->pClass->sendDialogEvent(mpThis, nWindowId, pArguments);
}
+
+ /**
+ * Generic function to toggle and tweak various things in the core LO
+ *
+ * The currently available option names and their allowed values are:
+ *
+ * "profilezonerecording": "start" or "stop"
+ * Start or stop recording profile zone trace data in the process.
+ *
+ * "sallogoverride": "<string>"
+ * Override the SAL_LOG environment variable
+ *
+ * For the syntax of the string see the documentation for "Basic
+ * logging functionality" in LibreOffice internal API
+ * documentation (include/sal/log.hxx). If the logging selector
+ * has been set by this function to a non-empty value, that is used
+ * instead of the environment variable SAL_LOG.
+ *
+ * The parameter is not copied so you should pass a value that
+ * points to memory that will stay valid until you call setOption
+ * with this option name the next time.
+ *
+ * If you pass nullptr or an empty string as value, the
+ * environment variable SAL_LOG is again used as by default. You
+ * can switch back and forth as you like.
+ *
+ * @param pOption the option name
+ * @param pValue its value
+ */
+ void setOption(const char* pOption, const char* pValue)
+ {
+ mpThis->pClass->setOption(mpThis, pOption, pValue);
+ }
};
/// Factory method to create a lok::Office instance.
diff --git a/include/sal/log.hxx b/include/sal/log.hxx
index 00d533ab5495..daa83bf70abd 100644
--- a/include/sal/log.hxx
+++ b/include/sal/log.hxx
@@ -30,6 +30,8 @@ extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log(
sal_detail_LogLevel level, char const * area, char const * where,
char const * message, sal_uInt32 backtraceDepth);
+extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_set_log_selector(char const *logSelector);
+
extern "C" SAL_DLLPUBLIC sal_Bool SAL_CALL sal_detail_log_report(
sal_detail_LogLevel level, char const * area);
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 5a6ffdff9110..e53c1ae712f4 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -125,7 +125,9 @@ char const* setEnvFromLoggingIniFile(const char* env, const char* key)
}
#endif
-char const * getLogLevel() {
+char const* pLogSelector = nullptr;
+
+char const* getLogLevelEnvVar() {
static char const* const pLevel = [] {
char const* pResult = nullptr;
@@ -176,33 +178,36 @@ std::ofstream * getLogFile() {
return pFile;
}
-void maybeOutputTimestamp(std::ostringstream &s) {
- static const std::pair<bool, bool> aFlags = [] {
- char const* env = getLogLevel();
- bool outputTimestamp = false;
- bool outputRelativeTimer = false;
- for (char const* p = env; p && *p;)
+
+const std::pair<bool, bool> getTimestampFlags(char const *selector)
+{
+ bool outputTimestamp = false;
+ bool outputRelativeTimer = false;
+ for (char const* p = selector; p && *p;)
{
if (*p++ == '+')
- {
- char const * p1 = p;
- while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
- ++p1;
- }
- if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")))
- outputTimestamp = true;
- else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
- outputRelativeTimer = true;
- char const * p2 = p1;
- while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
- ++p2;
+ {
+ char const * p1 = p;
+ while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
+ ++p1;
+ }
+ if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")))
+ outputTimestamp = true;
+ else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
+ outputRelativeTimer = true;
+ char const * p2 = p1;
+ while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
+ ++p2;
+ }
+ p = p2;
}
- p = p2;
- }
}
- return std::pair(outputTimestamp, outputRelativeTimer);
- }();
- const auto& [outputTimestamp, outputRelativeTimer] = aFlags;
+ return std::pair(outputTimestamp, outputRelativeTimer);
+}
+
+void maybeOutputTimestamp(std::ostringstream &s) {
+ static const std::pair<bool, bool> aEnvFlags = getTimestampFlags(getLogLevelEnvVar());
+ const auto& [outputTimestamp, outputRelativeTimer] = (pLogSelector == nullptr ? aEnvFlags : getTimestampFlags(pLogSelector));
if (outputTimestamp)
{
@@ -340,6 +345,11 @@ void sal_detail_log(
#endif
}
+void sal_detail_set_log_selector(char const *logSelector)
+{
+ pLogSelector = logSelector;
+}
+
void sal_detail_logFormat(
sal_detail_LogLevel level, char const * area, char const * where,
char const * format, ...)
@@ -365,12 +375,13 @@ sal_Bool sal_detail_log_report(sal_detail_LogLevel level, char const * area) {
return true;
}
assert(area != nullptr);
- static char const* const env = [] {
- char const* pResult = getLogLevel();
+ static char const* const envEnv = [] {
+ char const* pResult = getLogLevelEnvVar();
if (!pResult)
pResult = "+WARN";
return pResult;
}();
+ char const* const env = (pLogSelector == nullptr ? envEnv : pLogSelector);
std::size_t areaLen = std::strlen(area);
enum Sense { POSITIVE = 0, NEGATIVE = 1 };
std::size_t senseLen[2] = { 0, 1 };
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 48d76b1a3802..a43ae43e9cbe 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -747,6 +747,7 @@ PRIVATE_1.6 { # LibreOffice 6.4
global:
rtl_str_toInt64_WithLength;
rtl_ustr_toInt64_WithLength;
+ sal_detail_set_log_selector;
} PRIVATE_1.5;
PRIVATE_textenc.1 { # LibreOffice 3.6