00001 #ifndef SXCOMPONENT_H_INCLUDED
00002 #define SXCOMPONENT_H_INCLUDED
00003
00004 #include "sxPort.h"
00005 #include "sxPacket.h"
00006
00007 class sxNetwork;
00008 class sxComponentRunner;
00009 class sxUiAbstractComponent;
00010 class sxTimer;
00014 class SX_SDKEXPORT sxComponent : public sxCaptionItem
00015 {
00016 public:
00017 virtual ~sxComponent();
00023 virtual bool Work() = 0;
00028 virtual int Type() const = 0;
00036 virtual bool ConfigurePorts() = 0;
00037
00038
00039 virtual bool IsSource() const;
00040 virtual bool IsProcessor() const;
00041 virtual bool IsSink() const;
00042 virtual bool IsPassive() const;
00043 virtual bool IsMultipleInstanceAllowed() const;
00044 virtual bool IsManager() const;
00045
00046 virtual bool PreEvaluation();
00047 virtual bool OnEvaluate();
00048 virtual bool PreActivation();
00049 virtual bool PostDeactivation();
00050 virtual bool CheckConnections() const;
00051 virtual sxPacket * DataRequested();
00052
00053
00054 virtual bool OnCreate();
00055 virtual bool OnDestroy();
00056 virtual bool OnEnterWorkingLoop();
00057 virtual void OnExitWorkingLoop();
00058
00059
00060 virtual bool Load(const QDomElement& comps, const QList<sxPort *> & portList);
00061 virtual bool Save(QDomElement& comps);
00062 protected:
00063
00064 virtual bool SaveCustom(QDomElement & compNode);
00065 virtual bool LoadCustom(const QDomElement & compNode);
00066
00067 public:
00068
00069 enum {
00070 Terminated = 0x01,
00071 PreActivated = 0x02,
00072 Activated = 0x04,
00073 Deactivated = 0x08,
00074 Error = 0x10,
00075 PreEvaluating = 0x20,
00076 AbortByUser = 0x40
00077 };
00078
00079
00080 sxUiAbstractComponent * UiComponent() const;
00081 unsigned long RunCount() const;
00082 void SetRunner(sxComponentRunner * runer);
00083 sxComponentRunner * Runner() const;
00084 QList<sxComponent *> DownstreamComponents() const;
00085 bool IsError() const;
00086 void ClearErrors();
00087 QString ErrorMessage() const;
00088 QString ComponentId() const;
00089 QString Description() const;
00090 void SetDescription(const QString & txt);
00091 bool IsContinued() const;
00092 int State() const;
00093 void SetNetwork(sxNetwork * net);
00094 sxNetwork * Network() const;
00095 bool IsActivated() const;
00096 bool IsTerminated() const;
00097
00098
00099 double GTimerToc() const;
00100 qint64 GTimerBase() const;
00101 void TimerTic();
00102 double TimerToc() const;
00103
00104
00105 void DisplayMessage(const QString& msg, sx::MessageType type = sx::RegularMessage);
00106
00107
00108 bool HasInput() const;
00109 bool HasOutput() const;
00110 sxInPort * InputAt(int idx) const;
00111 int InputCount() const;
00112 sxOutPort * OutputAt(int idx) const;
00113 int OutputCount() const;
00114 sxOutPort * FirstOutput() const;
00115 sxInPort * FirstInput() const;
00116 void ClearPorts();
00117 bool OpenPorts();
00118 bool ClosePorts();
00119
00120
00121 void ResetStates();
00122 bool Evaluate();
00123 bool Activate(unsigned long rcount);
00124 bool Deactivate();
00125 void Terminate();
00126
00127 QString LibraryName() const;
00128 void SetLibraryName(const QString& name);
00129
00130 protected:
00131 sxComponent(const QString& name, const QString& cap,
00132 sxUiAbstractComponent * ui);
00133 void SetErrorMessage(const QString& msg);
00134 void SetComponentId(const QString& id);
00135 void SetComponentId(quintptr id);
00136 void SetState(int s);
00137
00138
00139 bool IsAllInputsConnected() const;
00140 bool IsAnyInputConnected() const;
00141 bool IsAllOutputsConnected() const;
00142 bool IsAnyOutputConnected() const;
00143
00144
00145 void RemovePorts();
00146 void AddPort(sxPort * p);
00147 sxOutPort * AddOutputPort(const QString & cap, sx::DataType dtype);
00148 sxInPort * AddInputPort(const QString & cap);
00149
00150 sxTimer * Timer();
00151 private:
00152 SX_DISABLE_COPY(sxComponent)
00153
00154 class PrivateData;
00155 PrivateData * d_p;
00156 };
00157
00158 #endif // SXCOMPONENT_H_INCLUDED