00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _Processing_hxx_
00024 #define _Processing_hxx_
00025
00026
00027 #include "ErrProcessingObj.hxx"
00028 #include "InControlRegistry.hxx"
00029 #include "OutControlRegistry.hxx"
00030 #include "TypedInControlRegistry.hxx"
00031 #include "TypedOutControlRegistry.hxx"
00032 #include "InPortRegistry.hxx"
00033 #include "OutPortRegistry.hxx"
00034 #include "ProcessingConfig.hxx"
00035 #include "NullProcessingConfig.hxx"
00036
00037 #include <list>
00038 #include <typeinfo>
00039 #include <string>
00040
00041 namespace CLAM
00042 {
00043
00044 class Processing;
00045 class InPortBase;
00046 class OutPortBase;
00047 class InControl;
00048 class OutControl;
00049 class ProcessingComposite;
00050 class Network;
00055 void ConnectPorts(
00056 Processing & sender, const std::string & outPortName,
00057 Processing & receiver, const std::string & inPortName );
00062 void ConnectPorts(
00063 Processing & sender, unsigned outPortNumber,
00064 Processing & receiver, unsigned inPortNumber );
00069 void ConnectControls(
00070 Processing & sender, unsigned outControlNumber,
00071 Processing & receiver, unsigned inControlNumber );
00076 void ConnectControls(
00077 Processing & sender, const std::string & outControlName,
00078 Processing & receiver, const std::string & inControlName );
00082 void ConnectTypedControls(
00083 Processing & sender, unsigned typedOutControlNumber,
00084 Processing & receiver, unsigned typedInControlNumber );
00088 void ConnectTypedControls(
00089 Processing & sender, const std::string & typedOutControlName,
00090 Processing & receiver, const std::string & typedInControlName );
00091
00096 void ConnectPorts(
00097 OutPortBase & sender,
00098 Processing & receiver, unsigned inPortNumber );
00103 void ConnectPorts(
00104 Processing & sender, unsigned outPortNumber,
00105 InPortBase & receiver );
00110 void SendFloatToInControl(Processing & receiver, const std::string & inControlName, float value);
00115 void SendFloatToInControl(Processing & receiver, int inControlIndex, float value);
00120 void SendFloatToOutControl(Processing & sender, const std::string & inControlName, float value);
00125 void SendFloatToOutControl(Processing & sender, int inControlIndex, float value);
00130 float GetFloatFromInControl(Processing & proc, const std::string & inControlName);
00135 float GetFloatFromInControl(Processing & proc, int inControlIndex);
00136
00181 class Processing {
00182 public:
00184 typedef enum {
00185 Unconfigured=0,
00186 Ready,
00187 Running
00188 } ExecState;
00189
00190 typedef NullProcessingConfig Config;
00191
00192
00193
00194 public:
00195
00209 bool Configure(const ProcessingConfig& config);
00210
00215 void Start(void);
00216
00221 virtual bool Do(void)=0;
00222
00228 void Stop(void);
00229
00230 Processing();
00231 virtual ~Processing();
00232
00233
00234 public:
00235
00237 virtual const char * GetClassName() const = 0;
00238
00240 virtual bool CanProcessInplace() { return true; }
00241
00242 protected:
00262 virtual bool ConcreteConfigure(const ProcessingConfig&) { return true; };
00263
00269 virtual bool ConcreteStart() {return true;};
00270
00276 virtual bool ConcreteStop() {return true;};
00277
00279 unsigned BackendBufferSize();
00281 unsigned BackendSampleRate();
00282
00283 public:
00285 bool CanConsumeAndProduce();
00286
00295 virtual const ProcessingConfig &GetConfig() const;
00296
00303 private:
00304 ExecState GetExecState() const {return _execState;}
00305 public:
00306 std::string GetExecStateString() const;
00307 bool IsConfigured() const { return _execState != Unconfigured; }
00308 bool IsRunning() const { return _execState == Running; }
00309
00310
00311 void RegisterOutPort(OutPortBase* out);
00312 void RegisterInPort(InPortBase* in);
00313 void RegisterOutControl(OutControl* out);
00314 void RegisterInControl(InControl* in);
00315 void RegisterTypedOutControl(BaseTypedOutControl* out);
00316 void RegisterTypedInControl(BaseTypedInControl* in);
00317
00318
00319 void SetParent(Processing *p);
00320 void SetNetworkBackLink(Network * network);
00327 virtual bool ModifiesPortsAndControlsAtConfiguration() { return false; }
00328
00329 bool HasInPort( const std::string & name )
00330 {
00331 return mInPortRegistry.Has(name);
00332 }
00333
00334 bool HasOutPort( const std::string & name )
00335 {
00336 return mOutPortRegistry.Has(name);
00337 }
00338
00339 bool HasInControl( const std::string & name )
00340 {
00341 return mInControlRegistry.Has(name);
00342 }
00343
00344 bool HasOutControl( const std::string & name )
00345 {
00346 return mOutControlRegistry.Has(name);
00347 }
00348
00349 bool HasTypedInControl( const std::string & name )
00350 {
00351 return mTypedInControlRegistry.Has(name);
00352 }
00353
00354 bool HasTypedOutControl( const std::string & name )
00355 {
00356 return mTypedOutControlRegistry.Has(name);
00357 }
00358
00359 InPortBase & GetInPort( const std::string & name )
00360 {
00361 return mInPortRegistry.Get(name);
00362 }
00363 OutPortBase & GetOutPort( const std::string & name )
00364 {
00365 return mOutPortRegistry.Get(name);
00366 }
00367 InControl & GetInControl( const std::string & name )
00368 {
00369 return mInControlRegistry.Get(name);
00370 }
00371 OutControl & GetOutControl( const std::string & name )
00372 {
00373 return mOutControlRegistry.Get(name);
00374 }
00375
00377 InControlRegistry& GetInControls() { return mInControlRegistry; }
00378
00380 OutControlRegistry& GetOutControls() { return mOutControlRegistry; }
00381
00383 TypedInControlRegistry& GetTypedInControls() { return mTypedInControlRegistry; }
00384
00386 TypedOutControlRegistry& GetTypedOutControls() { return mTypedOutControlRegistry; }
00387
00389 InPortRegistry& GetInPorts() { return mInPortRegistry; }
00390
00392 OutPortRegistry& GetOutPorts() { return mOutPortRegistry; }
00393
00395 const std::string& GetConfigErrorMessage() const { return _configErrorMessage; }
00396
00399 virtual bool IsSyncSource() const { return false; }
00400
00401
00402 protected:
00403
00406 void AddConfigErrorMessage( const std::string& msg );
00407
00410 bool AbleToExecute(void) const;
00411
00419 template <typename ConcreteConfig>
00420 void CopyAsConcreteConfig(ConcreteConfig & concrete, const ProcessingConfig & abstract) const;
00421 protected:
00422 void SetExecState(ExecState state)
00423 {
00424 _execState = state;
00425 }
00426
00428 ProcessingComposite *mpParent;
00431 Network * _network;
00432 private:
00433
00435 ExecState _execState;
00436
00438 std::string _configErrorMessage;
00439
00440
00441 private:
00442 InControlRegistry mInControlRegistry;
00443 OutControlRegistry mOutControlRegistry;
00444 TypedInControlRegistry mTypedInControlRegistry;
00445 TypedOutControlRegistry mTypedOutControlRegistry;
00446 InPortRegistry mInPortRegistry;
00447 OutPortRegistry mOutPortRegistry;
00448 };
00449
00450
00451
00452
00453
00454
00455 inline bool Processing::AbleToExecute(void) const
00456 {
00457 CLAM_BEGIN_DEBUG_CHECK
00458 if (!IsRunning())
00459 {
00460 std::string err(GetClassName());
00461 err += ": Do(): Not in execution mode - did you call Start on this "
00462 "object, the composite it is in, or the ToplevelProcessing singleton?";
00463 CLAM_DEBUG_ASSERT( false, err.c_str() );
00464 }
00465 CLAM_END_DEBUG_CHECK
00466 return IsRunning();
00467 }
00468
00469 template <typename ConcreteConfig>
00470 inline void Processing::CopyAsConcreteConfig(ConcreteConfig & concrete, const ProcessingConfig & abstract) const
00471 {
00472 CLAM_ASSERT(typeid(ConcreteConfig)==typeid(abstract),
00473 "Configuring a Processing with a configuration not being the proper type.");
00474 concrete = static_cast<const ConcreteConfig &>(abstract);
00475 }
00476
00477 };
00478
00479 #endif
00480