Network.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _Network_hxx_
00022 #define _Network_hxx_
00023
00024 #include "Processing.hxx"
00025 #include "InPort.hxx"
00026 #include "OutPort.hxx"
00027 #include "InControl.hxx"
00028 #include "OutControl.hxx"
00029 #include "Component.hxx"
00030 #include "Text.hxx"
00031 #include <string>
00032 #include <list>
00033 #include <map>
00034 #include <set>
00035
00036
00037 namespace CLAM
00038 {
00039
00040 class NetworkPlayer;
00041 class FlowControl;
00042 class ControlSink;
00043 class ControlSource;
00044
00045 class InformationText
00046 {
00047 public:
00048 int x;
00049 int y;
00050 Text text;
00051 };
00052
00053
00054 class Network : public Component
00055 {
00056
00057 public:
00058
00059 typedef std::list<std::string> NamesList;
00060 typedef std::map <std::string, Processing* > ProcessingsMap;
00061 typedef std::list<InPortBase *> InPortsList;
00062
00063 typedef std::vector<Processing*> Processings;
00064 typedef std::vector<ControlSource*> ControlSources;
00065 typedef std::vector<ControlSink*> ControlSinks;
00066
00067 typedef std::vector<InformationText*> InformationTexts;
00068
00069 typedef struct { int x, y, width, height; } Geometry;
00070 typedef std::map <std::string, Geometry> ProcessingsGeometriesMap;
00071
00072
00073 typedef std::set<std::string> NamesSet;
00074 public:
00075
00076 Network();
00077 virtual ~Network();
00078
00080
00081 const std::string& GetName() const { return _name; }
00082 void SetName( const std::string& name ) { _name=name; }
00083
00090 const Text& GetDescription() const {return _description;};
00095 void SetDescription( const Text& description ) {_description=description;};
00096
00097 virtual const char * GetClassName() const
00098 {
00099 return "Network";
00100 }
00101
00102
00103 bool IsStopped() const;
00104 bool IsPlaying() const;
00105 bool IsPaused() const;
00106 bool IsRealTime() const;
00107 void Start();
00108 void Stop();
00109 void Pause();
00110 void Do();
00112 void AddFlowControl( FlowControl* );
00113 void Clear();
00115 void SetPlayer( NetworkPlayer* player);
00116 unsigned BackendBufferSize();
00117 unsigned BackendSampleRate();
00118
00119
00120 virtual void StoreOn( Storage & storage) const;
00121 virtual void LoadFrom( Storage & storage);
00122
00124
00128 bool UpdateSelections (const NamesList & processingsNamesList);
00134 void setPasteMode() { _inPasteMode=true; }
00135
00136
00142 bool SetProcessingsGeometries (const ProcessingsGeometriesMap & processingsGeometries);
00151 const ProcessingsGeometriesMap GetAndClearGeometries();
00152
00157 const Geometry & getProcessingGeometry(const std::string & processingName ) const;
00162 const Processings getOrderedProcessings(const std::string & type, bool horizontalOrder) const;
00169 const Processings getOrderedProcessingsByAttribute(const std::string & attribute, bool horizontalOrder=false) const;
00170
00172 const ControlSinks getOrderedControlSinks() const;
00174 const ControlSources getOrderedControlSources() const;
00175
00177 bool ConnectPorts( const std::string &, const std::string & );
00178 bool ConnectControls( const std::string &, const std::string & );
00179 bool DisconnectPorts( const std::string &, const std::string & );
00180 bool DisconnectControls( const std::string &, const std::string & );
00181
00186 Processing& GetProcessing( const std::string & name ) const;
00187
00194 void AddProcessing( const std::string & name, Processing* processing, const ProcessingConfig * config=0 );
00195
00202 Processing & AddProcessing( const std::string & name, const std::string & type );
00207 std::string AddProcessing( const std::string & type );
00208
00210 std::string GetUnusedName( const std::string& prefix, const bool cutOnLastSeparator=false, const std::string separator="_") const;
00215 void RemoveProcessing ( const std::string & name);
00217 bool HasProcessing( const std::string & name ) const;
00223 bool ConfigureProcessing( const std::string &, const ProcessingConfig & );
00225 void ReconfigureAllProcessings();
00231 bool RenameProcessing( const std::string & oldName, const std::string & newName );
00236 const std::string & GetNetworkId(const Processing * proc) const;
00237
00238
00239 ProcessingsMap::iterator BeginProcessings();
00240 ProcessingsMap::iterator EndProcessings();
00241 ProcessingsMap::const_iterator BeginProcessings() const;
00242 ProcessingsMap::const_iterator EndProcessings() const;
00243
00244
00245 void addInformationText(InformationText * informationText);
00246 void removeInformationText(InformationText * informationText);
00247
00248 InformationTexts::iterator BeginInformationTexts();
00249 InformationTexts::iterator EndInformationTexts();
00250 InformationTexts::const_iterator BeginInformationTexts() const;
00251 InformationTexts::const_iterator EndInformationTexts() const;
00252
00253 InPortBase & GetInPortByCompleteName( const std::string& ) const;
00254 OutPortBase & GetOutPortByCompleteName( const std::string& ) const;
00255 InControlBase & GetInControlByCompleteName( const std::string& ) const;
00256 OutControlBase & GetOutControlByCompleteName( const std::string& ) const;
00257
00258 NamesList GetInPortsConnectedTo( const std::string & ) const;
00259 NamesList GetInControlsConnectedTo( const std::string & ) const;
00260 InPortsList GetInPortsConnectedTo( OutPortBase & ) const;
00261
00262 std::string GetConnectorIdentifier( const std::string& ) const;
00263 std::string GetProcessingIdentifier( const std::string& ) const;
00264
00270 bool IsReady() const;
00271
00273 bool IsEmpty() const;
00274
00276 bool HasMisconfiguredProcessings() const;
00277
00279 bool HasUnconnectedInPorts() const;
00280
00285 bool HasSyncSource() const;
00286
00288 bool SupportsVariableAudioSize() const;
00289
00294 std::string GetConfigurationErrors() const;
00299 std::string GetUnconnectedInPorts() const;
00300
00305 typedef std::pair<bool, std::string> ConnectionState;
00306 ConnectionState GetConnectionReport() const;
00307 void ResetConnectionReport();
00308
00309 private:
00310
00311 std::string _name;
00312 Text _description;
00313 ProcessingsMap _processings;
00314 FlowControl* _flowControl;
00315 NetworkPlayer* _player;
00316 InformationTexts _informationTexts;
00317
00319 mutable NamesSet _selectedProcessings;
00321 bool _inPasteMode;
00322
00327 bool SelectionAndDoesNotContain(const std::string & name) const;
00328
00329
00330 mutable ProcessingsGeometriesMap _processingsGeometries;
00331 void StringPairToInts(const std::string & geometryInString, int & a, int & b);
00332 const std::string IntsToString (const int & a, const int & b) const;
00333
00334 protected:
00335 static std::size_t PositionOfLastIdentifier( const std::string& str)
00336 {
00337 std::size_t result = str.find_last_of( NamesIdentifiersSeparator() );
00338 CLAM_ASSERT( result!=std::string::npos, "Malformed port/control name. It should be ProcessingName.[Port/Control]Name");
00339 return result;
00340 }
00341 static std::size_t PositionOfProcessingIdentifier( const std::string& str)
00342 {
00343 std::size_t endPos = PositionOfLastIdentifier(str)-1;
00344 std::size_t last_ofResult = str.find_last_of( NamesIdentifiersSeparator(), endPos );
00345 return last_ofResult == std::string::npos ? 0 : last_ofResult+1;
00346 }
00347 static char NamesIdentifiersSeparator()
00348 {
00349 return '.';
00350 }
00351 private:
00352 bool BrokenConnection( const std::string & producer, const std::string & consumer );
00353 std::vector<std::string> _brokenConnections;
00354 };
00355
00356 }
00357 #endif
00358