<commit_before>/*
    This file is part of KitchenSync.

    Copyright (c) 2003 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef CLIENTMANAGER_H
#define CLIENTMANAGER_H

#include <qobject.h>
#include <qapplication.h>
#include <qthread.h>
#include <qmutex.h>
#include <qwaitcondition.h>

#include <synceelist.h>
#include <error.h>
#include <progress.h>

#include "clientthread.h"

namespace Threaded {

  /**
     Client Thread. A QThread for the OBEX client.
     Note that this QObject is only accessed from the main thread. It is used
     to report events from the working thread.
   */
  class ClientManager
    : public QObject, public QThread {
    Q_OBJECT;
  public:
    /**
       Constructor with the usual parent handling.
     */
    ClientManager( QObject* = 0, const char* = 0 );
    /**
       Destructor, make sure that the thread terminated.
     */
    ~ClientManager();
    
    /**
       Returns if the worker is idel at the monment.
       Since we have only one manager this lock free access does not introduce
       a race condition.
     */
    bool isIdle();

    /**
       Starts reading the device and computing the synccees.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a @ref signalError( const KSync::Error& )
       or a @ref signalFinished( const KSync::Progress& ).
     */
    bool readSyncees();
    /**
       Starts writing the syncees to the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a @ref signalError( const KSync::Error& )
       or a @ref signalFinished( const KSync::Progress& ).
     */
    bool writeSyncees();

    /**
       Starts connecting the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a @ref signalError( const KSync::Error& )
       or a @ref signalFinished( const KSync::Progress& ).
     */
    bool connectDevice();
    /**
       Starts disconnecting the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a @ref signalError( const KSync::Error& )
       or a @ref signalFinished( const KSync::Progress& ).
     */
    bool disconnectDevice();

    /**
       Terminates ...
       FIXME, work out if the usual terminate does a better job ...
     */
    bool terminateThread();
    
    /**
       Sets a flag in the client thread. We hope, that the worker thread
       regularly reads that flag ...
     */
    void cancelJob();
    
  signals:
    /**
       Is emitted when the thread running has terminated.
       Then it is save to destroy this class.<commit_msg>Fix dox by removing @ref (it's not needed when referring to functions in the same class) and fixing the signature of signalFinished in the dox.<commit_after>/*
    This file is part of KitchenSync.

    Copyright (c) 2003 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef CLIENTMANAGER_H
#define CLIENTMANAGER_H

#include <qobject.h>
#include <qapplication.h>
#include <qthread.h>
#include <qmutex.h>
#include <qwaitcondition.h>

#include <synceelist.h>
#include <error.h>
#include <progress.h>

#include "clientthread.h"

namespace Threaded {

  /**
     Client Thread. A QThread for the OBEX client.
     Note that this QObject is only accessed from the main thread. It is used
     to report events from the working thread.
   */
  class ClientManager
    : public QObject, public QThread {
    Q_OBJECT;
  public:
    /**
       Constructor with the usual parent handling.
     */
    ClientManager( QObject* = 0, const char* = 0 );
    /**
       Destructor, make sure that the thread terminated.
     */
    ~ClientManager();
    
    /**
       Returns if the worker is idel at the monment.
       Since we have only one manager this lock free access does not introduce
       a race condition.
     */
    bool isIdle();

    /**
       Starts reading the device and computing the synccees.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a signalError( const KSync::Error& )
       or a signalFinished( ).
     */
    bool readSyncees();
    /**
       Starts writing the syncees to the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a signalError( const KSync::Error& )
       or a signalFinished( ).
     */
    bool writeSyncees();

    /**
       Starts connecting the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a signalError( const KSync::Error& )
       or a signalFinished( ).
     */
    bool connectDevice();
    /**
       Starts disconnecting the device.
       Returns if a backup could be started. If the function returns with true
       the job is terminated by by either a signalError( const KSync::Error& )
       or a signalFinished( ).
     */
    bool disconnectDevice();

    /**
       Terminates ...
       FIXME, work out if the usual terminate does a better job ...
     */
    bool terminateThread();
    
    /**
       Sets a flag in the client thread. We hope, that the worker thread
       regularly reads that flag ...
     */
    void cancelJob();
    
  signals:
    /**
       Is emitted when the thread running has terminated.
       Then it is save to destroy this class.
{'fraction_non_alphanumeric': 0.07014797951052931, 'fraction_numerical': 0.00597609561752988, 'mean_word_length': 2.5357142857142856, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4362804', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1839, 'n_words': 897}