00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00057
00058
00059
00060 #ifndef __MX_FILEWRITER_H__
00061 #define __MX_FILEWRITER_H__
00062
00063
00064
00065 #define MX_FILEWRITER_ID "FileWriter"
00066
00067
00068
00069 #include "StreamFile.h"
00070
00071 #include <interfaces/IFileWriter.h>
00072 #include <interfaces/IComponent.h>
00073 #include <interfaces/IComponentInvoker.h>
00074
00075 #include <Framework/Framework.h>
00076
00077 #include <mxm/core/mxmObject.h>
00078
00079
00080
00081 namespace mx {
00082
00084
00089 class FileWriter : public mxmObject,
00090 public virtual IComponent,
00091 public virtual IFileWriter {
00092
00096 private:
00097 static mxm::smart<mxmStringList> _enumerateInterfaces() {
00098 return(new mxmStringList(
00099 (mxmString(MX_FILEWRITER_ID),
00100 MX_ICOMPONENT_ID,
00101 MX_IFILEWRITER_ID,
00102 MX_ISUPPORTSFILESPECIFICATION_ID,
00103 MX_ISEGMENTEDSTREAMRECEIVER_ID,
00104 MX_ISTREAMRECEIVER_ID,
00105 MX_IERRORSTATE_ID)));
00106 }
00107 static mxm::smart<mxmStringList> _enumerateCapabilities(
00108 const mxmString &interface_id) {
00109 if(interface_id == mx::Framework::IdHintKey)
00110 return(new mxmStringList(MX_FILEWRITER_ID));
00111 else
00112 return(new mxmStringList());
00113 }
00114 private:
00115 class Invoker : public mxmObject, public virtual IComponentInvoker {
00116 public:
00117 mxm::smart<mxmStringList> enumerateInterfaces() {
00118 return(_enumerateInterfaces());
00119 }
00120 mxm::smart<mxmStringList> enumerateCapabilities(
00121 const mxmString &interface_id) {
00122 return(_enumerateCapabilities(interface_id));
00123 }
00124 IComponent *newComponent() {
00125 return(new FileWriter());
00126 }
00127 };
00128 public:
00130 static IComponentInvoker *newInvoker() {
00131 return(new Invoker());
00132 }
00133
00134 private:
00135 mxmString Filename;
00136 int FileDescriptor;
00137 mxm::smart<mx::StreamFile> File;
00138 bool IndividualFileMode;
00139 int IndividualFileNum;
00140 int IndividualFileCounter;
00141 mxmString Separator;
00142 bool ErrorEncountered;
00143 bool Fresh,
00144 FreshSegment;
00145 bool HasBeenShutDown;
00146
00147 public:
00148 FileWriter();
00149 ~FileWriter();
00150
00151 public:
00153 mxm::smart<mxmStringList> enumerateInterfaces();
00155 mxm::smart<mxmStringList> enumerateCapabilities(
00156 const mxmString &interface);
00157
00159 void setFilename(const mxmString &filename);
00161 void setFileDescriptor(int fd);
00162
00164 void receiveStreamBytes(const mxm::u8 *bytes, int byte_num);
00166 void newStreamSegment();
00167
00169 void writeSingleConcatenatedFile();
00171 void setSegmentSeparator(const mxmString &separator);
00173 void writeIndividualFiles(int num);
00174
00176 bool errorState();
00178 void setErrorState();
00180 void shutdown();
00181
00182 private:
00183 void openFile();
00184 void closeFile();
00185 void reset(bool safe_settings = false);
00186 };
00187 };
00188
00189
00190
00191 #endif // __MX_FILEWRITER_H__