ExecutableAgent.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef EXECUTABLE_AGENT_H
00011 #define EXECUTABLE_AGENT_H
00012 
00013 #include <string>
00014 
00015 class PlugIn;
00016 class PlugInArgList;
00017 class Progress;
00018 
00019 /**
00020  *  This is a helper class that makes working with Executable
00021  *  plug-ins easier.  This class will manage the lifecycle of
00022  *  the Executable plug-in.  When this object is destroyed, the
00023  *  plug-in will be destroyed if it is set to be
00024  *  destroyed after execution and it is not a background plug-in.
00025  *  You should not create an instance of this class using
00026  *  ObjectFactory, but you should use ExecutableResource.
00027  *
00028  *  @warning If you do not call an overload of instantiate() before
00029  *  calling any other methods, a std::logic_error will be thrown.
00030  *  You cannot call instantiate() twice on the same instance
00031  *  or a std::logic_error will be thrown.
00032  *
00033  *  @see         ExecutableResource, Executable
00034  */
00035 class ExecutableAgent
00036 {
00037 public:
00038    /**
00039     *  Creates an invalid object for delayed initialization of a ExecutableAgent.
00040     *
00041     *  Creates an invalid object where no plug-in is
00042     *  initially created.  The Executable can then be initialized later by calling
00043     *  setPlugIn().
00044     *
00045     *  @param   pProgress
00046     *           The progress object to pass into the plug-in.  If \b NULL is
00047     *           passed in, a progress object is obtained by calling
00048     *           PlugInManagerServices::getProgress().
00049     *  @param   batch
00050     *           Set this value to \b true to execute the plug-in in batch mode
00051     *           or to \b false to execute the plug-in in interactive mode.
00052     *           Background plug-ins executed in interactive mode are
00053     *           automatically added to the Background Plug-In %Window.
00054     *  @throw   std::logic_error
00055     *           Thrown if the instantiate() method is called more than
00056     *           once on a instance.
00057     */
00058    virtual void instantiate(Progress* pProgress, bool batch) = 0;
00059 
00060    /**
00061     *  Creates a Executable to execute.
00062     *
00063     *  @param   plugInName
00064     *           The name of the Executable to create and execute.
00065     *  @param   menuCommand
00066     *           The menu command name from which the plug-in is executed.  The
00067     *           menu command name is set into an arg with "Menu Command" as its
00068     *           name and "string" as its type.  If this arg does not exist in
00069     *           the arg list of the given plug-in, this parameter is ignored.
00070     *           If an empty string is passed in, no arg value is set.
00071     *  @param   pProgress
00072     *           The progress object to pass into the plug-in.  If \b NULL is
00073     *           passed in, a progress object is obtained by calling
00074     *           PlugInManagerServices::getProgress().
00075     *  @param   batch
00076     *           Set this value to \b true to execute the plug-in in batch mode
00077     *           or to \b false to execute the plug-in in interactive mode.
00078     *           Background plug-ins executed in interactive mode are
00079     *           automatically added to the Background Plug-In %Window.
00080     *  @throw   std::logic_error
00081     *           Thrown if the instantiate() method is called more than
00082     *           once on a instance.
00083     */
00084    virtual void instantiate(const std::string& plugInName, const std::string& menuCommand,
00085       Progress* pProgress, bool batch) = 0;
00086 
00087    /**
00088     *  Uses an Executable to execute.
00089     *
00090     *  @param   pPlugIn
00091     *           The plug-in to execute.  The agent assumes ownership of the
00092     *           given plug-in and will destroy it as necessary upon 
00093     *           destruction.
00094     *  @param   menuCommand
00095     *           The menu command name from which the plug-in is executed.  The
00096     *           menu command name is set into an arg with "Menu Command" as its
00097     *           name and "string" as its type.  If this arg does not exist in
00098     *           the arg list of the given plug-in, this parameter is ignored.
00099     *           If an empty string is passed in, no arg value is set.
00100     *  @param   pProgress
00101     *           The progress object to pass into the plug-in.  If \b NULL is
00102     *           passed in, a progress object is obtained by calling
00103     *           PlugInManagerServices::getProgress().
00104     *  @param   batch
00105     *           Set this value to \b true to execute the plug-in in batch mode
00106     *           or to \b false to execute the plug-in in interactive mode.
00107     *           Background plug-ins executed in interactive mode are
00108     *           automatically added to the Background Plug-In %Window.
00109     *  @throw   std::logic_error
00110     *           Thrown if the instantiate() method is called more than
00111     *           once on a instance.
00112     */
00113    virtual void instantiate(PlugIn* pPlugIn, const std::string& menuCommand,
00114       Progress* pProgress, bool batch) = 0;
00115 
00116 
00117    /**
00118     *  Sets the plug-in to execute.
00119     *
00120     *  @param   plugInName
00121     *           The name of the plug-in to execute.  If an empty string is
00122     *           passed in, the current plug-in is destroyed and no new plug-in
00123     *           is set, thereby creating an invalid object.
00124     *  @throw   std::logic_error
00125     *           Thrown if the instantiate() method has not yet
00126     *           been called on this instance.
00127     *
00128     *  @see     setPlugIn(PlugIn*)
00129     */
00130    virtual void setPlugIn(const std::string& plugInName) = 0;
00131 
00132    /**
00133     *  Sets the plug-in to execute.
00134     *
00135     *  @param   pPlugIn
00136     *           The plug-in to execute.  The agent assumes ownership of the
00137     *           given plug-in and will destroy it as necessary upon 
00138     *           destruction.  If \b NULL is passed in, the current plug-in is
00139     *           destroyed and no new plug-in is set, thereby creating an
00140     *           invalid object.
00141     *  @throw   std::logic_error
00142     *           Thrown if the instantiate() method has not yet
00143     *           been called on this instance.
00144     *
00145     *  @see     setPlugIn(const std::string&)
00146     */
00147    virtual void setPlugIn(PlugIn* pPlugIn) = 0;
00148 
00149    /**
00150     *  Creates a progress dialog when the agent is executed.
00151     *
00152     *  By default, if this method is not called, a progress dialog is not
00153     *  created.
00154     *
00155     *  This method does nothing if ApplicationServices::isInteractive() returns
00156     *  \c false.
00157     *
00158     *  @param   bCreate
00159     *           Set this parameter to \c true to create a progress dialog when
00160     *           the agent is executed.  A new progress dialog will then be
00161     *           created for each call to ExecutableAgent::execute() for this
00162     *           instance.
00163     *
00164     *  @throw   std::logic_error
00165     *           Thrown if ExecutableAgent::instantiate() method has not yet been
00166     *           called.
00167     *
00168     *  @see     ExecutableAgent::instantiate()
00169     */
00170    virtual void createProgressDialog(bool bCreate) = 0;
00171 
00172    /**
00173     *  Queries whether a progress dialog is created when the agent is executed.
00174     *
00175     *  @throw   std::logic_error
00176     *           Thrown if ExecutableAgent::instantiate() method has not yet been
00177     *           called.
00178     *
00179     *  @return  Returns \c true if a progress dialog is created when the agent
00180     *           is executed or \c false if the dialog is not created.  This
00181     *           method also returns \c false if createProgressDialog() has
00182     *           not been called or if ApplicationServices::isInteractive()
00183     *           returns \c false.
00184     */
00185    virtual bool isProgressDialogCreated() const = 0;
00186 
00187    /**
00188     *  Sets whether the input argument list will be automatically or manually
00189     *  populated.
00190     *
00191     *  If the input argument list is already populated, calling this function
00192     *  will not clear the list.
00193     *
00194     *  The Progress argument is always auto-populated with the current Progress
00195     *  object. This can be overridden by explicitly setting the Progress argument
00196     *  to \c NULL.
00197     *
00198     *  If this function is not called, the input argument list will be
00199     *  automatically populated.
00200     *
00201     *  @param   bAutoArg
00202     *           Set this parameter to \c true to automatically populate an
00203     *           input argument list or set it to \c false to populate the input
00204     *           argument list manually.
00205     */
00206    virtual void setAutoArg(bool bAutoArg) = 0;
00207 
00208    /**
00209     *  Gets whether the input argument list will be automatically or manually
00210     *  populated.
00211     *
00212     *  @return  Returns \c true if the input argument list is automatically
00213     *           populated or \c false if the input argument list is populated
00214     *           manually.
00215     */
00216    virtual bool getAutoArg() const = 0;
00217 
00218    /**
00219     *  Returns the progress object used by the plug-in.
00220     *
00221     *  @throw   std::logic_error
00222     *           Thrown if the instantiate() method has not yet
00223     *           been called on this instance.
00224     *
00225     *  @return  The progress object used by the plug-in.  This is either the
00226     *           progress object passed in upon instantiation of the agent or
00227     *           the progress object obtained by calling
00228     *           PlugInManagerServices::getProgress().
00229     */
00230    virtual Progress* getProgress() const = 0;
00231 
00232    /**
00233     *  Executes the underlying plug-in.
00234     *
00235     *  This method first creates the input and output arg lists if necessary,
00236     *  populates the input arg list, and then executes the plug-in.  If a
00237     *  background plug-in was executed successfully, an item is automatically
00238     *  added to the Background Plug-In %Window.
00239     *
00240     *  @par Arg Values:
00241     *  The following input arg values are automatically populated unless the
00242     *  actual value in the arg has already been set and
00243     *  PlugInArg::isActualSet() returns \c true:
00244     *  - Executable::WindowArg() is populated with the current workspace window
00245     *    as returned by DesktopServices::getCurrentWorkspaceWindow().
00246     *  - Executable::ViewArg() is populated with the view contained in the
00247     *    current workspace window as returned by WorkspaceWindow::getView().
00248     *    If this view is not a kind of View as the arg type, the arg is
00249     *    populated with the active view contained in the current workspace
00250     *    window as returned by WorkspaceWindow::getActiveView().
00251     *  - Executable::LayerArg() is populated with the active layer in the view
00252     *    of the current workspace window as returned by
00253     *    SpatialDataView::getActiveLayer() or ProductView::getActiveLayer().
00254     *  - Executable::DataElementArg() is populated with the first DataElement
00255     *    found in the following search order:
00256     *      -# The element displayed by the primary raster layer in the view of
00257     *         the current workspace window as returned by
00258     *         LayerList::getPrimaryRasterElement().
00259     *      -# The element displayed by the active layer in the view of the
00260     *         current workspace window as returned by Layer::getDataElement().
00261     *      -# The first child element of the primary raster layer element in
00262     *         the view of the current workspace window.
00263     *
00264     *  @par
00265     *  If more than one of the args listed above exist and the actual value is
00266     *  set in the input arg list, one arg value will be used to get the value
00267     *  for another arg where appropriate instead of getting the value according
00268     *  to the above descriptions.
00269     *
00270     *  @throw   std::logic_error
00271     *           Thrown if the instantiate() method has not yet been called on
00272     *           this instance.
00273     *
00274     *  @return  The success value returned by Executable::execute().  If the
00275     *           plug-in does not support the batch/interactive mode requested
00276     *           \c false will be returned and the plug-in will not be executed.
00277     */
00278    virtual bool execute() = 0;
00279 
00280    /**
00281     *  Aborts the underlying plug-in.
00282     *
00283     *  @throw   std::logic_error
00284     *           Thrown if the instantiate() method has not yet
00285     *           been called on this instance.
00286     *
00287     *  @return  The success value returned by the plug-in's abort function.
00288     */
00289    virtual bool abort() = 0;
00290 
00291    /**
00292     *  Runs the tests specified in the Testable interface of the plug-in.
00293     *
00294     *  @param   pProgress
00295     *           The progress object to pass through the Testable interface.
00296     *  @param   output
00297     *           The output stream for the plug-in's test suite to use for
00298     *           reporting errors.
00299     *  @throw   std::logic_error
00300     *           Thrown if the instantiate() method has not yet
00301     *           been called on this instance.
00302     *
00303     *  @return  The success value returned by Testable::runAllTests().  If
00304     *           the plug-in does not have a Testable interface, \b false is
00305     *           returned.
00306     */
00307    virtual bool runAllTests(Progress *pProgress, std::ostream &output) = 0;
00308 
00309    /**
00310     *  Access the input argument list.
00311     *
00312     *  This will ensure that the returned arg list has been built and has
00313     *  default values set.  It may or may not have actual values set, depending
00314     *  on when this function is called.
00315     *
00316     *  @warning The agent does not override actual values set into the input
00317     *           args.  Therefore, setting actual arg values on the returned
00318     *           PlugInArgList for objects that are explicitly set in the agent
00319     *           will cause the agent's values to not be passed into the
00320     *           plug-in.
00321     *
00322     *  @throw   std::logic_error
00323     *           Thrown if the instantiate() method has not yet
00324     *           been called on this instance.
00325     *
00326     *  @return A reference to the input argument list.
00327     */
00328    virtual PlugInArgList &getInArgList() const = 0;
00329 
00330    /**
00331     *  Access the output argument list.
00332     *
00333     *  This will ensure that the returned arg list has been built and has
00334     *  default values set.  It may or may not have actual values set, depending
00335     *  on when this function is called.
00336     *
00337     *  @throw   std::logic_error
00338     *           Thrown if the instantiate() method has not yet
00339     *           been called on this instance.
00340     *
00341     *  @return A reference to the input argument list.
00342     */
00343    virtual PlugInArgList &getOutArgList() const = 0;
00344 
00345    /**
00346     * Returns the plug-in instance being
00347     * executed.
00348     *
00349     * @throw   std::logic_error
00350     *          Thrown if the instantiate() method has not yet
00351     *          been called on this instance.
00352     *
00353     * @return plug-in instance or NULL if not available.
00354     */
00355    virtual const PlugIn* getPlugIn() const = 0;
00356 
00357    /**
00358     * Returns the plug-in instance being
00359     * executed.
00360     *
00361     * @throw   std::logic_error
00362     *          Thrown if the instantiate() method has not yet
00363     *          been called on this instance.
00364     *
00365     * @return plug-in instance or NULL if not available.
00366     */
00367    virtual PlugIn* getPlugIn() = 0;
00368 
00369    /**
00370     * Releases the plug-in instance being
00371     * executed.  The plug-in instance will
00372     * no longer be destroyed when this
00373     * ExecutableAgent is destroyed.
00374     *
00375     * @throw   std::logic_error
00376     *          Thrown if the instantiate() method has not yet
00377     *          been called on this instance.
00378     *
00379     * @return  plug-in instance or NULL if not available.
00380     */
00381    virtual PlugIn* releasePlugIn() = 0;
00382 
00383 protected:
00384    /**
00385     * This should be destroyed by calling ObjectFactory::destroyObject.
00386     */
00387    virtual ~ExecutableAgent() {}
00388 };
00389 
00390 #endif

Software Development Kit - Opticks 4.9.0 Build 16218