// Copyright (C) 2021 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "dockersettings.h" #include #include #include #include namespace Docker::Internal { class DockerDeviceData { public: bool operator==(const DockerDeviceData &other) const { return imageId == other.imageId && repo == other.repo && tag == other.tag && useLocalUidGid == other.useLocalUidGid && mounts == other.mounts && keepEntryPoint == other.keepEntryPoint && enableLldbFlags == other.enableLldbFlags && clangdExecutable == other.clangdExecutable; } bool operator!=(const DockerDeviceData &other) const { return !(*this == other); } // Used for "docker run" QString repoAndTag() const { if (repo == "") return imageId; if (tag == "") return repo; return repo + ':' + tag; } QString repoAndTagEncoded() const { return repoAndTag().replace(':', '.'); } QString imageId; QString repo; QString tag; QString size; bool useLocalUidGid = true; QStringList mounts = {Core::DocumentManager::projectsDirectory().toString()}; bool keepEntryPoint = false; bool enableLldbFlags = false; Utils::FilePath clangdExecutable; }; class DockerDevice : public ProjectExplorer::IDevice { public: using Ptr = QSharedPointer; using ConstPtr = QSharedPointer; explicit DockerDevice(const DockerDeviceData &data); ~DockerDevice(); void shutdown(); static Ptr create(const DockerDeviceData &data) { return Ptr(new DockerDevice(data)); } ProjectExplorer::IDeviceWidget *createWidget() override; QList validate() const override; Utils::ProcessInterface *createProcessInterface() const override; bool canCreateProcessModel() const override { return true; } bool hasDeviceTester() const override { return false; } ProjectExplorer::DeviceTester *createDeviceTester() const override; bool usableAsBuildDevice() const override; Utils::FilePath rootPath() const override; Utils::FilePath filePath(const QString &pathOnDevice) const override; bool handlesFile(const Utils::FilePath &filePath) const override; bool ensureReachable(const Utils::FilePath &other) const override; Utils::expected_str localSource(const Utils::FilePath &other) const override; Utils::Environment systemEnvironment() const override; const DockerDeviceData data() const; DockerDeviceData data(); void setData(const DockerDeviceData &data); bool updateContainerAccess() const; void setMounts(const QStringList &mounts) const; bool prepareForBuild(const ProjectExplorer::Target *target) override; std::optional clangdExecutable() const override; protected: void fromMap(const Utils::Storage &map) final; Utils::Storage toMap() const final; private: void aboutToBeRemoved() const final; class DockerDevicePrivate *d = nullptr; friend class DockerDeviceSetupWizard; friend class DockerDeviceWidget; }; class DockerDeviceFactory final : public ProjectExplorer::IDeviceFactory { public: DockerDeviceFactory(); void shutdownExistingDevices(); private: QMutex m_deviceListMutex; std::vector> m_existingDevices; }; } // namespace Docker::Internal Q_DECLARE_METATYPE(Docker::Internal::DockerDeviceData)