Blame src/QueueFeeder.h

Packit Service a2489d
/*
Packit Service a2489d
 * lftp - file transfer program
Packit Service a2489d
 *
Packit Service a2489d
 * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
Packit Service a2489d
 *
Packit Service a2489d
 * This program is free software; you can redistribute it and/or modify
Packit Service a2489d
 * it under the terms of the GNU General Public License as published by
Packit Service a2489d
 * the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
 * (at your option) any later version.
Packit Service a2489d
 *
Packit Service a2489d
 * This program is distributed in the hope that it will be useful,
Packit Service a2489d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
 * GNU General Public License for more details.
Packit Service a2489d
 *
Packit Service a2489d
 * You should have received a copy of the GNU General Public License
Packit Service a2489d
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service a2489d
 */
Packit Service a2489d
Packit Service a2489d
#ifndef QUEUEFEEDER_H
Packit Service a2489d
#define QUEUEFEEDER_H
Packit Service a2489d
Packit Service a2489d
#include "CmdExec.h"
Packit Service a2489d
Packit Service a2489d
class QueueFeeder : public CmdFeeder
Packit Service a2489d
{
Packit Service a2489d
   struct QueueJob {
Packit Service a2489d
      xstring_c cmd;
Packit Service a2489d
      xstring_c pwd;
Packit Service a2489d
      xstring_c lpwd;
Packit Service a2489d
Packit Service a2489d
      QueueJob *next, *prev;
Packit Service a2489d
      QueueJob(): next(0), prev(0) {}
Packit Service a2489d
   } *jobs, *lastjob;
Packit Service a2489d
   xstring_c cur_pwd;
Packit Service a2489d
   xstring_c cur_lpwd;
Packit Service a2489d
Packit Service a2489d
   xstring buffer;
Packit Service a2489d
Packit Service a2489d
   /* remove the given job from the list */
Packit Service a2489d
   void unlink_job(QueueJob *job);
Packit Service a2489d
Packit Service a2489d
   /* get the n'th job */
Packit Service a2489d
   QueueJob *get_job(int n);
Packit Service a2489d
Packit Service a2489d
   /* get the n'th job, removed from the list: */
Packit Service a2489d
   QueueJob *grab_job(int n);
Packit Service a2489d
Packit Service a2489d
   /* get all jobs (linked and removed from the list)
Packit Service a2489d
    * that match the cmd: */
Packit Service a2489d
   QueueJob *grab_job(const char *cmd);
Packit Service a2489d
Packit Service a2489d
   /* get the next job in j that matches cmd (including j) */
Packit Service a2489d
   static QueueJob *get_next_match(const char *cmd, QueueJob *j);
Packit Service a2489d
   void PrintJobs(const QueueJob *job, int v, const char *plur) const;
Packit Service a2489d
   xstring& FormatJobs(xstring& s,const QueueJob *job, int v, const char *plur) const;
Packit Service a2489d
Packit Service a2489d
   void insert_jobs(QueueJob *job,
Packit Service a2489d
		   QueueJob *&lst_head, QueueJob *&lst_tail,
Packit Service a2489d
		   QueueJob *before);
Packit Service a2489d
Packit Service a2489d
   void FreeList(QueueJob *j);
Packit Service a2489d
Packit Service a2489d
public:
Packit Service a2489d
   const char *NextCmd(CmdExec *exec,const char *prompt);
Packit Service a2489d
Packit Service a2489d
   /* Add a command to the queue at a given position; a 0 position inserts at the end. */
Packit Service a2489d
   void QueueCmd(const char *cmd, const char *pwd, const char *lpwd, int pos = 0, int verbose = 0);
Packit Service a2489d
Packit Service a2489d
   /* delete jobs (by index or wildcard expr) */
Packit Service a2489d
   bool DelJob(int from, int v = 0);
Packit Service a2489d
   bool DelJob(const char *cmd, int v = 0);
Packit Service a2489d
Packit Service a2489d
   /* move one or more jobs (by index or wildcard expr). */
Packit Service a2489d
   bool MoveJob(int from, int to, int v = 0);
Packit Service a2489d
   bool MoveJob(const char *cmd, int to, int v = 0);
Packit Service a2489d
Packit Service a2489d
   static int JobCount(const QueueJob *);
Packit Service a2489d
   int JobCount() const { return JobCount(jobs); }
Packit Service a2489d
Packit Service a2489d
   enum { PrintRequeue = 9999 };
Packit Service a2489d
   xstring& FormatStatus(xstring&,int v,const char *prefix="\t") const;
Packit Service a2489d
Packit Service a2489d
   QueueFeeder(const char *pwd, const char *lpwd):
Packit Service a2489d
      jobs(0), lastjob(0), cur_pwd(pwd), cur_lpwd(lpwd) {}
Packit Service a2489d
   virtual ~QueueFeeder();
Packit Service a2489d
};
Packit Service a2489d
Packit Service a2489d
#endif//QUEUEFEEDER_H