CTextFileLogComp.h
Go to the documentation of this file.
1 #ifndef ifile_CTextFileLogComp_included
2 #define ifile_CTextFileLogComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QFile>
7 #include <QtCore/QTextStream>
8 
9 // ACF includes
10 #include <imod/IModel.h>
12 #include <ifile/IFileNameParam.h>
14 
15 
16 namespace ifile
17 {
18 
19 
26 {
27 public:
29 
30  I_BEGIN_COMPONENT(CTextFileLogComp);
31  I_ASSIGN(m_fileNameCompPtr, "LogFile", "Name of the log file", true, "LogFile");
32  I_ASSIGN_TO(m_fileNameModelCompPtr, m_fileNameCompPtr, true);
33  I_ASSIGN(m_isAppendAttrPtr, "AppendToExisting", "Don't overwrite existing log file", true, false);
34  I_END_COMPONENT;
35 
37 
38 protected:
39  // reimplemented (CStreamLogCompBase)
40  virtual void WriteText(const QString& text, istd::IInformationProvider::InformationCategory category);
41 
42  // reimplemented (icomp::CComponentBase)
43  virtual void OnComponentCreated();
44  virtual void OnComponentDestroyed();
45 
46 private:
47  void OpenFileStream();
48  void CloseFileStream();
49 
50 private:
51  I_REF(ifile::IFileNameParam, m_fileNameCompPtr);
52  I_REF(imod::IModel, m_fileNameModelCompPtr);
53  I_ATTR(bool, m_isAppendAttrPtr);
54 
55  QFile m_outputFile;
56  QTextStream m_outputFileStream;
57 
58  class FilePathObserver: public imod::CSingleModelObserverBase
59  {
60  public:
62 
63  explicit FilePathObserver(CTextFileLogComp& parent);
64 
65  protected:
66  // reimplemented (imod::CSingleModelObserverBase)
67  virtual void OnUpdate(const istd::IChangeable::ChangeSet& changeSet);
68 
69  private:
70  CTextFileLogComp& m_parent;
71  };
72 
73  FilePathObserver m_filePathObserver;
74 
75  QMutex m_mutex;
76 };
77 
78 
79 } // namespace ifile
80 
81 
82 #endif // !ifile_CTextFileLogComp_included
83 
84 
Basic implementation for a single model observer.
Message container displaying messages as log list.
virtual void OnComponentDestroyed()
virtual void WriteText(const QString &text, istd::IInformationProvider::InformationCategory category)
Write a text line to the output stream.
Common interface for any file system item name (e.g directory, file or URL path)
Basic implementation for a log written to an output stream.
InformationCategory
Category of information.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30
virtual void OnComponentCreated()
ilog::CStreamLogCompBase BaseClass

© 2007-2017 Witold Gantzke and Kirill Lepskiy