AsynchronCreator.hpp

00001 #ifndef __FISH_BONE_ASYNCHRON_CREATOR_HPP
00002 #define __FISH_BONE_ASYNCHRON_CREATOR_HPP
00003 
00004 #include "fishboneDllApi.h"
00005 
00006 #include <ocean/plankton/VCreator.hpp>
00007 #include <ocean/plankton/VTime.hpp>
00008 #include <ocean/plankton/VThread.hpp>
00009 #include <ocean/plankton/VCotask.hpp>
00010 #include <bundle/Bundle.hpp>
00011 
00012 namespace Wizt
00013 {
00014 //using namespace Fiber;
00015 
00016 
00073 class   fishbone_API AsynchronCreator : public Fiber::CreativeArrayBase
00074 {
00075         RefPtr<Fiber::MemBase>  result;
00076 
00077 public: 
00078         typedef Fiber::CreativeArrayBase CreativeArrayBase; 
00079         typedef Fiber::MemBase           MemBase;
00080 
00081         RefPtr<VValueParameter<VThreadManager> >  ThreadManagerParam; 
00082 
00087         bool    do_async; 
00088 
00089         AsynchronCreator(RefPtr<VValueParameter<VThreadManager> >&TMPar, const RefPtr<Cache>&theCache = Cache::MemCache() );
00090 
00091         AsynchronCreator(VCotask*CoTask, const RefPtr<Cache>&theCache = Cache::MemCache() );
00092 
00093         ~AsynchronCreator();
00094 
00095         override bool release(); 
00096 
00097         virtual RefPtr<Fiber::MemBase> compute() = 0;
00098 
00099         struct  fishbone_API ComputationTask : VTask
00100         {
00101                 RefPtr<CreativeArrayBase>       Input;
00102                 WeakPtr<AsynchronCreator>       Output;
00103 
00104                 ComputationTask(const WeakPtr<VParameter>&Owner, 
00105                                 const RefPtr<AsynchronCreator>&AC);
00106 
00107                 ~ComputationTask(); 
00108 
00109                 override void run();
00110 
00111                 override void valueChanged(const RefPtr<VValueBase>&value,
00112                                            const ValueNotifierList*DoNotBroadcast,
00113                                            const ValueMap*VP=0);
00114         };
00115 
00116         RefPtr<ComputationTask> CT; 
00117 
00118         bool    isRunning() const; 
00119 
00120         override RefPtr<MemBase> create();
00121 
00122         override RefPtr<MemBase> get() const
00123         {
00124                 return result;
00125         }
00126 };
00127 
00128 template <class Type>
00129 class   fishbone_API TypedAsynchronCreator : public AsynchronCreator 
00130 {
00131 public:
00132         TypedAsynchronCreator( RefPtr<VValueParameter<VThreadManager> >&TMPar)
00133         : AsynchronCreator()
00134         {}
00135 
00136         const type_info&getType()
00137         {
00138                 return typeid(Type);
00139         }
00140 };
00141 
00142 } // namespace Wizt
00143 
00144 #endif // ASYNCHRON_CREATOR_HPP