File indexing completed on 2024-09-15 04:36:24

0001 /*
0002     SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadiprivate_export.h"
0010 
0011 #include <QString>
0012 
0013 #include <optional>
0014 
0015 /**
0016  * Helper methods for obtaining D-Bus identifiers.
0017  * This should be used instead of hardcoded identifiers or constants to support multi-instance namespacing
0018  * @since 1.7
0019  */
0020 
0021 #define AKONADI_DBUS_AGENTMANAGER_PATH "/AgentManager"
0022 #define AKONADI_DBUS_AGENTSERVER_PATH "/AgentServer"
0023 #define AKONADI_DBUS_STORAGEJANITOR_PATH "/Janitor"
0024 
0025 namespace Akonadi
0026 {
0027 namespace DBus
0028 {
0029 /** D-Bus service types used by the Akonadi server processes. */
0030 enum ServiceType {
0031     Server,
0032     Control,
0033     ControlLock,
0034     AgentServer,
0035     StorageJanitor,
0036     UpgradeIndicator,
0037 };
0038 
0039 /**
0040  * Returns the service name for the given @p serviceType.
0041  */
0042 AKONADIPRIVATE_EXPORT QString serviceName(ServiceType serviceType);
0043 
0044 /** Known D-Bus service name types for agents. */
0045 enum AgentType {
0046     Unknown,
0047     Agent,
0048     Resource,
0049     Preprocessor,
0050 };
0051 
0052 struct AgentService {
0053     QString identifier{};
0054     DBus::AgentType agentType{DBus::Unknown};
0055 };
0056 
0057 /**
0058  * Parses a D-Bus service name and checks if it belongs to an agent of this instance.
0059  * @param serviceName The service name to parse.
0060  * @return The identifier of the agent, empty string if that's not an agent (or an agent of a different Akonadi instance)
0061  */
0062 AKONADIPRIVATE_EXPORT std::optional<AgentService> parseAgentServiceName(const QString &serviceName);
0063 
0064 /**
0065  * Returns the D-Bus service name of the agent @p agentIdentifier for type @p agentType.
0066  */
0067 AKONADIPRIVATE_EXPORT QString agentServiceName(const QString &agentIdentifier, DBus::AgentType agentType);
0068 
0069 /**
0070  * Returns the Akonadi instance name encoded in the service name.
0071  */
0072 AKONADIPRIVATE_EXPORT std::optional<QString> parseInstanceIdentifier(const QString &serviceName);
0073 
0074 }
0075 
0076 }