X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.h;h=03015dc932f44322c2a4d34b9b61117e5e0618a6;hb=9f6d1a6420a64127d9b199fc0f55c01e85485c39;hp=1c809634ca804e83c65fb75ad934a48115a03c2d;hpb=a26195c366a89795288009cf7e20f11afa494970;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.h b/kernel/src/bbtkBlackBox.h index 1c80963..03015dc 100644 --- a/kernel/src/bbtkBlackBox.h +++ b/kernel/src/bbtkBlackBox.h @@ -3,8 +3,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.h,v $ Language: C++ - Date: $Date: 2008/01/22 15:02:00 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/10/06 09:11:21 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See doc/license.txt or @@ -30,8 +30,8 @@ #ifndef __bbtkBlackBox_h__ #define __bbtkBlackBox_h__ +#include "bbtkSystem.h" #include "bbtkBlackBoxDescriptor.h" -//#include "bbtkConnection.h" #include "bbtkBlackBoxInputConnector.h" #include "bbtkBlackBoxOutputConnector.h" #include @@ -43,18 +43,16 @@ namespace bbtk struct Void { Void(int = 0) {} }; class Factory; + class Connection; - class BBTK_EXPORT BlackBox + class BBTK_EXPORT BlackBox : public Object { - - + BBTK_ABSTRACT_OBJECT_INTERFACE(BlackBox); public: //================================================================== // INTERFACE //================================================================== - /// The type of pointer on a BlackBox - typedef BlackBox* Pointer; - + /// The type of map of output connector pointers typedef std::map OutputConnectorMapType; @@ -63,13 +61,11 @@ namespace bbtk InputConnectorMapType; /// Returns the pointer on the descriptor of the box - virtual BlackBoxDescriptor* bbGetDescriptor() const = 0; + virtual BlackBoxDescriptor::Pointer bbGetDescriptor() const = 0; /// Returns a pointer on a clone of the box with name - virtual BlackBox* bbClone(const std::string& name) = 0; + virtual BlackBox::Pointer bbClone(const std::string& name) = 0; - /// Destruction method of a black box - virtual void bbDelete(); /// User overloadable destruction method of a black box virtual void bbUserDelete(); @@ -85,12 +81,10 @@ namespace bbtk virtual std::string bbGetFullName() const; /// Returns the name with the name of the parent prepended if any - std::string bbGetNameWithParent() const; + virtual std::string bbGetNameWithParent() const; - /// Sets the parent of the BlackBox - void bbSetParent(BlackBox::Pointer p) { bbmParent = p; } /// Returns the parent of the BlackBox, i.e the BlackBox that contains it (0 if none) - BlackBox::Pointer bbGetParent() const { return bbmParent; } + BlackBox::Pointer bbGetParent() const { return bbmParent.lock(); } /// Main processing method of the box. @@ -150,15 +144,6 @@ bool reaction = true); /// Sets the data of the output called virtual void bbSetOutput( const std::string &name, Data data) = 0; - /// Connects the input to the connection c - virtual void bbConnectInput( const std::string& name, Connection* c); - /// Connects the output to the connection c - virtual void bbConnectOutput( const std::string& name, Connection* c); - - /// Disconnects the input from the connection c - virtual void bbDisconnectInput( const std::string& name, Connection* c); - /// Disconnects the output from the connection c - virtual void bbDisconnectOutput( const std::string& name, Connection* c); /// Returns the input connectors map InputConnectorMapType& bbGetInputConnectorMap() @@ -231,7 +216,7 @@ bool reaction = true); /// (uses bbGetInputAsString / bbGetOutputAsString which use adaptors) /// If relative_link is true then creates relative hrefs virtual void bbWriteDotFileBlackBox(FILE *ff, - BlackBox *parentblackbox, + BlackBox::Pointer parentblackbox, int detail, int level, bool instanceOrtype, bool relative_link ); @@ -241,13 +226,20 @@ bool reaction = true); int detail, int level); - virtual void bbShowRelations(BlackBox *parentblackbox, + virtual void bbShowRelations(BlackBox::Pointer parentblackbox, int detail, int level ); std::string bbGetOutputAsString( const std::string &output ); //,Factory *factory); std::string bbGetInputAsString( const std::string &input); //,Factory *factory); - virtual BlackBox *bbFindBlackBox(const std::string &blackboxname) { return NULL;} + virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname) + { return BlackBox::Pointer();} + + virtual void Check(bool recursive = true); + + virtual void bbUserOnShow() { } + void bbUserOnShowWidget(std::string nameInput); + protected: //================================================================== @@ -257,8 +249,6 @@ bool reaction = true); BlackBox(const std::string &name); /// Constructor from an existing box (copy) with a new name BlackBox(BlackBox& from, const std::string &name); - /// Destructor - virtual ~BlackBox(); //================================================================== @@ -267,6 +257,27 @@ bool reaction = true); void bbSetStatus( IOStatus t) { bbmStatus = t; } //================================================================== + private: + friend class Connection; + friend class ComplexBlackBox; + + /// Sets the parent of the BlackBox + void bbSetParent(BlackBox::Pointer p) { bbmParent = p; } + + + /// Connects the input to the connection c + virtual void bbConnectInput( const std::string& name, + Connection* c); + /// Connects the output to the connection c + virtual void bbConnectOutput( const std::string& name, + Connection* c); + /// Disconnects the input from the connection c + virtual void bbDisconnectInput( const std::string& name, + Connection* c); + /// Disconnects the output from the connection c + virtual void bbDisconnectOutput( const std::string& name, + Connection* c); + /// @name Pipeline processing methods @@ -286,13 +297,13 @@ bool reaction = true); /// /// First checks that re-processing is needed (either Status==MODIFIED or InputProcessMode==Always) /// then : - /// - updates its inputs by calling bbUpdateInputs (which recursively calls bbBackwardUpdate on amont boxes) + /// - updates its inputs by calling bbUpdateInputs (which recursively calls bbBackwardUpdate on upstream boxes) /// - calls bbCreateWidget /// - calls bbProcess which is the user callback which does the actual processing /// - calls bbUpdateChildren /// - calls bbShowWidget which shows the widget associated to the box (if any) - public: - virtual IOStatus bbBackwardUpdate(Connection* caller) = 0; + protected: + virtual IOStatus bbBackwardUpdate(Connection::Pointer caller) = 0; //================================================================== //================================================================== @@ -306,20 +317,20 @@ bool reaction = true); /// - calls bbCreateWidget /// - calls bbProcess which is the user callback which does the actual processing /// - calls bbUpdateChildren which recursively calls bbForwardUpdate on connections attached the "Child" output - // virtual void bbForwardUpdate(Connection* caller) = 0; + // virtual void bbForwardUpdate(Connection::Pointer caller) = 0; //================================================================== protected: //================================================================== /// Updates the BlackBox inputs and returns the final status of the inputs /// (==UPTODATE iff all inputs are UPTODATE) - // If excludeParent == true then excludes the amont box connected to input 'Parent' from recursive update + // If excludeParent == true then excludes the upstream box connected to input 'Parent' from recursive update IOStatus bbUpdateInputs(bool excludeParent=false); //================================================================== //================================================================== - /// Updates the pipeline in amont-aval direction along the "Child"-"Parent" connections only. + /// Updates the pipeline in upstream-downstream direction along the "Child"-"Parent" connections only. /// Does nothing here. Overloaded in WxContainerBlackbox - //virtual void bbUpdateChildren( Connection* caller ) { } + //virtual void bbUpdateChildren( Connection::Pointer caller ) { } //================================================================== //================================================================== @@ -330,33 +341,27 @@ bool reaction = true); /// Shows the window associated to the box /// (called after bbProcess during bbExecute) /// Does nothing here but overloaded in WxBlackBox and WxContainerBlackBox - virtual void bbShowWindow(Connection* caller) { } - + virtual void bbShowWindow(Connection::Pointer caller) { } + virtual void bbHideWindow() {} + virtual void bbCloseWindow() { } //================================================================== //@} public: - static bool bbGlobalGetSomeBoxExecuting() - { return bbmgSomeBoxExecuting; } - static void bbGlobalSetSomeBoxExecuting(bool b) - { bbmgSomeBoxExecuting = b; } + static bool bbGlobalGetSomeBoxExecuting(); + static void bbGlobalSetSomeBoxExecuting(bool b); - - static void bbGlobalSetFreezeExecution(bool b) { bbmgFreezeExecution = b;} - static bool bbGlobalGetFreezeExecution() { return bbmgFreezeExecution; } + static void bbGlobalSetFreezeExecution(bool b); + static bool bbGlobalGetFreezeExecution(); /// Returns true if the box can "react", /// which means execute in response to an input change virtual bool bbCanReact() const; - - static void bbGlobalAddToExecutionList( BlackBox* b ) - { - bbmgExecutionList.insert(b); -} - + protected: + static void bbGlobalAddToExecutionList( BlackBox::Pointer b ); static void bbGlobalProcessExecutionList(); //================================================================== @@ -370,13 +375,31 @@ bool reaction = true); virtual void bbCopyIOValues(BlackBox& from); //================================================================== + // Black box objects have a special deleter + // which must take care of releasing the descriptor + // **AFTER** the box is deleted + // (Releasing it in the destructor may cause dl close and crash) + /// Black box deleter + /// 1) Calls the user overloadable bbDelete method + /// 2) Releases the box descriptor + struct BBTK_EXPORT Deleter : public Object::Deleter + { + Deleter(); + void Delete(Object* p); + }; + + template + static boost::shared_ptr MakeBlackBoxPointer(U* s, bool lock = false) + { + return MakePointer(s,BlackBox::Deleter(),lock); + } + + virtual void bbDelete() { delete this; } private: //================================================================== // PRIVATE PART - /// Default constructor is private : derived classes must use the constructor with the BlackBox's name - BlackBox() {} /// The status of the box IOStatus bbmStatus; /// The name of the black-box @@ -384,15 +407,16 @@ bool reaction = true); /// The name of the package to which it belongs std::string bbmPackageName; - /// 0 : "Pipeline" mode : bbUpdate() only calls Process if Status == MODIFIED (normal pipeline processing) + /// 0 : "Pipeline" mode : bbBackwardUpdate() only calls Process if Status == MODIFIED (normal pipeline processing) /// 1 : "Always" mode : bbUpdate() always calls Process /// 2 : "Reactive" mode : bbSetModifiedStatus() calls bbUpdate() std::string bbmBoxProcessMode; /// The parent of the black box in the ComplexBlackBox hierarchy - BlackBox::Pointer bbmParent; + BlackBox::WeakPointer bbmParent; //================================================================== + //================================================================== // ATTRIBUTES /// Map that contains the output connectors of the black box @@ -401,12 +425,7 @@ bool reaction = true); InputConnectorMapType mInputConnectorMap; //================================================================== - - static bool bbmgSomeBoxExecuting; - static bool bbmgFreezeExecution; - - static std::set bbmgExecutionList; }; // Class BlackBox