MIDAS
Loading...
Searching...
No Matches
WriterPopen Class Reference
Inheritance diagram for WriterPopen:
Collaboration diagram for WriterPopen:

Public Member Functions

 WriterPopen (LOG_CHN *log_chn, const char *pipe_command, const char *file_ext)
 
 ~WriterPopen ()
 
int wr_open (LOG_CHN *log_chn, int run_number)
 
int wr_write (LOG_CHN *log_chn, const void *data, const int size)
 
int wr_close (LOG_CHN *log_chn, int run_number)
 
std::string wr_get_file_ext ()
 
std::string wr_get_chain ()
 
- Public Member Functions inherited from WriterInterface
 WriterInterface ()
 
virtual ~WriterInterface ()
 

Private Attributes

FILE * fFp
 
std::string fPipeCommand
 
std::string fCommand
 
std::string fFileExt
 
time_t fLastCheckTime
 

Additional Inherited Members

- Public Attributes inherited from WriterInterface
bool fTrace
 
double fBytesIn
 
double fBytesOut
 

Detailed Description

Definition at line 739 of file mlogger.cxx.

Constructor & Destructor Documentation

◆ WriterPopen()

WriterPopen::WriterPopen ( LOG_CHN log_chn,
const char *  pipe_command,
const char *  file_ext 
)
inline

Definition at line 742 of file mlogger.cxx.

743 {
744 if (fTrace)
745 printf("WriterPopen: path [%s]\n", log_chn->path.c_str());
746 fFp = NULL;
747 fPipeCommand = pipe_command;
748 fFileExt = file_ext;
749 fLastCheckTime = time(NULL);
750 }
time_t fLastCheckTime
Definition mlogger.cxx:877
FILE * fFp
Definition mlogger.cxx:873
std::string fFileExt
Definition mlogger.cxx:876
std::string fPipeCommand
Definition mlogger.cxx:874
std::string path
Definition mlogger.cxx:250

◆ ~WriterPopen()

WriterPopen::~WriterPopen ( )
inline

Definition at line 752 of file mlogger.cxx.

753 {
754 if (fTrace)
755 printf("WriterPopen: destructor\n");
756 if (fFp)
757 pclose(fFp);
758 fFp = NULL;
759 }

Member Function Documentation

◆ wr_close()

int WriterPopen::wr_close ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 831 of file mlogger.cxx.

832 {
833 int err;
834
835 if (fTrace)
836 printf("WriterPopen: close path [%s]\n", log_chn->path.c_str());
837
838 assert(fFp != NULL);
839
840 log_chn->handle = 0;
841
842#ifdef OS_WINNT
843 // sorry no popen?!?
844 return SS_FILE_ERROR;
845#else
846 err = pclose(fFp);
847 fFp = NULL;
848
849 if (err != 0) {
850 cm_msg(MERROR, "WriterPopen::wr_close", "Cannot write to pipe \'%s\', pclose() returned %d, errno %d (%s)", fCommand.c_str(), err, errno, strerror(errno));
851 return SS_FILE_ERROR;
852 }
853
854 chmod(log_chn->path.c_str(), 0444);
855
856 fBytesOut = ss_file_size(log_chn->path.c_str());
857
858 return SUCCESS;
859#endif
860 }
std::string fCommand
Definition mlogger.cxx:875
#define SS_FILE_ERROR
Definition midas.h:670
#define SUCCESS
Definition mcstd.h:54
#define MERROR
Definition midas.h:559
double ss_file_size(const char *path)
Definition system.cxx:7050
INT cm_msg(INT message_type, const char *filename, INT line, const char *routine, const char *format,...)
Definition midas.cxx:931
INT handle
Definition mlogger.cxx:249
Here is the call graph for this function:
Here is the caller graph for this function:

◆ wr_get_chain()

std::string WriterPopen::wr_get_chain ( )
inlinevirtual

Implements WriterInterface.

Definition at line 867 of file mlogger.cxx.

868 {
869 return fPipeCommand;
870 }

◆ wr_get_file_ext()

std::string WriterPopen::wr_get_file_ext ( )
inlinevirtual

Reimplemented from WriterInterface.

Definition at line 862 of file mlogger.cxx.

863 {
864 return fFileExt;
865 }

◆ wr_open()

int WriterPopen::wr_open ( LOG_CHN log_chn,
int  run_number 
)
inlinevirtual

Implements WriterInterface.

Definition at line 761 of file mlogger.cxx.

762 {
763 fBytesIn = 0;
764 fBytesOut = 0;
765
766 if (fTrace)
767 printf("WriterPopen: open path [%s] pipe [%s] ext [%s]\n", log_chn->path.c_str(), fPipeCommand.c_str(), fFileExt.c_str());
768
769 assert(fFp == NULL);
770
771 if (check_file_exists(log_chn->path.c_str()))
772 return SS_FILE_EXISTS;
773
774#ifdef OS_WINNT
775 // sorry no popen?!?
776 return SS_FILE_ERROR;
777#else
778 fCommand = fPipeCommand + log_chn->path;
779
780 fFp = popen(fCommand.c_str(), "w");
781 if (fFp == NULL) {
782 cm_msg(MERROR, "WriterPopen::wr_open", "Cannot write to pipe \'%s\', popen() errno %d (%s)", fCommand.c_str(), errno, strerror(errno));
783 return SS_FILE_ERROR;
784 }
785
786 log_chn->handle = 9999;
787
788 return SUCCESS;
789#endif
790 }
#define SS_FILE_EXISTS
Definition midas.h:687
static bool check_file_exists(const char *filename)
Definition mlogger.cxx:368
Here is the call graph for this function:

◆ wr_write()

int WriterPopen::wr_write ( LOG_CHN log_chn,
const void *  data,
const int  size 
)
inlinevirtual

Implements WriterInterface.

Definition at line 792 of file mlogger.cxx.

793 {
794 if (fTrace)
795 printf("WriterPopen: write path [%s], size %d\n", log_chn->path.c_str(), size);
796
797 if (size == 0)
798 return SUCCESS;
799
800 if (fFp == NULL) {
801 return SS_FILE_ERROR;
802 }
803
804 fBytesIn += size;
805
806 int wr = fwrite(data, 1, size, fFp);
807
808 //if (wr > 0)
809 //fBytesOut += wr;
810
811 if (wr != size) {
812 cm_msg(MERROR, "WriterPopen::wr_write", "Cannot write to pipe \'%s\', fwrite(%d) returned %d, errno %d (%s)", fCommand.c_str(), size, wr, errno, strerror(errno));
813
814 if (errno == EPIPE) {
815 cm_msg(MERROR, "WriterPopen::wr_write", "Cannot write to pipe \'%s\': broken pipe, closing the pipe", fCommand.c_str());
816 wr_close(log_chn, 0);
817 }
818
819 return SS_FILE_ERROR;
820 }
821
822 time_t now = time(NULL);
823 if (now - fLastCheckTime > 2) {
824 fLastCheckTime = now;
825 fBytesOut = ss_file_size(log_chn->path.c_str());
826 }
827
828 return SUCCESS;
829 }
int wr_close(LOG_CHN *log_chn, int run_number)
Definition mlogger.cxx:831
void * data
Definition mana.cxx:268
Here is the call graph for this function:

Member Data Documentation

◆ fCommand

std::string WriterPopen::fCommand
private

Definition at line 875 of file mlogger.cxx.

◆ fFileExt

std::string WriterPopen::fFileExt
private

Definition at line 876 of file mlogger.cxx.

◆ fFp

FILE* WriterPopen::fFp
private

Definition at line 873 of file mlogger.cxx.

◆ fLastCheckTime

time_t WriterPopen::fLastCheckTime
private

Definition at line 877 of file mlogger.cxx.

◆ fPipeCommand

std::string WriterPopen::fPipeCommand
private

Definition at line 874 of file mlogger.cxx.


The documentation for this class was generated from the following file: