File indexing completed on 2024-05-05 04:41:01

0001 /*
0002     SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
0003     SPDX-FileCopyrightText: 2007 Dukju Ahn <dukjuahn@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_PLUGIN_SVNINTERNALJOBBASE_H
0009 #define KDEVPLATFORM_PLUGIN_SVNINTERNALJOBBASE_H
0010 
0011 #include <ThreadWeaver/Job>
0012 #include <QSemaphore>
0013 #include <QMutex>
0014 
0015 extern "C" {
0016 #include <svn_wc.h>
0017 }
0018 
0019 #include "kdevsvncpp/context_listener.hpp"
0020 
0021 namespace KDevelop
0022 {
0023     class VcsRevision;
0024 }
0025 
0026 namespace svn
0027 {
0028     class Context;
0029     class Revision;
0030 }
0031 
0032 class SvnJobBase;
0033 
0034 class SvnInternalJobBase : public QObject, public ThreadWeaver::Job, public svn::ContextListener
0035 {
0036     Q_OBJECT
0037 public:
0038     explicit SvnInternalJobBase(SvnJobBase* parentJob);
0039     ~SvnInternalJobBase() override;
0040 
0041     bool success() const override;
0042 
0043     bool contextGetLogin( const std::string& realm,
0044                           std::string& username, std::string& password,
0045                           bool& maySave ) override;
0046     void contextNotify( const char* path, svn_wc_notify_action_t action,
0047                         svn_node_kind_t kind, const char* mimetype,
0048                         svn_wc_notify_state_t contentState,
0049                         svn_wc_notify_state_t propState, svn_revnum_t rev ) override;
0050     bool contextCancel() override;
0051     bool contextGetLogMessage( std::string& msg ) override;
0052     svn::ContextListener::SslServerTrustAnswer contextSslServerTrustPrompt(
0053             const svn::ContextListener::SslServerTrustData& data,
0054             apr_uint32_t& acceptedFailures ) override;
0055     bool contextSslClientCertPrompt( std::string& cert ) override;
0056     bool contextSslClientCertPwPrompt( std::string& pw, const std::string& realm,
0057                                        bool& maySave ) override;
0058 
0059     void initBeforeRun();
0060     
0061     void kill();
0062     
0063     bool wasKilled();
0064 
0065     QString errorMessage() const;
0066 
0067     svn::Context* m_ctxt;
0068     QSemaphore m_guiSemaphore;
0069     QString m_login_username;
0070     QString m_login_password;
0071     bool m_maySave;
0072     QString m_commitMessage;
0073     svn::ContextListener::SslServerTrustAnswer m_trustAnswer;
0074 
0075     static svn::Revision createSvnCppRevisionFromVcsRevision( const KDevelop::VcsRevision& );
0076 
0077 Q_SIGNALS:
0078     void needLogin( const QString& );
0079     void showNotification( const QString&, const QString& );
0080     void needCommitMessage();
0081     void needSslServerTrust( const QStringList&, const QString&, const QString&,
0082                              const QString&, const QString&, const QString&,
0083                              const QString& );
0084     void needSslClientCert( const QString& );
0085     void needSslClientCertPassword( const QString& );
0086 
0087     /** This signal is emitted when this job is being processed by a thread. */
0088     void started();
0089     /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */
0090     void done();
0091     /** This job has failed.
0092      *
0093      * This signal is emitted when success() returns false after the job is executed. */
0094     void failed();
0095 
0096 protected:
0097     void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0098     void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0099 
0100     mutable QMutex m_mutex;
0101     mutable QMutex m_killMutex;
0102     bool m_success = true;
0103     void setErrorMessage( const QString& );
0104 
0105 private:
0106     bool sendFirstDelta = false;
0107     bool killed = false;
0108     QString m_errorMessage;
0109     SvnJobBase* m_parentJob;
0110 };
0111 
0112 
0113 #endif
0114