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_STREAMFILE_H__
00061 #define __MX_STREAMFILE_H__
00062
00063
00064
00065 #define MX_STREAMFILE_ID "StreamFile"
00066
00067
00068
00069 #include <interfaces/IComponent.h>
00070 #include <interfaces/IComponentInvoker.h>
00071 #include <interfaces/IStreamSourceFile.h>
00072 #include <interfaces/IStreamReceiver.h>
00073
00074 #include <Framework/Framework.h>
00075
00076 #include <mxm/core/mxmObject.h>
00077
00078
00079
00080 namespace mx {
00081
00084
00115 class StreamFile : public mxmObject,
00116 public virtual IComponent,
00117 public virtual IStreamSourceFile,
00118 public virtual IStreamReceiver {
00119
00123 private:
00124 static mxm::smart<mxmStringList> _enumerateInterfaces() {
00125 return(new mxmStringList((mxmString(MX_STREAMFILE_ID),
00126 MX_ICOMPONENT_ID,
00127 MX_ISTREAMSOURCEFILE_ID,
00128 MX_ISUPPORTSFILESPECIFICATION_ID,
00129 MX_ISTREAMSOURCE_ID,
00130 MX_IREQUIRESACTIVATION_ID,
00131 MX_ISTREAMRECEIVER_ID,
00132 MX_ISUPPORTSSHUTTINGDOWN_ID,
00133 MX_IERRORSTATE_ID)));
00134 }
00135 static mxm::smart<mxmStringList> _enumerateCapabilities(
00136 const mxmString &interface) {
00137 if(interface == mx::Framework::IdHintKey)
00138 return(new mxmStringList(MX_STREAMFILE_ID));
00139 else
00140 return(new mxmStringList());
00141 }
00142
00143 private:
00144 class Invoker : public mxmObject, public virtual IComponentInvoker {
00145 public:
00146 mxm::smart<mxmStringList> enumerateInterfaces() {
00147 return(_enumerateInterfaces());
00148 }
00149 mxm::smart<mxmStringList> enumerateCapabilities(
00150 const mxmString &interface) {
00151 return(_enumerateCapabilities(interface));
00152 }
00153 IComponent *newComponent() {
00154 return(new StreamFile());
00155 }
00156 };
00157 public:
00159 static IComponentInvoker *newInvoker() {
00160 return(new Invoker());
00161 }
00162
00163 private:
00164 mxmString Filename;
00165 int FileDescriptor;
00166 bool WriteMode;
00167 bool Online;
00168
00169 int FD;
00170 bool StillUp;
00171 bool ErrorEncountered;
00172 bool HasBeenShutDown;
00173 bool CloseFileUponDestruction;
00174 #ifdef MX_PLATFORM_WINDOWS
00175 int RestoreMode;
00176 long OSFHandle;
00177 #endif
00178 bool TimedBlockMode;
00179 long BlockTimeout;
00180
00181 public:
00182 StreamFile();
00183 ~StreamFile();
00184
00185 public:
00187 mxm::smart<mxmStringList> enumerateInterfaces() {
00188 return(_enumerateInterfaces());
00189 }
00191 mxm::smart<mxmStringList> enumerateCapabilities(
00192 const mxmString &interface) {
00193 return(_enumerateCapabilities(interface));
00194 }
00195
00197 void setFilename(const mxmString &filename);
00199 void setFileDescriptor(int fd);
00202 void setWriteMode(bool enabled);
00203
00205 void setTimedBlockModeEnabled(bool enabled, long timeout = 1000);
00206
00208 int fetchStreamBytes(mxm::u8 *buffer, int num);
00210 bool stillUp(void);
00211
00213 void receiveStreamBytes(const mxm::u8 *bytes, int byte_num);
00214
00216 bool errorState();
00218 void setErrorState();
00220 void shutdown();
00221
00223 bool activate();
00224
00225 private:
00227 void closeFile();
00228 };
00229 };
00230
00231
00232
00233 #endif // __MX_STREAMFILE_H__