Blame src/OutputJob.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 OUTPUTJOB_H
Packit Service a2489d
#define OUTPUTJOB_H
Packit Service a2489d
Packit Service a2489d
#include "Job.h"
Packit Service a2489d
#include "FileCopy.h"
Packit Service a2489d
#include "CopyJob.h"
Packit Service a2489d
#include "Timer.h"
Packit Service a2489d
Packit Service a2489d
class StatusBar;
Packit Service a2489d
Packit Service a2489d
class OutputJob : public Job
Packit Service a2489d
{
Packit Service a2489d
   /* Main CopyJob: */
Packit Service a2489d
   CopyJob *input;
Packit Service a2489d
Packit Service a2489d
   /* CopyJob that sends to the output.  (output may be equal to input) */
Packit Service a2489d
   CopyJob *output;
Packit Service a2489d
Packit Service a2489d
   Ref<Buffer> tmp_buf;	// to store data while !initialized
Packit Service a2489d
   Ref<FDStream> output_fd;	// to initialize CopyJobs
Packit Service a2489d
   FileAccessRef fa;
Packit Service a2489d
   xstring_c fa_path;
Packit Service a2489d
Packit Service a2489d
   bool initialized;
Packit Service a2489d
Packit Service a2489d
   xstring_c a0;
Packit Service a2489d
   xstring_c filter;
Packit Service a2489d
Packit Service a2489d
   bool error;
Packit Service a2489d
   bool is_stdout;
Packit Service a2489d
   bool fail_if_broken;
Packit Service a2489d
   bool statusbar_redisplay;
Packit Service a2489d
Packit Service a2489d
   int width;
Packit Service a2489d
   bool is_a_tty;
Packit Service a2489d
Packit Service a2489d
   /* if true, we never contribute to the parent job's status
Packit Service a2489d
    * (Status() == "") */
Packit Service a2489d
   bool no_status;
Packit Service a2489d
Packit Service a2489d
   Timer update_timer;
Packit Service a2489d
Packit Service a2489d
   void Init(const char *a0);
Packit Service a2489d
   void InitCopy();
Packit Service a2489d
Packit Service a2489d
   /* Get the input FileCopyPeer */
Packit Service a2489d
   const SMTaskRef<FileCopyPeer>& InputPeer() const;
Packit Service a2489d
Packit Service a2489d
   /* Get the output FileCopyPeer (the FileCopyPeer that's doing the final output) */
Packit Service a2489d
   const SMTaskRef<FileCopyPeer>& OutputPeer() const;
Packit Service a2489d
Packit Service a2489d
public:
Packit Service a2489d
   OutputJob(FDStream *output, const char *a0);
Packit Service a2489d
   OutputJob(const char *path, const char *a0, FA *fa=0);
Packit Service a2489d
   void PrepareToDie();
Packit Service a2489d
Packit Service a2489d
   /* Set the main filter: */
Packit Service a2489d
   void SetFilter(const char *f) { filter.set(f); }
Packit Service a2489d
   /* Prepend a filter before the main filter: */
Packit Service a2489d
   void PreFilter(const char *f);
Packit Service a2489d
Packit Service a2489d
   void DontFailIfBroken(bool y=true) { fail_if_broken=!y; }
Packit Service a2489d
   bool Error();
Packit Service a2489d
Packit Service a2489d
   int Done();
Packit Service a2489d
   int Do();
Packit Service a2489d
Packit Service a2489d
   void Put(const char *buf,int size);
Packit Service a2489d
   void Put(const char *buf) { Put(buf,strlen(buf)); }
Packit Service a2489d
   void Put(const xstring& str) { Put(str.get(),str.length()); }
Packit Service a2489d
   void Format(const char *f,...) PRINTF_LIKE(2,3);
Packit Service a2489d
   void PutEOF();
Packit Service a2489d
Packit Service a2489d
   /* If sending large amounts of data, call this function and stop
Packit Service a2489d
    * sending if it returns true.  (This always accept more input;
Packit Service a2489d
    * this is optional.) */
Packit Service a2489d
   bool Full();
Packit Service a2489d
Packit Service a2489d
   /* Get properties of the output: */
Packit Service a2489d
   int GetWidth() const;
Packit Service a2489d
   bool IsTTY() const;
Packit Service a2489d
   /* Whether the ultimate destination is stdout: */
Packit Service a2489d
   bool IsStdout() const { return is_stdout; }
Packit Service a2489d
   /* Whether the output is filtered: */
Packit Service a2489d
   bool IsFiltered() const { return filter; }
Packit Service a2489d
Packit Service a2489d
   /* Call before showing a StatusLine on a job using this class.  If it
Packit Service a2489d
    * returns false, don't display it. */
Packit Service a2489d
   bool ShowStatusLine(const SMTaskRef<StatusLine>&);
Packit Service a2489d
Packit Service a2489d
   /* For commands that stream output from servers, redisplaying the
Packit Service a2489d
    * statusbar when output becomes idle can be annoying, especially
Packit Service a2489d
    * if the line is rate-limited. */
Packit Service a2489d
   void DontRedisplayStatusbar() { statusbar_redisplay=false; }
Packit Service a2489d
Packit Service a2489d
   const char *Status(const StatusLine *s);
Packit Service a2489d
Packit Service a2489d
   void Fg();
Packit Service a2489d
   void Bg();
Packit Service a2489d
   void SuspendInternal();
Packit Service a2489d
   void ResumeInternal();
Packit Service a2489d
   int AcceptSig(int sig);
Packit Service a2489d
};
Packit Service a2489d
Packit Service a2489d
#endif