Blame view

GUI/SW2/SRC/src/base/PrcBase.hpp 4.05 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//**************************************************************************************************
//                                           PrcBase.hpp                                           *
//                                          -------------                                          *
// Description : Provides a wrapper for the wxProcess class adding a bit of extra desirable        *
//               functionality.                                                                    *
// Started     : 2004-01-29                                                                        *
// Last Update : 2016-09-30                                                                        *
// Copyright   : (C) 2004-2016 MSWaters                                                            *
//**************************************************************************************************

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

#ifndef PRCBASE_HPP
#define PRCBASE_HPP

// Application Includes

#include "TypeDefs.hpp"
#include "utility/TextCtrl.hpp"
#include "utility/StrUtils.hpp"

// wxWidgets Includes

#include <wx/filename.h>
#include <wx/process.h>
#include <wx/utils.h>

// Local Constant Declarations

#define DEF_LOG_FILE  wxT("./prcbase.log")  // Default log file path and name

//**************************************************************************************************

class PrcBase : protected wxProcess
{
  protected :

    wxFileName  m_oNameBin;   // The file name of the binary to be executed
    wxFileName  m_oNameLog;   // The log file name for the textual process output
    wxString    m_osArgLst;   // The argument list appended to the binary name
    wxString    m_osErrMsg;   // Error message
    int         m_iPid;       // The process ID number
    int         m_iExitCode;  // The process exit code

    bool  bFindBinary( wxFileName & roFileBin );
    bool  bLogOutput ( void );

  public :

          PrcBase( int iFlags=wxPROCESS_REDIRECT );
         ~PrcBase( );

    bool  bBinExists( void );

    bool  bIsExec( void ) { return( m_iPid>0 ? true : false ); }
    bool  bIsOk  ( void ) { return( m_iExitCode==0 && m_osErrMsg.IsEmpty( ) ); }

    bool  bSetBinFile( const wxString & rosFileName  );
    bool  bSetLogFile( const wxString & rosFileName  );
    bool  bSetArgLst ( const wxString & rosArgLst );
    void   SetErrMsg ( const wxString & rosErrMsg )
                                             { if( m_osErrMsg.IsEmpty( ) ) m_osErrMsg = rosErrMsg; }

    const wxFileName &  roGetBinFile ( void ) { return( m_oNameBin  ); }
    const wxFileName &  roGetLogFile ( void ) { return( m_oNameLog  ); }
    const wxString   & rosGetArgLst  ( void ) { return( m_osArgLst  ); }
    const wxString   & rosGetErrMsg  ( void ) { return( m_osErrMsg  ); }
          int            iGetExitCode( void ) { return( m_iExitCode ); }

    virtual  bool  bExecAsync( void );
    virtual  bool  bExecSync ( void );
    virtual  bool  bKill     ( void );

    bool  bDelLogFile( void );

    void  Print   ( TextCtrl & roTxtCtl );
    void  PrintCmd( TextCtrl & roTxtCtl );
    void  PrintRsp( TextCtrl & roTxtCtl );

    // The following function is intended for debugging
    void  Print( const wxString & rosPrefix=wxT("  ") );

    // Event handlers
    void  OnTerminate( int iPid, int iStatus );
};

//**************************************************************************************************

#endif // PRCBASE_HPP