Blame src/OutputJob.h

Packit 8f70b4
/*
Packit 8f70b4
 * lftp - file transfer program
Packit 8f70b4
 *
Packit 8f70b4
 * Copyright (c) 1996-2012 by Alexander V. Lukyanov (lav@yars.free.net)
Packit 8f70b4
 *
Packit 8f70b4
 * This program is free software; you can redistribute it and/or modify
Packit 8f70b4
 * it under the terms of the GNU General Public License as published by
Packit 8f70b4
 * the Free Software Foundation; either version 3 of the License, or
Packit 8f70b4
 * (at your option) any later version.
Packit 8f70b4
 *
Packit 8f70b4
 * This program is distributed in the hope that it will be useful,
Packit 8f70b4
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8f70b4
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 8f70b4
 * GNU General Public License for more details.
Packit 8f70b4
 *
Packit 8f70b4
 * You should have received a copy of the GNU General Public License
Packit 8f70b4
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 8f70b4
 */
Packit 8f70b4
Packit 8f70b4
#ifndef OUTPUTJOB_H
Packit 8f70b4
#define OUTPUTJOB_H
Packit 8f70b4
Packit 8f70b4
#include "Job.h"
Packit 8f70b4
#include "FileCopy.h"
Packit 8f70b4
#include "CopyJob.h"
Packit 8f70b4
#include "Timer.h"
Packit 8f70b4
Packit 8f70b4
class StatusBar;
Packit 8f70b4
Packit 8f70b4
class OutputJob : public Job
Packit 8f70b4
{
Packit 8f70b4
   /* Main CopyJob: */
Packit 8f70b4
   CopyJob *input;
Packit 8f70b4
Packit 8f70b4
   /* CopyJob that sends to the output.  (output may be equal to input) */
Packit 8f70b4
   CopyJob *output;
Packit 8f70b4
Packit 8f70b4
   Ref<Buffer> tmp_buf;	// to store data while !initialized
Packit 8f70b4
   Ref<FDStream> output_fd;	// to initialize CopyJobs
Packit 8f70b4
   FileAccessRef fa;
Packit 8f70b4
   xstring_c fa_path;
Packit 8f70b4
Packit 8f70b4
   bool initialized;
Packit 8f70b4
Packit 8f70b4
   xstring_c a0;
Packit 8f70b4
   xstring_c filter;
Packit 8f70b4
Packit 8f70b4
   bool error;
Packit 8f70b4
   bool is_stdout;
Packit 8f70b4
   bool fail_if_broken;
Packit 8f70b4
   bool statusbar_redisplay;
Packit 8f70b4
Packit 8f70b4
   int width;
Packit 8f70b4
   bool is_a_tty;
Packit 8f70b4
Packit 8f70b4
   /* if true, we never contribute to the parent job's status
Packit 8f70b4
    * (Status() == "") */
Packit 8f70b4
   bool no_status;
Packit 8f70b4
Packit 8f70b4
   Timer update_timer;
Packit 8f70b4
Packit 8f70b4
   void Init(const char *a0);
Packit 8f70b4
   void InitCopy();
Packit 8f70b4
Packit 8f70b4
   /* Get the input FileCopyPeer */
Packit 8f70b4
   const SMTaskRef<FileCopyPeer>& InputPeer() const;
Packit 8f70b4
Packit 8f70b4
   /* Get the output FileCopyPeer (the FileCopyPeer that's doing the final output) */
Packit 8f70b4
   const SMTaskRef<FileCopyPeer>& OutputPeer() const;
Packit 8f70b4
Packit 8f70b4
public:
Packit 8f70b4
   OutputJob(FDStream *output, const char *a0);
Packit 8f70b4
   OutputJob(const char *path, const char *a0, FA *fa=0);
Packit 8f70b4
   void PrepareToDie();
Packit 8f70b4
Packit 8f70b4
   /* Set the main filter: */
Packit 8f70b4
   void SetFilter(const char *f) { filter.set(f); }
Packit 8f70b4
   /* Prepend a filter before the main filter: */
Packit 8f70b4
   void PreFilter(const char *f);
Packit 8f70b4
Packit 8f70b4
   void DontFailIfBroken(bool y=true) { fail_if_broken=!y; }
Packit 8f70b4
   bool Error();
Packit 8f70b4
Packit 8f70b4
   int Done();
Packit 8f70b4
   int Do();
Packit 8f70b4
Packit 8f70b4
   void Put(const char *buf,int size);
Packit 8f70b4
   void Put(const char *buf) { Put(buf,strlen(buf)); }
Packit 8f70b4
   void Put(const xstring& str) { Put(str.get(),str.length()); }
Packit 8f70b4
   void Format(const char *f,...) PRINTF_LIKE(2,3);
Packit 8f70b4
   void PutEOF();
Packit 8f70b4
Packit 8f70b4
   /* If sending large amounts of data, call this function and stop
Packit 8f70b4
    * sending if it returns true.  (This always accept more input;
Packit 8f70b4
    * this is optional.) */
Packit 8f70b4
   bool Full();
Packit 8f70b4
Packit 8f70b4
   /* Get properties of the output: */
Packit 8f70b4
   int GetWidth() const;
Packit 8f70b4
   bool IsTTY() const;
Packit 8f70b4
   /* Whether the ultimate destination is stdout: */
Packit 8f70b4
   bool IsStdout() const { return is_stdout; }
Packit 8f70b4
   /* Whether the output is filtered: */
Packit 8f70b4
   bool IsFiltered() const { return filter; }
Packit 8f70b4
Packit 8f70b4
   /* Call before showing a StatusLine on a job using this class.  If it
Packit 8f70b4
    * returns false, don't display it. */
Packit 8f70b4
   bool ShowStatusLine(const SMTaskRef<StatusLine>&);
Packit 8f70b4
Packit 8f70b4
   /* For commands that stream output from servers, redisplaying the
Packit 8f70b4
    * statusbar when output becomes idle can be annoying, especially
Packit 8f70b4
    * if the line is rate-limited. */
Packit 8f70b4
   void DontRedisplayStatusbar() { statusbar_redisplay=false; }
Packit 8f70b4
Packit 8f70b4
   const char *Status(const StatusLine *s);
Packit 8f70b4
Packit 8f70b4
   void Fg();
Packit 8f70b4
   void Bg();
Packit 8f70b4
   void SuspendInternal();
Packit 8f70b4
   void ResumeInternal();
Packit 8f70b4
   int AcceptSig(int sig);
Packit 8f70b4
};
Packit 8f70b4
Packit 8f70b4
#endif