PLearn 0.1
Public Member Functions | Static Protected Attributes
PLearn::AutoRunCommand Class Reference

#include <AutoRunCommand.h>

Inheritance diagram for PLearn::AutoRunCommand:
Inheritance graph
[legend]
Collaboration diagram for PLearn::AutoRunCommand:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 AutoRunCommand ()
virtual void run (const vector< string > &args)
 The actual implementation of the 'AutoRunCommand' command.

Static Protected Attributes

static PLearnCommandRegistry reg_
 This allows to register the 'AutoRunCommand' command in the command registry.

Detailed Description

Definition at line 50 of file AutoRunCommand.h.


Constructor & Destructor Documentation

PLearn::AutoRunCommand::AutoRunCommand ( ) [inline]

Definition at line 53 of file AutoRunCommand.h.

                    :
        PLearnCommand("autorun",

                      "watches files for changes and reruns the .plearn script",

                      "watch <script.plearn> [other files to watch]\n"
                      "Will run the .plearn script once and watches its and other files for changes.\n"
                      "Will rerun the script automatically each time its date changes \n"
                      "or the date of one of the watched files changes. \n"
            ) 
    {}

Member Function Documentation

void PLearn::AutoRunCommand::run ( const vector< string > &  args) [virtual]

The actual implementation of the 'AutoRunCommand' command.

Implements PLearn::PLearnCommand.

Definition at line 60 of file AutoRunCommand.cc.

References PLearn::endl(), PLearn::PLearnError::message(), PLearn::mtime(), PLearn::RunCommand::run(), and PLearn::times().

{
    string scriptname = args[0];
    int nargs = int(args.size());

    vector<string> runargs(1);
    runargs[0] = scriptname;

    TVec<time_t> times(nargs);

    for(;;)
    {
        try 
        {
            RunCommand rc;
            cerr << ">>> Running script " << scriptname << endl; 
            rc.run(runargs);
        }
        catch(const PLearnError& e)
        {
            cerr << "FATAL ERROR running script " << scriptname << "\n"
                 << e.message() << endl;
        }
      
        sleep(1);

        // Store times
        for(int k=0; k<nargs; k++)
            times[k] = mtime(args[k]);

        bool up_to_date = true;
        while(up_to_date)
        {
            sleep(1);
            for(int k=0; k<nargs; k++)
                if(times[k] < mtime(args[k]))
                {
                    cerr << " File " << args[k] << " has changed." << endl;
                    up_to_date = false;
                }
        }
    }

}

Here is the call graph for this function:


Member Data Documentation

This allows to register the 'AutoRunCommand' command in the command registry.

Definition at line 68 of file AutoRunCommand.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines