Scopira 20080306

sidekick.h

00001 
00002 /*
00003  *  Copyright (c) 2005    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_CORE_SIDEKICK_H__
00015 #define __INCLUDED_SCOPIRA_CORE_SIDEKICK_H__
00016 
00017 #include <scopira/tool/export.h>
00018 #include <scopira/tool/thread.h>
00019 #include <scopira/tool/object.h>
00020 
00021 namespace scopira
00022 {
00023   namespace core
00024   {
00025     class sidekick_i;
00026     class sidekick_reactor_i;
00027     
00028     class sidekick_queue_i;
00029 
00039     SCOPIRA_EXPORT void enqueue_sidekick(sidekick_i *t, sidekick_reactor_i *reac = 0);
00040 
00049     SCOPIRA_EXPORT bool is_sidekick_running(void);
00050   }
00051 }
00052 
00061 class scopira::core::sidekick_i : public virtual scopira::tool::object,
00062                              public virtual scopira::tool::runnable_i
00063 {
00064   public:
00065   protected:
00067     sidekick_i(void) : dm_treact(0) { }
00068 
00074     SCOPIRA_EXPORT void notify_reactors(void);
00075 
00077     //virtual void run(void);
00078 
00079   protected:
00080     // in the future, make a class sidekick_msg_window that allows
00081     // a window to be open the whole time during the run.
00082     // ... allow output too?
00083     // ... allow cancelability?
00084     // bah, make them use core?
00085 
00086   private:
00087     sidekick_reactor_i *dm_treact;
00088 
00089     friend class scopira::core::sidekick_queue_i;
00090     friend void scopira::core::enqueue_sidekick(sidekick_i *, sidekick_reactor_i *);
00091 };
00092 
00098 class scopira::core::sidekick_reactor_i
00099 {
00100   public:
00101     virtual ~sidekick_reactor_i() { }
00110     SCOPIRA_EXPORT virtual void react_sidekick_notify(sidekick_i *t) = 0;
00119     SCOPIRA_EXPORT virtual void react_sidekick_done(sidekick_i *t) = 0;
00120 };
00121 
00127 class scopira::core::sidekick_queue_i : public virtual scopira::tool::object
00128 {
00129   protected:
00131     SCOPIRA_EXPORT sidekick_queue_i(void);
00133     SCOPIRA_EXPORT virtual ~sidekick_queue_i();
00134 
00136     SCOPIRA_EXPORT virtual void enqueue_sidekick(sidekick_i *t) = 0;
00138     SCOPIRA_EXPORT virtual bool is_sidekick_running(void) = 0;
00139 
00141     sidekick_reactor_i * & get_reactor(sidekick_i &sk) { return sk.dm_treact; }
00142 
00143   protected:
00145     SCOPIRA_EXPORT static sidekick_queue_i *dm_instance;
00146 
00147     friend void scopira::core::enqueue_sidekick(sidekick_i *, sidekick_reactor_i *);
00148     friend bool scopira::core::is_sidekick_running(void);
00149 };
00150 
00151 // impls are in sidekickthread
00152 
00319 #endif
00320